CI: Call GHA workflow for tox verify.
[sim/a1-interface.git] / near-rt-ric-simulator / README.md
1 # O-RAN-SC A1 Simulator
2
3 The O-RAN SC A1 simulator simulates the A1 as an generic REST API which can receive and send northbound messages. The simulator validates the payload and applies policy.
4
5 The simulator supports multiple A1 interface versions (version of the open API yaml file\):
6
7 | Yaml file version     | Version id|
8 | --------------------- | ------------------- |
9 | OSC 2.1.0,            |      OSC\_2.1.0     |
10 | A1 Standard 1.1.3,    |      STD\_1.1.3     |
11 | A1 Standard 2.0.0,    |      STD\_2.0.0     |
12
13 All versions are supported by the same container, see section 'Configuring the simulator' below for details about how to the start the simulator with the intended version id.
14
15 The overall folder structure is \(relative to the location of this README file\):
16
17 | Dir              | Description |
18 | ---------------- | ----------- |
19 |.                 |Dockerfile and README |
20 |api               |The open api yaml for each supported version |
21 |src               |Python source code for each supported version |
22 |test              |Basic test using script|
23 |tests             |Basic test using pytest unit test|
24 |certificate       |A self-signed certificate and a key
25
26 The simulator handles the requests that are defined in the A1 open API yaml file. All these requests are implemented in the a1.py file in the source folder. In addition, a number of administrative functions are also supported and implemented by the main.py in the source folder.
27
28 The section below outlines the supported open api REST operations as well as the adminstrative REST operations. For the
29 documentation of the common parts in the admin API, see [Common Functions](https://docs.o-ran-sc.org/projects/o-ran-sc-sim-a1-interface/en/latest/simulator-api.html#common-functions).
30
31 # Ports and certificates
32
33 The simulator normally opens the port 8085 for http. If a certificate and a key are provided the simulator will open port 8185 for https instead. The port 8185 is only opened if a valid certificate and key is found.
34 The certificate and key shall be placed in the same dir and the dir shall be mounted to /usr/src/app/cert in the container.
35
36 | Port     | Protocol |
37 | -------- | ----- |
38 | 8085     | http  |
39 | 8185     | https |
40
41 The dir certificate contains a self-signed cert. Use the script generate_cert_and_key.sh to generate a new certificate and key. The password of the certificate must be set 'test'.
42 The same urls are availables on both the http port 8085 and the https port 8185. If using curl and https, the flag -k shall be given to make curl ignore checking the certificate.
43
44 # Supported operations in simulator OSC 2.1.0
45
46 For the complete yaml specification, see [openapi.yaml](../near-rt-ric-simulator/api/OSC_2.1.0/openapi.yaml).
47
48 URIs for A1:
49
50 | Function              | Path and parameters |
51 | --------------------- | ------------------- |
52 |  GET, do a healthcheck |  http://localhost:8085/a1-p/healthcheck |
53 |  GET, get all policy type ids | http://localhost:8085/a1-p/policytypes |
54 |  DELETE, delete a policy type | http://localhost:8085/a1-p/policytypes/{policy\_type\_id} |
55 |  GET, get a policy type | http://localhost:8085/a1-p/policytypes/{policy\_type\_id} |
56 |  PUT, create/update a policy type | http://localhost:8085/a1-p/policytypes/{policy\_type\_id} |
57 |  GET, get all policy ids for a type | http://localhost:8085/a1-p/policytypes/{policy\_type\_id}/policies |
58 |  DELETE, delete a policy | http://localhost:8085/a1-p/policytypes/{policy\_type\_id}/policies/{policy\_instance\_id} |
59 |  GET, get a policy | http://localhost:8085/a1-p/policytypes/{policy\_type\_id}/policies/{policy\_instance\_id} |
60 |  PUT, create/update a policy | http://localhost:8085/a1-p/policytypes/{policy\_type\_id}/policies/{policy\_instance\_id} |
61 |  GET, get policy status | http://localhost:8085/a1-p/policytypes/{policy\_type\_id}/policies/{policy\_instance\_id}/status |
62 |  PUT, deliver data produced by data producer | http://localhost:8085/data-delivery json payload = {"job":"101",    "payload":"another payload"}|
63
64 Swagger UI at: http://localhost:8085/ui/
65
66 For the documentation of the admin API, see [OSC_2.1.0](https://docs.o-ran-sc.org/projects/o-ran-sc-sim-a1-interface/en/latest/simulator-api.html#osc-2-1-0).
67
68 URIs for admin operations:
69
70 | Function              | Path and parameters |
71 | --------------------- | ------------------- |
72 |  GET, a basic healthcheck | http://localhost:8085/ |
73 |  GET, a list of all supported interfaces | http://localhost:8085/container\_interfaces |
74 |  POST, delete all policy instances | http://localhost:8085/deleteinstances |
75 |  POST, full reset | http://localhost:8085/deleteall |
76 |  PUT, create/update a policy type | http://localhost:8085/policytype?id=<policytypeid> |
77 |  DELETE, delete a policy type | http://localhost:8085/policytype?id=<policytypeid> |
78 |  GET, list of policy type id | http://localhost:8085/policytypes |
79 |  POST, force a specific response code for an A1 operation | http://localhost:8085/forceresponse?code=<http-code> |
80 |  POST, force delayed response of all A1 operations | http://localhost:8085/forcedelay?delay=<seconds> |
81 |  PUT, set status and optional reason, delete and timestamp | http://localhost:8085/status?status=<status>&reason=<reason>[&deleted=<boolean>][&created\_at=<timestamp>]  |
82 |  GET a counter  <br> (counter-name: 'num\_instances', 'num\_types', 'interface' or 'remote\_hosts') | http://localhost:8085/counter/&lt;counter-name&gt; |
83 |  Turn on http header and payload logging | http://localhost:8085payload_logging/on |
84 |  Turn off http header and payload logging | http://localhost:8085payload_logging/off |
85
86 # Supported operations in simulator A1 Standard 1.1.3
87
88 For the complete yaml specification, see [STD_A1.yaml](../near-rt-ric-simulator/api/STD_1.1.3/STD_A1.yaml).
89
90 URIs for A1:
91
92 | Function              | Path and parameters |
93 | --------------------- | ------------------- |
94 |  GET all policy identities | http://localhost:8085/A1-P/v1/policies |
95 |  PUT a policy instance(create or update it) | http://localhost:8085/A1-P/v1/policies/{policyId} |
96 |  GET a policy | http://localhost:8085/A1-P/v1/policies/{policyId} |
97 |  DELETE a policy instance | http://localhost:8085/A1-P/v1/policies/{policyId} |
98 |  GET a policy status | http://localhost:8085/A1-P/v1/policies/{policyid}/status |
99
100 Swagger UI at: http://localhost:8085/A1-P/v1/ui/
101
102 For the documentation of the admin API, see [A1 Standard 1.1.3](https://docs.o-ran-sc.org/projects/o-ran-sc-sim-a1-interface/en/latest/simulator-api.html#a1-standard-1-1-3).
103
104 URIs for admin operations:
105
106 | Function              | Path and parameters |
107 | --------------------- | ------------------- |
108 |  GET, a basic healthcheck | http://localhost:8085/ |
109 |  GET, a list of all supported interfaces | http://localhost:8085/container\_interfaces |
110 |  POST, delete all policy instances | http://localhost:8085/deleteinstances |
111 |  POST, full reset | http://localhost:8085/deleteall |
112 |  POST, force a specific response code for an A1 operation | http://localhost:8085/forceresponse?code=&lt;http-code&gt; |
113 |  POST, force delayed response of all A1 operations | http://localhost:8085/forcedelay?delay=&lt;seconds&gt; |
114 |  PUT, set status and optional reason | http://localhost:8085/status?status=&lt;status&gt;[&amp;reason=&lt;reason&gt;] |
115 |  POST, send status for policy | http://localhost:8085/sendstatus?policyid=&lt;policyid&gt; |
116 |  GET a counter <br> (counter-name: 'num\_instances', 'num\_types'(always 0), 'interface' or 'remote\_hosts') | http://localhost:8085/counter/&lt;counter-name&gt; |
117 |  Turn on http header and payload logging | http://localhost:8085payload_logging/on |
118 |  Turn off http header and payload logging | http://localhost:8085payload_logging/off |
119
120 # Supported operations in simulator A1 Standard 2.0.0
121
122 For the complete yaml specification, see [ORAN_A1-p_V2.0.0_api.yaml](../near-rt-ric-simulator/api/STD_2.0.0/ORAN_A1-p_V2.0.0_api.yaml).
123
124 URIs for A1:
125
126 | Function              | Path and parameters |
127 | --------------------- | ------------------- |
128 |  GET all policy type identities | http://localhost:8085/A1-P/v2/policytypes |
129 |  GET a policy type | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId} |
130 |  GET all policy identities | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId}/policies |
131 |  PUT a policy instance(create or update it) | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId}/policies/{policyId} |
132 |  GET a policy | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId}/policies/{policyId} |
133 |  DELETE a policy instance | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId}/policies/{policyId} |
134 |  GET a policy status | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId}/policies/{policyid}/status |
135
136 Swagger UI at: http://localhost:8085/A1-P/v2/ui/
137
138 For the documentation of the admin API, see [A1 Standard 2.0.0](https://docs.o-ran-sc.org/projects/o-ran-sc-sim-a1-interface/en/latest/simulator-api.html#a1-standard-2-0-0).
139
140 URIs for admin operations:
141
142 | Function              | Path and parameters |
143 | --------------------- | ------------------- |
144 |  GET, a basic healthcheck | http://localhost:8085/ |
145 |  GET, a list of all supported interfaces | http://localhost:8085/container\_interfaces |
146 |  POST, delete all policy instances | http://localhost:8085/deleteinstances |
147 |  POST, full reset | http://localhost:8085/deleteall |
148 |  PUT, create/update a policy type | http://localhost:8085/policytype?id=&lt;policytypeid&gt; |
149 |  DELETE, delete a policy type | http://localhost:8085/policytype?id=&lt;policytypeid&gt; |
150 |  GET, list of policy type id | http://localhost:8085/policytypes |
151 |  POST, force a specific response code for an A1 operation | http://localhost:8085/forceresponse?code=&lt;http-code&gt; |
152 |  POST, force delayed response of all A1 operations | http://localhost:8085/forcedelay?delay=&lt;seconds&gt; |
153 |  PUT, set status and optional reason | http://localhost:8085/status?status=&lt;status&gt;[&amp;reason=&lt;reason&gt;] |
154 |  POST, send status for policy | http://localhost:8085/sendstatus?policyid=&lt;policyid&gt; |
155 |  POST, deliver data | http://localhost:8085/datadelivery |
156 |  GET a counter <br> (counter-name: 'num\_instances', 'num\_types'(always 0), 'interface', 'remote\_hosts' or 'datadelivery') | http://localhost:8085/counter/&lt;counter-name&gt; |
157 |  Turn on http header and payload logging | http://localhost:8085payload_logging/on |
158 |  Turn off http header and payload logging | http://localhost:8085payload_logging/off |
159
160
161 # Configuring the simulator
162 An env variable, A1\_VERSION need to be passed to the container at start to select the desired interface version. The variable shall be set to one of the version-ids shown in the table in the first section. For example A1\_VERSIION=STD\_1.1.3.
163
164 An env variable, REMOTE_HOSTS_LOGGING, can be set (any value is ok) and the the counter remote\_hosts will log the host names of all remote hosts that has accessed the A1 URIs. If host names cannot be resolved, the ip address of the remote host is logged instead. This logging is default off so must be configured to be enabled. If not configured, the counter remote\_hosts will return a fixed text indicating that host name logging is not enabled. Use this feature with caution, remote host lookup may take time in certain environments.
165
166 And optional env variable, DUPLICATE_CHECK, can be set to '1' to turn on duplicate check of policy json. A duplicate policy is when the policy json is exactly same as for a different policy id of the same type.  This function is default set off if the variable is not set at all or set to '0'.
167
168 The simulator can also run using the https protocol. The enable https, a valid certificate and key need to provided. There is self-signed certificate available in the certificate dir and that dir shall be mounted to the container to make it available
169
170 By default, this image has default certificates under /usr/src/app/cert
171 file "cert.crt" is the certificate file
172 file "key.crt" is the key file
173 file "generate_cert_and_key.sh" is a shell script to generate certificate and key
174 file "pass" stores the password when you run the shell script
175
176 Start the a1-interface container without specifing external certificates:
177
178 'docker run --rm -it -p 8085:8085 -p 8185:8185 -e A1\_VERSION=STD\_1.1.3 -e REMOTE_HOSTS_LOGGING=1 -e DUPLICATE_CHECK=0 a1test'
179
180 It will listen to https 8185 port(using default certificates) by default.
181 Http can be enabled on port 8085 using an environment variable "ALLOW_HTTP".
182 If this environment variable is left out or set to false, the nginx server will send
183 "444 Connection Closed Without Response" when making a call using http.
184 Example command to enable http:
185
186 'docker run -it -p 8085:8085 -p 8185:8185 -e A1\_VERSION=OSC\_2.1.0 -e ALLOW_HTTP=true -e DUPLICATE_CHECK=0 a1test'
187
188 This certificates/key can be overriden by mounting a volume when using "docker run" or "docker-compose"
189 In 'docker run', use field:
190 --volume "$PWD/certificate:/usr/src/app/cert" a1test
191 In 'docker-compose.yml', use field:
192 volumes:
193       - ./certificate:/usr/src/app/cert:ro
194
195 In docker run the full command could look like this:<br>
196 'docker run -it -p 8085:8085 -p 8185:8185 -e A1\_VERSION=STD\_1.1.3 -e ALLOW_HTTP=true -e REMOTE_HOSTS_LOGGING=1 -e DUPLICATE_CHECK=0 --volume /PATH_TO_CERT_DIR/certificate:/usr/src/app/cert a1test'
197
198 http port 8085 and https port 8185
199
200 The variable for A1 version is set with the '-e' flag.
201
202 With logging of remote host enabled "-e REMOTE_HOSTS_LOGGING=1 "
203
204 With policy json duplicate check set to off (0)
205
206 With certificate dir mounted  "--volume /PATH_TO_CERT_DIR/certificate:/usr/src/app/cert"
207
208 # Updating the openapi specs
209 The openapi specifications are stored in the 'api/&lt;version&gt;/'. If adding/replacing with a new file, make sure to copy the 'operationId' parameter for each operation to the new file.
210
211 # Start and test of the simulator
212 See also 'Basic test and code coverage'.
213
214 First, download the sim/a1-interface repo on gerrit:
215 git clone "https://gerrit.o-ran-sc.org/oransc/sim/a1-interface"
216
217 Goto the main directory, 'a1-interface/near-rt-ric-simulator'.
218 There is a folder 'test/&lt;version&gt;/' for each supported simulator version. This folder contains a script to build and start the simulator (as a container in interactive mode), a script for basic testing as well as json files for the test script.
219
220 Go to the test folder of the selected version, 'test/&lt;version&gt;/.
221
222 Note that test can be performed both using the nonsecure http port and the secure https port.
223
224 Build and start the simulator containers: STD_1.1.3 and OSC_2.1.0, using:
225
226 ./build_and_start.sh duplicate-check|ignore-duplicate
227
228 Build and start the simulator container version STD_2.0.0, using two alternatives: ext-srv or kafka-srv. However, both can not be used at the same time to start A1 sim.
229
230 In order to start with ext-srv:
231 ./build_and_start.sh duplicate-check|ignore-duplicate ext-srv|ext-srv-secure|ignore-ext-srv
232
233 In order to start with kafka-srv:
234 ./build_and_start.sh duplicate-check|ignore-duplicate kafka-srv|kafka-srv-secure publish-resp|ignore-publish
235
236 STD_2.0.0 version is now including an external server that is a Python server building RESTful API. The external server supports HTTP/HTTPS protocols.
237 The description of the start parameters are explained below:
238 ext-srv: Runs external server that supports HTTP protocol only.
239 ext-srv-secure: Runs external server that supports HTTPS protocol as well.
240 ignore-ext-srv: Ignores external server to run.
241
242 STD_2.0.0 version also includes an kafka message dispatcher that is a Python server building RESTful APIs. The kafka server supports HTTP/HTTPS protocols.
243 The description of the start parameters are explained below:
244 kafka-srv: Runs kafka server that supports HTTP protocol only.
245 kafka-srv-secure: Runs kafka server that supports HTTPS protocol as well.
246 publish-resp: The flag controls the dispatcher module to decide auto responding to each requests for test purposes only.
247 ignore-publish: If the A1 sim is being started using ignore flag, then the dispatcher module will look for a respone message published by south-bound module.
248
249 This will build and start the container in interactive mode. The built container only resides in the local docker repository.
250 Note, the default port is 8085 for http and 8185 for https. When running the simulator as a container, the defualt ports can be re-mapped to any port on the localhost.
251
252 In a second terminal, go to the same folder and run the basic test script, basic_test.sh nonsecure|secure or commands.sh nonsecure|secure duplicate-check|ignore-duplicate for STD_1.1.3 and OSC_2.1.0 versions.
253
254 For the STD_2.0.0 version, in a second terminal, go to the same folder and run the basic test script for external server activated case:
255 ./basic_test.sh nonsecure|secure duplicate-check|ignore-duplicate ext-srv|ext-srv-secure|ignore-ext-srv
256 The description of the test script parameters are explained below:
257 nonsecure|secure: Runs test cases with either support of HTTP/HTTPS protocol.
258 duplicate-check|ignore-duplicate: Runs test cases with either support of duplicate/ignore-duplicate flag for the policies.
259 ext-srv|ext-srv-secure|ignore-ext-srv: If the simulator started with ext-srv or ext-srv-secure parameter, then one of these options can be used. Otherwise, ignore-ext-srv parameter should be used.
260
261 For the STD_2.0.0 version, in a second terminal, go to the same folder and run the basic test script for kafka dispatcher server activated case:
262 ./basic_test.sh nonsecure|secure duplicate-check|ignore-duplicate ext-srv|ext-srv-secure|ignore-ext-srv
263 The description of the test script parameters are explained below:
264 nonsecure|secure: Runs test cases with either support of HTTP/HTTPS protocol.
265 duplicate-check|ignore-duplicate: Runs test cases with either support of duplicate/ignore-duplicate flag in accordance with the one which used while starting A1 sim.
266 ext-srv|ext-srv-secure|ignore-ext-srv: If the simulator started with kafka-srv or kafka-srv-secure parameter, then ignore-ext-srv option should be used.
267
268 Note that the arg for duplicate check must match in both scripts.
269 This script runs a number of tests towards the simulator to make sure it works properply.
270
271 # Basic test and code coverage
272
273 Basic test, or unit test, using a python script is also supported. This test basically the same thing as the bash script mentioned in the section above. Follow the instruction of how to clone the repo described in that section.
274 Only http is tested as the internal flask server is only using http (https is part of the webserver inteface).
275
276 Navigate to 'near-rt-ric-simulator/tests'. Choose the version to test and use that file for test.
277
278 Use 'python3 -m pytest \<filename>' to run unit test only with no coverage check. Before running that command, the dependencies which are pytest and connexion should be installed in your virtual environment. If the latest connexion version arises DeprecationWarning, you may try to install connexion with version 2.6.0.
279
280 Or use 'coverage run  -m pytest \<filename>' to run unit test and produce coverage data.
281
282 List coverage data by 'coverage report -m --include=../../*' - the include flag makes the list to only contain coverage data from the simulator python file.
283
284 To use the 'coverage' cmd, coverage need to be installed use 'pip install coverage'
285
286 ## License
287
288 Copyright (C) 2023 Nordix Foundation.
289 Licensed under the Apache License, Version 2.0 (the "License")
290 you may not use this file except in compliance with the License.
291 You may obtain a copy of the License at
292
293       http://www.apache.org/licenses/LICENSE-2.0
294
295 Unless required by applicable law or agreed to in writing, software
296 distributed under the License is distributed on an "AS IS" BASIS,
297 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
298 See the License for the specific language governing permissions and
299 limitations under the License.
300
301 For more information about license please see the [LICENSE](LICENSE.txt) file for details.