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