Loading scripts/run_tests_locally-nbi-all.sh +6 −0 Viewed Changes for scripts/run_tests_locally-nbi-all.sh: 6 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -22,8 +22,14 @@ RCFILE=$PROJECTDIR/coverage/.coveragerc # Run unitary tests and analyze coverage of code at same time # helpful pytest flags: --log-level=INFO -o log_cli=true --verbose --maxfail=1 --durations=0 coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ nbi/tests/test_etsi_bwm.py coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ nbi/tests/test_ietf_l2vpn.py coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ nbi/tests/test_ietf_l3vpn.py coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ nbi/tests/test_ietf_network.py scripts/run_tests_locally-nbi-etsi-bwm.sh 0 → 100755 +25 −0 Viewed Changes for scripts/run_tests_locally-nbi-etsi-bwm.sh: 25 added lines, 0 removed lines. Original line number Diff line number Diff line #!/bin/bash # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) # # 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. PROJECTDIR=`pwd` cd $PROJECTDIR/src RCFILE=$PROJECTDIR/coverage/.coveragerc # Run unitary tests and analyze coverage of code at same time # helpful pytest flags: --log-level=INFO -o log_cli=true --verbose --maxfail=1 --durations=0 coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ nbi/tests/test_etsi_bwm.py src/nbi/service/rest_server/nbi_plugins/etsi_bwm/Resources.py +21 −10 Viewed Changes for src/nbi/service/rest_server/nbi_plugins/etsi_bwm/Resources.py: 21 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -12,14 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. import copy import copy, deepmerge, json, logging from common.Constants import DEFAULT_CONTEXT_NAME from flask_restful import Resource, request from context.client.ContextClient import ContextClient from flask_restful import Resource, request from service.client.ServiceClient import ServiceClient from .Tools import ( format_grpc_to_json, grpc_context_id, grpc_service_id, bwInfo_2_service, service_2_bwInfo) LOGGER = logging.getLogger(__name__) class _Resource(Resource): Loading @@ -39,7 +40,6 @@ class BwInfo(_Resource): bwinfo = request.get_json() service = bwInfo_2_service(self.client, bwinfo) stripped_service = copy.deepcopy(service) stripped_service.ClearField('service_endpoint_ids') stripped_service.ClearField('service_constraints') stripped_service.ClearField('service_config') Loading @@ -57,19 +57,30 @@ class BwInfoId(_Resource): return service_2_bwInfo(service) def put(self, allocationId: str): json_data = request.get_json() json_data = json.loads(request.get_json()) service = bwInfo_2_service(self.client, json_data) response = self.service_client.UpdateService(service) return format_grpc_to_json(response) self.service_client.UpdateService(service) service = self.client.GetService(grpc_service_id(DEFAULT_CONTEXT_NAME, json_data['appInsId'])) response_bwm = service_2_bwInfo(service) return response_bwm def patch(self, allocationId: str): json_data = request.get_json() if not 'appInsId' in json_data: json_data['appInsId'] = allocationId service = bwInfo_2_service(self.client, json_data) response = self.service_client.UpdateService(service) return format_grpc_to_json(response) service = self.client.GetService(grpc_service_id(DEFAULT_CONTEXT_NAME, json_data['appInsId'])) current_bwm = service_2_bwInfo(service) new_bmw = deepmerge.always_merger.merge(current_bwm, json_data) service = bwInfo_2_service(self.client, new_bmw) self.service_client.UpdateService(service) service = self.client.GetService(grpc_service_id(DEFAULT_CONTEXT_NAME, json_data['appInsId'])) response_bwm = service_2_bwInfo(service) return response_bwm def delete(self, allocationId: str): self.service_client.DeleteService(grpc_service_id(DEFAULT_CONTEXT_NAME, allocationId)) return src/nbi/service/rest_server/nbi_plugins/etsi_bwm/Tools.py +10 −11 Viewed Changes for src/nbi/service/rest_server/nbi_plugins/etsi_bwm/Tools.py: 10 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -15,8 +15,11 @@ import json import logging import time from decimal import ROUND_HALF_EVEN, Decimal from flask.json import jsonify from common.proto.context_pb2 import ContextId, Empty, EndPointId, ServiceId, ServiceTypeEnum, Service, Constraint, Constraint_SLA_Capacity, ConfigRule, ConfigRule_Custom, ConfigActionEnum from common.proto.context_pb2 import ( ContextId, Empty, EndPointId, ServiceId, ServiceTypeEnum, Service, Constraint, Constraint_SLA_Capacity, ConfigRule, ConfigRule_Custom, ConfigActionEnum) from common.tools.grpc.Tools import grpc_message_to_json from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Service import json_service_id Loading @@ -27,13 +30,15 @@ LOGGER = logging.getLogger(__name__) def service_2_bwInfo(service: Service) -> dict: response = {} # allocationDirection = '??' # String: 00 = Downlink (towards the UE); 01 = Uplink (towards the application/session); 10 = Symmetrical response['appInsId'] = service.service_id.context_id.context_uuid.uuid # String: Application instance identifier response['appInsId'] = service.service_id.service_uuid.uuid # String: Application instance identifier for constraint in service.service_constraints: if constraint.WhichOneof('constraint') == 'sla_capacity': response['fixedAllocation'] = str(constraint.sla_capacity.capacity_gbps*1000) # String: Size of requested fixed BW allocation in [bps] # String: Size of requested fixed BW allocation in [bps] fixed_allocation = Decimal(constraint.sla_capacity.capacity_gbps * 1.e9) fixed_allocation = fixed_allocation.quantize(Decimal('0.1'), rounding=ROUND_HALF_EVEN) response['fixedAllocation'] = str(fixed_allocation) break for config_rule in service.service_config.config_rules: for key in ['allocationDirection', 'fixedBWPriority', 'requestType', 'sourceIp', 'sourcePort', 'dstPort', 'protocol', 'sessionFilter']: if config_rule.custom.resource_key == key: Loading @@ -42,7 +47,6 @@ def service_2_bwInfo(service: Service) -> dict: else: response[key] = json.loads(config_rule.custom.resource_value) unixtime = time.time() response['timeStamp'] = { # Time stamp to indicate when the corresponding information elements are sent "seconds": int(unixtime), Loading @@ -53,7 +57,6 @@ def service_2_bwInfo(service: Service) -> dict: def bwInfo_2_service(client, bwInfo: dict) -> Service: service = Service() for key in ['allocationDirection', 'fixedBWPriority', 'requestType', 'timeStamp', 'sessionFilter']: if key not in bwInfo: continue Loading Loading @@ -83,10 +86,6 @@ def bwInfo_2_service(client, bwInfo: dict) -> Service: ep_id.device_id.device_uuid.uuid = device.device_id.device_uuid.uuid service.service_endpoint_ids.append(ep_id) if len(service.service_endpoint_ids) < 2: LOGGER.error('No endpoints matched') return None service.service_type = ServiceTypeEnum.SERVICETYPE_L3NM if 'appInsId' in bwInfo: Loading @@ -96,7 +95,7 @@ def bwInfo_2_service(client, bwInfo: dict) -> Service: if 'fixedAllocation' in bwInfo: capacity = Constraint_SLA_Capacity() capacity.capacity_gbps = float(bwInfo['fixedAllocation']) capacity.capacity_gbps = float(bwInfo['fixedAllocation']) / 1.e9 constraint = Constraint() constraint.sla_capacity.CopyFrom(capacity) service.service_constraints.append(constraint) Loading src/nbi/service/rest_server/nbi_plugins/etsi_bwm/__init__.py +1 −1 Viewed Changes for src/nbi/service/rest_server/nbi_plugins/etsi_bwm/__init__.py: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ from nbi.service.rest_server.RestServer import RestServer from .Resources import BwInfo, BwInfoId URL_PREFIX = '/bwm/v1' URL_PREFIX = '/restconf/bwm/v1' # Use 'path' type since some identifiers might contain char '/' and Flask is unable to recognize them in 'string' type. RESOURCES = [ Loading Loading
scripts/run_tests_locally-nbi-all.sh +6 −0 Viewed Changes for scripts/run_tests_locally-nbi-all.sh: 6 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -22,8 +22,14 @@ RCFILE=$PROJECTDIR/coverage/.coveragerc # Run unitary tests and analyze coverage of code at same time # helpful pytest flags: --log-level=INFO -o log_cli=true --verbose --maxfail=1 --durations=0 coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ nbi/tests/test_etsi_bwm.py coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ nbi/tests/test_ietf_l2vpn.py coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ nbi/tests/test_ietf_l3vpn.py coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ nbi/tests/test_ietf_network.py
scripts/run_tests_locally-nbi-etsi-bwm.sh 0 → 100755 +25 −0 Viewed Changes for scripts/run_tests_locally-nbi-etsi-bwm.sh: 25 added lines, 0 removed lines. Original line number Diff line number Diff line #!/bin/bash # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) # # 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. PROJECTDIR=`pwd` cd $PROJECTDIR/src RCFILE=$PROJECTDIR/coverage/.coveragerc # Run unitary tests and analyze coverage of code at same time # helpful pytest flags: --log-level=INFO -o log_cli=true --verbose --maxfail=1 --durations=0 coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ nbi/tests/test_etsi_bwm.py
src/nbi/service/rest_server/nbi_plugins/etsi_bwm/Resources.py +21 −10 Viewed Changes for src/nbi/service/rest_server/nbi_plugins/etsi_bwm/Resources.py: 21 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -12,14 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. import copy import copy, deepmerge, json, logging from common.Constants import DEFAULT_CONTEXT_NAME from flask_restful import Resource, request from context.client.ContextClient import ContextClient from flask_restful import Resource, request from service.client.ServiceClient import ServiceClient from .Tools import ( format_grpc_to_json, grpc_context_id, grpc_service_id, bwInfo_2_service, service_2_bwInfo) LOGGER = logging.getLogger(__name__) class _Resource(Resource): Loading @@ -39,7 +40,6 @@ class BwInfo(_Resource): bwinfo = request.get_json() service = bwInfo_2_service(self.client, bwinfo) stripped_service = copy.deepcopy(service) stripped_service.ClearField('service_endpoint_ids') stripped_service.ClearField('service_constraints') stripped_service.ClearField('service_config') Loading @@ -57,19 +57,30 @@ class BwInfoId(_Resource): return service_2_bwInfo(service) def put(self, allocationId: str): json_data = request.get_json() json_data = json.loads(request.get_json()) service = bwInfo_2_service(self.client, json_data) response = self.service_client.UpdateService(service) return format_grpc_to_json(response) self.service_client.UpdateService(service) service = self.client.GetService(grpc_service_id(DEFAULT_CONTEXT_NAME, json_data['appInsId'])) response_bwm = service_2_bwInfo(service) return response_bwm def patch(self, allocationId: str): json_data = request.get_json() if not 'appInsId' in json_data: json_data['appInsId'] = allocationId service = bwInfo_2_service(self.client, json_data) response = self.service_client.UpdateService(service) return format_grpc_to_json(response) service = self.client.GetService(grpc_service_id(DEFAULT_CONTEXT_NAME, json_data['appInsId'])) current_bwm = service_2_bwInfo(service) new_bmw = deepmerge.always_merger.merge(current_bwm, json_data) service = bwInfo_2_service(self.client, new_bmw) self.service_client.UpdateService(service) service = self.client.GetService(grpc_service_id(DEFAULT_CONTEXT_NAME, json_data['appInsId'])) response_bwm = service_2_bwInfo(service) return response_bwm def delete(self, allocationId: str): self.service_client.DeleteService(grpc_service_id(DEFAULT_CONTEXT_NAME, allocationId)) return
src/nbi/service/rest_server/nbi_plugins/etsi_bwm/Tools.py +10 −11 Viewed Changes for src/nbi/service/rest_server/nbi_plugins/etsi_bwm/Tools.py: 10 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -15,8 +15,11 @@ import json import logging import time from decimal import ROUND_HALF_EVEN, Decimal from flask.json import jsonify from common.proto.context_pb2 import ContextId, Empty, EndPointId, ServiceId, ServiceTypeEnum, Service, Constraint, Constraint_SLA_Capacity, ConfigRule, ConfigRule_Custom, ConfigActionEnum from common.proto.context_pb2 import ( ContextId, Empty, EndPointId, ServiceId, ServiceTypeEnum, Service, Constraint, Constraint_SLA_Capacity, ConfigRule, ConfigRule_Custom, ConfigActionEnum) from common.tools.grpc.Tools import grpc_message_to_json from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Service import json_service_id Loading @@ -27,13 +30,15 @@ LOGGER = logging.getLogger(__name__) def service_2_bwInfo(service: Service) -> dict: response = {} # allocationDirection = '??' # String: 00 = Downlink (towards the UE); 01 = Uplink (towards the application/session); 10 = Symmetrical response['appInsId'] = service.service_id.context_id.context_uuid.uuid # String: Application instance identifier response['appInsId'] = service.service_id.service_uuid.uuid # String: Application instance identifier for constraint in service.service_constraints: if constraint.WhichOneof('constraint') == 'sla_capacity': response['fixedAllocation'] = str(constraint.sla_capacity.capacity_gbps*1000) # String: Size of requested fixed BW allocation in [bps] # String: Size of requested fixed BW allocation in [bps] fixed_allocation = Decimal(constraint.sla_capacity.capacity_gbps * 1.e9) fixed_allocation = fixed_allocation.quantize(Decimal('0.1'), rounding=ROUND_HALF_EVEN) response['fixedAllocation'] = str(fixed_allocation) break for config_rule in service.service_config.config_rules: for key in ['allocationDirection', 'fixedBWPriority', 'requestType', 'sourceIp', 'sourcePort', 'dstPort', 'protocol', 'sessionFilter']: if config_rule.custom.resource_key == key: Loading @@ -42,7 +47,6 @@ def service_2_bwInfo(service: Service) -> dict: else: response[key] = json.loads(config_rule.custom.resource_value) unixtime = time.time() response['timeStamp'] = { # Time stamp to indicate when the corresponding information elements are sent "seconds": int(unixtime), Loading @@ -53,7 +57,6 @@ def service_2_bwInfo(service: Service) -> dict: def bwInfo_2_service(client, bwInfo: dict) -> Service: service = Service() for key in ['allocationDirection', 'fixedBWPriority', 'requestType', 'timeStamp', 'sessionFilter']: if key not in bwInfo: continue Loading Loading @@ -83,10 +86,6 @@ def bwInfo_2_service(client, bwInfo: dict) -> Service: ep_id.device_id.device_uuid.uuid = device.device_id.device_uuid.uuid service.service_endpoint_ids.append(ep_id) if len(service.service_endpoint_ids) < 2: LOGGER.error('No endpoints matched') return None service.service_type = ServiceTypeEnum.SERVICETYPE_L3NM if 'appInsId' in bwInfo: Loading @@ -96,7 +95,7 @@ def bwInfo_2_service(client, bwInfo: dict) -> Service: if 'fixedAllocation' in bwInfo: capacity = Constraint_SLA_Capacity() capacity.capacity_gbps = float(bwInfo['fixedAllocation']) capacity.capacity_gbps = float(bwInfo['fixedAllocation']) / 1.e9 constraint = Constraint() constraint.sla_capacity.CopyFrom(capacity) service.service_constraints.append(constraint) Loading
src/nbi/service/rest_server/nbi_plugins/etsi_bwm/__init__.py +1 −1 Viewed Changes for src/nbi/service/rest_server/nbi_plugins/etsi_bwm/__init__.py: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ from nbi.service.rest_server.RestServer import RestServer from .Resources import BwInfo, BwInfoId URL_PREFIX = '/bwm/v1' URL_PREFIX = '/restconf/bwm/v1' # Use 'path' type since some identifiers might contain char '/' and Flask is unable to recognize them in 'string' type. RESOURCES = [ Loading