Added payload logging and configurable duplicate check
[sim/a1-interface.git] / near-rt-ric-simulator / test / STD_1.1.3 / basic_test.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2021 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 # Script for basic test of the simulator.
21 # Run the build_and_start with the same arg, except arg 'nonsecure|secure', as this script
22
23 print_usage() {
24     echo "Usage: ./basic_test.sh nonsecure|secure duplicate-check|ignore-duplicate "
25     exit 1
26 }
27
28 if [ $# -ne 2 ]; then
29     print_usage
30 fi
31 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
32     print_usage
33 fi
34 if [ "$2" == "duplicate-check" ]; then
35     DUP_CHECK=1
36 elif [ "$2" == "ignore-duplicate" ]; then
37     DUP_CHECK=0
38 else
39     print_usage
40 fi
41
42 if [ $1 == "nonsecure" ]; then
43     #Default http port for the simulator
44     PORT=8085
45     # Set http protocol
46     HTTPX="http"
47 else
48     #Default https port for the simulator
49     PORT=8185
50     # Set https protocol
51     HTTPX="https"
52 fi
53
54 . ../common/test_common.sh
55
56
57 echo "=== Simulator hello world ==="
58 RESULT="OK"
59 do_curl GET / 200
60
61 echo "=== Check used and implemented interfaces ==="
62 RESULT="Current interface: STD_1.1.3 All supported A1 interface yamls in this container: ['OSC_2.1.0', 'STD_1.1.3', 'STD_2.0.0']"
63 do_curl GET /container_interfaces 200
64
65 echo "=== Reset simulator instances ==="
66 RESULT="All policy instances deleted"
67 do_curl POST /deleteinstances 200
68
69 echo "=== Reset simulator, all ==="
70 RESULT="All policy instances deleted"
71 do_curl POST /deleteall 200
72
73 echo "=== API: Get policy instances, shall be empty=="
74 RESULT="json:[]"
75 do_curl GET /A1-P/v1/policies 200
76
77 echo "=== API: Create policy instance pi1 ==="
78 RESULT="json:{\"scope\": {\"ueId\": \"ue1\", \"groupId\": \"group1\", \"sliceId\": \"slice1\", \"qosId\": \"qos1\", \"cellId\": \"cell1\"}, \"statement\": {\"priorityLevel\": 5}}"
79 do_curl PUT /A1-P/v1/policies/pi1 201 jsonfiles/pi1.json
80
81 echo "=== API: Update policy instance pi1 ==="
82 RESULT="json:{\"scope\": {\"ueId\": \"ue1\", \"groupId\": \"group1\", \"sliceId\": \"slice1\", \"qosId\": \"qos1\", \"cellId\": \"cell1\"}, \"statement\": {\"priorityLevel\": 6}}"
83 do_curl PUT /A1-P/v1/policies/pi1 200 jsonfiles/pi1_updated.json
84
85 echo "=== API: Get policy instances, shall contain pi1=="
86 RESULT="json:[ \"pi1\" ]"
87 do_curl GET /A1-P/v1/policies 200
88
89 if [ $DUP_CHECK == 1 ]; then
90     echo "=== API: Create policy instance pi2 (copy of pi1). Shall fail ==="
91     RESULT="json:{\"title\": \"The policy json already exists.\", \"status\": 400, \"instance\": \"pi2\"}"
92     do_curl PUT /A1-P/v1/policies/pi2 400 jsonfiles/pi1_updated.json
93 else
94     echo "=== API: Create policy instance pi2 (copy of pi1). Shall succeed ==="
95     RESULT="json:{\"scope\": {\"ueId\": \"ue1\", \"groupId\": \"group1\", \"sliceId\": \"slice1\", \"qosId\": \"qos1\", \"cellId\": \"cell1\"}, \"statement\": {\"priorityLevel\": 5}}"
96     do_curl PUT /A1-P/v1/policies/pi2 201 jsonfiles/pi1.json
97
98     echo "=== API: DELETE policy instance pi2 ==="
99     RESULT=""
100     do_curl DELETE /A1-P/v1/policies/pi2 204
101 fi
102
103 echo "=== Set force response code 409. ==="
104 RESULT="*"
105 do_curl POST '/forceresponse?code=409' 200
106
107 echo "=== API: Get policy instances, shall fail =="
108 RESULT="json:{\"title\": \"Conflict\", \"status\": 409, \"detail\": \"Request could not be processed in the current state of the resource\"}"
109 do_curl GET /A1-P/v1/policies 409
110
111 echo "=== API: Get policy status ==="
112 RESULT="json:{\"enforceStatus\": \"UNDEFINED\"}"
113 do_curl GET /A1-P/v1/policies/pi1/status 200
114
115 echo "=== API: Create policy instance pi2 ==="
116 RESULT="json:{\"scope\": {\"ueId\": \"ue2\", \"groupId\": \"group2\", \"sliceId\": \"slice2\", \"qosId\": \"qos2\", \"cellId\": \"cell2\"}, \"statement\": {\"priorityLevel\": 10}}"
117 do_curl PUT /A1-P/v1/policies/pi2 201 jsonfiles/pi2.json
118
119 echo "=== API: Update policy instance pi2 ==="
120 RESULT="json:{\"scope\": {\"ueId\": \"ue2\", \"groupId\": \"group2\", \"sliceId\": \"slice2\", \"qosId\": \"qos2\", \"cellId\": \"cell2\"}, \"statement\": {\"priorityLevel\": 10}}"
121 do_curl PUT '/A1-P/v1/policies/pi2?notificationDestination=http://localhost:2223/statustest' 200 jsonfiles/pi2.json
122
123 echo "=== API: Get policy instances, shall contain pi1 and pi2=="
124 RESULT="json:[ \"pi1\", \"pi2\" ]"
125 do_curl GET /A1-P/v1/policies 200
126
127 echo "=== Set force delay 10. ==="
128 RESULT="Force delay: 10 sec set for all A1 responses"
129 do_curl POST '/forcedelay?delay=10' 200
130
131 echo "=== API: Get policy instances, shall contain pi1 and pi2 and delayed 10 sec=="
132 RESULT="json:[ \"pi1\", \"pi2\" ]"
133 do_curl GET /A1-P/v1/policies 200
134
135 echo "=== Reset force delay. ==="
136 RESULT="Force delay: None sec set for all A1 responses"
137 do_curl POST /forcedelay 200
138
139 echo "=== API: GET policy instance pi1 ==="
140 RESULT="json:{\"scope\": {\"ueId\": \"ue1\", \"groupId\": \"group1\", \"sliceId\": \"slice1\", \"qosId\": \"qos1\", \"cellId\": \"cell1\"}, \"statement\": {\"priorityLevel\": 6}}"
141 do_curl GET /A1-P/v1/policies/pi1 200
142
143 echo "=== API: GET policy instance pi2 ==="
144 RESULT="json:{\"scope\": {\"ueId\": \"ue2\", \"groupId\": \"group2\", \"sliceId\": \"slice2\", \"qosId\": \"qos2\", \"cellId\": \"cell2\"}, \"statement\": {\"priorityLevel\": 10}}"
145 do_curl GET /A1-P/v1/policies/pi2 200
146
147 echo "=== API: DELETE policy instance pi1 ==="
148 RESULT=""
149 do_curl DELETE /A1-P/v1/policies/pi1 204
150
151 echo "=== API: Get policy status for pi1, shall fail==="
152 RESULT="json:{\"title\": \"The policy identity does not exist.\", \"status\": 404, \"detail\": \"There is no existing policy instance with the identity: pi1\", \"instance\": \"pi1\"}"
153 do_curl GET /A1-P/v1/policies/pi1/status 404
154
155 echo "=== Set status for policy instance pi2 ==="
156 RESULT="Status set to OK for policy: pi2"
157 do_curl PUT '/status?policyid=pi2&status=OK' 200
158
159 echo "=== API: Get policy status for pi2==="
160 RESULT="json:{\"enforceStatus\": \"OK\"}"
161 do_curl GET /A1-P/v1/policies/pi2/status 200
162
163 echo "=== Set status for policy instance pi2 ==="
164 RESULT="Status set to NOTOK and notok_reason for policy: pi2"
165 do_curl PUT '/status?policyid=pi2&status=NOTOK&reason=notok_reason' 200
166
167 echo "=== API: Get policy status for pi2 ==="
168 RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}"
169 do_curl GET /A1-P/v1/policies/pi2/status 200
170
171 echo "=== Send status for pi2==="
172 RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}"
173 do_curl POST '/sendstatus?policyid=pi2' 200
174
175 echo "=== Get counter: intstance ==="
176 RESULT="1"
177 do_curl GET /counter/num_instances 200
178
179 echo "=== Get counter: types (shall be 0)==="
180 RESULT="0"
181 do_curl GET /counter/num_types 200
182
183 echo "=== Get counter: interface ==="
184 RESULT="STD_1.1.3"
185 do_curl GET /counter/interface 200
186
187 echo "=== Get counter: remote hosts ==="
188 RESULT="*"
189 do_curl GET '/counter/remote_hosts' 200
190
191 echo "********************"
192 echo "*** All tests ok ***"
193 echo "********************"