A1 simulator for STD 2.0.0
[sim/a1-interface.git] / near-rt-ric-simulator / README.md
index 5152042..b3c35d2 100644 (file)
@@ -7,7 +7,7 @@ The simulator supports multiple A1 interface versions (version of the open API y
 | --------------------- | ------------------- |
 | OSC 2.1.0,            |      OSC\_2.1.0     |
 | A1 Standard 1.1.3,    |      STD\_1.1.3     |
-| 1.1.x-alpha.2 ,       |      1.1.x-alpha.2  |
+| A1 Standard 2.0.0,    |      STD\_2.0.0     |
 
 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.
 
@@ -17,7 +17,8 @@ The overall folder structure is \(relative to the location of this README file\)
 |.                 |Dockerfile and README |
 |api               |The open api yaml for each supported version |
 |src               |Python source code for each supported version |
-|test              |Basic test |
+|test              |Basic test using script|
+|tests             |Basic test using pytest unit test|
 |certificate       |A self-signed certificate and a key
 
 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.
@@ -87,7 +88,7 @@ URIs for A1:
 |  PUT a policy instance(create or update it) | http://localhost:8085/A1-P/v1/policies/{policyId} |
 |  GET a policy | http://localhost:8085/A1-P/v1/policies/{policyId} |
 |  DELETE a policy instance | http://localhost:8085/A1-P/v1/policies/{policyId} |
-|  GET a policy status | http://localhost:8085/A1-P/v1/policies/{policyid} |
+|  GET a policy status | http://localhost:8085/A1-P/v1/policies/{policyid}/status |
 Swagger UI at: http://localhost:8085/A1-P/v1/ui/
 
 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).
@@ -105,40 +106,42 @@ URIs for admin operations:
 |  POST, send status for policy | http://localhost:8085/sendstatus?policyid=<policyid> |
 |  GET a counter <br> (counter-name: 'num\_instances', 'num\_types'(always 0), 'interface' or 'remote\_hosts') | http://localhost:8085/counter/&lt;counter-name&gt; |
 
+# Supported operations in simulator A1 Standard 2.0.0
 
+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).
 
-# Supported operations in simulator 1.1.x-alpha.2
-
-For the complete yaml specification, see [a1-openapi.yaml](../near-rt-ric-simulator/api/1.1.x-alpha.2/a1-openapi.yaml).
-
-The available requests and the addresses are currently:
+URIs for A1:
 | Function              | Path and parameters |
 | --------------------- | ------------------- |
-|  GET all policy identities (respectively for a policy type if query parameter used) | http://localhost:8085/A1-P/v1/policies?policyTypeId={policyTypeId} |
-|  PUT a policy instance(create or update it) | http://localhost:8085/A1-P/v1/policies/{policyId}?policyTypeId={policyTypeId} |
-|  GET a policy | http://localhost:8085/A1-P/v1/policies/{policyId} |
-|  DELETE a policy instance | http://localhost:8085/A1-P/v1/policies/{policyId} |
-|  GET a policy status | http://localhost:8085/A1-P/v1/policystatus |
-|  GET all policy types | http://localhost:8085/A1-P/v1/policytypes |
-|  GET the schemas for a policy type | http://localhost:8085/A1-P/v1/policytypes/{policyTypeId} |
-
-Nota Bene: It could happen that this page is not updated as soon as the yaml file is. The yaml file can be found under /near-rt-ric-simulator/a1-openapi.yaml.
+|  GET all policy type identities | http://localhost:8085/A1-P/v2/policytypes |
+|  GET a policy type | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId} |
+|  GET all policy identities | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId}/policies |
+|  PUT a policy instance(create or update it) | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId}/policies/{policyId} |
+|  GET a policy | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId}/policies/{policyId} |
+|  DELETE a policy instance | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId}/policies/{policyId} |
+|  GET a policy status | http://localhost:8085/A1-P/v2/policytypes/{policyTypeId}/policies/{policyid}/status |
+Swagger UI at: http://localhost:8085/A1-P/v2/ui/
 
-For the documentation of the admin API, see [1.1.x-alpha.2](https://docs.o-ran-sc.org/projects/o-ran-sc-sim-a1-interface/en/latest/simulator-api.html#x-alpha-2).
+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).
 
-Additionally, there are requests that are defined in main.py as an administrative API. The goal is to handle information that couldn't be handled using the A1 interface. The available requests and the addresses are currently:
+URIs for admin operations:
 | Function              | Path and parameters |
 | --------------------- | ------------------- |
 |  GET, a basic healthcheck | http://localhost:8085/ |
