diff --git a/near-rt-ric-simulator/Dockerfile b/near-rt-ric-simulator/Dockerfile deleted file mode 100644 index b079d730a7e054f3f8bb08e5e909a86d3466cda2..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/Dockerfile +++ /dev/null @@ -1,38 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -FROM python:3.8-slim-buster - -WORKDIR /usr/src/app - -RUN pip install connexion[swagger-ui] - -#install nginx -RUN apt-get update -RUN apt-get install -y nginx=1.14.* -RUN apt-get install -y nginx-extras - -#install curl -RUN apt-get install -y curl - -COPY src src -COPY api api -COPY nginx.conf nginx.conf -COPY certificate /usr/src/app/cert - -RUN chmod +x src/start.sh -CMD src/start.sh ${A1_VERSION} diff --git a/near-rt-ric-simulator/LICENSES.txt b/near-rt-ric-simulator/LICENSES.txt deleted file mode 100644 index 9e98e141bd46ad4daa87326574449b14f3efc55a..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/LICENSES.txt +++ /dev/null @@ -1,30 +0,0 @@ -LICENSES.txt - - -Unless otherwise specified, all software contained herein is licensed -under the Apache License, Version 2.0 (the "Software License"); -you may not use this software except in compliance with the Software -License. You may obtain a copy of the Software License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the Software License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the Software License for the specific language governing permissions -and limitations under the Software License. - - -Unless otherwise specified, all documentation contained herein is licensed -under the Creative Commons License, Attribution 4.0 Intl. (the -"Documentation License"); you may not use this documentation except in -compliance with the Documentation License. You may obtain a copy of the -Documentation License at - -https://creativecommons.org/licenses/by/4.0/ - -Unless required by applicable law or agreed to in writing, documentation -distributed under the Documentation License is distributed on an "AS IS" -BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -implied. See the Documentation License for the specific language governing -permissions and limitations under the Documentation License. diff --git a/near-rt-ric-simulator/api/STD_1.1.3/STD_A1.yaml b/near-rt-ric-simulator/STD_A1.yaml similarity index 96% rename from near-rt-ric-simulator/api/STD_1.1.3/STD_A1.yaml rename to near-rt-ric-simulator/STD_A1.yaml index 71638f4b9d8e35c83abd8a47bd1c2c0387a45cea..c68d1757b2c23f4b7ec7c26ff3567d2f6c2946b0 100644 --- a/near-rt-ric-simulator/api/STD_1.1.3/STD_A1.yaml +++ b/near-rt-ric-simulator/STD_A1.yaml @@ -3,14 +3,14 @@ info: title: 'A1-P Policy Management Service' version: 1.1.3 description: | - API for Policy Management Service. - © 2019, O-RAN Alliance. + API for Policy Management Service Near. + © 2023, S. Kumar Chaudhary. All rights reserved. externalDocs: - description: 'ORAN-WG2.A1.AP-v01.01 A1 interface: Application protocol' - url: 'https://www.o-ran.org/specifications' + description: 'As per ORAN Specification version-1, A1 interface Application protocol' + url: 'https://orandownloadsweb.azurewebsites.net/specifications' servers: - - url: '{apiRoot}/A1-P/v1' + - url: '{apiRoot}/A1AP/v1' variables: apiRoot: default: 'https://example.com' diff --git a/near-rt-ric-simulator/__pycache__/a1.cpython-38.pyc b/near-rt-ric-simulator/__pycache__/a1.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..06b7b5a3b47f807322d2f9e9bcb3e3066bff453a Binary files /dev/null and b/near-rt-ric-simulator/__pycache__/a1.cpython-38.pyc differ diff --git a/near-rt-ric-simulator/__pycache__/main.cpython-38.pyc b/near-rt-ric-simulator/__pycache__/main.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4d2afa16cb4ad4624d825f6e3e6970f9239c8b76 Binary files /dev/null and b/near-rt-ric-simulator/__pycache__/main.cpython-38.pyc differ diff --git a/near-rt-ric-simulator/__pycache__/maincommon.cpython-38.pyc b/near-rt-ric-simulator/__pycache__/maincommon.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..28076139988fa26400390ec78075ec0f76afc894 Binary files /dev/null and b/near-rt-ric-simulator/__pycache__/maincommon.cpython-38.pyc differ diff --git a/near-rt-ric-simulator/__pycache__/utils.cpython-38.pyc b/near-rt-ric-simulator/__pycache__/utils.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..aa958261a4cb89274089866b4a90c1a3b9ab3185 Binary files /dev/null and b/near-rt-ric-simulator/__pycache__/utils.cpython-38.pyc differ diff --git a/near-rt-ric-simulator/__pycache__/var_declaration.cpython-38.pyc b/near-rt-ric-simulator/__pycache__/var_declaration.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a63e44cebc38c86e54bf0e73b8717de5c532d61b Binary files /dev/null and b/near-rt-ric-simulator/__pycache__/var_declaration.cpython-38.pyc differ diff --git a/near-rt-ric-simulator/src/STD_1.1.3/a1.py b/near-rt-ric-simulator/a1.py similarity index 99% rename from near-rt-ric-simulator/src/STD_1.1.3/a1.py rename to near-rt-ric-simulator/a1.py index d7169b19e81b63e076ea82243f01958005dd17aa..5310334ad5d4008963190cc4e6a2100c18845742 100644 --- a/near-rt-ric-simulator/src/STD_1.1.3/a1.py +++ b/near-rt-ric-simulator/a1.py @@ -1,5 +1,5 @@ # ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# Copyright (C) 2023, S. K. Chaudhary, All rights reserved. # ======================================================================== # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/near-rt-ric-simulator/api/OSC_2.1.0/openapi.yaml b/near-rt-ric-simulator/api/OSC_2.1.0/openapi.yaml deleted file mode 100644 index 828a6bf79d335688e2590c181865226174f5bd2f..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/api/OSC_2.1.0/openapi.yaml +++ /dev/null @@ -1,349 +0,0 @@ -# ================================================================================== -# Copyright (c) 2019-2020 Nokia -# Copyright (c) 2018-2020 AT&T Intellectual Property. -# Copyright (c) 2020 Nordix Foundation, Modifications -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ================================================================================== -openapi: 3.0.0 -info: - version: 2.1.0 - title: RIC A1 -paths: - '/a1-p/healthcheck': - get: - description: > - Perform a healthcheck on a1 - tags: - - A1 Mediator - operationId: a1.get_healthcheck - responses: - 200: - description: > - A1 is healthy. - Anything other than a 200 should be considered a1 as failing - - '/a1-p/policytypes': - get: - description: "Get a list of all registered policy type ids" - tags: - - A1 Mediator - operationId: a1.get_all_policy_types - responses: - 200: - description: "list of all registered policy type ids" - content: - application/json: - schema: - type: array - items: - "$ref": "#/components/schemas/policy_type_id" - example: [20000, 20020] - 503: - description: "Potentially transient backend database error. Client should attempt to retry later." - - '/a1-p/policytypes/{policy_type_id}': - parameters: - - name: policy_type_id - in: path - required: true - schema: - "$ref": "#/components/schemas/policy_type_id" - get: - description: > - Get this policy type - tags: - - A1 Mediator - operationId: a1.get_policy_type - responses: - '200': - description: "policy type successfully found" - content: - application/json: - schema: - "$ref": "#/components/schemas/policy_type_schema" - '404': - description: > - policy type not found - '503': - description: "Potentially transient backend database error. Client should attempt to retry later." - delete: - description: > - Delete this policy type. Can only be performed if there are no instances of this type - tags: - - A1 Mediator - operationId: a1.delete_policy_type - responses: - '204': - description: > - policy type successfully deleted - '400': - description: > - Policy type cannot be deleted because there are instances - All instances must be removed before a policy type can be deleted - '404': - description: > - policy type not found - '503': - description: "Potentially transient backend database error. Client should attempt to retry later." - put: - description: > - Create a new policy type . - Replace is not currently allowed; to replace, for now do a DELETE and then a PUT again. - - tags: - - A1 Mediator - operationId: a1.create_policy_type - requestBody: - content: - application/json: - schema: - "$ref": "#/components/schemas/policy_type_schema" - example: - name: admission_control_policy - description: various parameters to control admission of dual connection - policy_type_id: 20000 - create_schema: - $schema: 'http://json-schema.org/draft-07/schema#' - type: object - properties: - enforce: - type: boolean - default: true - window_length: - type: integer - default: 1 - minimum: 1 - maximum: 60 - description: Sliding window length (in minutes) - blocking_rate: - type: number - default: 10 - minimum: 1 - maximum: 100 - description: '% Connections to block' - trigger_threshold: - type: integer - default: 10 - minimum: 1 - description: Minimum number of events in window to trigger blocking - additionalProperties: false - - responses: - '201': - description: "policy type successfully created" - '400': - description: "illegal ID, or object already existed" - '503': - description: "Potentially transient backend database error. Client should attempt to retry later." - - '/a1-p/policytypes/{policy_type_id}/policies': - parameters: - - name: policy_type_id - in: path - required: true - schema: - "$ref": "#/components/schemas/policy_type_id" - get: - description: "get a list of all policy instance ids for this policy type id" - tags: - - A1 Mediator - operationId: a1.get_all_policy_identities - responses: - 200: - description: "list of all policy instance ids for this policy type id" - content: - application/json: - schema: - type: array - items: - "$ref": "#/components/schemas/policy_instance_id" - example: ["3d2157af-6a8f-4a7c-810f-38c2f824bf12", "06911bfc-c127-444a-8eb1-1bffad27cc3d"] - '503': - description: "Potentially transient backend database error. Client should attempt to retry later." - - - '/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}': - parameters: - - name: policy_type_id - in: path - required: true - schema: - "$ref": "#/components/schemas/policy_type_id" - - - name: policy_instance_id - in: path - required: true - schema: - "$ref": "#/components/schemas/policy_instance_id" - - get: - description: > - Retrieve the policy instance - - tags: - - A1 Mediator - operationId: a1.get_policy_instance - responses: - '200': - description: > - The policy instance. - the schema of this object is defined by the create_schema field of the policy type - content: - application/json: - schema: - type: object - '404': - description: > - there is no policy instance with this policy_instance_id or there is no policy type with this policy_type_id - '503': - description: "Potentially transient backend database error. Client should attempt to retry later." - - delete: - description: > - Delete this policy instance - - tags: - - A1 Mediator - operationId: a1.delete_policy_instance - responses: - '202': - description: > - policy instance deletion initiated - '404': - description: > - there is no policy instance with this policy_instance_id or there is no policy type with this policy_type_id - '503': - description: "Potentially transient backend database error. Client should attempt to retry later." - - put: - description: > - Create or replace a policy instance of type policy_type_id. - The schema of the PUT body is defined by the create_schema field of the policy type. - - tags: - - A1 Mediator - operationId: a1.create_or_replace_policy_instance - requestBody: - content: - application/json: - schema: - type: object - description: > - the schema of this object is defined by the create_schema field of the policy type - example: - enforce: true - window_length: 10 - blocking_rate: 20 - trigger_threshold: 10 - - responses: - '202': - description: > - Policy instance creation initiated - '400': - description: > - Bad PUT body for this policy instance - '404': - description: > - There is no policy type with this policy_type_id - '503': - description: "Potentially transient backend database error. Client should attempt to retry later." - - '/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}/status': - parameters: - - name: policy_type_id - in: path - required: true - schema: - "$ref": "#/components/schemas/policy_type_id" - - - name: policy_instance_id - in: path - required: true - schema: - "$ref": "#/components/schemas/policy_instance_id" - - get: - description: > - Retrieve the policy instance status across all handlers of the policy - If this endpoint returns successfully (200), it is either IN EFFECT or NOT IN EFFECT. - IN EFFECT is returned if at least one policy handler in the RIC is implementing the policy - NOT IN EFFECT is returned otherwise - If a policy instance is successfully deleted, this endpoint will return a 404 (not a 200) - tags: - - A1 Mediator - operationId: a1.get_policy_instance_status - responses: - '200': - description: > - successfully retrieved the status - content: - application/json: - schema: - type: object - properties: - instance_status: - type: string - enum: - - IN EFFECT - - NOT IN EFFECT - has_been_deleted: - type: boolean - created_at: - type: string - format: date-time - - '404': - description: > - there is no policy instance with this policy_instance_id or there is no policy type with this policy_type_id - '503': - description: "Potentially transient backend database error. Client should attempt to retry later." - -components: - schemas: - policy_type_schema: - type: object - required: - - name - - description - - policy_type_id - - create_schema - additionalProperties: false - properties: - name: - type: string - description: name of the policy type - description: - type: string - description: description of the policy type - policy_type_id: - description: the integer of the policy type - type: integer - create_schema: - type: object - description: > - jsonschema (following http://json-schema.org/draft-07/schema) of the CREATE payload to be sent to handlers of this policy - - policy_type_id: - description: > - represents a policy type identifier. Currently this is restricted to an integer range. - type: integer - minimum: 1 - maximum: 2147483647 - - policy_instance_id: - description: > - represents a policy instance identifier. UUIDs are advisable but can be any string - type: string - example: "3d2157af-6a8f-4a7c-810f-38c2f824bf12" diff --git a/near-rt-ric-simulator/api/STD_2.0.0/ORAN_A1-p_V2.0.0_api.yaml b/near-rt-ric-simulator/api/STD_2.0.0/ORAN_A1-p_V2.0.0_api.yaml deleted file mode 100644 index 3cb62c5b0817e1af94e217afbca0188622b39c56..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/api/STD_2.0.0/ORAN_A1-p_V2.0.0_api.yaml +++ /dev/null @@ -1,341 +0,0 @@ -openapi: 3.0.0 -info: - title: 'A1-P Policy Management Service' - version: 2.0.0 - description: | - API for Policy Management Service. - © 2020, O-RAN Alliance. - All rights reserved. -externalDocs: - description: 'O-RAN.WG2.A1AP-v02.00 A1 interface: Application Protocol' - url: 'https://www.o-ran.org/specifications' -servers: - - url: '{apiRoot}/A1-P/v2' - variables: - apiRoot: - default: 'https://example.com' - description: 'apiRoot as defined in clause 4.2.1 in ORAN-WG2.A1.AP' -paths: - '/policytypes': - get: - operationId: a1.get_all_policy_types - description: 'Get all policy type identifiers' - tags: - - All Policy Type Identifiers - responses: - 200: - description: 'Array of all policy type identifiers' - content: - application/json: - schema: - type: array - items: - "$ref": "#/components/schemas/PolicyTypeId" - minItems: 0 - 429: - "$ref": "#/components/responses/429-TooManyRequests" - 503: - "$ref": "#/components/responses/503-ServiceUnavailable" - - '/policytypes/{policyTypeId}': - parameters: - - name: policyTypeId - in: path - required: true - schema: - "$ref": "#/components/schemas/PolicyTypeId" - get: - operationId: a1.get_policy_type - description: 'Get the schemas for a policy type' - tags: - - Individual Policy Type - responses: - 200: - description: 'The policy type schemas' - content: - application/json: - schema: - "$ref": "#/components/schemas/PolicyTypeObject" - 404: - "$ref": "#/components/responses/404-NotFound" - 429: - "$ref": "#/components/responses/429-TooManyRequests" - 503: - "$ref": "#/components/responses/503-ServiceUnavailable" - - '/policytypes/{policyTypeId}/policies': - get: - operationId: a1.get_all_policy_identities - description: 'Get all policy identifiers' - tags: - - All Policy Identifiers - parameters: - - name: policyTypeId - in: path - required: true - schema: - "$ref": "#/components/schemas/PolicyTypeId" - responses: - 200: - description: 'Array of all policy identifiers' - content: - application/json: - schema: - type: array - items: - "$ref": "#/components/schemas/PolicyId" - minItems: 0 - 429: - "$ref": "#/components/responses/429-TooManyRequests" - 503: - "$ref": "#/components/responses/503-ServiceUnavailable" - - '/policytypes/{policyTypeId}/policies/{policyId}': - parameters: - - name: policyTypeId - in: path - required: true - schema: - "$ref": "#/components/schemas/PolicyTypeId" - - name: policyId - in: path - required: true - schema: - "$ref": "#/components/schemas/PolicyId" - put: - operationId: a1.put_policy - description: 'Create, or update, a policy' - tags: - - Individual Policy Object - parameters: - - name: notificationDestination - in: query - required: false - schema: - "$ref": "#/components/schemas/NotificationDestination" - requestBody: - required: true - content: - application/json: - schema: - "$ref": "#/components/schemas/PolicyObject" - responses: - 200: - description: 'The policy was updated' - content: - application/json: - schema: - "$ref": "#/components/schemas/PolicyObject" - 201: - description: 'The policy was created' - content: - application/json: - schema: - "$ref": "#/components/schemas/PolicyObject" - headers: - Location: - description: 'Contains the URI of the created policy' - required: true - schema: - type: string - 400: - "$ref": "#/components/responses/400-BadRequest" - 409: - "$ref": "#/components/responses/409-Conflict" - 429: - "$ref": "#/components/responses/429-TooManyRequests" - 503: - "$ref": "#/components/responses/503-ServiceUnavailable" - 507: - "$ref": "#/components/responses/507-InsufficientStorage" - callbacks: - policyStatusNotification: - '{$request.query.notificationDestination}': - post: - description: 'Notify about status changes for this policy' - requestBody: - required: true - content: - application/json: - schema: - "$ref": "#/components/schemas/PolicyStatusObject" - responses: - 204: - description: 'Notification received' - get: - operationId: a1.get_policy - description: 'Query a policy' - tags: - - Individual Policy Object - responses: - 200: - description: 'The requested policy' - content: - application/json: - schema: - "$ref": "#/components/schemas/PolicyObject" - 404: - "$ref": "#/components/responses/404-NotFound" - 409: - "$ref": "#/components/responses/409-Conflict" - 429: - "$ref": "#/components/responses/429-TooManyRequests" - 503: - "$ref": "#/components/responses/503-ServiceUnavailable" - delete: - operationId: a1.delete_policy - description: 'Delete a policy' - tags: - - Individual Policy Object - responses: - 204: - description: 'The policy was deleted' - 404: - "$ref": "#/components/responses/404-NotFound" - 429: - "$ref": "#/components/responses/429-TooManyRequests" - 503: - "$ref": "#/components/responses/503-ServiceUnavailable" - - '/policytypes/{policyTypeId}/policies/{policyId}/status': - parameters: - - name: policyTypeId - in: path - required: true - schema: - "$ref": "#/components/schemas/PolicyTypeId" - - name: policyId - in: path - required: true - schema: - "$ref": "#/components/schemas/PolicyId" - get: - operationId: a1.get_policy_status - description: 'Query a policy status' - tags: - - Individual Policy Status Object - responses: - 200: - description: 'The requested policy status' - content: - application/json: - schema: - "$ref": "#/components/schemas/PolicyStatusObject" - 404: - "$ref": "#/components/responses/404-NotFound" - 409: - "$ref": "#/components/responses/409-Conflict" - 429: - "$ref": "#/components/responses/429-TooManyRequests" - 503: - "$ref": "#/components/responses/503-ServiceUnavailable" - -components: - schemas: - # - # Representation objects - # - PolicyObject: - description: 'A generic policy object that can be used to transport any policy. Additionally, a policy shall be valid according to the schema of its specific policy type.' - type: object - - PolicyStatusObject: - description: 'A generic policy status object that can be used to transport any policy status. Additionally, a policy status shall be valid according to the schema of its specific policy type.' - type: object - - PolicyTypeObject: - description: 'A definition of a policy type, i.e. the schemas for a policy respectively its status' - type: object - properties: - policySchema: - "$ref": "#/components/schemas/JsonSchema" - statusSchema: - "$ref": "#/components/schemas/JsonSchema" - required: - - policySchema - - ProblemDetails: - description: 'A problem detail to carry details in a HTTP response according to RFC 7807' - type: object - properties: - type: - type: string - title: - type: string - status: - type: number - detail: - type: string - instance: - type: string - - # - # Simple data types - # - JsonSchema: - description: 'A JSON schema following http://json-schema.org/draft-07/schema' - type: object - - NotificationDestination: - description: 'A complete callback URI defined according to IETF RFC 3986 where to send notifications' - type: string - - PolicyId: - description: 'Policy identifier assigned by the A1-P Consumer when a policy is created' - type: string - - PolicyTypeId: - description: 'Policy type identifier assigned by the A1-P Provider' - type: string - - responses: - 400-BadRequest: - description: 'Object in payload not properly formulated or not related to the method' - content: - application/problem+json: - schema: - "$ref": "#/components/schemas/ProblemDetails" - - 404-NotFound: - description: 'No resource found at the URI' - content: - application/problem+json: - schema: - "$ref": "#/components/schemas/ProblemDetails" - - 405-MethodNotAllowed: - description: 'Method not allowed for the URI' - content: - application/problem+json: - schema: - "$ref": "#/components/schemas/ProblemDetails" - - 409-Conflict: - description: 'Request could not be processed in the current state of the resource' - content: - application/problem+json: - schema: - "$ref": "#/components/schemas/ProblemDetails" - - 429-TooManyRequests: - description: 'Too many requests have been sent in a given amount of time' - content: - application/problem+json: - schema: - "$ref": "#/components/schemas/ProblemDetails" - - 503-ServiceUnavailable: - description: 'The provider is currently unable to handle the request due to a temporary overload' - content: - application/problem+json: - schema: - "$ref": "#/components/schemas/ProblemDetails" - - 507-InsufficientStorage: - description: 'The method could not be performed on the resource because the provider is unable to store the representation needed to successfully complete the request' - content: - application/problem+json: - schema: - "$ref": "#/components/schemas/ProblemDetails" - - diff --git a/near-rt-ric-simulator/src/STD_2.0.0/callBack.py b/near-rt-ric-simulator/callBack.py similarity index 79% rename from near-rt-ric-simulator/src/STD_2.0.0/callBack.py rename to near-rt-ric-simulator/callBack.py index 0e8e416c341f8e0b8d7218715199e6cf06b64bec..1ae89641d88f5e0e38750d97f9509b3974b31bb7 100644 --- a/near-rt-ric-simulator/src/STD_2.0.0/callBack.py +++ b/near-rt-ric-simulator/callBack.py @@ -1,18 +1,14 @@ # ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# Copyright (C) 2023, S. K. Chaudhary. All rights reserved. # ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============LICENSE_END================================================= + # import json @@ -38,6 +34,6 @@ def statustest(): return Response(json.dumps(data), 200, mimetype='application/json') -port_number = 2223 +port_number = 2222 app.run(port=port_number, host="127.0.0.1", threaded=False) \ No newline at end of file diff --git a/near-rt-ric-simulator/certificate/cert.crt b/near-rt-ric-simulator/certificate/cert.crt deleted file mode 100644 index 51e37a79a508242a2179f0607df61fb795e94a6a..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/certificate/cert.crt +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICljCCAX4CCQDVlvlNzxH9FzANBgkqhkiG9w0BAQsFADANMQswCQYDVQQGEwJT -RTAeFw0yMDA0MjgxOTE2MTNaFw00NzA5MTMxOTE2MTNaMA0xCzAJBgNVBAYTAlNF -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqpnXP5VmOvMPOTWaxWvm -zfSBRvnioEFHoriGld+pW+vvvrma9UiWfxX3GaGFItxuwbwLwqwvR2LDo6wQQpbl -SaNhg89DYD/NZvlRlLNcYOL218LjfFf4xaKVQGBHfT0Ts9JGTbTD/zcR2VS+3DUR -lvLzbNpQ+Rdvwls7wsL1ZblR+1lry9HMGKCrtsYDSOMSyGqE40u1bOYAw1+VMrfp -cK14u9toNPIbvk+HDP5yYnjC4FEp0ai07s3T6YDWHvp0WNIFJHCVFYzYQgS79/2b -8zg4H7ZMQ5XjxcenU6f8Q97nN0VMk46LIutGe/7rYO0uYKrHcJz1qUu1ui96zOVC -DQIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQBGvmFRHuUESpwijkekR0WFBuW6UNE5 -J7cZ9CXm7Mz06jeTAZWoCWVAZjYnpQ/MjvyzFglD9wL+A6LblIU+yNctYwtfspAq -xDYmBKlhsKzlgZ3fyBUlfrM5BFxZR2uu1/4bUU4geEQrI2rYzif3Flj0a55EIeSa -37fa7Acc+nNfy47mAa8Dsog6LHMs+FXGmuMS31c9lc70c9v4jCArctdDn/zKg9A7 -HCwd0+icgyDD+9U9eBhcFreBWyA1tPREWyx0qbhlw43OsVMpB6VM4exLGs/v1e0x -/Nmmsis1o54eu2cLGjr5EYlDmdFD3Dn458r0zFkxg4CE23lRUtFz8d6F ------END CERTIFICATE----- diff --git a/near-rt-ric-simulator/certificate/key.crt b/near-rt-ric-simulator/certificate/key.crt deleted file mode 100644 index 380e145b047c8d1d13dc89ce4f71b8b0afd0cac4..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/certificate/key.crt +++ /dev/null @@ -1,30 +0,0 @@ ------BEGIN ENCRYPTED PRIVATE KEY----- -MIIFHzBJBgkqhkiG9w0BBQ0wPDAbBgkqhkiG9w0BBQwwDgQIoefVgflG3OYCAggA -MB0GCWCGSAFlAwQBKgQQEaJvnbiOIkAwGcyqi6eYCQSCBNDnK9PT/NdGvZAriJAg -VYbqJiCxrqfrfRDAKU4Z4GWFnodzLt2+Xe6iEeOmCkCfs/oVaWx+yIMFzZKY2sq/ -jMmiihJggV+R+hIEXBsVnvqL/nqbchQ7ckhJK8ofXMcpdUdCd8CHylRPNmNNfMsu -o3BbDjKEdCtWMmBWuMWI3DtF0U5Tu5d+nH2ZHpl7YtA7U+N5w3nWBlxoPVXmqsEH -YE8cL0C/b+nFNs81FXKlbIPGNSv51c5YPjS0WQneci2Vj9JMPHWT6VMCaxVlv3js -droG6AxzHH+UpB1Lx4BfVunHR79nmhzmH9mo74rWCiYZ+Kh7DnC26WHrJW/tqJX8 -AvDPIEyVsQ8JQH7omBviVs6NCwoDCwS7jX0NUTy2aWgd4feI+BLwt9SDpEIzyQHt -YXZnwREd2ymDhS0ewvC4fjV82PJHc/yGBlNnXTh4er8hpUPjxTIuNZGaaWP7fcYP -qqPuyfTZvTkKtzHKYsrOk6Fq7M5kMGjFBrGWK3dCNptCXM/R8gaxRqcOvEOb9G5g -ISlC+TZy5T/EUZXJUJEK3gGMrQY4LYCxGm71Wnwe89zmC6bK/z/2XvNts867YKU+ -pODWHcxntJhwlzBRLL56dn2T0OhJEiynUMtpm45O3bHBtRkMjlQ5BhNic0Tog6fb -757gJnbnSNFB5mCSkB09iPt8LEEamQGYUGbXE+0mPTdqwaAaKbz4Gh1yV3T9alh+ -AxJu/YaB52mmf2KdFVUuPBVzSMawYvp6hXHIgzJ6tb/GmYFI7P21RBQfVR/fKuJx -pQMgRclNdYCAC0VCqHxSZdO0Lu7Sd/SWybCCNbfw+0tEO1fDlZwWbVQiF79AL62J -VvaWX3pX8IF227astnyMxkCH6MB4fvu7CSZKTYgdkXekP81Ck5ZxStRcSj4jOvYj -xuMqIvGzy16JRG1aGE1jpzunYBdDKiKKOIphH+jBK3NPk3b7wkTLxi7IkdS4MUf1 -e5E50W/Xx3wUlfyBvuc1TQy/1Moh+HvXIIG3JHU9MjfPkYwHvDITWIdXJb1vSEAE -opi+zNt7C5A+mC1/CC2MCjHk+g+cqpLcSFmv9MXnhg8bHmuhSjaXWChD8sj/S7H4 -Kazc87gikvQguxFv+bFiVQ6+GdPcGvsrnh+UFn/kfHUM8wt2AWnrKc8OLWXbs8Ge -0bCqXo1uy2sZEv558BGRKI35c/F4sovf0FLe8+M+UHPqOeYVaxSt9accXTHK2ajN -IEEKuL5v0BDNTQqo0uDw0HJyKW+L55UpJQ9nNSdVjtQUnPJtbWlVg0V2Q7mnVOSF -GRMqBtu+U9sejR03odkURjDFULntSw80M+U0LC+ceOrESLkO0AK2Yub1+IhR3OBh -jICv3eTZbqZ27ltZrsyDTAYoRVnTvPQwSZoUJ6cQS6XgLa3QitDcj+Zqch9z7sV2 -ydkEHEbLXPIt/sQyASluKm5j1tHJVtzwezb5GO54WYwdpy3MmZ3VhXsagJc9oLHX -MtsDGZR0hXMgzPp49leBhcieWW6fWXAZKt2oa64eI/12i2wSTjNsxPfsu45tJYXO -GAPL0OYBKeVLi1Pfa3kCLqlMDAyC4GzTScWXad5/FEeo189JU1aGcJn7Gn7Ao805 -wuOOs1TQk+KHvAFDEGkkJEM0lg== ------END ENCRYPTED PRIVATE KEY----- diff --git a/near-rt-ric-simulator/certificate/pass b/near-rt-ric-simulator/certificate/pass deleted file mode 100644 index 30d74d258442c7c65512eafab474568dd706c430..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/certificate/pass +++ /dev/null @@ -1 +0,0 @@ -test \ No newline at end of file diff --git a/near-rt-ric-simulator/container-tag.yaml b/near-rt-ric-simulator/container-tag.yaml deleted file mode 100644 index 51b0588d57b0dac58f506d83b861eda3b8fa6c26..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/container-tag.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -tag: 2.1.0 diff --git a/near-rt-ric-simulator/src/STD_1.1.3/main.py b/near-rt-ric-simulator/main.py similarity index 96% rename from near-rt-ric-simulator/src/STD_1.1.3/main.py rename to near-rt-ric-simulator/main.py index 5742791263a88a0994b47d49cf6e2d2e98b8a05f..0d9f00a361f876392405ee8c380fd80961344d26 100644 --- a/near-rt-ric-simulator/src/STD_1.1.3/main.py +++ b/near-rt-ric-simulator/main.py @@ -1,5 +1,5 @@ # ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# Copyright (C) 2023, S. K. Chaudhary. All rights reserved. # ======================================================================== # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -33,13 +33,13 @@ check_apipath() -app = connexion.App(__name__, specification_dir=apipath) +app = connexion.App(__name__) #Check alive function @app.route('/', methods=['GET']) def test(): - return Response("OK", 200, mimetype=TEXT_PLAIN) + return Response("This is connection Test and the status is OK", 200, mimetype=TEXT_PLAIN) #Return the current and all supported yamls for the this container @app.route('/container_interfaces', methods=['GET']) @@ -176,4 +176,4 @@ def getcounter(countername): app.add_api('STD_A1.yaml') if __name__ == '__main__': - app.run(port=port_number, host="127.0.0.1", threaded=False) \ No newline at end of file + app.run(port=port_number, host="127.0.0.1", threaded=False) diff --git a/near-rt-ric-simulator/src/common/maincommon.py b/near-rt-ric-simulator/maincommon.py similarity index 86% rename from near-rt-ric-simulator/src/common/maincommon.py rename to near-rt-ric-simulator/maincommon.py index 7dc8024779842ca3d545cbb4bb8edd448d431200..b04ef41dc64f47a0dbb9950155db059c3a7fdd1f 100644 --- a/near-rt-ric-simulator/src/common/maincommon.py +++ b/near-rt-ric-simulator/maincommon.py @@ -1,12 +1,7 @@ # ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# Copyright (C) 2023, S. K. Chaudhary. All rights reserved. # ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,7 +18,7 @@ import ssl #Must exist -apipath=os.environ['APIPATH'] +apipath='127.0.0.1:2222' #May exist remote_hosts_logging=os.getenv('REMOTE_HOSTS_LOGGING') diff --git a/near-rt-ric-simulator/nginx.conf b/near-rt-ric-simulator/nginx.conf deleted file mode 100644 index 3087a3fe5625297edaed20b413c89e85f740b5f8..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/nginx.conf +++ /dev/null @@ -1,122 +0,0 @@ -user www-data; -worker_processes auto; -pid /run/nginx.pid; -include /etc/nginx/modules-enabled/*.conf; - -env ALLOW_HTTP; - -events { - worker_connections 768; - # multi_accept on; -} - -http { - - ## - # Basic Settings - ## - - sendfile on; - tcp_nopush on; - tcp_nodelay on; - keepalive_timeout 65; - types_hash_max_size 2048; - # server_tokens off; - - # server_names_hash_bucket_size 64; - # server_name_in_redirect off; - - include /etc/nginx/mime.types; - default_type application/octet-stream; - - perl_set $allow_http 'sub { return $ENV{"ALLOW_HTTP"}; }'; - - server { # simple reverse-proxy - listen 8085; - listen [::]:8085; - server_name localhost; - if ($allow_http != true) { - return 444; - } - - # serve dynamic requests - location / { - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_pass http://localhost:2222; - } - } - - server { # simple reverse-proxy - listen 8185 ssl; - listen [::]:8185 ssl; - server_name localhost; - ssl_certificate /usr/src/app/cert/cert.crt; - ssl_certificate_key /usr/src/app/cert/key.crt; - ssl_password_file /usr/src/app/cert/pass; - - # serve dynamic requests - location / { - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_pass http://localhost:2222; - } - } - ## - # SSL Settings - ## - - ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE - ssl_prefer_server_ciphers on; - - ## - # Logging Settings - ## - - access_log /var/log/nginx/access.log; - error_log /var/log/nginx/error.log; - - ## - # Gzip Settings - ## - - gzip on; - - # gzip_vary on; - # gzip_proxied any; - # gzip_comp_level 6; - # gzip_buffers 16 8k; - # gzip_http_version 1.1; - # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; - - ## - # Virtual Host Configs - ## - - include /etc/nginx/conf.d/*.conf; - include /etc/nginx/sites-enabled/*; -} - - -#mail { -# # See sample authentication script at: -# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript -# -# # auth_http localhost/auth.php; -# # pop3_capabilities "TOP" "USER"; -# # imap_capabilities "IMAP4rev1" "UIDPLUS"; -# -# server { -# listen localhost:110; -# protocol pop3; -# proxy on; -# } -# -# server { -# listen localhost:143; -# protocol imap; -# proxy on; -# } -#} \ No newline at end of file diff --git a/near-rt-ric-simulator/src/OSC_2.1.0/.gitignore b/near-rt-ric-simulator/src/OSC_2.1.0/.gitignore deleted file mode 100644 index bee8a64b79a99590d5303307144172cfe824fbf7..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/src/OSC_2.1.0/.gitignore +++ /dev/null @@ -1 +0,0 @@ -__pycache__ diff --git a/near-rt-ric-simulator/src/OSC_2.1.0/a1.py b/near-rt-ric-simulator/src/OSC_2.1.0/a1.py deleted file mode 100644 index 6ec59ff13a49e9141e91e15b0352eec3d394bd16..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/src/OSC_2.1.0/a1.py +++ /dev/null @@ -1,275 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -import json -import datetime -import time - -from datetime import datetime -from connexion import NoContent -from flask import Flask, request, Response -from jsonschema import validate -from var_declaration import policy_instances, policy_types, policy_status, policy_fingerprint, forced_settings, hosts_set -from utils import calcFingerprint -from maincommon import extract_host_name - -#Constsants -APPL_JSON='application/json' - -# API Function: Health check -def get_healthcheck(): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - return (None, 200) - -# API Function: Get all policy type ids -def get_all_policy_types(): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - res = list(policy_instances.keys()) - res = list(map(int, res)) - return (res, 200) - -# API Function: Get a policy type -def get_policy_type(policy_type_id): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - policy_type_id=str(policy_type_id) - - if (policy_type_id not in policy_types.keys()): - return (None, 404) - - return Response(json.dumps(policy_types[policy_type_id]), 200, mimetype=APPL_JSON) - -# API Function: Delete a policy type -def delete_policy_type(policy_type_id): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - policy_type_id=str(policy_type_id) - - if (policy_type_id not in policy_instances.keys()): - return (None, 404) - - if (len(policy_instances[policy_type_id]) > 0): - return (None, 400) - - del policy_instances[policy_type_id] - del policy_types[policy_type_id] - - return (None, 204) - - -# API Function: Create a policy type -def create_policy_type(policy_type_id): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - try: - int(policy_type_id) - except Exception: - return Response("The policy type id is not an int", 400, mimetype='text/plain') - - policy_type_id=str(policy_type_id) - - if (policy_type_id in policy_instances.keys()): - if (len(policy_instances[policy_type_id]) > 0): - return (None, 400) - - try: - data = request.data - data = json.loads(data) - except Exception: - return (None, 400) - - if (('name' not in data.keys()) or ('description' not in data.keys()) or ('policy_type_id' not in data.keys()) or ('create_schema' not in data.keys())): - return (None, 400) - - if (policy_type_id not in policy_instances.keys()): - policy_instances[policy_type_id]={} - - policy_types[policy_type_id]=data - - return (None, 201) - - -# API Function: Get all policy ids for a type -def get_all_policy_identities(policy_type_id): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - policy_type_id=str(policy_type_id) - - if (policy_type_id not in policy_instances.keys()): - return (None, 404) - return (list(policy_instances[policy_type_id].keys()), 200) - -# API Function: Get a policy instance -def get_policy_instance(policy_type_id, policy_instance_id): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - policy_type_id=str(policy_type_id) - - if (policy_type_id not in policy_instances.keys()): - return (None, 404) - - if (policy_instance_id not in policy_instances[policy_type_id].keys()): - return (None, 404) - - return Response(json.dumps(policy_instances[policy_type_id][policy_instance_id]), 200, mimetype=APPL_JSON) - -# API function: Delete a policy -def delete_policy_instance(policy_type_id, policy_instance_id): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - policy_type_id=str(policy_type_id) - - if (policy_type_id not in policy_instances.keys()): - return (None, 404) - - if (policy_instance_id not in policy_instances[policy_type_id].keys()): - return (None, 404) - - fp_previous=calcFingerprint(policy_instances[policy_type_id][policy_instance_id]) - del policy_fingerprint[fp_previous] - del policy_instances[policy_type_id][policy_instance_id] - del policy_status[policy_instance_id] - - return (None, 202) - -# API function: Create/update a policy -def create_or_replace_policy_instance(policy_type_id, policy_instance_id): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - policy_type_id=str(policy_type_id) - - if (policy_type_id not in policy_instances.keys()): - return (None, 404) - - try: - data = request.data - data = json.loads(data) - except Exception: - return (None, 400) - - try: - validate(instance=data, schema=policy_types[policy_type_id]['create_schema']) - except Exception: - return (None, 400) - - fp_previous=None - if policy_instance_id in policy_instances[policy_type_id].keys(): - retcode=200 - fp_previous=calcFingerprint(policy_instances[policy_type_id][policy_instance_id]) - else: - if (policy_instance_id in policy_fingerprint.values()): - return (None, 400) - - fp=calcFingerprint(data) - if (fp in policy_fingerprint.keys()): - p_id=policy_fingerprint[fp] - if (p_id != policy_instance_id): - return (None, 400) - - if (fp_previous is not None): - del policy_fingerprint[fp_previous] - - policy_fingerprint[fp]=policy_instance_id - - policy_instances[policy_type_id][policy_instance_id]=data - ps={} - ps["instance_status"] = "NOT IN EFFECT" - ps["has_been_deleted"] = "false" - ps["created_at"] = str(datetime.now().strftime("%m/%d/%Y, %H:%M:%S")) - policy_status[policy_instance_id]=ps - - return (None, 202) - -# API function: Get policy status -def get_policy_instance_status(policy_type_id, policy_instance_id): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - policy_type_id=str(policy_type_id) - if (policy_type_id not in policy_instances.keys()): - return (None, 404) - - if (policy_instance_id not in policy_instances[policy_type_id].keys()): - return (None, 404) - - return Response(json.dumps(policy_status[policy_instance_id]), 200, mimetype=APPL_JSON) - -# Helper: Create a response object if forced http response code is set -def get_forced_response(): - - response_code=forced_settings['code'] - if (response_code is not None): - forced_settings['code'] = None - return (None, response_code) - return None - -# Helper: Delay if delayed response code is set -def do_delay(): - - if (forced_settings['delay'] is not None): - try: - val=int(forced_settings['delay']) - time.sleep(val) - except Exception: - return - return - -# Helper: Check if response shall be delayed or a forced response shall be sent -def check_modified_response(): - do_delay() - return get_forced_response() \ No newline at end of file diff --git a/near-rt-ric-simulator/src/OSC_2.1.0/main.py b/near-rt-ric-simulator/src/OSC_2.1.0/main.py deleted file mode 100644 index e0766d86468f965a3993a8a3aae817d720073c88..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/src/OSC_2.1.0/main.py +++ /dev/null @@ -1,222 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -import connexion -import json -import sys -import os -import requests - -from pathlib import Path -from flask import Flask, escape, request, Response, jsonify -from jsonschema import validate -from var_declaration import policy_instances, policy_types, policy_status, policy_fingerprint, forced_settings, hosts_set -from maincommon import check_apipath, apipath, get_supported_interfaces_response, extract_host_name -from time import sleep - -#Constants -TEXT_PLAIN='text/plain' - -check_apipath() - -app = connexion.FlaskApp(__name__, specification_dir=apipath) - -#Check alive function -@app.route('/', methods=['GET']) -def test(): - - return Response("OK", 200, mimetype=TEXT_PLAIN) - -@app.route('/ip', methods=['GET']) -def get_ip(): - if request.environ.get('HTTP_X_FORWARDED_FOR') is None: - return jsonify({'ip': request.environ['REMOTE_ADDR']}), 200 - else: - return jsonify({'ip': request.environ['HTTP_X_FORWARDED_FOR']}), 200 - -#Return the current and all supported yamls for the this container -@app.route('/container_interfaces', methods=['GET']) -def container_interfaces(): - - return get_supported_interfaces_response() - -#Delete all created instances and status -@app.route('/deleteinstances', methods=['POST']) -def deleteinstances(): - - for i in policy_instances.keys(): - policy_instances[i]={} - - policy_status.clear() - forced_settings.clear() - forced_settings['code']=None - forced_settings['delay']=None - policy_fingerprint.clear() - return Response("All policy instances deleted", 200, mimetype=TEXT_PLAIN) - -#Delete all - all reset -@app.route('/deleteall', methods=['POST']) -def deleteall(): - - policy_instances.clear() - policy_types.clear() - policy_status.clear() - forced_settings['code']=None - forced_settings['delay']=None - policy_fingerprint.clear() - return Response("All policy instances and types deleted", 200, mimetype=TEXT_PLAIN) - -#Load a policy type -@app.route('/policytype', methods=['PUT']) -def policytype(): - - policy_type_id=request.args.get('id') - if (policy_type_id is None): - return Response('Parameter <id> missing in request', status=400, mimetype=TEXT_PLAIN) - try: - int(policy_type_id) - except Exception: - return Response("The policy type id is not an int", 400, mimetype=TEXT_PLAIN) - try: - data = request.data - data = json.loads(data) - except Exception: - return Response("The policy type is corrupt or missing", 400, mimetype=TEXT_PLAIN) - - if ('name' not in data.keys() or 'description' not in data.keys() or 'policy_type_id' not in data.keys() or'create_schema' not in data.keys()): - return Response("The policy type missing atributes", 400, mimetype=TEXT_PLAIN) - - retcode=201 - if (policy_type_id in policy_types.keys()): - retcode=200 - if (len(policy_instances[policy_type_id]) > 0): - return Response("The policy type already exists and instances exists", 400, mimetype=TEXT_PLAIN) - - policy_types[policy_type_id]=data - policy_instances[policy_type_id]={} - return Response("Policy type " + policy_type_id + " is OK.", retcode, mimetype=TEXT_PLAIN) - -#Delete a policy type -@app.route('/policytype', methods=['DELETE']) -def del_policytype(): - - policy_type_id=request.args.get('id') - if (policy_type_id is None): - return Response('Parameter <id> missing in request', status=400, mimetype=TEXT_PLAIN) - try: - int(policy_type_id) - except Exception: - return Response("The policy type id is not an int", 400, mimetype=TEXT_PLAIN) - - if (policy_type_id in policy_types.keys()): - if (len(policy_instances[policy_type_id]) > 0): - return Response("The policy type already exists and instances exists", 400, mimetype=TEXT_PLAIN) - - del policy_types[policy_type_id] - del policy_instances[policy_type_id] - return Response("Policy type " + policy_type_id + " is OK.", 204, mimetype=TEXT_PLAIN) - - return Response("Policy type " + policy_type_id + " not found.", 204, mimetype=TEXT_PLAIN) - - -# Get all policy type ids -@app.route('/policytypes', methods=['GET']) -def get_policytype_ids(): - - return (json.dumps(list(policy_instances.keys())), 200) - -#Set force response for one A1 response -#/forceresponse?code=<responsecode> -@app.route('/forceresponse', methods=['POST']) -def forceresponse(): - - try: - forced_settings['code']=int(request.args.get('code')) - except Exception: - forced_settings['code']=None - return Response("Force response code: " + str(forced_settings['code']) + " set for one single A1 response", 200, mimetype=TEXT_PLAIN) - -#Set force delay response, in seconds, for all A1 responses -#/froceesponse?delay=<seconds> -@app.route('/forcedelay', methods=['POST']) -def forcedelay(): - - try: - forced_settings['delay']=int(request.args.get('delay')) - except Exception: - forced_settings['delay']=None - return Response("Force delay: " + str(forced_settings['delay']) + " sec set for all A1 responses", 200, mimetype=TEXT_PLAIN) - - -#Set status and reason -#/status?policyid=<policyid>&status=<status>[&deleted=<boolean>][&created_at=<timestamp>] -@app.route('/status', methods=['PUT']) -def setstatus(): - - policy_id=request.args.get('policyid') - if (policy_id is None): - return Response('Parameter <policyid> missing in request', status=400, mimetype=TEXT_PLAIN) - - if policy_id not in policy_status.keys(): - return Response('Policyid: '+policy_id+' not found.', status=404, mimetype=TEXT_PLAIN) - status=request.args.get('status') - if (status is None): - return Response('Parameter <status> missing in request', status=400, mimetype=TEXT_PLAIN) - policy_status[policy_id]["instance_status"]=status - msg = "Status set to "+status - deleted_policy=request.args.get('deleted') - if (deleted_policy is not None): - policy_status[policy_id]["has_been_deleted"]=deleted_policy - msg = msg + " and has_been_deleted set to "+deleted_policy - created_at = request.args.get('created_at') - if (created_at is not None): - policy_status[policy_id]["created_at"]=created_at - msg = msg + " and created_at set to "+created_at - msg=msg + " for policy: " + policy_id - return Response(msg, 200, mimetype=TEXT_PLAIN) - - -#Metrics function -#Get a named counter -@app.route('/counter/<string:countername>', methods=['GET']) -def getcounter(countername): - - if (countername == "num_instances"): - return Response(str(len(policy_fingerprint)), 200, mimetype=TEXT_PLAIN) - elif (countername == "num_types"): - return Response(str(len(policy_instances)),200, mimetype=TEXT_PLAIN) - elif (countername == "interface"): - p=Path(os.getcwd()) - pp=p.parts - return Response(str(pp[len(pp)-1]),200, mimetype=TEXT_PLAIN) - elif (countername == "remote_hosts"): - hosts=",".join(hosts_set) - return str(hosts),200 - elif (countername == "datadelivery"): - return Response(str(0),200, mimetype=TEXT_PLAIN) - else: - return Response("Counter name: "+countername+" not found.",404, mimetype=TEXT_PLAIN) - -port_number = 2222 -if len(sys.argv) >= 2 : - if isinstance(sys.argv[1], int): - port_number = sys.argv[1] - -app.add_api('openapi.yaml') - -if __name__ == '__main__': - app.run(port=port_number, host="127.0.0.1", threaded=False) \ No newline at end of file diff --git a/near-rt-ric-simulator/src/OSC_2.1.0/var_declaration.py b/near-rt-ric-simulator/src/OSC_2.1.0/var_declaration.py deleted file mode 100644 index 5fe04698061aae6ab743b5a3ce5a5230e88dc37b..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/src/OSC_2.1.0/var_declaration.py +++ /dev/null @@ -1,25 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -policy_types={} -policy_instances={} -policy_status={} -forced_settings={} -forced_settings['code']=None -forced_settings['delay']=None -policy_fingerprint={} -hosts_set=set() diff --git a/near-rt-ric-simulator/src/STD_1.1.3/.gitignore b/near-rt-ric-simulator/src/STD_1.1.3/.gitignore deleted file mode 100644 index bee8a64b79a99590d5303307144172cfe824fbf7..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/src/STD_1.1.3/.gitignore +++ /dev/null @@ -1 +0,0 @@ -__pycache__ diff --git a/near-rt-ric-simulator/src/STD_1.1.3/callBack.py b/near-rt-ric-simulator/src/STD_1.1.3/callBack.py deleted file mode 100644 index 0e8e416c341f8e0b8d7218715199e6cf06b64bec..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/src/STD_1.1.3/callBack.py +++ /dev/null @@ -1,43 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -import json -from flask import Flask, request, Response - -app = Flask(__name__) #NOSONAR - -#Check alive function -@app.route('/', methods=['GET']) -def test(): - - return Response("OK", 200, mimetype='text/plain') - -#Receive status (only for testing callbacks) -#/statustest -@app.route('/statustest', methods=['POST', 'PUT']) -def statustest(): - try: - data = request.data - data = json.loads(data) - except Exception: - return Response("The status data is corrupt or missing.", 400, mimetype='text/plain') - - return Response(json.dumps(data), 200, mimetype='application/json') - -port_number = 2223 - -app.run(port=port_number, host="127.0.0.1", threaded=False) \ No newline at end of file diff --git a/near-rt-ric-simulator/src/STD_2.0.0/.gitignore b/near-rt-ric-simulator/src/STD_2.0.0/.gitignore deleted file mode 100644 index bee8a64b79a99590d5303307144172cfe824fbf7..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/src/STD_2.0.0/.gitignore +++ /dev/null @@ -1 +0,0 @@ -__pycache__ diff --git a/near-rt-ric-simulator/src/STD_2.0.0/a1.py b/near-rt-ric-simulator/src/STD_2.0.0/a1.py deleted file mode 100644 index c4aa4ca6260d3648320b1b20bc7c712546ecaa6a..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/src/STD_2.0.0/a1.py +++ /dev/null @@ -1,271 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -import copy -import datetime -import json -import logging -import collections -import time - -from connexion import NoContent -from flask import Flask, escape, request, Response, make_response -from jsonschema import validate -from var_declaration import policy_instances, policy_types, policy_status, callbacks, forced_settings, policy_fingerprint, hosts_set -from utils import calcFingerprint -from maincommon import check_apipath, apipath, get_supported_interfaces_response, extract_host_name - -#Constsants -APPL_JSON='application/json' -APPL_PROB_JSON='application/problem+json' - -# API Function: Get all policy type ids -def get_all_policy_types(): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - res = list(policy_types.keys()) - return (res, 200) - -# API Function: Get a policy type -def get_policy_type(policyTypeId): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - policy_type_id=str(policyTypeId) - - if (policy_type_id not in policy_types.keys()): - pjson=create_problem_json(None, "The policy type does not exist.", 404, None, policy_type_id) - return Response(json.dumps(pjson), 404, mimetype=APPL_PROB_JSON) - - return Response(json.dumps(policy_types[policy_type_id]), 200, mimetype=APPL_JSON) - -# API Function: Get all policy ids -def get_all_policy_identities(policyTypeId): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - policy_type_id=str(policyTypeId) - - if (policy_type_id not in policy_types.keys()): - pjson=create_problem_json(None, "The policy type does not exist.", 404, None, policy_type_id) - return Response(json.dumps(pjson), 404, mimetype=APPL_PROB_JSON) - - return (list(policy_instances[policy_type_id].keys()), 200) - -# API Function: Create or update a policy -def put_policy(policyTypeId, policyId): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - policy_type_id=str(policyTypeId) - policy_id=str(policyId) - - if (policy_type_id not in policy_types.keys()): - pjson=create_problem_json(None, "The policy type does not exist.", 404, None, policy_id) - return Response(json.dumps(pjson), 404, mimetype=APPL_PROB_JSON) - - try: - data = request.data - data = json.loads(data) - except Exception: - pjson=create_problem_json(None, "The policy is corrupt or missing.", 400, None, policy_id) - return Response(json.dumps(pjson), 400, mimetype=APPL_PROB_JSON) - - try: - validate(instance=data, schema=policy_types[policy_type_id]['policySchema']) - except Exception: - return (None, 400) - - fp_previous=None - retcode=201 - if policy_id in policy_instances[policy_type_id].keys(): - retcode=200 - fp_previous=calcFingerprint(policy_instances[policy_type_id][policy_id]) - else: - if (policy_id in policy_fingerprint.values()): - return (None, 400) - - fp=calcFingerprint(data) - if (fp in policy_fingerprint.keys()): - p_id=policy_fingerprint[fp] - if (p_id != policy_id): - pjson=create_problem_json(None, "Duplicate, the policy json already exists.", 400, None, policy_id) - return Response(json.dumps(pjson), 400, mimetype=APPL_PROB_JSON) - - if (fp_previous is not None): - del policy_fingerprint[fp_previous] - - policy_fingerprint[fp]=policy_id - - noti=request.args.get('notificationDestination') - callbacks[policy_id]=noti - - policy_instances[policy_type_id][policy_id]=data - - if (policy_types[policy_type_id]['statusSchema'] is not None): - ps = {} - ps["enforceStatus"] = "" - ps["enforceReason"] = "" - policy_status[policy_id] = ps - - if (retcode == 200): - return Response(json.dumps(data), 200, mimetype=APPL_JSON) - else: - headers={} - headers['Location']='/A1-P/v2/policytypes/' + policy_type_id + '/policies/' + policy_id - return Response(json.dumps(data), 201, headers=headers, mimetype=APPL_JSON) - -# API Function: Get a policy -def get_policy(policyTypeId, policyId): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - policy_type_id=str(policyTypeId) - policy_id=str(policyId) - - if (policy_type_id not in policy_types.keys()): - pjson=create_problem_json(None, "The policy type does not exist.", 404, None, policy_id) - return Response(json.dumps(pjson), 404, mimetype=APPL_PROB_JSON) - - if (policy_id not in policy_instances[policy_type_id].keys()): - pjson=create_problem_json(None, "The requested policy does not exist.", 404, None, policy_id) - return Response(json.dumps(pjson), 404, mimetype=APPL_PROB_JSON) - - return Response(json.dumps(policy_instances[policy_type_id][policy_id]), 200, mimetype=APPL_JSON) - - -# API Function: Delete a policy -def delete_policy(policyTypeId, policyId): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - policy_type_id=str(policyTypeId) - policy_id=str(policyId) - - if (policy_type_id not in policy_types.keys()): - pjson=create_problem_json(None, "The policy type does not exist.", 404, None, policy_id) - return Response(json.dumps(pjson), 404, mimetype=APPL_PROB_JSON) - - if (policy_id not in policy_instances[policy_type_id].keys()): - pjson=create_problem_json(None, "The requested policy does not exist.", 404, None, policy_id) - return Response(json.dumps(pjson), 404, mimetype=APPL_PROB_JSON) - - fp_previous=calcFingerprint(policy_instances[policy_type_id][policy_id]) - policy_fingerprint.pop(fp_previous) - policy_instances[policy_type_id].pop(policy_id) - policy_status.pop(policy_id) - callbacks.pop(policy_id) - return Response('', 204, mimetype=APPL_JSON) - - -# API Function: Get status for a policy -def get_policy_status(policyTypeId, policyId): - - extract_host_name(hosts_set, request) - - if ((r := check_modified_response()) is not None): - return r - - policy_type_id=str(policyTypeId) - policy_id=str(policyId) - - if (policy_type_id not in policy_types.keys()): - pjson=create_problem_json(None, "The policy type does not exist.", 404, None, policy_id) - return Response(json.dumps(pjson), 404, mimetype=APPL_PROB_JSON) - - if (policy_id not in policy_instances[policy_type_id].keys()): - pjson=create_problem_json(None, "The requested policy does not exist.", 404, None, policy_id) - return Response(json.dumps(pjson), 404, mimetype=APPL_PROB_JSON) - - return Response(json.dumps(policy_status[policy_id]), status=200, mimetype=APPL_JSON) - -# Helper: Create a response object if forced http response code is set -def get_forced_response(): - if (forced_settings['code'] is not None): - pjson=create_error_response(forced_settings['code']) - forced_settings['code']=None - return Response(json.dumps(pjson), pjson['status'], mimetype=APPL_PROB_JSON) - return None - -# Helper: Delay if delayed response code is set -def do_delay(): - if (forced_settings['delay'] is not None): - try: - val=int(forced_settings['delay']) - time.sleep(val) - except Exception: - return - -# Helper: Check if response shall be delayed or a forced response shall be sent -def check_modified_response(): - do_delay() - return get_forced_response() - -# Helper: Create a problem json object -def create_problem_json(type_of, title, status, detail, instance): - - error = {} - if type_of is not None: - error["type"] = type_of - if title is not None: - error["title"] = title - if status is not None: - error["status"] = status - if detail is not None: - error["detail"] = detail - if instance is not None: - error["instance"] = instance - return error - -# Helper: Create a problem json based on a generic http response code -def create_error_response(code): - - if code == '400': - return(create_problem_json(None, "Bad request", 400, "Object in payload not properly formulated or not related to the method", None)) - elif code == '404': - return(create_problem_json(None, "Not found", 404, "No resource found at the URI", None)) - elif code == '405': - return(create_problem_json(None, "Method not allowed", 405, "Method not allowed for the URI", None)) - elif code == '409': - return(create_problem_json(None, "Conflict", 409, "Request could not be processed in the current state of the resource", None)) - elif code == '429': - return(create_problem_json(None, "Too many requests", 429, "Too many requests have been sent in a given amount of time", None)) - elif code == '507': - return(create_problem_json(None, "Insufficient storage", 507, "The method could not be performed on the resource because the provider is unable to store the representation needed to successfully complete the request", None)) - elif code == '503': - return(create_problem_json(None, "Service unavailable", 503, "The provider is currently unable to handle the request due to a temporary overload", None)) - else: - return(create_problem_json(None, "Unknown", code, "Not implemented response code", None)) diff --git a/near-rt-ric-simulator/src/STD_2.0.0/main.py b/near-rt-ric-simulator/src/STD_2.0.0/main.py deleted file mode 100644 index dcf835e5aa4ad497195fcfa3b76a18c5552ac028..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/src/STD_2.0.0/main.py +++ /dev/null @@ -1,255 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -import connexion -import json -import sys -import os -import requests - - -from pathlib import Path -from flask import Flask, escape, request, Response -from jsonschema import validate -from var_declaration import policy_instances, policy_types, policy_status, callbacks, forced_settings, policy_fingerprint, hosts_set, data_delivery_counter -from maincommon import check_apipath, apipath, get_supported_interfaces_response, extract_host_name - -#Constants -TEXT_PLAIN='text/plain' - -check_apipath() - -app = connexion.App(__name__, specification_dir=apipath) - -#Check alive function -@app.route('/', methods=['GET']) -def test(): - - return Response("OK", 200, mimetype=TEXT_PLAIN) - -#Return the current and all supported yamls for the this container -@app.route('/container_interfaces', methods=['GET']) -def container_interfaces(): - - return get_supported_interfaces_response() - -#Delete all created instances and status -@app.route('/deleteinstances', methods=['POST']) -def delete_instances(): - - for i in policy_instances.keys(): - policy_instances[i]={} - policy_status.clear() - callbacks.clear() - forced_settings['code']=None - forced_settings['delay']=None - policy_fingerprint.clear() - return Response("All policy instances deleted", 200, mimetype=TEXT_PLAIN) - -#Delete all - all reset -#(same as delete_instances but kept to in order to use the same interface as other version of the simulator) -@app.route('/deleteall', methods=['POST']) -def delete_all(): - - policy_instances.clear() - policy_types.clear() - policy_status.clear() - callbacks.clear() - forced_settings['code']=None - forced_settings['delay']=None - policy_fingerprint.clear() - return Response("All policy instances and types deleted", 200, mimetype=TEXT_PLAIN) - -#Load a policy type -@app.route('/policytype', methods=['PUT']) -def policytype(): - - policy_type_id=request.args.get('id') - if (policy_type_id is None): - return Response('Parameter <id> missing in request', status=400, mimetype=TEXT_PLAIN) - - try: - data = request.data - data = json.loads(data) - except Exception: - return Response("The policy type is corrupt or missing", 400, mimetype=TEXT_PLAIN) - - if ('policySchema' not in data.keys()): - return Response("The policy type atribute policySchema is missing", 400, mimetype=TEXT_PLAIN) - - retcode=201 - if (policy_type_id in policy_types.keys()): - retcode=200 - if (len(policy_instances[policy_type_id]) > 0): - return Response("The policy type already exists and instances exists", 400, mimetype=TEXT_PLAIN) - - policy_types[policy_type_id]=data - policy_instances[policy_type_id]={} - return Response("Policy type " + policy_type_id + " is OK.", retcode, mimetype=TEXT_PLAIN) - -#Delete a policy type -@app.route('/policytype', methods=['DELETE']) -def del_policytype(): - - policy_type_id=request.args.get('id') - if (policy_type_id is None): - return Response('Parameter <id> missing in request', status=400, mimetype=TEXT_PLAIN) - - if (policy_type_id in policy_types.keys()): - if (len(policy_instances[policy_type_id]) > 0): - return Response("The policy type already exists and instances exists", 400, mimetype=TEXT_PLAIN) - - del policy_types[policy_type_id] - del policy_instances[policy_type_id] - return Response("Policy type " + policy_type_id + " is OK.", 204, mimetype=TEXT_PLAIN) - - return Response("Policy type " + policy_type_id + " not found.", 204, mimetype=TEXT_PLAIN) - - -# Get all policy type ids -@app.route('/policytypes', methods=['GET']) -def get_policytype_ids(): - - return (json.dumps(list(policy_instances.keys())), 200) - - -#Set force response for one A1 response -#/forceresponse?code=<responsecode> -@app.route('/forceresponse', methods=['POST']) -def forceresponse(): - - try: - forced_settings['code']=request.args.get('code') - except Exception: - forced_settings['code']=None - return Response("Force response code: " + str(forced_settings['code']) + " set for one single A1 response", 200, mimetype=TEXT_PLAIN) - -#Set force delay response, in seconds, for all A1 responses -#/froceesponse?delay=<seconds> -@app.route('/forcedelay', methods=['POST']) -def forcedelay(): - - try: - forced_settings['delay']=request.args.get('delay') - except Exception: - forced_settings['delay']=None - return Response("Force delay: " + str(forced_settings['delay']) + " sec set for all A1 responses", 200, mimetype=TEXT_PLAIN) - - -#Set status and reason -#/status?policyid=<policyid>&status=<status>[&reason=<reason>] -@app.route('/status', methods=['PUT']) -def setstatus(): - - policy_id=request.args.get('policyid') - if (policy_id is None): - return Response('Parameter <policyid> missing in request', status=400, mimetype=TEXT_PLAIN) - if policy_id not in policy_status.keys(): - return Response('Policyid: '+policy_id+' not found.', status=404, mimetype=TEXT_PLAIN) - status=request.args.get('status') - if (status is None): - return Response('Parameter <status> missing in request', status=400, mimetype=TEXT_PLAIN) - reason=request.args.get('reason') - ps = {} - ps["enforceStatus"] = status - msg="Status set to "+status - if (reason is not None): - ps["enforceReason"] = reason - msg=msg+" and "+reason - policy_status[policy_id] = ps - msg=msg+" for policy: " + policy_id - return Response(msg, 200, mimetype=TEXT_PLAIN) - -#Send status -#/status?policyid=<policyid> -@app.route('/sendstatus', methods=['POST']) -def sendstatus(): - policyid=request.args.get('policyid') - if (policyid is None): - return Response('Parameter <policyid> missing in request', status=400, mimetype=TEXT_PLAIN) - - if (policyid not in policy_status.keys()): - return Response('Policyid: '+policyid+' not found.', status=404, mimetype=TEXT_PLAIN) - - ps=policy_status[policyid] - cb=callbacks[policyid] - try: - print("Callback url: " + str(cb)) - resp=requests.post(cb,json=json.dumps(ps), verify=False) # NOSONAR - except: - return Response('Post status failed, could not send to: '+str(cb), status=500, mimetype=TEXT_PLAIN) - if (resp.status_code<199 & resp.status_code > 299): - return Response('Post status failed with code: '+resp.status_code, status=500, mimetype=TEXT_PLAIN) - - data = resp.json() - return Response(data, 200, mimetype='application/json') - -#Receive status (only for testing callbacks) -#/statustest -@app.route('/statustest', methods=['POST', 'PUT']) -def statustest(): - try: - data = request.data - data = json.loads(data) - except Exception: - return Response("The status data is corrupt or missing.", 400, mimetype=TEXT_PLAIN) - - return Response(json.dumps(data), 200, mimetype='application/json') - -#Receive a data delivery package -#/datadelivery -@app.route('/datadelivery', methods=['POST']) -def datadelivery(): - global data_delivery_counter - try: - data = request.data - data = json.loads(data) - except Exception: - return Response("The data is corrupt or missing.", 400, mimetype=TEXT_PLAIN) - data_delivery_counter += 1 - return Response("", 200, mimetype=TEXT_PLAIN) - -#Metrics function -#Get a named counter -@app.route('/counter/<string:countername>', methods=['GET']) -def getcounter(countername): - - if (countername == "num_instances"): - return Response(str(len(policy_fingerprint)), 200, mimetype=TEXT_PLAIN) - elif (countername == "num_types"): - return Response(str(len(policy_instances)),200, mimetype=TEXT_PLAIN) - elif (countername == "interface"): - p=Path(os.getcwd()) - pp=p.parts - return Response(str(pp[len(pp)-1]),200, mimetype=TEXT_PLAIN) - elif (countername == "remote_hosts"): - hosts=",".join(hosts_set) - return str(hosts),200 - elif (countername == "datadelivery"): - return Response(str(data_delivery_counter),200, mimetype=TEXT_PLAIN) - else: - return Response("Counter name: "+countername+" not found.",404, mimetype=TEXT_PLAIN) - -port_number = 2222 -if len(sys.argv) >= 2: - if isinstance(sys.argv[1], int): - port_number = sys.argv[1] - -app.add_api('ORAN_A1-p_V2.0.0_api.yaml') - -if __name__ == '__main__': - app.run(port=port_number, host="127.0.0.1", threaded=False) \ No newline at end of file diff --git a/near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py b/near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py deleted file mode 100644 index 513640476c89926adb460a2ed9f3ee9c297571ee..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/src/STD_2.0.0/var_declaration.py +++ /dev/null @@ -1,27 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -policy_types={} -policy_instances = {} -policy_status = {} -callbacks = {} -forced_settings = {} -forced_settings['code']=None -forced_settings['delay']=None -policy_fingerprint={} -hosts_set=set() -data_delivery_counter=0 diff --git a/near-rt-ric-simulator/src/common/.gitignore b/near-rt-ric-simulator/src/common/.gitignore deleted file mode 100644 index bee8a64b79a99590d5303307144172cfe824fbf7..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/src/common/.gitignore +++ /dev/null @@ -1 +0,0 @@ -__pycache__ diff --git a/near-rt-ric-simulator/src/start.sh b/near-rt-ric-simulator/src/start.sh deleted file mode 100755 index feb5a1dd012dfffce9b95f0cc2ce8e6a7419c1f0..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/src/start.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -if [ $# -ne 1 ]; then - echo "Expected folder name of simulator." - echo "The container shall be started with env variable 'A1_VERSION' set to the folder name of the A1 version to use." - echo "Exiting...." - exit 1 -fi -echo "Version folder for simulator: "$1 - -#Set path to open api -export APIPATH=$PWD/api/$1 -echo "APIPATH set to: "$APIPATH - -cd src - -#Include common module(s) -export PYTHONPATH=$PWD/common -echo "PYTHONPATH set to: "$PYTHONPATH - -cd $1 - -#start nginx -nginx -c /usr/src/app/nginx.conf - -#start callBack server -if [[ ${A1_VERSION} == "STD"* ]]; then - echo "Path to callBack.py: "$PWD - python -u callBack.py & -fi - -#start near-rt-ric-simulator -echo "Path to main.py: "$PWD -python -u main.py diff --git a/near-rt-ric-simulator/certificate/generate_cert_and_key.sh b/near-rt-ric-simulator/start.sh similarity index 55% rename from near-rt-ric-simulator/certificate/generate_cert_and_key.sh rename to near-rt-ric-simulator/start.sh index 0f79bbf71990710f5b5b5e75b14855ca9a5e0a1a..bade4f2f54a103cdbd6a58c946046831337ee63b 100755 --- a/near-rt-ric-simulator/certificate/generate_cert_and_key.sh +++ b/near-rt-ric-simulator/start.sh @@ -1,14 +1,9 @@ #!/bin/bash # ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# Copyright (C) 2023. S.K. Chaudhary. All rights reserved. # ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,5 +12,14 @@ # ============LICENSE_END================================================= # -# This will generate a self-signed certificate with password 'test' -openssl req -x509 -passout pass:"test" -newkey rsa:2048 -keyout key.crt -out cert.crt -days 9999 + + +#start callBack server +if [[ ${A1_VERSION} == "STD"* ]]; then + echo "Path to callBack.py: "$PWD + python -u callBack.py & +fi + +#start near-rt-ric-simulator +echo "Path to main.py: "$PWD +python -u main.py diff --git a/near-rt-ric-simulator/test/OSC_2.1.0/basic_test.sh b/near-rt-ric-simulator/test/OSC_2.1.0/basic_test.sh deleted file mode 100755 index bc2413d17c1a6c49751e995deb937a3950f942f1..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/test/OSC_2.1.0/basic_test.sh +++ /dev/null @@ -1,275 +0,0 @@ -#!/bin/bash - -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -# Script for basic test of the simulator. -# Run the build_and_start with the same arg as this script -if [ $# -ne 1 ]; then - echo "Usage: ./basic_test.sh nonsecure|secure" - exit 1 -fi -if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then - echo "Usage: ./basic_test.sh nonsecure|secure" - exit 1 -fi - -if [ $1 == "nonsecure" ]; then - #Default http port for the simulator - PORT=8085 - # Set http protocol - HTTPX="http" -else - #Default https port for the simulator - PORT=8185 - # Set https protocol - HTTPX="https" -fi - -. ../common/test_common.sh - -echo "=== Simulator hello world ===" -RESULT="OK" -do_curl GET / 200 - -echo "=== Check used and implemented interfaces ===" -RESULT="Current interface: OSC_2.1.0 All supported A1 interface yamls in this container: ['OSC_2.1.0', 'STD_1.1.3', 'STD_2.0.0']" -do_curl GET /container_interfaces 200 - -echo "=== Reset simulator instances ===" -RESULT="All policy instances deleted" -do_curl POST /deleteinstances 200 - -echo "=== Reset simulator, all ===" -RESULT="All policy instances and types deleted" -do_curl POST /deleteall 200 - -echo "=== API: Healthcheck ===" -RESULT="" -do_curl GET /a1-p/healthcheck 200 - -echo "=== API: Get policy types, shall be empty array ==" -RESULT="json:[]" -do_curl GET /a1-p/policytypes 200 - -echo "=== API: Delete a policy type, shall fail ==" -RESULT="" -do_curl DELETE /a1-p/policytypes/1 404 - -echo "=== API: Get policy instances for type 1, shall fail ==" -RESULT="" -do_curl GET /a1-p/policytypes/1/policies 404 - -echo "=== API: Put a policy type: 1 ===" -RESULT="" -do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json - -echo "=== API: Put a policy type: 1, again ===" -RESULT="" -do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json - -echo "=== API: Delete a policy type: 1 ===" -RESULT="" -do_curl DELETE /a1-p/policytypes/1 204 - -echo "=== API: Get policy type ids, shall be empty ==" -RESULT="json:[]" -do_curl GET /a1-p/policytypes 200 - -echo "=== API: Load a policy type: 1 ===" -RESULT="" -do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json - -echo "=== API: Get policy type ids, shall contain type 1 ==" -RESULT="json:[ 1 ]" -do_curl GET /a1-p/policytypes 200 - -echo "=== API: Get instances for type 1, shall be empty ===" -RESULT="json:[]" -do_curl GET '/a1-p/policytypes/1/policies' 200 - -echo "=== API: Create policy instance pi1 of type: 1 ===" -RESULT="" -do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json - -echo "=== API: Update policy instance pi1 of type: 1 ===" -RESULT="" -do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json - -echo "=== API: Load a policy type: 1, shall fail ===" -RESULT="" -do_curl PUT /a1-p/policytypes/1 400 jsonfiles/pt1.json - -echo "=== API: Get instances for type 1, shall contain pi1 ===" -RESULT="json:[ \"pi1\" ]" -do_curl GET '/a1-p/policytypes/1/policies' 200 - -echo "=== API: Create policy instance pi2 (copy of pi1) of type: 1. Shall fail ===" -RESULT="" -do_curl PUT '/a1-p/policytypes/1/policies/pi2' 400 jsonfiles/pi1.json - -echo "=== Set force response code 401. ===" -RESULT="*" -do_curl POST '/forceresponse?code=401' 200 - -echo "=== API: Get policy type 1. Shall fail with forced code ===" -RESULT="" -do_curl GET '/a1-p/policytypes/1' 401 - -echo "=== API: Get policy status ===" -RESULT="json:{\"instance_status\": \"NOT IN EFFECT\", \"has_been_deleted\": \"false\", \"created_at\": \"????\"}" -do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200 - -echo "=== Load a policy type: 2 ===" -RESULT="Policy type 2 is OK." -do_curl PUT '/policytype?id=2' 201 jsonfiles/pt2.json - -echo "=== Load a policy type: 2 again. ===" -RESULT="Policy type 2 is OK." -do_curl PUT '/policytype?id=2' 200 jsonfiles/pt2.json - -echo "=== API: Get policy type ids, shall contain type 1 and 2 ==" -RESULT="json:[ 1, 2 ]" -do_curl GET /a1-p/policytypes 200 - -echo "=== Get policy type ids, shall contain type 1 and 2 ==" -RESULT="json:[\"1\", \"2\"]" -do_curl GET /policytypes 200 - -echo "=== API: Get policy type 2 ==" -RESULT="json:{\"name\": \"pt2\", \"description\": \"pt2 policy type\", \"policy_type_id\": 2, \"create_schema\": {\"\$schema\": \"http://json-schema.org/draft-07/schema#\", \"title\": \"STD_QoSNudging_0.2.0\", \"description\": \"QoS policy type\", \"type\": \"object\", \"properties\": {\"scope\": {\"type\": \"object\", \"properties\": {\"ueId\": {\"type\": \"string\"}, \"qosId\": {\"type\": \"string\"}}, \"additionalProperties\": false, \"required\": [\"ueId\", \"qosId\"]}, \"statement\": {\"type\": \"object\", \"properties\": {\"priorityLevel\": {\"type\": \"number\"}}, \"additionalProperties\": false, \"required\": [\"priorityLevel\"]}}}}" -do_curl GET /a1-p/policytypes/2 200 - -echo "=== Delete policy type: 2 ===" -RESULT="" -do_curl DELETE '/policytype?id=2' 204 jsonfiles/pt2.json - -echo "=== API: Get policy type ids, shall contain type 1 ==" -RESULT="json:[ 1 ]" -do_curl GET /a1-p/policytypes 200 - -echo "=== Load a policy type: 2 ===" -RESULT="Policy type 2 is OK." -do_curl PUT '/policytype?id=2' 201 jsonfiles/pt2.json - -echo "=== API: Get policy type 2 ==" -RESULT="json:{\"name\": \"pt2\", \"description\": \"pt2 policy type\", \"policy_type_id\": 2, \"create_schema\": {\"\$schema\": \"http://json-schema.org/draft-07/schema#\", \"title\": \"STD_QoSNudging_0.2.0\", \"description\": \"QoS policy type\", \"type\": \"object\", \"properties\": {\"scope\": {\"type\": \"object\", \"properties\": {\"ueId\": {\"type\": \"string\"}, \"qosId\": {\"type\": \"string\"}}, \"additionalProperties\": false, \"required\": [\"ueId\", \"qosId\"]}, \"statement\": {\"type\": \"object\", \"properties\": {\"priorityLevel\": {\"type\": \"number\"}}, \"additionalProperties\": false, \"required\": [\"priorityLevel\"]}}}}" -do_curl GET /a1-p/policytypes/2 200 - -echo "=== API: Get instances for type 2, shall be empty ===" -RESULT="json:[]" -do_curl GET '/a1-p/policytypes/2/policies' 200 - -echo "=== API: Create policy instance pi1 of type: 2, shall fail===" -RESULT="" -do_curl PUT '/a1-p/policytypes/2/policies/pi1' 400 jsonfiles/pi1.json - -echo "=== API: Create policy instance pi2 of type: 2. Missing param, shall fail. ===" -RESULT="" -do_curl PUT '/a1-p/policytypes/2/policies/pi2' 400 jsonfiles/pi2_missing_param.json - -echo "=== API: Create policy instance pi2 of type: 2 ===" -RESULT="" -do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json - -echo "=== API: Update policy instance pi2 of type: 2 ===" -RESULT="" -do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json - -echo "=== API: Get instances for type 1, shall contain pi1 ===" -RESULT="json:[ \"pi1\" ]" -do_curl GET '/a1-p/policytypes/1/policies' jsonfiles/200 - -echo "=== API: Get instances for type 2, shall contain pi2 ===" -RESULT="json:[ \"pi2\" ]" -do_curl GET '/a1-p/policytypes/2/policies' 200 - -echo "=== API: Create policy instance pi11 (copy of pi1) of type: 1. Shall fail ===" -RESULT="" -do_curl PUT '/a1-p/policytypes/1/policies/pi11' 400 jsonfiles/pi1.json - -echo "=== Set force response code 401. ===" -RESULT="*" -do_curl POST '/forceresponse?code=401' 200 - -echo "=== API: Get policy status for pi1, shall fail ===" -RESULT="" -do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 401 - -echo "=== Set force delay 10. ===" -RESULT="Force delay: 10 sec set for all A1 responses" -do_curl POST '/forcedelay?delay=10' 200 - -echo "=== API: Get policy status for pi1. Shall delay 10 sec ===" -RESULT="json:{\"instance_status\": \"NOT IN EFFECT\", \"has_been_deleted\": \"false\", \"created_at\": \"????\"}" -do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200 - -echo "=== Reset force delay. ===" -RESULT="Force delay: None sec set for all A1 responses" -do_curl POST '/forcedelay' 200 - -echo "=== Set status for pi1 ===" -RESULT="Status set to IN EFFECT for policy: pi1" -do_curl PUT '/status?policyid=pi1&status=IN%20EFFECT' 200 - -echo "=== API: Get policy status for pi1 ===" -RESULT="json:{\"instance_status\": \"IN EFFECT\", \"has_been_deleted\": \"false\", \"created_at\": \"????\"}" -do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200 - -echo "=== Set status for pi1 ===" -RESULT="Status set to IN EFFECT and has_been_deleted set to true and created_at set to 2020-03-30 12:00:00 for policy: pi1" -do_curl PUT '/status?policyid=pi1&status=IN%20EFFECT&deleted=true&created_at=2020-03-30%2012:00:00' 200 - -echo "=== API: Get policy status for pi1 ===" -RESULT="json:{\"instance_status\": \"IN EFFECT\", \"has_been_deleted\": \"true\", \"created_at\": \"2020-03-30 12:00:00\"}" -do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200 - -echo "=== Get counter: instances ===" -RESULT="2" -do_curl GET '/counter/num_instances' 200 - -echo "=== Get counter: types ===" -RESULT="2" -do_curl GET '/counter/num_types' 200 - -echo "=== Get counter: interface ===" -RESULT="OSC_2.1.0" -do_curl GET '/counter/interface' 200 - -echo "=== Get counter: remote hosts ===" -RESULT="*" -do_curl GET '/counter/remote_hosts' 200 - -echo "=== DELETE policy pi1 ===" -RESULT="" -do_curl DELETE /a1-p/policytypes/1/policies/pi1 202 - -echo "=== API: Get instances for type 1, shall be empty ===" -RESULT="[]" -do_curl GET /a1-p/policytypes/1/policies 200 - -echo "=== API: Get instances for type 2, shall contain pi2 ===" -RESULT="[ \"pi2\" ]" -do_curl GET /a1-p/policytypes/2/policies 200 - -echo "=== Get counter: instances ===" -RESULT="1" -do_curl GET /counter/num_instances 200 - -echo "********************" -echo "*** All tests ok ***" -echo "********************" diff --git a/near-rt-ric-simulator/test/OSC_2.1.0/build_and_start.sh b/near-rt-ric-simulator/test/OSC_2.1.0/build_and_start.sh deleted file mode 100755 index f376971f49e6ccc6be191a844b9a71490f2a8796..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/test/OSC_2.1.0/build_and_start.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -# Script to build and start the container - -echo "Building image" -cd ../../ - -#Build the image -docker build -t a1test . - -docker stop a1OscSimulator > /dev/null 2>&1 -docker rm -f a1OscSimulator > /dev/null 2>&1 - -echo "Starting $1 mode" -#Run the container in interactive mode, unsecure port 8085, secure port 8185. -docker run -it -p 8085:8085 -p 8185:8185 -e A1_VERSION=OSC_2.1.0 -e ALLOW_HTTP=true -e REMOTE_HOSTS_LOGGING=1 --volume "$PWD/certificate:/usr/src/app/cert" --name a1OscSimulator a1test - diff --git a/near-rt-ric-simulator/test/OSC_2.1.0/jsonfiles/pi1.json b/near-rt-ric-simulator/test/OSC_2.1.0/jsonfiles/pi1.json deleted file mode 100644 index 25247a1b276ddeaa5b0e8b69e1c9c724593eb50a..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/test/OSC_2.1.0/jsonfiles/pi1.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "scope": { - "ueId": "ue1", - "qosId": "qos1" - }, - "statement": { - "priorityLevel": 5 - } -} - diff --git a/near-rt-ric-simulator/test/OSC_2.1.0/jsonfiles/pi2.json b/near-rt-ric-simulator/test/OSC_2.1.0/jsonfiles/pi2.json deleted file mode 100644 index ef076e4eec119ddaa581b33612e5819e5863e50b..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/test/OSC_2.1.0/jsonfiles/pi2.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "scope": { - "ueId": "ue2", - "qosId": "qos2" - }, - "statement": { - "priorityLevel": 10 - } - } \ No newline at end of file diff --git a/near-rt-ric-simulator/test/OSC_2.1.0/jsonfiles/pi2_missing_param.json b/near-rt-ric-simulator/test/OSC_2.1.0/jsonfiles/pi2_missing_param.json deleted file mode 100644 index 11e325df1729c772e3b2a3343a76ee2890c1ebe5..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/test/OSC_2.1.0/jsonfiles/pi2_missing_param.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "scope": { - "qosId": "qos2" - }, - "statement": { - "priorityLevel": 10 - } - } \ No newline at end of file diff --git a/near-rt-ric-simulator/test/OSC_2.1.0/jsonfiles/pt1.json b/near-rt-ric-simulator/test/OSC_2.1.0/jsonfiles/pt1.json deleted file mode 100644 index ba0c6d1946fb80753137b3ff11f5344b2b2ec0a0..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/test/OSC_2.1.0/jsonfiles/pt1.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "name": "pt1", - "description": "pt1 policy type", - "policy_type_id": 1, - "create_schema": { - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "STD_QoSNudging_0.2.0", - "description": "QoS policy type", - "type": "object", - "properties": { - "scope": { - "type": "object", - "properties": { - "ueId": { - "type": "string" - }, - "qosId": { - "type": "string" - } - }, - "additionalProperties": false, - "required": [ - "ueId", - "qosId" - ] - }, - "statement": { - "type": "object", - "properties": { - "priorityLevel": { - "type": "number" - } - }, - "additionalProperties": false, - "required": [ - "priorityLevel" - ] - } - } - } -} diff --git a/near-rt-ric-simulator/test/OSC_2.1.0/jsonfiles/pt2.json b/near-rt-ric-simulator/test/OSC_2.1.0/jsonfiles/pt2.json deleted file mode 100644 index 68c5e7307edf56e4fbe7e688737d2cdbc1e8f40c..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/test/OSC_2.1.0/jsonfiles/pt2.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "name": "pt2", - "description": "pt2 policy type", - "policy_type_id": 2, - "create_schema": { - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "STD_QoSNudging_0.2.0", - "description": "QoS policy type", - "type": "object", - "properties": { - "scope": { - "type": "object", - "properties": { - "ueId": { - "type": "string" - }, - "qosId": { - "type": "string" - } - }, - "additionalProperties": false, - "required": [ - "ueId", - "qosId" - ] - }, - "statement": { - "type": "object", - "properties": { - "priorityLevel": { - "type": "number" - } - }, - "additionalProperties": false, - "required": [ - "priorityLevel" - ] - } - } - } - } \ No newline at end of file diff --git a/near-rt-ric-simulator/test/STD_1.1.3/basic_test.sh b/near-rt-ric-simulator/test/STD_1.1.3/basic_test.sh index 3a828d2f7bf30d12884497e3d201d2ffbf78caf7..a021982bcf7866de2edbc7b9aad8997c1cb1931b 100755 --- a/near-rt-ric-simulator/test/STD_1.1.3/basic_test.sh +++ b/near-rt-ric-simulator/test/STD_1.1.3/basic_test.sh @@ -1,14 +1,9 @@ #!/bin/bash # ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# Copyright (C) 2023, S.K Chaudhary. All rights reserved. # ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -30,12 +25,12 @@ fi if [ $1 == "nonsecure" ]; then #Default http port for the simulator - PORT=8085 + PORT=2222 # Set http protocol HTTPX="http" else #Default https port for the simulator - PORT=8185 + PORT=2223 # Set https protocol HTTPX="https" fi @@ -44,40 +39,42 @@ fi echo "=== Simulator hello world ===" -RESULT="OK" +RESULT="This is connection Test and the status is OK" do_curl GET / 200 -echo "=== Check used and implemented interfaces ===" -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']" -do_curl GET /container_interfaces 200 +#echo "=== Check used and implemented interfaces ===" +#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']" +#do_curl GET /container_interfaces 200 -echo "=== Reset simulator instances ===" -RESULT="All policy instances deleted" -do_curl POST /deleteinstances 200 +#echo "=== Reset simulator instances ===" +#RESULT="All policy instances deleted" +#do_curl POST /deleteinstances 200 -echo "=== Reset simulator, all ===" -RESULT="All policy instances deleted" -do_curl POST /deleteall 200 +#echo "=== Reset simulator, all ===" +#RESULT="All policy instances deleted" +#do_curl POST /deleteall 200 + +#if you are running the script second time then first delete the instance pi2 through swagger ui. Then it will run properly or restart the esrver. echo "=== API: Get policy instances, shall be empty==" RESULT="json:[]" -do_curl GET /A1-P/v1/policies 200 +do_curl GET /A1AP/v1/policies 200 echo "=== API: Create policy instance pi1 ===" RESULT="json:{\"scope\": {\"ueId\": \"ue1\", \"groupId\": \"group1\", \"sliceId\": \"slice1\", \"qosId\": \"qos1\", \"cellId\": \"cell1\"}, \"statement\": {\"priorityLevel\": 5}}" -do_curl PUT /A1-P/v1/policies/pi1 201 jsonfiles/pi1.json +do_curl PUT /A1AP/v1/policies/pi1 201 jsonfiles/pi1.json echo "=== API: Update policy instance pi1 ===" RESULT="json:{\"scope\": {\"ueId\": \"ue1\", \"groupId\": \"group1\", \"sliceId\": \"slice1\", \"qosId\": \"qos1\", \"cellId\": \"cell1\"}, \"statement\": {\"priorityLevel\": 6}}" -do_curl PUT /A1-P/v1/policies/pi1 200 jsonfiles/pi1_updated.json +do_curl PUT /A1AP/v1/policies/pi1 200 jsonfiles/pi1_updated.json echo "=== API: Get policy instances, shall contain pi1==" RESULT="json:[ \"pi1\" ]" -do_curl GET /A1-P/v1/policies 200 +do_curl GET /A1AP/v1/policies 200 echo "=== API: Create policy instance pi2 (copy of pi1). Shall fail ===" RESULT="json:{\"title\": \"The policy json already exists.\", \"status\": 400, \"instance\": \"pi2\"}" -do_curl PUT /A1-P/v1/policies/pi2 400 jsonfiles/pi1_updated.json +do_curl PUT /A1AP/v1/policies/pi2 400 jsonfiles/pi1_updated.json echo "=== Set force response code 409. ===" RESULT="*" @@ -85,23 +82,23 @@ do_curl POST '/forceresponse?code=409' 200 echo "=== API: Get policy instances, shall fail ==" RESULT="json:{\"title\": \"Conflict\", \"status\": 409, \"detail\": \"Request could not be processed in the current state of the resource\"}" -do_curl GET /A1-P/v1/policies 409 +do_curl GET /A1AP/v1/policies 409 echo "=== API: Get policy status ===" RESULT="json:{\"enforceStatus\": \"UNDEFINED\"}" -do_curl GET /A1-P/v1/policies/pi1/status 200 +do_curl GET /A1AP/v1/policies/pi1/status 200 echo "=== API: Create policy instance pi2 ===" RESULT="json:{\"scope\": {\"ueId\": \"ue2\", \"groupId\": \"group2\", \"sliceId\": \"slice2\", \"qosId\": \"qos2\", \"cellId\": \"cell2\"}, \"statement\": {\"priorityLevel\": 10}}" -do_curl PUT /A1-P/v1/policies/pi2 201 jsonfiles/pi2.json +do_curl PUT /A1AP/v1/policies/pi2 201 jsonfiles/pi2.json echo "=== API: Update policy instance pi2 ===" RESULT="json:{\"scope\": {\"ueId\": \"ue2\", \"groupId\": \"group2\", \"sliceId\": \"slice2\", \"qosId\": \"qos2\", \"cellId\": \"cell2\"}, \"statement\": {\"priorityLevel\": 10}}" -do_curl PUT '/A1-P/v1/policies/pi2?notificationDestination=http://localhost:2223/statustest' 200 jsonfiles/pi2.json +do_curl PUT '/A1AP/v1/policies/pi2?notificationDestination=http://localhost:2223/statustest' 200 jsonfiles/pi2.json echo "=== API: Get policy instances, shall contain pi1 and pi2==" RESULT="json:[ \"pi1\", \"pi2\" ]" -do_curl GET /A1-P/v1/policies 200 +do_curl GET /A1AP/v1/policies 200 echo "=== Set force delay 10. ===" RESULT="Force delay: 10 sec set for all A1 responses" @@ -109,7 +106,7 @@ do_curl POST '/forcedelay?delay=10' 200 echo "=== API: Get policy instances, shall contain pi1 and pi2 and delayed 10 sec==" RESULT="json:[ \"pi1\", \"pi2\" ]" -do_curl GET /A1-P/v1/policies 200 +do_curl GET /A1AP/v1/policies 200 echo "=== Reset force delay. ===" RESULT="Force delay: None sec set for all A1 responses" @@ -117,19 +114,19 @@ do_curl POST /forcedelay 200 echo "=== API: GET policy instance pi1 ===" RESULT="json:{\"scope\": {\"ueId\": \"ue1\", \"groupId\": \"group1\", \"sliceId\": \"slice1\", \"qosId\": \"qos1\", \"cellId\": \"cell1\"}, \"statement\": {\"priorityLevel\": 6}}" -do_curl GET /A1-P/v1/policies/pi1 200 +do_curl GET /A1AP/v1/policies/pi1 200 echo "=== API: GET policy instance pi2 ===" RESULT="json:{\"scope\": {\"ueId\": \"ue2\", \"groupId\": \"group2\", \"sliceId\": \"slice2\", \"qosId\": \"qos2\", \"cellId\": \"cell2\"}, \"statement\": {\"priorityLevel\": 10}}" -do_curl GET /A1-P/v1/policies/pi2 200 +do_curl GET /A1AP/v1/policies/pi2 200 echo "=== API: DELETE policy instance pi1 ===" RESULT="" -do_curl DELETE /A1-P/v1/policies/pi1 204 +do_curl DELETE /A1AP/v1/policies/pi1 204 echo "=== API: Get policy status for pi1, shall fail===" RESULT="json:{\"title\": \"The policy identity does not exist.\", \"status\": 404, \"detail\": \"There is no existing policy instance with the identity: pi1\", \"instance\": \"pi1\"}" -do_curl GET /A1-P/v1/policies/pi1/status 404 +do_curl GET /A1AP/v1/policies/pi1/status 404 echo "=== Set status for policy instance pi2 ===" RESULT="Status set to OK for policy: pi2" @@ -137,7 +134,7 @@ do_curl PUT '/status?policyid=pi2&status=OK' 200 echo "=== API: Get policy status for pi2===" RESULT="json:{\"enforceStatus\": \"OK\"}" -do_curl GET /A1-P/v1/policies/pi2/status 200 +do_curl GET /A1AP/v1/policies/pi2/status 200 echo "=== Set status for policy instance pi2 ===" RESULT="Status set to NOTOK and notok_reason for policy: pi2" @@ -145,11 +142,11 @@ do_curl PUT '/status?policyid=pi2&status=NOTOK&reason=notok_reason' 200 echo "=== API: Get policy status for pi2 ===" RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}" -do_curl GET /A1-P/v1/policies/pi2/status 200 +do_curl GET /A1AP/v1/policies/pi2/status 200 -echo "=== Send status for pi2===" -RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}" -do_curl POST '/sendstatus?policyid=pi2' 200 +#echo "=== Send status for pi2===" +#RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}" +#do_curl POST '/sendstatus?policyid=pi2' 200 echo "=== Get counter: intstance ===" RESULT="1" @@ -160,7 +157,7 @@ RESULT="0" do_curl GET /counter/num_types 200 echo "=== Get counter: interface ===" -RESULT="STD_1.1.3" +RESULT="near-rt-ric-simulator" do_curl GET /counter/interface 200 echo "=== Get counter: remote hosts ===" diff --git a/near-rt-ric-simulator/test/STD_2.0.0/.p.json b/near-rt-ric-simulator/test/STD_2.0.0/.p.json deleted file mode 100644 index 0967ef424bce6791893e9a57bb952f80fd536e93..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/test/STD_2.0.0/.p.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh b/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh deleted file mode 100755 index 576bd5ed28fdda0864bdc0c98422cd69299baea0..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh +++ /dev/null @@ -1,288 +0,0 @@ -#!/bin/bash - -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -# Script for basic test of the simulator. -# Run the build_and_start with the same arg as this script -if [ $# -ne 1 ]; then - echo "Usage: ./basic_test.sh nonsecure|secure" - exit 1 -fi -if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then - echo "Usage: ./basic_test.sh nonsecure|secure" - exit 1 -fi - -if [ $1 == "nonsecure" ]; then - #Default http port for the simulator - PORT=8085 - # Set http protocol - HTTPX="http" -else - #Default https port for the simulator - PORT=8185 - # Set https protocol - HTTPX="https" -fi - -. ../common/test_common.sh - - -echo "=== Simulator hello world ===" -RESULT="OK" -do_curl GET / 200 - -echo "=== Check used and implemented interfaces ===" -RESULT="Current interface: STD_2.0.0 All supported A1 interface yamls in this container: ['OSC_2.1.0', 'STD_1.1.3', 'STD_2.0.0']" -do_curl GET /container_interfaces 200 - -echo "=== Reset simulator instances ===" -RESULT="All policy instances deleted" -do_curl POST /deleteinstances 200 - -echo "=== Reset simulator, all ===" -RESULT="All policy instances and types deleted" -do_curl POST /deleteall 200 - -echo "=== Get counter: interface ===" -RESULT="STD_2.0.0" -do_curl GET /counter/interface 200 - -echo "=== Get counter: remote hosts ===" -RESULT="*" -do_curl GET /counter/remote_hosts 200 - -echo "=== Get counter: intstance ===" -RESULT="0" -do_curl GET /counter/num_instances 200 - -echo "=== Get counter: types (shall be 0)===" -RESULT="0" -do_curl GET /counter/num_types 200 - -echo "=== API: Get policy types, shall be empty array ==" -RESULT="json:[]" -do_curl GET /A1-P/v2/policytypes 200 - -echo "=== API: Get policy instances for type 1, type not found==" -RESULT="json:{\"title\": \"The policy type does not exist.\", \"status\": 404, \"instance\": \"1\"}" -do_curl GET /A1-P/v2/policytypes/1/policies 404 - -echo "=== API: Get policy instances, type not found==" -RESULT="json:{\"title\": \"The policy type does not exist.\", \"status\": 404, \"instance\": \"test\"}" -do_curl GET /A1-P/v2/policytypes/test/policies 404 - -echo "=== Put a policy type: STD_1 ===" -RESULT="Policy type STD_1 is OK." -do_curl PUT '/policytype?id=STD_1' 201 jsonfiles/std_1.json - -echo "=== Put a policy type: STD_1, again ===" -RESULT="Policy type STD_1 is OK." -do_curl PUT '/policytype?id=STD_1' 200 jsonfiles/std_1.json - -echo "=== API: Get policy type ids, shall contain type STD_1 ==" -RESULT="json:[ \"STD_1\" ]" -do_curl GET /A1-P/v2/policytypes 200 - -echo "=== Delete a policy type: STD_1 ===" -RESULT="" -do_curl DELETE '/policytype?id=STD_1' 204 - -echo "=== API: Get policy type ids, shall be empty ==" -RESULT="json:[]" -do_curl GET /A1-P/v2/policytypes 200 - -echo "=== Put a policy type: STD_1 ===" -RESULT="Policy type STD_1 is OK." -do_curl PUT '/policytype?id=STD_1' 201 jsonfiles/std_1.json - -echo "=== API: Get policy type ids, shall contain type STD_1 ==" -RESULT="json:[ \"STD_1\" ]" -do_curl GET /A1-P/v2/policytypes 200 - -echo "=== Get counter: types (shall be 1)===" -RESULT="1" -do_curl GET /counter/num_types 200 - -echo "=== API: Get policy type: STD_1 ===" -res=$(cat jsonfiles/std_1.json) -RESULT="json:$res" -do_curl GET /A1-P/v2/policytypes/STD_1 200 - -echo "=== API: Get policy instances, shall be empty==" -RESULT="json:[ ]" -do_curl GET /A1-P/v2/policytypes/STD_1/policies 200 - -echo "=== API: Create policy instance pi1 of type: STD_1 ===" -res=$(cat jsonfiles/pi1.json) -RESULT="json:$res" -do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 201 jsonfiles/pi1.json - -echo "=== API: Get policy instance pi1 of type: STD_1 ===" -res=$(cat jsonfiles/pi1.json) -RESULT="json:$res" -do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1 200 - -echo "=== API: Update policy instance pi1 of type: STD_1===" -res=$(cat jsonfiles/pi1.json) -RESULT="json:$res" -do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1.json - -echo "=== API: Update policy instance pi1 of type: STD_1===" -res=$(cat jsonfiles/pi1_updated.json) -RESULT="json:$res" -do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1_updated.json - -echo "=== API: Duplicate policy instance pi2 of type: STD_1===" -res=$(cat jsonfiles/pi1_updated.json) -RESULT="json:{\"title\": \"Duplicate, the policy json already exists.\", \"status\": 400, \"instance\": \"pi2\"}" -do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 400 jsonfiles/pi1_updated.json - -echo "=== API: Get policy instances, shall contain pi1==" -RESULT="json:[ \"pi1\" ]" -do_curl GET /A1-P/v2/policytypes/STD_1/policies 200 - -echo "=== Get counter: types (shall be 1)===" -RESULT="1" -do_curl GET /counter/num_types 200 - -echo "=== Get counter: intstance ===" -RESULT="1" -do_curl GET /counter/num_instances 200 - - -echo "=== Set force response code 409. ===" -RESULT="*" -do_curl POST '/forceresponse?code=409' 200 - -echo "=== API: Get policy instances, shall fail with 409 ==" -RESULT="json:{\"title\": \"Conflict\", \"status\": 409, \"detail\": \"Request could not be processed in the current state of the resource\"}" -do_curl GET /A1-P/v2/policytypes/STD_1/policies 409 - -echo "=== API: Get policy status ===" -RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}" -do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1/status 200 - -echo "=== API: Create policy instance pi2 of type: STD_1 ===" -res=$(cat jsonfiles/pi2.json) -RESULT="json:$res" -do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 201 jsonfiles/pi2.json - -echo "=== API: Update policy instance pi2 of type: STD_1 ===" -res=$(cat jsonfiles/pi2.json) -RESULT="json:$res" -do_curl PUT '/A1-P/v2/policytypes/STD_1/policies/pi2?notificationDestination=http://localhost:2223/statustest' 200 jsonfiles/pi2.json - -echo "=== API: Get policy instances, shall contain pi1 and pi2==" -RESULT="json:[ \"pi1\", \"pi2\" ]" -do_curl GET /A1-P/v2/policytypes/STD_1/policies 200 - -echo "=== Get counter: types (shall be 1)===" -RESULT="1" -do_curl GET /counter/num_types 200 - -echo "=== Get counter: intstance ===" -RESULT="2" -do_curl GET /counter/num_instances 200 - -echo "=== Set force delay 10. ===" -RESULT="Force delay: 10 sec set for all A1 responses" -do_curl POST '/forcedelay?delay=10' 200 - -echo "=== API: Get policy instances, shall contain pi1 and pi2==" -RESULT="json:[ \"pi1\", \"pi2\" ]" -do_curl GET /A1-P/v2/policytypes/STD_1/policies 200 - -echo "=== Reset force delay. ===" -RESULT="Force delay: None sec set for all A1 responses" -do_curl POST /forcedelay 200 - -echo "=== API: Get policy instance pi1 of type: STD_1 ===" -res=$(cat jsonfiles/pi1_updated.json) -RESULT="json:$res" -do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1 200 - -echo "=== API: Get policy instance pi2 of type: STD_1 ===" -res=$(cat jsonfiles/pi2.json) -RESULT="json:$res" -do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2 200 - -echo "=== API: DELETE policy instance pi1 ===" -RESULT="" -do_curl DELETE /A1-P/v2/policytypes/STD_1/policies/pi1 204 - -echo "=== API: Get policy instances, shall contain pi1 and pi2==" -RESULT="json:[ \"pi2\" ]" -do_curl GET /A1-P/v2/policytypes/STD_1/policies 200 - -echo "=== API: Get policy status ===" -RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}" -do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200 - -echo "=== Set status for policy instance pi2 ===" -RESULT="Status set to OK for policy: pi2" -do_curl PUT '/status?policyid=pi2&status=OK' 200 - -echo "=== API: Get policy status ===" -RESULT="json:{\"enforceStatus\": \"OK\"}" -do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200 - -echo "=== Set status for policy instance pi2 ===" -RESULT="Status set to NOTOK and notok_reason for policy: pi2" -do_curl PUT '/status?policyid=pi2&status=NOTOK&reason=notok_reason' 200 - -echo "=== API: Get policy status ===" -RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\":\"notok_reason\"}" -do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200 - -echo "=== Send status for pi2===" -RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}" -do_curl POST '/sendstatus?policyid=pi2' 200 - -echo "=== Get counter: datadelivery ===" -RESULT="0" -do_curl GET /counter/datadelivery 200 - -echo "=== Send data ===" -echo "{}" > .p.json -RESULT="" -do_curl POST /datadelivery 200 .p.json - -echo "=== Get counter: datadelivery ===" -RESULT="1" -do_curl GET /counter/datadelivery 200 - -echo "=== Get counter: intstance ===" -RESULT="1" -do_curl GET /counter/num_instances 200 - -echo "=== Get counter: types (shall be 0)===" -RESULT="1" -do_curl GET /counter/num_types 200 - -echo "=== Get counter: interface ===" -RESULT="STD_2.0.0" -do_curl GET /counter/interface 200 - -echo "=== Get counter: remote hosts ===" -RESULT="*" -do_curl GET /counter/remote_hosts 200 - -echo "********************" -echo "*** All tests ok ***" -echo "********************" diff --git a/near-rt-ric-simulator/test/STD_2.0.0/build_and_start.sh b/near-rt-ric-simulator/test/STD_2.0.0/build_and_start.sh deleted file mode 100755 index 2cba8c1b46410ff603f3a5c225878f50d9f1e1e1..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/test/STD_2.0.0/build_and_start.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -# Script to build and start the container - -echo "Building image" -cd ../../ - -#Build the image -docker build -t a1test . - -docker stop a1StdSimulator > /dev/null 2>&1 -docker rm -f a1StdSimulator > /dev/null 2>&1 - -echo "Starting ric-sim" -#Run the container in interactive mode, unsecure port 8085, secure port 8185 -docker run -it -p 8085:8085 -p 8185:8185 -e A1_VERSION=STD_2.0.0 -e ALLOW_HTTP=true -e REMOTE_HOSTS_LOGGING=1 --volume "$PWD/certificate:/usr/src/app/cert" --name a1StdSimulator a1test diff --git a/near-rt-ric-simulator/test/STD_2.0.0/jsonfiles/pi1.json b/near-rt-ric-simulator/test/STD_2.0.0/jsonfiles/pi1.json deleted file mode 100644 index 25247a1b276ddeaa5b0e8b69e1c9c724593eb50a..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/test/STD_2.0.0/jsonfiles/pi1.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "scope": { - "ueId": "ue1", - "qosId": "qos1" - }, - "statement": { - "priorityLevel": 5 - } -} - diff --git a/near-rt-ric-simulator/test/STD_2.0.0/jsonfiles/pi1_updated.json b/near-rt-ric-simulator/test/STD_2.0.0/jsonfiles/pi1_updated.json deleted file mode 100644 index 7b4ada78b2b95803e97c9cb3b11896f618a6ec37..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/test/STD_2.0.0/jsonfiles/pi1_updated.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "scope": { - "ueId": "ue1", - "qosId": "qos1" - }, - "statement": { - "priorityLevel": 6 - } -} - diff --git a/near-rt-ric-simulator/test/STD_2.0.0/jsonfiles/pi2.json b/near-rt-ric-simulator/test/STD_2.0.0/jsonfiles/pi2.json deleted file mode 100644 index 441a9cf15679a3000583ce8798e038f3148da010..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/test/STD_2.0.0/jsonfiles/pi2.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "scope": { - "ueId": "ue2", - "qosId": "qos2" - }, - "statement": { - "priorityLevel": 5 - } -} - diff --git a/near-rt-ric-simulator/test/STD_2.0.0/jsonfiles/std_1.json b/near-rt-ric-simulator/test/STD_2.0.0/jsonfiles/std_1.json deleted file mode 100644 index 9b0c302de2af4efd920c458be0cfbbe2fb6616b2..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/test/STD_2.0.0/jsonfiles/std_1.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "policySchema": { - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "STD_1_0.2.0", - "description": "STD 1 policy type", - "type": "object", - "properties": { - "scope": { - "type": "object", - "properties": { - "ueId": { - "type": "string" - }, - "qosId": { - "type": "string" - } - }, - "additionalProperties": false, - "required": [ - "ueId", - "qosId" - ] - }, - "statement": { - "type": "object", - "properties": { - "priorityLevel": { - "type": "number" - } - }, - "additionalProperties": false, - "required": [ - "priorityLevel" - ] - } - } - }, - "statusSchema": { - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "STD_1_0.2.0", - "description": "STD 1 policy type status", - "type": "object", - "properties": { - "enforceStatus": { - "type": "string" - }, - "enforceReason": { - "type": "string" - }, - "additionalProperties": false, - "required": [ - "enforceStatus" - ] - } - } -} \ No newline at end of file diff --git a/near-rt-ric-simulator/tests/.gitignore b/near-rt-ric-simulator/tests/.gitignore deleted file mode 100644 index bee8a64b79a99590d5303307144172cfe824fbf7..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/tests/.gitignore +++ /dev/null @@ -1 +0,0 @@ -__pycache__ diff --git a/near-rt-ric-simulator/tests/test_osc_2_1_0.py b/near-rt-ric-simulator/tests/test_osc_2_1_0.py deleted file mode 100644 index 9d70ed0726f82231d1595b168c0b834e4348151f..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/tests/test_osc_2_1_0.py +++ /dev/null @@ -1,510 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -# This test case test the OSC_2.1.0 version of the simulator - -import json - -#Version of simulator -INTERFACE_VERSION="OSC_2.1.0" - -from unittest_setup import SERVER_URL, setup_env, get_testdata_dir, client - -#Setup env and import paths -setup_env(INTERFACE_VERSION) - -from compare_json import compare - -def test_apis(client): - - testdata=get_testdata_dir() - - # Simulator hello world - response=client.get(SERVER_URL) - assert response.status_code == 200 - - # Check used and implemented interfaces - response=client.get(SERVER_URL+'container_interfaces') - assert response.status_code == 200 - assert response.data == b"Current interface: OSC_2.1.0 All supported A1 interface yamls in this container: ['OSC_2.1.0', 'STD_1.1.3', 'STD_2.0.0']" - - # Reset simulator instances - response=client.post(SERVER_URL+'deleteinstances') - assert response.status_code == 200 - - # Reset simulator, all - response=client.post(SERVER_URL+'deleteall') - assert response.status_code == 200 - - # API: Healthcheck - response=client.get(SERVER_URL+'a1-p/healthcheck') - assert response.status_code == 200 - - # API: Get policy types, shall be empty - data_policytypes_get = [ ] - response=client.get(SERVER_URL+'a1-p/policytypes') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policytypes_get, result) - assert res == True - - # API: Delete a policy type, shall fail - response=client.delete(SERVER_URL+'a1-p/policytypes/1') - assert response.status_code == 404 - - # API: Get policy instances for type 1, shall fail - response=client.get(SERVER_URL+'a1-p/policytypes/1/policies') - assert response.status_code == 404 - - # Header for json payload - header = { - "Content-Type" : "application/json" - } - - # API: Put a policy type: 1 - with open(testdata+'pt1.json') as json_file: - policytype_1 = json.load(json_file) - response=client.put(SERVER_URL+'a1-p/policytypes/1', headers=header, data=json.dumps(policytype_1)) - assert response.status_code == 201 - - # API: Put a policy type: 1 again - with open(testdata+'pt1.json') as json_file: - policytype_1 = json.load(json_file) - response=client.put(SERVER_URL+'a1-p/policytypes/1', headers=header, data=json.dumps(policytype_1)) - assert response.status_code == 201 - - # API: Delete a policy type - response=client.delete(SERVER_URL+'a1-p/policytypes/1') - assert response.status_code == 204 - - # API: Get policy type ids, shall be empty - data_policytypes_get = [ ] - response=client.get(SERVER_URL+'a1-p/policytypes') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policytypes_get, result) - assert res == True - - # API: Put a policy type: 1 - with open(testdata+'pt1.json') as json_file: - policytype_1 = json.load(json_file) - response=client.put(SERVER_URL+'a1-p/policytypes/1', headers=header, data=json.dumps(policytype_1)) - assert response.status_code == 201 - - # API: Get policy type ids, shall contain '1' - data_policytypes_get = [ 1 ] - response=client.get(SERVER_URL+'a1-p/policytypes') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policytypes_get, result) - assert res == True - - # API: Get instances for type 1, shall be empty - data_policies_get = [ ] - response=client.get(SERVER_URL+'a1-p/policytypes/1/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policies_get, result) - assert res == True - - # API: Create policy instance pi1 of type: 1 - with open(testdata+'pi1.json') as json_file: - policy_1 = json.load(json_file) - response=client.put(SERVER_URL+'a1-p/policytypes/1/policies/pi1', headers=header, data=json.dumps(policy_1)) - assert response.status_code == 202 - - # API: Get policy instance pi1 of type: 1 - with open(testdata+'pi1.json') as json_file: - policy_1 = json.load(json_file) - response=client.get(SERVER_URL+'a1-p/policytypes/1/policies/pi1') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(policy_1, result) - assert res == True - - # API: Update policy instance pi1 of type: 1 - with open(testdata+'pi1.json') as json_file: - policy_1 = json.load(json_file) - response=client.put(SERVER_URL+'a1-p/policytypes/1/policies/pi1', headers=header, data=json.dumps(policy_1)) - assert response.status_code == 202 - - # API: Update policy type: 1, shall fail - with open(testdata+'pt1.json') as json_file: - policytype_1 = json.load(json_file) - response=client.put(SERVER_URL+'a1-p/policytypes/1', headers=header, data=json.dumps(policytype_1)) - assert response.status_code == 400 - - # API: Get instances for type 1, shall contain 'pi1' - data_policies_get = [ "pi1" ] - response=client.get(SERVER_URL+'a1-p/policytypes/1/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policies_get, result) - assert res == True - - # API: Create policy instance pi2 (copy of pi1) of type: 1. Shall fail - with open(testdata+'pi1.json') as json_file: - policy_2 = json.load(json_file) - response=client.put(SERVER_URL+'a1-p/policytypes/1/policies/pi2', headers=header, data=json.dumps(policy_2)) - assert response.status_code == 400 - - # Set force response code 401 - response=client.post(SERVER_URL+'forceresponse?code=401') - assert response.status_code == 200 - - # API: Get policy type 1. Shall fail with forced code - response=client.get(SERVER_URL+'a1-p/policytypes/1') - assert response.status_code == 401 - - # API: Get policy status - policy_status = { - "instance_status" : "NOT IN EFFECT", - "has_been_deleted" : "false", - "created_at" : "????" - } - response=client.get(SERVER_URL+'a1-p/policytypes/1/policies/pi1/status') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(policy_status, result) - assert res == True - - # Load a policy type: 2 - with open(testdata+'pt2.json') as json_file: - policytype_2 = json.load(json_file) - response=client.put(SERVER_URL+'policytype?id=2', headers=header, data=json.dumps(policytype_2)) - assert response.status_code == 201 - assert response.data == b"Policy type 2 is OK." - - # Load a policy type: 2, again - with open(testdata+'pt2.json') as json_file: - policytype_2 = json.load(json_file) - response=client.put(SERVER_URL+'policytype?id=2', headers=header, data=json.dumps(policytype_2)) - assert response.status_code == 200 - assert response.data == b"Policy type 2 is OK." - - # API: Get policy type ids, shall contain '1' and '2' - data_policytypes_get = [ 1,2 ] - response=client.get(SERVER_URL+'a1-p/policytypes') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policytypes_get, result) - assert res == True - - # Get policy type ids, shall contain type 1 and 2 ==" - data_policytypes_get = [ "1","2" ] - response=client.get(SERVER_URL+'policytypes') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policytypes_get, result) - assert res == True - - # API: Get policy type 2 - with open(testdata+'pt2.json') as json_file: - policytype_2 = json.load(json_file) - response=client.get(SERVER_URL+'a1-p/policytypes/2') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(policytype_2, result) - assert res == True - - # Delete a policy type - response=client.delete(SERVER_URL+'policytype?id=2') - assert response.status_code == 204 - - # API: Get policy type ids, shall contain '1' - data_policytypes_get = [ 1] - response=client.get(SERVER_URL+'a1-p/policytypes') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policytypes_get, result) - assert res == True - - # Load a policy type: 2 - with open(testdata+'pt2.json') as json_file: - policytype_2 = json.load(json_file) - response=client.put(SERVER_URL+'policytype?id=2', headers=header, data=json.dumps(policytype_2)) - assert response.status_code == 201 - assert response.data == b"Policy type 2 is OK." - - # API: Get policy type 2 - with open(testdata+'pt2.json') as json_file: - policytype_2 = json.load(json_file) - response=client.get(SERVER_URL+'a1-p/policytypes/2') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(policytype_2, result) - assert res == True - - # API: Get instances for type 2, shall be empty - data_policies_get = [ ] - response=client.get(SERVER_URL+'a1-p/policytypes/2/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policies_get, result) - assert res == True - - # API: Create policy instance pi1 of type: 2, shall fail - with open(testdata+'pi1.json') as json_file: - policy_1 = json.load(json_file) - response=client.put(SERVER_URL+'a1-p/policytypes/2/policies/pi1', headers=header, data=json.dumps(policy_1)) - assert response.status_code == 400 - - # API: Create policy instance pi2 of type: 2. Missing param, shall fail - with open(testdata+'pi2_missing_param.json') as json_file: - policy_2 = json.load(json_file) - response=client.put(SERVER_URL+'a1-p/policytypes/2/policies/pi1', headers=header, data=json.dumps(policy_2)) - assert response.status_code == 400 - - # API: Create policy instance pi2 of type: 2 - with open(testdata+'pi2.json') as json_file: - policy_2 = json.load(json_file) - response=client.put(SERVER_URL+'a1-p/policytypes/2/policies/pi2', headers=header, data=json.dumps(policy_2)) - assert response.status_code == 202 - - with open(testdata+'pi2.json') as json_file: - policy_2 = json.load(json_file) - response=client.put(SERVER_URL+'a1-p/policytypes/2/policies/pi2', headers=header, data=json.dumps(policy_2)) - assert response.status_code == 202 - - # API: Get instances for type 1, shall contain pi1 - data_policies_get = [ "pi1" ] - response=client.get(SERVER_URL+'a1-p/policytypes/1/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policies_get, result) - assert res == True - - # API: Get instances for type 2, shall contain pi2 - data_policies_get = ["pi2" ] - response=client.get(SERVER_URL+'a1-p/policytypes/2/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policies_get, result) - assert res == True - - # API: Create policy instance pi11 (copy of pi1) of type: 1. Shall fail - with open(testdata+'pi1.json') as json_file: - policy_1 = json.load(json_file) - response=client.put(SERVER_URL+'a1-p/policytypes/1/policies/pi11', headers=header, data=json.dumps(policy_1)) - assert response.status_code == 400 - - # Set force response code 409. ===" - response=client.post(SERVER_URL+'forceresponse?code=401') - assert response.status_code == 200 - - # API: Get policy status for pi1, shall fail - response=client.get(SERVER_URL+'a1-p/policytypes/1/policies/pi1/status') - assert response.status_code == 401 - - # Set force delay 10 - response=client.post(SERVER_URL+'forcedelay?delay=10') - assert response.status_code == 200 - assert response.data == b"Force delay: 10 sec set for all A1 responses" - - # API: Get policy status for pi1. Shall delay 10 sec - policy_status = { - "instance_status" : "NOT IN EFFECT", - "has_been_deleted" : "false", - "created_at" : "????" - } - response=client.get(SERVER_URL+'a1-p/policytypes/1/policies/pi1/status') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(policy_status, result) - assert res == True - - # Reset force delay - response=client.post(SERVER_URL+'forcedelay') - assert response.status_code == 200 - assert response.data == b"Force delay: None sec set for all A1 responses" - - # Set status for pi1 - response=client.put(SERVER_URL+'status?policyid=pi1&status=IN%20EFFECT') - assert response.status_code == 200 - - # API: Get policy status for pi1 - policy_status = { - "instance_status" : "IN EFFECT", - "has_been_deleted" : "false", - "created_at" : "????" - } - response=client.get(SERVER_URL+'a1-p/policytypes/1/policies/pi1/status') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(policy_status, result) - assert res == True - - # Set status for pi1 - response=client.put(SERVER_URL+'status?policyid=pi1&status=IN%20EFFECT&deleted=true&created_at=2020-03-30%2012:00:00') - assert response.status_code == 200 - - # API: Get policy status for pi1 - policy_status = { - "instance_status" : "IN EFFECT", - "has_been_deleted" : "true", - "created_at" : "????" - } - response=client.get(SERVER_URL+'a1-p/policytypes/1/policies/pi1/status') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(policy_status, result) - assert res == True - - # Get counter: intstance - response=client.get(SERVER_URL+'counter/num_instances') - assert response.status_code == 200 - assert response.data == b"2" - - # Get counter: types (shall be 2) - response=client.get(SERVER_URL+'counter/num_types') - assert response.status_code == 200 - assert response.data == b"2" - - # Get counter: interface - response=client.get(SERVER_URL+'counter/interface') - assert response.status_code == 200 - assert response.data == b"OSC_2.1.0" - - # Get counter: remote hosts - response=client.get(SERVER_URL+'counter/remote_hosts') - assert response.status_code == 200 - - # Get counter: test, shall fail - response=client.get(SERVER_URL+'counter/test') - assert response.status_code == 404 - - # API: DELETE policy instance pi1 - response=client.delete(SERVER_URL+'a1-p/policytypes/1/policies/pi1') - assert response.status_code == 202 - - # API: Get instances for type 1, shall be empty - data_policies_get = [ ] - response=client.get(SERVER_URL+'a1-p/policytypes/1/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policies_get, result) - assert res == True - - # API: Get instances for type 2, shall contain pi2 - data_policies_get = ["pi2" ] - response=client.get(SERVER_URL+'a1-p/policytypes/2/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policies_get, result) - assert res == True - - # Get counter: instances - response=client.get(SERVER_URL+'counter/num_instances') - assert response.status_code == 200 - assert response.data == b"1" - - - ### Tests to increase code coverage - - # Set force response code 500 - response=client.post(SERVER_URL+'forceresponse?code=500') - assert response.status_code == 200 - - # API: Healthcheck - response=client.get(SERVER_URL+'a1-p/healthcheck') - assert response.status_code == 500 - - # Set force response code 501 - response=client.post(SERVER_URL+'forceresponse?code=501') - assert response.status_code == 200 - - # API: Get policy types - data_policytypes_get = [ ] - response=client.get(SERVER_URL+'a1-p/policytypes') - assert response.status_code == 501 - - # Set force response code 502 - response=client.post(SERVER_URL+'forceresponse?code=502') - assert response.status_code == 200 - - # API: Delete a policy type, shall fail - response=client.delete(SERVER_URL+'a1-p/policytypes/55') - assert response.status_code == 502 - - # Set force response code 503. ===" - response=client.post(SERVER_URL+'forceresponse?code=503') - assert response.status_code == 200 - - with open(testdata+'pi1.json') as json_file: - policy_1 = json.load(json_file) - response=client.put(SERVER_URL+'a1-p/policytypes/1/policies/pi11', headers=header, data=json.dumps(policy_1)) - assert response.status_code == 503 - - # Set force response code 504 - response=client.post(SERVER_URL+'forceresponse?code=504') - assert response.status_code == 200 - - # API: Get instances for type 1, shall fail - data_policies_get = [ ] - response=client.get(SERVER_URL+'a1-p/policytypes/1/policies') - assert response.status_code == 504 - - # Set force response code 505. ===" - response=client.post(SERVER_URL+'forceresponse?code=505') - assert response.status_code == 200 - - # API: delete instance pi1, shall fail - response=client.delete(SERVER_URL+'a1-p/policytypes/1/policies/pi1') - assert response.status_code == 505 - - # API: Delete a policy type having instances, shall fail - response=client.delete(SERVER_URL+'a1-p/policytypes/2') - assert response.status_code == 400 - - # API: delete instance pi1 in type 5, shall fail - response=client.delete(SERVER_URL+'a1-p/policytypes/5/policies/pi1') - assert response.status_code == 404 - - # API: delete instance pi99 in type 1, shall fail - response=client.delete(SERVER_URL+'a1-p/policytypes/1/policies/pi99') - assert response.status_code == 404 - - # API: Create policy instance pi80 of type: 5 - with open(testdata+'pi1.json') as json_file: - policy_80 = json.load(json_file) - response=client.put(SERVER_URL+'a1-p/policytypes/5/policies/pi80', headers=header, data=json.dumps(policy_80)) - assert response.status_code == 404 - - # API: Get policy type - data_policytypes_get = [ ] - response=client.get(SERVER_URL+'a1-p/policytypes/55') - assert response.status_code == 404 - - # API: Get status, bad type - shall fail - response=client.get(SERVER_URL+'a1-p/policytypes/99/policies/pi1/status') - assert response.status_code == 404 - - # API: Get status, bad instance - shall fail - response=client.get(SERVER_URL+'a1-p/policytypes/1/policies/pi111/status') - assert response.status_code == 404 - - # Load policy type, no type in url - shall faill - with open(testdata+'pt2.json') as json_file: - policytype_2 = json.load(json_file) - response=client.put(SERVER_URL+'policytype', headers=header, data=json.dumps(policytype_2)) - assert response.status_code == 400 - - # Load policy type - duplicatee - shall faill - with open(testdata+'pt1.json') as json_file: - policytype_1 = json.load(json_file) - response=client.put(SERVER_URL+'policytype?id=2', headers=header, data=json.dumps(policytype_1)) - assert response.status_code == 400 diff --git a/near-rt-ric-simulator/tests/test_std_1_1_3.py b/near-rt-ric-simulator/tests/test_std_1_1_3.py deleted file mode 100644 index 721d7a68e9228f67575809ba21d6e9fff191e3ce..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/tests/test_std_1_1_3.py +++ /dev/null @@ -1,459 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -# This test case test the STD_1.1.3 version of the simulator - -import json - -#Version of simulator -INTERFACE_VERSION="STD_1.1.3" - -from unittest_setup import SERVER_URL, HOST_IP, PORT_NUMBER, setup_env, client - -#Setup env and import paths -setup_env(INTERFACE_VERSION) - -from compare_json import compare - -def test_apis(client): - - # Simulator hello world - response=client.get(SERVER_URL) - assert response.status_code == 200 - - # Check used and implemented interfaces - response=client.get(SERVER_URL+'container_interfaces') - assert response.status_code == 200 - assert response.data == b"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']" - - # Reset simulator instances - response=client.post(SERVER_URL+'deleteinstances') - assert response.status_code == 200 - - # Reset simulator, all - response=client.post(SERVER_URL+'deleteall') - assert response.status_code == 200 - - # API: Get policy instances, shall be empty - data_policy_get = [ ] - response=client.get(SERVER_URL+'A1-P/v1/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policy_get, result) - assert res == True - - #API: Create policy instance pi1 - data_pi1 = { - "scope": { - "ueId": "ue1", - "groupId": "group1", - "sliceId": "slice1", - "qosId": "qos1", - "cellId": "cell1" - }, - "statement": { - "priorityLevel": 5 - } - } - # header for json payload - header = { - "Content-Type" : "application/json" - } - response=client.put(SERVER_URL+'A1-P/v1/policies/pi1', headers=header, data=json.dumps(data_pi1)) - assert response.status_code == 201 - result=json.loads(response.data) - res=compare(data_pi1, result) - assert res == True - - #API: Update policy instance pi1 - data_pi1_updated = { - "scope": { - "ueId": "ue1", - "groupId": "group1", - "sliceId": "slice1", - "qosId": "qos1", - "cellId": "cell1" - }, - "statement": { - "priorityLevel": 6 - } - } - response=client.put(SERVER_URL+'A1-P/v1/policies/pi1', headers=header, data=json.dumps(data_pi1_updated)) - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_pi1_updated, result) - assert res == True - - #API: Create policy instance pi9, bad json - response=client.put(SERVER_URL+'A1-P/v1/policies/pi9', headers=header, data="test") - assert response.status_code == 400 - - # API: Get policy instances, shall contain pi1 - data_policy_get = [ "pi1" ] - response=client.get(SERVER_URL+'A1-P/v1/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policy_get, result) - assert res == True - - # API: Create policy instance pi2 (copy of pi1). Shall fail - data_create_errror_pi1 = { - "title" : "The policy json already exists.", - "status" : 400, - "instance" : "pi2" - } - response=client.put(SERVER_URL+'A1-P/v1/policies/pi2', headers=header, data=json.dumps(data_pi1_updated)) - assert response.status_code == 400 - result=json.loads(response.data) - res=compare(data_create_errror_pi1, result) - assert res == True - - # Set force response code 409. ===" - response=client.post(SERVER_URL+'forceresponse?code=409') - assert response.status_code == 200 - - # API: Get policy instances, shall fail - data_get_errror = { - "title" : "Conflict", - "status" : 409, - "detail" : "Request could not be processed in the current state of the resource" - } - response=client.get(SERVER_URL+'A1-P/v1/policies') - assert response.status_code == 409 - result=json.loads(response.data) - res=compare(data_get_errror, result) - assert res == True - - # Reset force response - response=client.post(SERVER_URL+'forceresponse') - assert response.status_code == 200 - assert response.data == b"Force response code: None set for one single A1 response" - - ### - ### Repeating the above two test for code coverage - ### - # Set force response code 400 - response=client.post(SERVER_URL+'forceresponse?code=400') - assert response.status_code == 200 - - #API: Create policy instance pi3, shall fail - data_pi3 = { - "scope": { - "ueId": "ue3" - }, - "statement": { - "priorityLevel": 5 - } - } - data_get_errror = { - "title" : "Bad request", - "status" : 400, - "detail" : "Object in payload not properly formulated or not related to the method" - } - response=client.put(SERVER_URL+'A1-P/v1/policies/pi3', headers=header, data=json.dumps(data_pi3)) - assert response.status_code == 400 - result=json.loads(response.data) - res=compare(data_get_errror, result) - assert res == True - - # Set force response code 404 - response=client.post(SERVER_URL+'forceresponse?code=404') - assert response.status_code == 200 - - # API: Get policy instance pi1, shall fail ==" - data_get_errror = { - "title" : "Not found", - "status" : 404, - "detail" : "No resource found at the URI" - } - response=client.get(SERVER_URL+'A1-P/v1/policies/pi1') - assert response.status_code == 404 - result=json.loads(response.data) - res=compare(data_get_errror, result) - assert res == True - - # Set force response code 405 - response=client.post(SERVER_URL+'forceresponse?code=405') - assert response.status_code == 200 - - # API: Delete policy instances pi1, shall fail ==" - data_get_errror = { - "title" : "Method not allowed", - "status" : 405, - "detail" : "Method not allowed for the URI" - } - response=client.delete(SERVER_URL+'A1-P/v1/policies/pi1') - assert response.status_code == 405 - result=json.loads(response.data) - res=compare(data_get_errror, result) - assert res == True - - # Set force response code 429 - response=client.post(SERVER_URL+'forceresponse?code=429') - assert response.status_code == 200 - - # API: Get policy status pi3, shall fail ==" - data_get_errror = { - "title" : "Too many requests", - "status" : 429, - "detail" : "Too many requests have been sent in a given amount of time" - } - response=client.get(SERVER_URL+'A1-P/v1/policies/pi3/status') - assert response.status_code == 429 - result=json.loads(response.data) - res=compare(data_get_errror, result) - assert res == True - - # Set force response code 507 - response=client.post(SERVER_URL+'forceresponse?code=507') - assert response.status_code == 200 - - # API: Get policy instances, shall fail - data_get_errror = { - "title" : "Insufficient storage", - "status" : 507, - "detail" : "The method could not be performed on the resource because the provider is unable to store the representation needed to successfully complete the request" - } - response=client.get(SERVER_URL+'A1-P/v1/policies') - assert response.status_code == 507 - result=json.loads(response.data) - res=compare(data_get_errror, result) - assert res == True - - # Set force response code 503. ===" - response=client.post(SERVER_URL+'forceresponse?code=503') - assert response.status_code == 200 - - # API: Get policy instances, shall fail - data_get_errror = { - "title" : "Service unavailable", - "status" : 503, - "detail" : "The provider is currently unable to handle the request due to a temporary overload" - } - response=client.get(SERVER_URL+'A1-P/v1/policies') - assert response.status_code == 503 - result=json.loads(response.data) - res=compare(data_get_errror, result) - assert res == True - - # Set force response code 555. ===" - response=client.post(SERVER_URL+'forceresponse?code=555') - assert response.status_code == 200 - - # API: Get policy instances, shall fail - data_get_errror = { - "title" : "Unknown", - "status" : "555", - "detail" : "Not implemented response code" - } - response=client.get(SERVER_URL+'A1-P/v1/policies') - assert response.status_code == 555 - result=json.loads(response.data) - res=compare(data_get_errror, result) - assert res == True - - ### - ### End of repeated test - ### - - - # API: Get policy status - data_policy_status = { - "enforceStatus" : "UNDEFINED" - } - response=client.get(SERVER_URL+'A1-P/v1/policies/pi1/status') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policy_status, result) - assert res == True - - # API: Create policy instance pi2 - data_pi2 = { - "scope": { - "ueId": "ue2", - "groupId": "group2", - "sliceId": "slice2", - "qosId": "qos2", - "cellId": "cell2" - }, - "statement": { - "priorityLevel": 10 - } - } - response=client.put(SERVER_URL+'A1-P/v1/policies/pi2', headers=header, data=json.dumps(data_pi2)) - assert response.status_code == 201 - result=json.loads(response.data) - res=compare(data_pi2, result) - assert res == True - - - # API: Update policy instance pi2 - # Reuse same policy data - response=client.put(SERVER_URL+'A1-P/v1/policies/pi2?notificationDestination=http://'+HOST_IP+':'+PORT_NUMBER+'/statustest', headers=header, data=json.dumps(data_pi2)) - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_pi2, result) - assert res == True - - # API: Get policy instances, shall contain pi1 and pi2 - data_policy_get = [ "pi1", "pi2" ] - response=client.get(SERVER_URL+'A1-P/v1/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policy_get, result) - assert res == True - - # Set force delay 10 - response=client.post(SERVER_URL+'forcedelay?delay=10') - assert response.status_code == 200 - assert response.data == b"Force delay: 10 sec set for all A1 responses" - - # API: Get policy instances, shall contain pi1 and pi2 and delayed 10 sec - data_policy_get = [ "pi1", "pi2" ] - response=client.get(SERVER_URL+'A1-P/v1/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_policy_get, result) - assert res == True - - # Reset force delay - response=client.post(SERVER_URL+'forcedelay') - assert response.status_code == 200 - assert response.data == b"Force delay: None sec set for all A1 responses" - - # API: GET policy instance pi1 - response=client.get(SERVER_URL+'A1-P/v1/policies/pi1') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_pi1_updated, result) - assert res == True - - # API: GET policy instance pi2 - response=client.get(SERVER_URL+'A1-P/v1/policies/pi2') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_pi2, result) - assert res == True - - # API: GET policy instance pi9, shall fail - response=client.get(SERVER_URL+'A1-P/v1/policies/pi9') - assert response.status_code == 404 - - # API: DELETE policy instance pi1 - response=client.delete(SERVER_URL+'A1-P/v1/policies/pi1') - assert response.status_code == 204 - - # API: DELETE policy instance pi9, shall fail - response=client.delete(SERVER_URL+'A1-P/v1/policies/pi9') - assert response.status_code == 404 - - # API: Get policy status for pi1, shall fail - data_get_errror = { - "title" : "The policy identity does not exist.", - "status" : 404, - "detail" : "There is no existing policy instance with the identity: pi1", - "instance" : "pi1" - } - response=client.get(SERVER_URL+'A1-P/v1/policies/pi1/status') - assert response.status_code == 404 - result=json.loads(response.data) - res=compare(data_get_errror, result) - assert res == True - - # Set status for policy instance pi2 - response=client.put(SERVER_URL+'status?policyid=pi2&status=OK') - assert response.status_code == 200 - - # API: Get policy status for pi2 - data_get_status = { - "enforceStatus" : "OK" - } - response=client.get(SERVER_URL+'A1-P/v1/policies/pi2/status') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_get_status, result) - assert res == True - - # Set status for policy instance pi2 - response=client.put(SERVER_URL+'status?policyid=pi2&status=NOTOK&reason=notok_reason') - assert response.status_code == 200 - - # API: Get policy status for pi2 - data_get_status = { - "enforceStatus" : "NOTOK", - "enforceReason" : "notok_reason" - } - response=client.get(SERVER_URL+'A1-P/v1/policies/pi2/status') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_get_status, result) - assert res == True - - #Found no way to test these functions - #'sendstatus' will send a http request that will fail - #since no server will receive the call - #These function is instead tested when running the bash script in the 'test' dir - # # Send status for pi2 - # response=client.post(SERVER_URL+'sendstatus?policyid=pi2') - # assert response.status_code == 200 - # result=json.loads(response.data) - # res=compare(data_get_status, result) - # assert res == True - - # # Send status, shall fail - # response=client.post(SERVER_URL+'sendstatus') - # assert response.status_code == 400 - - # # Send status pi9, shall fail - # response=client.post(SERVER_URL+'sendstatus?policyid=pi9') - # assert response.status_code == 404 - - # Set status for policy instance , shall fail - response=client.put(SERVER_URL+'status') - assert response.status_code == 400 - - # Set status for policy instance pi9, shall fail - response=client.put(SERVER_URL+'status?policyid=pi9') - assert response.status_code == 404 - - # Set status for policy instance pi2, shall fail - response=client.put(SERVER_URL+'status?policyid=pi2') - assert response.status_code == 400 - - - # Get counter: intstance - response=client.get(SERVER_URL+'counter/num_instances') - assert response.status_code == 200 - assert response.data == b"1" - - # Get counter: types (shall be 0) - response=client.get(SERVER_URL+'counter/num_types') - assert response.status_code == 200 - assert response.data == b"0" - - # Get counter: interface - response=client.get(SERVER_URL+'counter/interface') - assert response.status_code == 200 - assert response.data == b"STD_1.1.3" - - # Get counter: remote hosts - response=client.get(SERVER_URL+'counter/remote_hosts') - assert response.status_code == 200 - - # Get counter: test, shall fail - response=client.get(SERVER_URL+'counter/test') - assert response.status_code == 404 diff --git a/near-rt-ric-simulator/tests/test_std_2_0_0.py b/near-rt-ric-simulator/tests/test_std_2_0_0.py deleted file mode 100644 index d63d4c349a25148338976bb171cad1109ad578e6..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/tests/test_std_2_0_0.py +++ /dev/null @@ -1,436 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -# This test case test the STD_2.0.0 version of the simulator - -import json -import time - -#Version of simulator -INTERFACE_VERSION="STD_2.0.0" - -from unittest_setup import SERVER_URL, HOST_IP, PORT_NUMBER, setup_env, get_testdata_dir, client - -#Setup env and import paths -setup_env(INTERFACE_VERSION) - -from compare_json import compare - -def test_apis(client): - - testdata=get_testdata_dir() - - # Header for json payload - header = { - "Content-Type" : "application/json" - } - - # Simulator hello world - response=client.get(SERVER_URL) - assert response.status_code == 200 - - # Check used and implemented interfaces - response=client.get(SERVER_URL+'container_interfaces') - assert response.status_code == 200 - assert response.data == b"Current interface: STD_2.0.0 All supported A1 interface yamls in this container: ['OSC_2.1.0', 'STD_1.1.3', 'STD_2.0.0']" - - # Reset simulator instances - response=client.post(SERVER_URL+'deleteinstances') - assert response.status_code == 200 - - # Reset simulator, all - response=client.post(SERVER_URL+'deleteall') - assert response.status_code == 200 - - # Get counter: interface - response=client.get(SERVER_URL+'counter/interface') - assert response.status_code == 200 - assert response.data == b"STD_2.0.0" - - # Get counter: remote hosts - response=client.get(SERVER_URL+'counter/remote_hosts') - assert response.status_code == 200 - - # Get counter: intstance - response=client.get(SERVER_URL+'counter/num_instances') - assert response.status_code == 200 - assert response.data == b"0" - - # Get counter: types - response=client.get(SERVER_URL+'counter/num_types') - assert response.status_code == 200 - assert response.data == b"0" - - # API: Get policy type, shall be empty - data_response = [ ] - response=client.get(SERVER_URL+'A1-P/v2/policytypes') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # API: Get policy instances for type 1, type not found - data_response = {"title": "The policy type does not exist.", "status": 404, "instance": "1"} - response=client.get(SERVER_URL+'A1-P/v2/policytypes/1/policies') - assert response.status_code == 404 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # API: Get policy instances, type not found - data_response = {"title": "The policy type does not exist.", "status": 404, "instance": "test"} - response=client.get(SERVER_URL+'A1-P/v2/policytypes/test/policies') - assert response.status_code == 404 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # Put a policy type: STD_1 - with open(testdata+'std_1.json') as json_file: - data_response = b"Policy type STD_1 is OK." - json_payload=json.load(json_file) - response=client.put(SERVER_URL+'policytype?id=STD_1', headers=header, data=json.dumps(json_payload)) - assert response.status_code == 201 - assert data_response == response.data - - # Put a policy type: STD_1, again - with open(testdata+'std_1.json') as json_file: - data_response = b"Policy type STD_1 is OK." - json_payload=json.load(json_file) - response=client.put(SERVER_URL+'policytype?id=STD_1', headers=header, data=json.dumps(json_payload)) - assert response.status_code == 200 - assert data_response == response.data - - # API: Get policy type ids, shall contain type STD_1 - data_response = [ "STD_1" ] - response=client.get(SERVER_URL+'A1-P/v2/policytypes') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # Delete a policy type: STD_1 - data_response = b"" - response=client.delete(SERVER_URL+'policytype?id=STD_1') - assert response.status_code == 204 - assert data_response == response.data - - # API: Get policy type ids, shall be empty - data_response = [ ] - response=client.get(SERVER_URL+'A1-P/v2/policytypes') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # Put a policy type: STD_1 - with open(testdata+'std_1.json') as json_file: - data_response = b"Policy type STD_1 is OK." - json_payload=json.load(json_file) - response=client.put(SERVER_URL+'policytype?id=STD_1', headers=header, data=json.dumps(json_payload)) - assert response.status_code == 201 - assert data_response == response.data - - # API: Get policy type ids, shall contain type STD_1 - data_response = [ "STD_1" ] - response=client.get(SERVER_URL+'A1-P/v2/policytypes') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # Get counter: types (shall be 1) - response=client.get(SERVER_URL+'counter/num_types') - assert response.status_code == 200 - assert response.data == b"1" - - # API: Get policy type: STD_1 - with open(testdata+'std_1.json') as json_file: - data_response = json.load(json_file) - response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # API: API: Get policy instances, shall be empty - data_response = [] - response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # API: Create policy instance pi1 of type: STD_1 - with open(testdata+'pi1.json') as json_file: - json_payload=json.load(json_file) - response=client.put(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi1', headers=header, data=json.dumps(json_payload)) - assert response.status_code == 201 - result=json.loads(response.data) - res=compare(json_payload, result) - assert res == True - - # API: API: Get policy instance pi1 of type: STD_1 - with open(testdata+'pi1.json') as json_file: - data_response = json.load(json_file) - response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi1') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # API: Update policy instance pi1 of type: STD_1 - with open(testdata+'pi1.json') as json_file: - json_payload=json.load(json_file) - response=client.put(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi1', headers=header, data=json.dumps(json_payload)) - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(json_payload, result) - assert res == True - - # API: Update policy instance pi1 of type: STD_1 - with open(testdata+'pi1_updated.json') as json_file: - json_payload=json.load(json_file) - response=client.put(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi1', headers=header, data=json.dumps(json_payload)) - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(json_payload, result) - assert res == True - - # API: Duplicate policy instance pi2 of type: STD_1 - with open(testdata+'pi1_updated.json') as json_file: - data_response = {"title": "Duplicate, the policy json already exists.", "status": 400, "instance": "pi2"} - json_payload=json.load(json_file) - response=client.put(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi2', headers=header, data=json.dumps(json_payload)) - assert response.status_code == 400 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # API: Get policy instances, shall contain pi1 - data_response = ["pi1"] - response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # Get counter: intstance - response=client.get(SERVER_URL+'counter/num_instances') - assert response.status_code == 200 - assert response.data == b"1" - - # Get counter: types - response=client.get(SERVER_URL+'counter/num_types') - assert response.status_code == 200 - assert response.data == b"1" - - # Set force response code 409. ===" - response=client.post(SERVER_URL+'forceresponse?code=409') - assert response.status_code == 200 - - # API: Get policy instances, shall fail - data_response = {"title" : "Conflict", "status" : 409, "detail" : "Request could not be processed in the current state of the resource"} - response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies') - assert response.status_code == 409 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # API: API: Get policy status - data_response = {"enforceStatus" : "", "enforceReason" : ""} - response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi1/status') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # API: Create policy instance pi2 of type: STD_1 - with open(testdata+'pi2.json') as json_file: - json_payload=json.load(json_file) - response=client.put(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi2', headers=header, data=json.dumps(json_payload)) - assert response.status_code == 201 - result=json.loads(response.data) - res=compare(json_payload, result) - assert res == True - - # API: Update policy instance pi2 of type: STD_1 - with open(testdata+'pi2.json') as json_file: - json_payload=json.load(json_file) - response=client.put(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi2', headers=header, data=json.dumps(json_payload)) - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(json_payload, result) - assert res == True - - # API: Get policy instances, shall contain pi1 and pi2 - data_response = ["pi1","pi2"] - response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # Get counter: intstance - response=client.get(SERVER_URL+'counter/num_instances') - assert response.status_code == 200 - assert response.data == b"2" - - # Get counter: types - response=client.get(SERVER_URL+'counter/num_types') - assert response.status_code == 200 - assert response.data == b"1" - - # Set force delay 10 - response=client.post(SERVER_URL+'forcedelay?delay=10') - assert response.status_code == 200 - assert response.data == b"Force delay: 10 sec set for all A1 responses" - - #start time stamp - start=time.time() - - # API: Get policy instances, shall contain pi1 and pi2 and delayed 10 sec - data_response = ["pi1","pi2"] - response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - end=time.time() - - assert (end-start) > 9 - - # Reset force delay - response=client.post(SERVER_URL+'forcedelay') - assert response.status_code == 200 - assert response.data == b"Force delay: None sec set for all A1 responses" - - # API: API: Get policy instance pi1 of type: STD_1 - with open(testdata+'pi1_updated.json') as json_file: - data_response = json.load(json_file) - response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi1') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # API: API: Get policy instance pi2 of type: STD_1 - with open(testdata+'pi2.json') as json_file: - data_response = json.load(json_file) - response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi2') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # API: DELETE policy instance pi1 - data_response = b"" - response=client.delete(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi1') - assert response.status_code == 204 - assert data_response == response.data - - # API: Get policy instances, shall contain pi2 - data_response = ["pi2"] - response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # API: API: Get policy status - data_response = {"enforceStatus" : "", "enforceReason" : ""} - response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi2/status') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - # Set status for policy instance pi2 - response=client.put(SERVER_URL+'status?policyid=pi2&status=OK') - assert response.status_code == 200 - - # API: API: Get policy status - data_response = {"enforceStatus" : "OK"} - response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi2/status') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - print(response.data) - assert res == True - - # Set status for policy instance pi2 - response=client.put(SERVER_URL+'status?policyid=pi2&status=NOTOK&reason=notok_reason') - assert response.status_code == 200 - - # API: API: Get policy status - data_response = {"enforceStatus" : "NOTOK", "enforceReason" : "notok_reason"} - response=client.get(SERVER_URL+'A1-P/v2/policytypes/STD_1/policies/pi2/status') - assert response.status_code == 200 - result=json.loads(response.data) - res=compare(data_response, result) - assert res == True - - - # #Found no way to test these functions - # #'sendstatus' will send a http request that will fail - # #since no server will receive the call - # #These function is instead tested when running the bash script in the 'test' dir - # # # Send status for pi2 - # # response=client.post(SERVER_URL+'sendstatus?policyid=pi2') - # # assert response.status_code == 200 - # # result=json.loads(response.data) - # # res=compare(data_get_status, result) - # # assert res == True - - # # # Send status, shall fail - # # response=client.post(SERVER_URL+'sendstatus') - # # assert response.status_code == 400 - - # Get counter: data_delivery - response=client.get(SERVER_URL+'counter/datadelivery') - assert response.status_code == 200 - assert response.data == b"0" - - # Send data - json_payload={} - response=client.post(SERVER_URL+'datadelivery', headers=header, data=json.dumps(json_payload)) - assert response.status_code == 200 - - # Get counter: data_delivery - response=client.get(SERVER_URL+'counter/datadelivery') - assert response.status_code == 200 - assert response.data == b"1" - - # Get counter: interface - response=client.get(SERVER_URL+'counter/interface') - assert response.status_code == 200 - assert response.data == b"STD_2.0.0" - - # Get counter: remote hosts - response=client.get(SERVER_URL+'counter/remote_hosts') - assert response.status_code == 200 - - # Get counter: intstance - response=client.get(SERVER_URL+'counter/num_instances') - assert response.status_code == 200 - assert response.data == b"1" - - # Get counter: types - response=client.get(SERVER_URL+'counter/num_types') - assert response.status_code == 200 - assert response.data == b"1" \ No newline at end of file diff --git a/near-rt-ric-simulator/tests/unittest_setup.py b/near-rt-ric-simulator/tests/unittest_setup.py deleted file mode 100644 index 0dbbd22cc2dcf420e68d1915f6bd289124051817..0000000000000000000000000000000000000000 --- a/near-rt-ric-simulator/tests/unittest_setup.py +++ /dev/null @@ -1,58 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -# Setting up dir and env for unit test of simualators -import sys -import os -import pytest - -#Server port and base path -PORT_NUMBER="2222" -HOST_IP="localhost" -SERVER_URL="http://"+HOST_IP+":"+PORT_NUMBER+"/" - -#Dir for json test data files -testdata="" - -def setup_env(interface_version): - global testdata - cwd=os.getcwd()+"/" - # Env TESTS_BASE_PATH is set when executed via tox.ini - # If basic test is executed from cmd line, that env var is not needed - if 'TESTS_BASE_PATH' in os.environ: - cwd=os.environ['TESTS_BASE_PATH']+"/" - testdata=cwd+"../test/"+interface_version+"/jsonfiles/" - - #Env var to setup version and host logging - os.environ['APIPATH'] = cwd+"../api/"+interface_version - os.environ['REMOTE_HOSTS_LOGGING'] = "ON" - - # Paths need to run the sim, including needed source file dirs - sys.path.append(os.path.abspath(cwd+'../src/common')) - sys.path.append(os.path.abspath(cwd+'../test/common')) - sys.path.append(os.path.abspath(cwd+'../src/'+interface_version)) - os.chdir(cwd+"../src/"+interface_version) - -def get_testdata_dir(): - return testdata - -#Test client for rest calls -@pytest.fixture -def client(): - from main import app - with app.app.test_client() as c: - yield c \ No newline at end of file diff --git a/near-rt-ric-simulator/src/common/utils.py b/near-rt-ric-simulator/utils.py similarity index 72% rename from near-rt-ric-simulator/src/common/utils.py rename to near-rt-ric-simulator/utils.py index 1ed2a7ed88c5a37d6531637e40cb0e48e32ad3d9..8f7e284037b46fbceb98b85596f0cb73ca1a971a 100644 --- a/near-rt-ric-simulator/src/common/utils.py +++ b/near-rt-ric-simulator/utils.py @@ -1,12 +1,7 @@ # ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# Copyright (C) 2023, S. K. Chaudhary. All rights reserved. # ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/near-rt-ric-simulator/src/STD_1.1.3/var_declaration.py b/near-rt-ric-simulator/var_declaration.py similarity index 71% rename from near-rt-ric-simulator/src/STD_1.1.3/var_declaration.py rename to near-rt-ric-simulator/var_declaration.py index 06b0031dc440d923809c810d9c10c260942d3d2e..f4a1d8b329000dce0d5b7a9c657f32a03dd79fd2 100644 --- a/near-rt-ric-simulator/src/STD_1.1.3/var_declaration.py +++ b/near-rt-ric-simulator/var_declaration.py @@ -1,12 +1,7 @@ # ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# Copyright (C) 2023, S. K. Chaudhary. All rights reserved. # ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/tox.ini b/tox.ini index 82507995b1ffc7f7576d0f5b27345a7018b68cb8..8c68c26dbc5bac4ddbcf75736c6791ac0e00d0d9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,18 +1,14 @@ -# ================================================================================== -# Copyright (c) 2020 Nordix +# ============LICENSE_START=============================================== +# Copyright (C) 2023, S. K. Chaudhary. All rights reserved. +# ======================================================================== +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ================================================================================== [tox] envlist = code,docs,docs-linkcheck