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
10 # http://www.apache.org/licenses/LICENSE-2.0
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=================================================
21 ### Admin API functions for the RIC simulator
24 # Excute a curl cmd towards a ricsimulator and check the response code.
25 # args: <expected-response-code> <curl-cmd-string> [<file>]
26 __execute_curl_to_sim() {
27 echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
28 echo " CMD: $2" >> $HTTPLOG
30 echo " FILE: $(<$3)" >> $HTTPLOG
33 echo " RESP: $res" >> $HTTPLOG
35 if [ $retcode -ne 0 ]; then
36 echo " RETCODE: "$retcode
37 echo -e $RED" ERROR - fatal error when executing curl."$ERED
40 status=${res:${#res}-3}
41 if [ $status -eq $1 ]; then
42 echo -e $GREEN" OK"$EGREEN
45 echo -e $RED" ERROR - expected http response: "$1" but got http response: "$status $ERED
49 # Tests if a variable value in the ricsimulator is equal to a target value and and optional timeout.
50 # Arg: <ric-id> <variable-name> <target-value> - This test set pass or fail depending on if the variable is
51 # equal to the target or not.
52 # Arg: <ric-id> <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
53 # before setting pass or fail depending on if the variable value becomes equal to the target
55 # (Function for test scripts)
58 if [ $# -eq 3 ] || [ $# -eq 4 ]; then
60 port=$(__find_sim_port $app)
61 __var_test $app "$RIC_SIM_LOCALHOST$port/counter/" $2 "=" $3 $4
65 __print_err "needs three or four args: <ric-id> <sim-param> <target-value> [ timeout ]"
70 # Print a variable value from the RIC sim.
71 # args: <ric-id> <variable-name>
72 # (Function for test scripts)
77 __print_err "need two args, <ric-id> <sim-param>" $@
81 port=$(__find_sim_port $app)
82 echo -e $BOLD"INFO(${BASH_LINENO[0]}): $app, $2 = $(__do_curl $RIC_SIM_LOCALHOST$port/counter/$2)"$EBOLD
85 # Simulator API: Put a policy type in a ric
86 # args: <response-code> <ric-id> <policy-type-id> <policy-type-file>
87 # (Function for test scripts)
88 sim_put_policy_type() {
89 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
92 __print_err "<response-code> <ric-id> <policy-type-id> <policy-type-file>" $@
96 res=$(__find_sim_port $app)
98 curlString="curl -X PUT -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/policytype?id="$3" -H Content-Type:application/json --data-binary @"$4
100 __execute_curl_to_sim $1 "$curlString" $4
104 # DSimulator API: Delete a policy type in a ric
105 # <response-code> <ric-id> <policy-type-id>
106 # (Function for test scripts)
107 sim_delete_policy_type() {
108 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
109 if [ $# -ne 3 ]; then
111 __print_err "<response-code> <ric-id> <policy_type_id>" $@
115 res=$(__find_sim_port $app)
117 curlString="curl -X DELETE -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/policytype?id="$3
119 __execute_curl_to_sim $1 "$curlString"
123 # Simulator API: Delete instances (and status), for one ric
124 # <response-code> <ric-id>
125 # (Function for test scripts)
126 sim_post_delete_instances() {
127 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
128 if [ $# -ne 2 ]; then
130 __print_err "<response-code> <ric-id>" $@
134 res=$(__find_sim_port $app)
136 curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/deleteinstances"
138 __execute_curl_to_sim $1 "$curlString"
142 # Simulator API: Delete all (instances/types/statuses/settings), for one ric
143 # <response-code> <ric-id>
144 # (Function for test scripts)
145 sim_post_delete_all() {
146 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
147 if [ $# -ne 3 ]; then
149 __print_err "<response-code> <numericic-id>" $@
153 res=$(__find_sim_port $app)
155 curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/deleteall"
157 __execute_curl_to_sim $1 "$curlString"
161 # Simulator API: Set (or reset) response code for next A1 message, for one ric
162 # <response-code> <ric-id> [<forced_response_code>]
163 # (Function for test scripts)
164 sim_post_forcedresponse() {
165 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
166 if [ $# -ne 3 ]; then
168 __print_err "<response-code> <ric-id> <forced_response_code>" $@
172 res=$(__find_sim_port $app)
174 curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/forceresponse"
175 if [ $# -eq 3 ]; then
176 curlString=$curlString"?code="$3
179 __execute_curl_to_sim $1 "$curlString"
183 # Simulator API: Set (or reset) A1 response delay, for one ric
184 # <response-code> <ric-id> [<delay-in-seconds>]
185 # (Function for test scripts)
186 sim_post_forcedelay() {
187 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
188 if [ $# -ne 3 ]; then
190 __print_err "<response-code> <ric-id> [<delay-in-seconds>]" $@
194 res=$(__find_sim_port $app)
196 curlString="curl -X POST -skw %{http_code} $RIC_SIM_LOCALHOST$res/delay"
197 if [ $# -eq 3 ]; then
198 curlString=$curlString"?delay="$3
201 __execute_curl_to_sim $1 "$curlString"