-|  PUT a policy type | http://localhost:8085/policytypes/{policyTypeId} |
-|  DELETE a policy type | http://localhost:8085/policytypes/{policyTypeId} |
-|  DELETE all policy instances | http://localhost:8085/deleteinstances |
-|  DELETE all policy types | http://localhost:8085/deletetypes |
-|  PUT a status to a policy instance with an enforceStatus parameter only | http://localhost:8085/{policyId}/{enforceStatus} |
-|  PUT a status to a policy instance with both enforceStatus and enforceReason | http://localhost:8085/{policyId}/{enforceStatus}/{enforceReason} |
-|  GET a counter  <br> (counter-name: 'num\_instances', 'num\_types', 'interface' or 'remote\_hosts') | http://localhost:8085/counter/{counter-name} |
+|  GET, a list of all supported interfaces | http://localhost:8085/container\_interfaces |
+|  POST, delete all policy instances | http://localhost:8085/deleteinstances |
+|  POST, full reset | http://localhost:8085/deleteall |
+|  PUT, create/update a policy type | http://localhost:8085/policytype?id=&lt;policytypeid&gt; |
+|  DELETE, delete a policy type | http://localhost:8085/policytype?id=&lt;policytypeid&gt; |
+|  GET, list of policy type id | http://localhost:8085/policytypes |
+|  POST, force a specific response code for an A1 operation | http://localhost:8085/forceresponse?code=&lt;http-code&gt; |
+|  POST, force delayed response of all A1 operations | http://localhost:8085/forcedelay?delay=&lt;seconds&gt; |
+|  PUT, set status and optional reason | http://localhost:8085/status?status=&lt;status&gt;[&amp;reason=&lt;reason&gt;] |
+|  POST, send status for policy | http://localhost:8085/sendstatus?policyid=&lt;policyid&gt; |
+|  POST, deliver data | http://localhost:8085/datadelivery |
+|  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; |
+
 
-The backend server publishes live API documentation at the URL `http://localhost:8085/A1-P/v1/ui/`
 
 # Configuring the simulator
 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.
@@ -154,7 +157,12 @@ file "pass" stores the password when you run the shell script
 Start the a1-interface container without specifing external certificates:
 'docker run -it -p 8085:8085 -p 8185:8185 -e A1\_VERSION=STD\_1.1.3 -e REMOTE_HOSTS_LOGGING=1 a1test'
 
-It will listen to http 8085 port and https 8185 port(using default certificates) at the same time.
+It will listen to https 8185 port(using default certificates) by default.
+Http can be enabled on port 8085 using an environment variable "ALLOW_HTTP".
+If this environment variable is left out or set to false, the nginx server will send
+"444 Connection Closed Without Response" when making a call using http.
+Example command to enable http:
+'docker run -it -p 8085:8085 -p 8185:8185 -e A1\_VERSION=OSC\_2.1.0 -e ALLOW_HTTP=true a1test'
 
 This certificates/key can be overriden by mounting a volume when using "docker run" or "docker-compose"
 In 'docker run', use field:
@@ -163,7 +171,7 @@ In 'docker-compose.yml', use field:
 volumes:
       - ./certificate:/usr/src/app/cert:ro
 
-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 REMOTE_HOSTS_LOGGING=1 --volume /PATH_TO_CERT_DIR/certificate:/usr/src/app/cert a1test'
+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'
 http port 8085 and https port 8185
 The variable for A1 version is set with the '-e' flag.
 With logging of remote host enabled "-e REMOTE_HOSTS_LOGGING=1 "
@@ -173,6 +181,8 @@ With certificate dir mounted  "--volume /PATH_TO_CERT_DIR/certificate:/usr/src/a
 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.
 
 # Start and test of the simulator
+See also 'Basic test and code coverage'.
+
 First, download the sim/a1-interface repo on gerrit:
 git clone "https://gerrit.o-ran-sc.org/oransc/sim/a1-interface"
 
@@ -190,9 +200,19 @@ Note, the default port is 8085 for http and 8185 for https. When running the sim
 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.
 This script runs a number of tests towards the simulator to make sure it works properply.
 
-Only for version 1.1.x-alpha.2
-Let the simulator run in one terminal; in another terminal, one can run the command ./commands.sh nonsecure|secure. It contains the main requests, and will eventually leave the user with a policy type STD\_QoSNudging\_0.2.0 and a policy instance pi1 with an enforceStatus set to NOT\_ENFORCED and an enforce Reason set to 300.
-All the response codes should be 20X, otherwise something went wrong.
+# Basic test and code coverage
+
+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.
+Only http is tested as the internal flask server is only using http (https is part of the webserver inteface).
+
+Navigate to 'near-rt-ric-simulator/tests'. Choose the version to test and use that file for test.
+
+Use 'python3 -m pytest <filename>' to run unit test only with no coverage check
+
+Or use 'coverage run  -m pytest <filename>' to run unit test and produce coverage data.
+List coverage data by 'coverage report -m --include=../../*' - the include flag makes the list to only contain coverage data from the simulator python file.
+
+To use the 'coverage' cmd, coverage need to be installed use 'pip install coverage'
 
 ## License