A1 simulator for STD 2.0.0
[sim/a1-interface.git] / near-rt-ric-simulator / README.md
1 # O-RAN-SC Near-RealTime RIC Simulator
2
3 The O-RAN SC Near-RealTime RIC 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 | Yaml file version     | Version id|
7 | --------------------- | ------------------- |
8 | OSC 2.1.0,            |      OSC\_2.1.0     |
9 | A1 Standard 1.1.3,    |      STD\_1.1.3     |
10 | A1 Standard 2.0.0,    |      STD\_2.0.0     |
11
12 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.
13
14 The overall folder structure is \(relative to the location of this README file\):
15 | Dir              | Description |
16 | ---------------- | ----------- |
17 |.                 |Dockerfile and README |
18 |api               |The open api yaml for each supported version |
19 |src               |Python source code for each supported version |
20 |test              |Basic test using script|
21 |tests             |Basic test using pytest unit test|
22 |certificate       |A self-signed certificate and a key
23
24 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.
25
26 The section below outlines the supported open api REST operations as well as the adminstrative REST operations. For the
27 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).
28
29 # Ports and certificates
30
31 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.
32 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.
33
34 | Port     | Protocol |
35 | -------- | ----- |
36 | 8085     | http  |
37 | 8185     | https |
38
39 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'.
40 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.
41
42 # Supported operations in simulator OSC 2.1.0
43
44 For the complete yaml specification, see [openapi.yaml](../near-rt-ric-simulator/api/OSC_2.1.0/openapi.yaml).
45
46 URIs for A1:
47 | Function              | Path and parameters |
48 | --------------------- | ------------------- |
49 |  GET, do a healthcheck |  http://localhost:8085/a1-p/healthcheck |
50 |  GET, get all policy type ids | http://localhost:8085/a1-p/policytypes |
51 |  DELETE, delete a policy type | http://localhost:8085/a1-p/policytypes/{policy\_type\_id} |
52 |  GET, get a policy type | http://localhost:8085/a1-p/policytypes/{policy\_type\_id} |
53 |  PUT, create/update a policy type | http://localhost:8085/a1-p/policytypes/{policy\_type\_id} |
54 |  GET, get all policy ids for a type | http://localhost:8085/a1-p/policytypes/{policy\_type\_id}/policies |
55 |  DELETE, delete a policy | http://localhost:8085/a1-p/policytypes/{policy\_type\_id}/policies/{policy\_instance\_id} |
56 |  GET, get a policy | http://localhost:8085/a1-p/policytypes/{policy\_type\_id}/policies/{policy\_instance\_id} |
57 |  PUT, create/update a policy | http://localhost:8085/a1-p/policytypes/{policy\_type\_id}/policies/{policy\_instance\_id} |
58 |  GET, get policy status | http://localhost:8085/a1-p/policytypes/{policy\_type\_id}/policies/{policy\_instance\_id}/status |
59
60 Swagger UI at: http://localhost:8085/ui/
61
62 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).
63
64 URIs for admin operations:
65 | Function              | Path and parameters |
66 | --------------------- | ------------------- |
67 |  GET, a basic healthcheck | http://localhost:8085/ |
68 |  GET, a list of all supported interfaces | http://localhost:8085/container\_interfaces |
69 |  POST, delete all policy instances | http://localhost:8085/deleteinstances |
70 |  POST, full reset | http://localhost:8085/deleteall |
71 |  PUT, create/update a policy type | http://localhost:8085/policytype?id=<policytypeid> |
72 |  DELETE, delete a policy type | http://localhost:8085/policytype?id=<policytypeid> |
73 |  GET, list of policy type id | http://localhost:8085/policytypes |
74 |  POST, force a specific response code for an A1 operation | http://localhost:8085/forceresponse?code=<http-code> |
75 |  POST, force delayed response of all A1 operations | http://localhost:8085/forcedelay?delay=<seconds> |
76 |  PUT, set status and optional reason, delete and timestamp | http://localhost:8085/status?status=<status>&reason=<reason>[&deleted=<boolean>][&created\_at=<timestamp>]  |
77 |  GET a counter  <br> (counter-name: 'num\_instances', 'num\_types', 'interface' or 'remote\_hosts') | http://localhost:8085/counter/&lt;counter-name&gt; |
78
79
80 # Supported operations in simulator A1 Standard 1.1.3
81
82 For the complete yaml specification, see [STD_A1.yaml](../near-rt-ric-simulator/api/STD_1.1.3/STD_A1.yaml).
83
84 URIs for A1:
85 | Function              | Path and parameters |
86 | --------------------- | ------------------- |
87 |  GET all policy identities | http://localhost:8085/A1-P/v1/policies |
88 |  PUT a policy instance(create or update it) | http://localhost:8085/A1-P/v1/policies/{policyId} |
89 |  GET a policy | http://localhost:8085/A1-P/v1/policies/{policyId} |
90 |  DELETE a policy instance | http://localhost:8085/A1-P/v1/policies/{policyId} |
91 |  GET a policy status | http://localhost:8085/A1-P/v1/policies/{policyid}/status |
92 Swagger UI at: http://localhost:8085/A1-P/v1/ui/
93
94 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).
95
96 URIs for admin operations:
97 | Function              | Path and parameters |
98 | --------------------- | ------------------- |
99 |  GET, a basic healthcheck | http://localhost:8085/ |
100 |  GET, a list of all supported interfaces | http://localhost:8085/container\_interfaces |
101 |  POST, delete all policy instances | http://localhost:8085/deleteinstances |
102 |  POST, full reset | http://localhost:8085/deleteall |
103 |  POST, force a specific response code for an A1 operation | http://localhost:8085/forceresponse?code=&lt;http-code&gt; |
104 |  POST, force delayed response of all A1 operations | http://localhost:8085/forcedelay?delay=&lt;seconds&gt; |
105 |  PUT, set status and optional reason | http://localhost:8085/status?status=&lt;status&gt;[&amp;reason=&lt;reason&gt;] |
106 |  POST, send status for policy | http://localhost:8085/sendstatus?policyid=&lt;policyid&gt; |
107 |  GET a counter <br> (counter-name: 'num\_instances', 'num\_types'(always 0), 'interface' or 'remote\_hosts') | http://localhost:8085/counter/&lt;counter-name&gt; |
108
109 # Supported operations in simulator A1 Standard 2.0.0
110
111 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).
112
113 URIs for A1:
114 | Function              | Path and parameters |
115 | --------------------- | ------------------- |
116 |  GET all policy type identities | http://localhost:8085/A1-P/v2/policytypes |
117 |  GET a policy type | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId} |
118 |  GET all policy identities | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId}/policies |
119 |  PUT a policy instance(create or update it) | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId}/policies/{policyId} |
120 |  GET a policy | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId}/policies/{policyId} |
121 |  DELETE a policy instance | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId}/policies/{policyId} |
122 |  GET a policy status | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId}/policies/{policyid}/status |
123 Swagger UI at: http://localhost:8085/A1-P/v2/ui/
124
125 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).
126
127 URIs for admin operations:
128 | Function              | Path and parameters |
129 | --------------------- | ------------------- |
130 |  GET, a basic healthcheck | http://localhost:8085/ |
131 |  GET, a list of all supported interfaces | http://localhost:8085/container\_interfaces |
132 |  POST, delete all policy instances | http://localhost:8085/deleteinstances |
133 |  POST, full reset | http://localhost:8085/deleteall |
134 |  PUT, create/update a policy type | http://localhost:8085/policytype?id=&lt;policytypeid&gt; |
135 |  DELETE, delete a policy type | http://localhost:8085/policytype?id=&lt;policytypeid&gt; |
136 |  GET, list of policy type id | http://localhost:8085/policytypes |
137 |  POST, force a specific response code for an A1 operation | http://localhost:8085/forceresponse?code=&lt;http-code&gt; |
138 |  POST, force delayed response of all A1 operations | http://localhost:8085/forcedelay?delay=&lt;seconds&gt; |
139 |  PUT, set status and optional reason | http://localhost:8085/status?status=&lt;status&gt;[&amp;reason=&lt;reason&gt;] |
140 |  POST, send status for policy | http://localhost:8085/sendstatus?policyid=&lt;policyid&gt; |
141 |  POST, deliver data | http://localhost:8085/datadelivery |
142 |  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; |
143
144
145
146 # Configuring the simulator
147 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.
148 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.
149 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
150
151 By default, this image has default certificates under /usr/src/app/cert
152 file "cert.crt" is the certificate file
153 file "key.crt" is the key file
154 file "generate_cert_and_key.sh" is a shell script to generate certificate and key
155 file "pass" stores the password when you run the shell script
156
157 Start the a1-interface container without specifing external certificates:
158 'docker run -it -p 8085:8085 -p 8185:8185 -e A1\_VERSION=STD\_1.1.3 -e REMOTE_HOSTS_LOGGING=1 a1test'
159
160 It will listen to https 8185 port(using default certificates) by default.
161 Http can be enabled on port 8085 using an environment variable "ALLOW_HTTP".
162 If this environment variable is left out or set to false, the nginx server will send
163 "444 Connection Closed Without Response" when making a call using http.
164 Example command to enable http:
165 'docker run -it -p 8085:8085 -p 8185:8185 -e A1\_VERSION=OSC\_2.1.0 -e ALLOW_HTTP=true a1test'
166
167 This certificates/key can be overriden by mounting a volume when using "docker run" or "docker-compose"
168 In 'docker run', use field:
169 --volume "$PWD/certificate:/usr/src/app/cert" a1test
170 In 'docker-compose.yml', use field:
171 volumes:
172       - ./certificate:/usr/src/app/cert:ro
173
174 In docker run the full command could look like this:<br> '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 --volume /PATH_TO_CERT_DIR/certificate:/usr/src/app/cert a1test'
175 http port 8085 and https port 8185
176 The variable for A1 version is set with the '-e' flag.
177 With logging of remote host enabled "-e REMOTE_HOSTS_LOGGING=1 "
178 With certificate dir mounted  "--volume /PATH_TO_CERT_DIR/certificate:/usr/src/app/cert"
179
180 # Updating the openapi specs
181 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.
182
183 # Start and test of the simulator
184 See also 'Basic test and code coverage'.
185
186 First, download the sim/a1-interface repo on gerrit:
187 git clone "https://gerrit.o-ran-sc.org/oransc/sim/a1-interface"
188
189 Goto the main directory, 'a1-interface/near-rt-ric-simulator'.
190 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.
191
192 Go to the test folder of the selected version, 'test/&lt;version&gt;/.
193
194 Note that test can be performed both using the nonsecure http port and the secure https port.
195
196 Build and start the simulator container using: ./build\_and\_start.sh
197 This will build and start the container in interactive mode. The built container only resides in the local docker repository.
198 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.
199
200 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 depending on version.
201 This script runs a number of tests towards the simulator to make sure it works properply.
202
203 # Basic test and code coverage
204
205 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.
206 Only http is tested as the internal flask server is only using http (https is part of the webserver inteface).
207
208 Navigate to 'near-rt-ric-simulator/tests'. Choose the version to test and use that file for test.
209
210 Use 'python3 -m pytest <filename>' to run unit test only with no coverage check
211
212 Or use 'coverage run  -m pytest <filename>' to run unit test and produce coverage data.
213 List coverage data by 'coverage report -m --include=../../*' - the include flag makes the list to only contain coverage data from the simulator python file.
214
215 To use the 'coverage' cmd, coverage need to be installed use 'pip install coverage'
216
217 ## License
218
219 Copyright (C) 2019 Nordix Foundation.
220 Licensed under the Apache License, Version 2.0 (the "License")
221 you may not use this file except in compliance with the License.
222 You may obtain a copy of the License at
223
224       http://www.apache.org/licenses/LICENSE-2.0
225
226 Unless required by applicable law or agreed to in writing, software
227 distributed under the License is distributed on an "AS IS" BASIS,
228 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
229 See the License for the specific language governing permissions and
230 limitations under the License.
231
232 For more information about license please see the [LICENSE](LICENSE.txt) file for details.