Yet more documentation updates
[nonrtric.git] / test / common / ricsim_api_functions.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2020 Nordix Foundation. All rights reserved.
5 #  ========================================================================
6 #  Licensed under the Apache License, Version 2.0 (the "License");
7 #  you may not use this file except in compliance with the License.
8 #  You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #  Unless required by applicable law or agreed to in writing, software
13 #  distributed under the License is distributed on an "AS IS" BASIS,
14 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #  See the License for the specific language governing permissions and
16 #  limitations under the License.
17 #  ============LICENSE_END=================================================
18 #
19
20 # This is a script that contains container/service management functions and test functions for RICSIM A1 simulators
21
22 ################ Test engine functions ################
23
24 # Create the image var used during the test
25 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
26 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
27 __RICSIM_imagesetup() {
28         __check_and_create_image_var RICSIM "RIC_SIM_IMAGE" "RIC_SIM_IMAGE_BASE" "RIC_SIM_IMAGE_TAG" $1 "$RIC_SIM_DISPLAY_NAME"
29 }
30
31 # Pull image from remote repo or use locally built image
32 # arg: <pull-policy-override> <pull-policy-original>
33 # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
34 # <pull-policy-original> Shall be used for images that does not allow overriding
35 # Both var may contain: 'remote', 'remote-remove' or 'local'
36 __RICSIM_imagepull() {
37         __check_and_pull_image $1 "$RIC_SIM_DISPLAY_NAME" $RIC_SIM_PREFIX"_"$RIC_SIM_BASE RIC_SIM_IMAGE
38 }
39
40 # Generate a string for each included image using the app display name and a docker images format string
41 # If a custom image repo is used then also the source image from the local repo is listed
42 # arg: <docker-images-format-string> <file-to-append>
43 __RICSIM_image_data() {
44         echo -e "$RIC_SIM_DISPLAY_NAME\t$(docker images --format $1 $RIC_SIM_IMAGE)" >>   $2
45         if [ ! -z "$RIC_SIM_IMAGE_SOURCE" ]; then
46                 echo -e "-- source image --\t$(docker images --format $1 $RIC_SIM_IMAGE_SOURCE)" >>   $2
47         fi
48 }
49
50 # Scale kubernetes resources to zero
51 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
52 # This function is called for apps fully managed by the test script
53 __RICSIM_kube_scale_zero() {
54         __kube_scale_all_resources $KUBE_A1SIM_NAMESPACE autotest RICSIM
55 }
56
57 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
58 # This function is called for prestarted apps not managed by the test script.
59 __RICSIM_kube_scale_zero_and_wait() {
60         #__kube_scale_and_wait_all_resources $KUBE_A1SIM_NAMESPACE app $KUBE_A1SIM_NAMESPACE"-"$RIC_SIM_PREFIX
61         __kube_scale_and_wait_all_resources $KUBE_A1SIM_NAMESPACE app $KUBE_A1SIM_NAMESPACE"-a1simulator"
62 }
63
64 # Delete all kube resouces for the app
65 # This function is called for apps managed by the test script.
66 __RICSIM_kube_delete_all() {
67         __kube_delete_all_resources $KUBE_A1SIM_NAMESPACE autotest RICSIM
68 }
69
70 # Store docker logs
71 # This function is called for apps managed by the test script.
72 # args: <log-dir> <file-prexix>
73 __RICSIM_store_docker_logs() {
74         if [ $RUNMODE == "KUBE" ]; then
75                 for podname in $(kubectl get pods -n $KUBE_A1SIM_NAMESPACE -l "autotest=RICSIM" -o custom-columns=":metadata.name"); do
76                         kubectl logs -n $KUBE_A1SIM_NAMESPACE $podname --tail=-1 > $1$2_$podname.log 2>&1
77                 done
78         else
79
80                 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}})
81                 for ric in $rics; do
82                         docker logs $ric > $1$2_$ric.log 2>&1
83                 done
84         fi
85 }
86
87 # Initial setup of protocol, host and ports
88 # This function is called for apps managed by the test script.
89 # args: -
90 __RICSIM_initial_setup() {
91         use_simulator_http
92 }
93
94 # Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
95 # For docker, the namespace shall be excluded
96 # This function is called for apps managed by the test script as well as for prestarted apps.
97 # args: -
98 __RICSIM_statisics_setup() {
99         for ((RICSIM_INSTANCE=10; RICSIM_INSTANCE>0; RICSIM_INSTANCE-- )); do
100                 if [ $RUNMODE == "KUBE" ]; then
101                         RICSIM_INSTANCE_KUBE=$(($RICSIM_INSTANCE-1))
102                         echo -n " RICSIM_G1_$RICSIM_INSTANCE_KUBE ${RIC_SIM_PREFIX}-g1-$RICSIM_INSTANCE_KUBE $KUBE_A1SIM_NAMESPACE "
103                         echo -n " RICSIM_G2_$RICSIM_INSTANCE_KUBE ${RIC_SIM_PREFIX}-g2-$RICSIM_INSTANCE_KUBE $KUBE_A1SIM_NAMESPACE "
104                         echo -n " RICSIM_G3_$RICSIM_INSTANCE_KUBE ${RIC_SIM_PREFIX}-g3-$RICSIM_INSTANCE_KUBE $KUBE_A1SIM_NAMESPACE "
105                 else
106                         if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
107                                 echo -n " RICSIM_G1_$RICSIM_INSTANCE ${RIC_SIM_PREFIX}_g1_$RICSIM_INSTANCE "
108                                 echo -n " RICSIM_G2_$RICSIM_INSTANCE ${RIC_SIM_PREFIX}_g2_$RICSIM_INSTANCE "
109                                 echo -n " RICSIM_G3_$RICSIM_INSTANCE ${RIC_SIM_PREFIX}_g3_$RICSIM_INSTANCE "
110                         else
111                                 echo -n " RICSIM_G1_$RICSIM_INSTANCE ${RIC_SIM_PREFIX}-g1-$RICSIM_INSTANCE "
112                                 echo -n " RICSIM_G2_$RICSIM_INSTANCE ${RIC_SIM_PREFIX}-g2-$RICSIM_INSTANCE "
113                                 echo -n " RICSIM_G3_$RICSIM_INSTANCE ${RIC_SIM_PREFIX}-g3-$RICSIM_INSTANCE "
114                         fi
115                 fi
116         done
117 }
118
119 #######################################################
120
121
122 RIC_SIM_HTTPX="http"
123 RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
124
125
126 #Vars for container count
127 G1_COUNT=0
128 G2_COUNT=0
129 G3_COUNT=0
130 G4_COUNT=0
131 G5_COUNT=0
132
133
134 ###########################
135 ### RIC Simulator functions
136 ###########################
137
138 use_simulator_http() {
139         echo -e $BOLD"RICSIM protocol setting"$EBOLD
140         echo -e " Using $BOLD http $EBOLD towards the simulators"
141         RIC_SIM_HTTPX="http"
142         RIC_SIM_PORT=$RIC_SIM_INTERNAL_PORT
143         echo ""
144 }
145
146 use_simulator_https() {
147         echo -e $BOLD"RICSIM protocol setting"$EBOLD
148         echo -e " Using $BOLD https $EBOLD towards the simulators"
149         RIC_SIM_HTTPX="https"
150         RIC_SIM_PORT=$RIC_SIM_INTERNAL_SECURE_PORT
151         echo ""
152 }
153
154 # Start one group (ricsim_g1, ricsim_g2 .. ricsim_g5) with a number of RIC Simulators using a given A interface
155 # 'ricsim' may be set on command line to other prefix
156 # args:  ricsim_g1|ricsim_g2|ricsim_g3|ricsim_g4|ricsim_g5 <count> <interface-id>
157 # (Function for test scripts)
158 start_ric_simulators() {
159
160         echo -e $BOLD"Starting $RIC_SIM_DISPLAY_NAME"$EBOLD
161
162         if [ $RUNMODE == "KUBE" ]; then
163
164                 # Check if app shall be fully managed by the test script
165                 __check_included_image "RICSIM"
166                 retcode_i=$?
167
168                 # Check if app shall only be used by the testscipt
169                 __check_prestarted_image "RICSIM"
170                 retcode_p=$?
171
172                 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
173                         echo -e $RED"The $1 app is not included as managed nor prestarted in this test script"$ERED
174                         echo -e $RED"The $1 will not be started"$ERED
175                         exit
176                 fi
177                 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
178                         echo -e $RED"The $1 stub app is included both as managed and prestarted in this test script"$ERED
179                         echo -e $RED"The $1 will not be started"$ERED
180                         exit
181                 fi
182
183                 if [ $retcode_p -eq 0 ]; then
184                         echo -e " Using existing $1 statefulset and service"
185                         echo " Using existing simulator deployment and service for statefulset $1"
186                         echo " Setting $1 replicas=$2"
187                         __kube_scale statefulset $1 $KUBE_A1SIM_NAMESPACE $2
188                         echo ""
189                         return
190                 fi
191         fi
192
193         RIC1=$RIC_SIM_PREFIX"_g1"
194         RIC2=$RIC_SIM_PREFIX"_g2"
195         RIC3=$RIC_SIM_PREFIX"_g3"
196         RIC4=$RIC_SIM_PREFIX"_g4"
197         RIC5=$RIC_SIM_PREFIX"_g5"
198
199         if [ $# != 3 ]; then
200                 ((RES_CONF_FAIL++))
201                 __print_err "need three args,  $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
202                 exit 1
203         fi
204
205         echo " $2 simulators using basename: $1 on interface: $3"
206         #Set env var for simulator count and A1 interface vesion for the given group
207         if [ $1 == "$RIC1" ]; then
208                 G1_COUNT=$2
209         elif [ $1 == "$RIC2" ]; then
210                 G2_COUNT=$2
211         elif [ $1 == "$RIC3" ]; then
212                 G3_COUNT=$2
213         elif [ $1 == "$RIC4" ]; then
214                 G4_COUNT=$2
215         elif [ $1 == "$RIC5" ]; then
216                 G5_COUNT=$2
217         else
218                 ((RES_CONF_FAIL++))
219                 __print_err "need three args, $RIC1|$RIC2|$RIC3|$RIC4|$RIC5 <count> <interface-id>" $@
220                 exit 1
221         fi
222
223         if [ $RUNMODE == "KUBE" ]; then
224
225                 if [ $retcode_i -eq 0 ]; then
226
227                         #export needed env var for statefulset
228                         export RIC_SIM_SET_NAME=$(echo "$1" | tr '_' '-')  #kube does not accept underscore in names
229                         export KUBE_A1SIM_NAMESPACE
230                         export RIC_SIM_IMAGE
231                         #Adding 1 more instance, instance 0 is never used. This is done to keep test scripts compatible
232                         # with docker that starts instance index on 1.....
233                         export RIC_SIM_COUNT=$(($2+1))
234                         export A1_VERSION=$3
235                         export RIC_SIM_INTERNAL_PORT
236                         export RIC_SIM_INTERNAL_SECURE_PORT
237
238                         echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
239
240                         #Check if nonrtric namespace exists, if not create it
241                         __kube_create_namespace $KUBE_A1SIM_NAMESPACE
242
243                         # Create service
244                         input_yaml=$SIM_GROUP"/"$RIC_SIM_COMPOSE_DIR"/"svc.yaml
245                         output_yaml=$PWD/tmp/ric_${1}_svc.yaml
246                         __kube_create_instance service $RIC_SIM_SET_NAME $input_yaml $output_yaml
247
248                         # Create app
249                         input_yaml=$SIM_GROUP"/"$RIC_SIM_COMPOSE_DIR"/"app.yaml
250                         output_yaml=$PWD/tmp/pa_${1}_app.yaml
251                         __kube_create_instance app $RIC_SIM_SET_NAME $input_yaml $output_yaml
252
253                         #Using only instance from index 1 to keep compatability with docker
254                         for (( count=1; count<${RIC_SIM_COUNT}; count++ )); do
255                                 host=$(__find_sim_host $RIC_SIM_SET_NAME"-"$count)
256                                 __check_service_start $RIC_SIM_SET_NAME"-"$count $host"/"
257                         done
258                 fi
259         else
260
261                 __check_included_image 'RICSIM'
262                 if [ $? -eq 1 ]; then
263                         echo -e $RED"The Near-RT RIC Simulator app is not included as managed in this test script"$ERED
264                         echo -e $RED"Near-RT RIC Simulator will not be started"$ERED
265                         exit 1
266                 fi
267
268                 # Create .env file to compose project, all ric container will get this prefix
269                 echo "COMPOSE_PROJECT_NAME="$RIC_SIM_PREFIX > $SIM_GROUP/$RIC_SIM_COMPOSE_DIR/.env
270
271                 #extract service name (group), g1, g2, g3, g4 or g5 from var $1
272                 #E.g. ricsim_g1 -> g1 is the service name
273                 TMP_GRP=$1
274                 RICSIM_COMPOSE_SERVICE_NAME=$(echo "${TMP_GRP##*_}")
275
276                 export RICSIM_COMPOSE_A1_VERSION=$3
277                 export RICSIM_COMPOSE_SERVICE_NAME
278                 export RIC_SIM_INTERNAL_PORT
279                 export RIC_SIM_INTERNAL_SECURE_PORT
280                 export RIC_SIM_CERT_MOUNT_DIR
281                 export DOCKER_SIM_NWNAME
282                 export RIC_SIM_DISPLAY_NAME
283
284                 docker_args="--no-recreate --scale $RICSIM_COMPOSE_SERVICE_NAME=$2"
285
286                 #Create a list of contsiner names
287                 #Will be <ricsim-prefix>_<service-name>_<index>
288                 # or
289                 # <ricsim-prefix>-<service-name>-<index>
290                 app_data=""
291                 cntr=1
292                 if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
293                         app_name_prefix=$RIC_SIM_PREFIX"_"$RICSIM_COMPOSE_SERVICE_NAME"_"
294                 else
295                         app_name_prefix=$RIC_SIM_PREFIX"-"$RICSIM_COMPOSE_SERVICE_NAME"-"
296                 fi
297                 while [ $cntr -le $2 ]; do
298                         app=$app_name_prefix$cntr
299                         app_data="$app_data $app"
300                         let cntr=cntr+1
301                 done
302
303                 __start_container $RIC_SIM_COMPOSE_DIR "" "$docker_args" $2 $app_data
304
305                 cntr=1
306                 while [ $cntr -le $2 ]; do
307                         if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
308                                 app=$RIC_SIM_PREFIX"_"$RICSIM_COMPOSE_SERVICE_NAME"_"$cntr
309                         else
310                                 app=$RIC_SIM_PREFIX"-"$RICSIM_COMPOSE_SERVICE_NAME"-"$cntr
311                         fi
312                         __check_service_start $app $RIC_SIM_HTTPX"://"$app:$RIC_SIM_PORT$RIC_SIM_ALIVE_URL
313                         let cntr=cntr+1
314                 done
315
316         fi
317         echo ""
318         return 0
319 }
320
321 # Translate ric name to kube host name
322 # args: <ric-name>
323 # For test scripts
324 get_kube_sim_host() {
325         name=$(echo "$1" | tr '_' '-')  #kube does not accept underscore in names
326         #example gnb_1_2 -> gnb-1-2
327         set_name=$(echo $name | rev | cut -d- -f2- | rev) # Cut index part of ric name to get the name of statefulset
328         # example gnb-g1-2 -> gnb-g1 where gnb-g1-2 is the ric name and gnb-g1 is the set name
329         echo $name"."$set_name"."$KUBE_A1SIM_NAMESPACE
330 }
331
332 # Helper function to get a the port and host name of a specific ric simulator
333 # args: <ric-id>
334 # (Not for test scripts)
335 __find_sim_host() {
336         if [ $RUNMODE == "KUBE" ]; then
337                 ricname=$(echo "$1" | tr '_' '-') # Kube does not accept underscore in names as docker do
338                 if [ -z "$RIC_SIM_COMMON_SVC_NAME" ]; then
339                         ric_setname="${ricname%-*}"  #Extract the stateful set name
340                 else
341                         ric_setname=$RIC_SIM_COMMON_SVC_NAME # Use the common svc name in the host name of the sims
342                 fi
343                 echo $RIC_SIM_HTTPX"://"$ricname.$ric_setname.$KUBE_A1SIM_NAMESPACE":"$RIC_SIM_PORT
344         else
345                 if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
346                         echo $RIC_SIM_HTTPX"://"$1":"$RIC_SIM_PORT
347                 else
348                         ricname=$(echo "$1" | tr '_' '-')
349                         echo $RIC_SIM_HTTPX"://"$ricname":"$RIC_SIM_PORT
350                 fi
351
352         fi
353 }
354
355 # Generate a UUID to use as prefix for policy ids
356 generate_policy_uuid() {
357         UUID=$(python3 -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')
358         #Reduce length to make space for serial id, uses 'a' as marker where the serial id is added
359         UUID=${UUID:0:${#UUID}-4}"a"
360 }
361
362 # Excute a curl cmd towards a ricsimulator and check the response code.
363 # args: <expected-response-code> <curl-cmd-string>
364 __execute_curl_to_sim() {
365         echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
366         proxyflag=""
367         if [ ! -z "$KUBE_PROXY_PATH" ]; then
368                 if [ $KUBE_PROXY_HTTPX == "http" ]; then
369                         proxyflag=" --proxy $KUBE_PROXY_PATH"
370                 else
371                         proxyflag=" --proxy-insecure --proxy $KUBE_PROXY_PATH"
372                 fi
373         fi
374         echo " CMD: $2 $proxyflag" >> $HTTPLOG
375         res="$($2 $proxyflag)"
376         echo " RESP: $res" >> $HTTPLOG
377         retcode=$?
378     if [ $retcode -ne 0 ]; then
379                 ((RES_CONF_FAIL++))
380                 echo " RETCODE: "$retcode
381         echo -e $RED" FAIL - fatal error when executing curl."$ERED
382         return 1
383     fi
384     status=${res:${#res}-3}
385     if [ $status -eq $1 ]; then
386         echo -e $GREEN" OK"$EGREEN
387         return 0
388     fi
389     echo -e $RED" FAIL - expected http response: "$1" but got http response: "$status $ERED
390         ((RES_CONF_FAIL++))
391     return 1
392 }
393
394 # Tests if a variable value in the ricsimulator is equal to a target value and and optional timeout.
395 # Arg: <ric-id> <variable-name> <target-value> - This test set pass or fail depending on if the variable is
396 # equal to the target or not.
397 # Arg: <ric-id> <variable-name> <target-value> <timeout-in-sec>  - This test waits up to the timeout seconds
398 # before setting pass or fail depending on if the variable value becomes equal to the target
399 # value or not.
400 # (Function for test scripts)
401 sim_equal() {
402
403         if [ $# -eq 3 ] || [ $# -eq 4 ]; then
404                 host=$(__find_sim_host $1)
405                 __var_test $1 "$host/counter/" $2 "=" $3 $4
406                 return 0
407         else
408                 __print_err "needs three or four args: <ric-id> <sim-param> <target-value> [ timeout ]"
409                 return 1
410         fi
411 }
412
413 # Print a variable value from the RIC sim.
414 # args: <ric-id> <variable-name>
415 # (Function for test scripts)
416 sim_print() {
417
418         if [ $# != 2 ]; then
419         __print_err "need two args, <ric-id> <sim-param>" $@
420                 exit 1
421         fi
422         host=$(__find_sim_host $1)
423         echo -e $BOLD"INFO(${BASH_LINENO[0]}): $1, $2 = $(__do_curl $host/counter/$2)"$EBOLD
424 }
425
426 # Tests if a variable value in the RIC simulator contains the target string and and optional timeout
427 # Arg: <ric-id> <variable-name> <target-value> - This test set pass or fail depending on if the variable contains
428 # the target or not.
429 # Arg: <ric-id> <variable-name> <target-value> <timeout-in-sec>  - This test waits up to the timeout seconds
430 # before setting pass or fail depending on if the variable value contains the target
431 # value or not.
432 # (Function for test scripts)
433 sim_contains_str() {
434
435         if [ $# -eq 3 ] || [ $# -eq 4 ]; then
436                 host=$(__find_sim_host $1)
437                 __var_test $1 "$host/counter/" $2 "contain_str" $3 $4
438                 return 0
439         else
440                 __print_err "needs three or four args: <ric-id> <sim-param> <target-value> [ timeout ]"
441                 return 1
442         fi
443 }
444
445 # Simulator API: Put a policy type in a ric
446 # args: <response-code> <ric-id> <policy-type-id> <policy-type-file>
447 # (Function for test scripts)
448 sim_put_policy_type() {
449         __log_conf_start $@
450         if [ $# -ne 4 ]; then
451                 __print_err "<response-code> <ric-id> <policy-type-id> <policy-type-file>" $@
452                 return 1
453         fi
454         host=$(__find_sim_host $2)
455     curlString="curl -X PUT -skw %{http_code} "$host"/policytype?id="$3" -H Content-Type:application/json --data-binary @"$4
456         __execute_curl_to_sim $1 "$curlString"
457         return $?
458 }
459
460 # Simulator API: Delete a policy type in a ric
461 # <response-code> <ric-id> <policy-type-id>
462 # (Function for test scripts)
463 sim_delete_policy_type() {
464         __log_conf_start $@
465         if [ $# -ne 3 ]; then
466                 __print_err "<response-code> <ric-id> <policy_type_id>" $@
467                 return 1
468         fi
469         host=$(__find_sim_host $2)
470     curlString="curl -X DELETE -skw %{http_code} "$host"/policytype?id="$3
471     __execute_curl_to_sim $1 "$curlString"
472         return $?
473 }
474
475 # Simulator API: Delete instances (and status), for one ric
476 # <response-code> <ric-id>
477 # (Function for test scripts)
478 sim_post_delete_instances() {
479         __log_conf_start $@
480         if [ $# -ne 2 ]; then
481                 __print_err "<response-code> <ric-id>" $@
482                 return 1
483         fi
484         host=$(__find_sim_host $2)
485     curlString="curl -X POST -skw %{http_code} "$host"/deleteinstances"
486     __execute_curl_to_sim $1 "$curlString"
487         return $?
488 }
489
490 # Simulator API: Delete all (instances/types/statuses/settings), for one ric
491 # <response-code> <ric-id>
492 # (Function for test scripts)
493 sim_post_delete_all() {
494         __log_conf_start $@
495         if [ $# -ne 2 ]; then
496                 __print_err "<response-code> <numericic-id>" $@
497                 return 1
498         fi
499         host=$(__find_sim_host $2)
500     curlString="curl -X POST -skw %{http_code} "$host"/deleteall"
501     __execute_curl_to_sim $1 "$curlString"
502         return $?
503 }
504
505 # Simulator API: Set (or reset) response code for next A1 message, for one ric
506 # <response-code> <ric-id> [<forced_response_code>]
507 # (Function for test scripts)
508 sim_post_forcedresponse() {
509         __log_conf_start $@
510         if [ $# -ne 3 ]; then
511                 __print_err "<response-code> <ric-id> <forced_response_code>" $@
512                 return 1
513         fi
514         host=$(__find_sim_host $2)
515     curlString="curl -X POST -skw %{http_code} "$host"/forceresponse"
516         if [ $# -eq 3 ]; then
517                 curlString=$curlString"?code="$3
518         fi
519     __execute_curl_to_sim $1 "$curlString"
520         return $?
521 }
522
523 # Simulator API: Set (or reset) A1 response delay, for one ric
524 # <response-code> <ric-id> [<delay-in-seconds>]
525 # (Function for test scripts)
526 sim_post_forcedelay() {
527         __log_conf_start $@
528         if [ $# -ne 3 ]; then
529                 __print_err "<response-code> <ric-id> [<delay-in-seconds>]" $@
530                 return 1
531         fi
532         host=$(__find_sim_host $2)
533     curlString="curl -X POST -skw %{http_code} $host/forcedelay"
534         if [ $# -eq 3 ]; then
535                 curlString=$curlString"?delay="$3
536         fi
537     __execute_curl_to_sim $1 "$curlString"
538         return $?
539 }