diff --git a/src/service/service/service_handlers/optical_tfs/OpticalTfsServiceHandler.py b/src/service/service/service_handlers/optical_tfs/OpticalTfsServiceHandler.py index 93dfce19e81f34b399fcdcdb626154dece5c8111..1b48f90f1abaac155a38479667e77b803f30437d 100644 --- a/src/service/service/service_handlers/optical_tfs/OpticalTfsServiceHandler.py +++ b/src/service/service/service_handlers/optical_tfs/OpticalTfsServiceHandler.py @@ -16,7 +16,7 @@ import json, logging from typing import Any, Dict, List, Optional, Tuple, Union from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method from common.proto.context_pb2 import ConfigRule, DeviceId, Service -from common.tools.object_factory.ConfigRule import json_config_rule_set +from common.tools.object_factory.ConfigRule import json_config_rule_delete, json_config_rule_set from common.tools.object_factory.Device import json_device_id from common.type_checkers.Checkers import chk_type from service.service.service_handler_api.Tools import get_device_endpoint_uuids @@ -36,6 +36,20 @@ class OpticalTfsServiceHandler(_ServiceHandler): self.__task_executor = task_executor self.__settings_handler = SettingsHandler(service.service_config, **settings) + def _get_constraints(self) -> Tuple[Optional[int], Optional[int], Optional[int]]: + bitrate = None + bidir = None + ob_width = None + for constraint in self.__service.service_constraints: + if constraint.WhichOneof('constraint') != 'custom': continue + if constraint.custom.constraint_type == 'bandwidth[gbps]': + bitrate = int(float(constraint.custom.constraint_value)) + elif constraint.custom.constraint_type == 'bidirectionality': + bidir = int(constraint.custom.constraint_value) == 1 + elif constraint.custom.constraint_type == 'optical-band-width[GHz]': + ob_width = int(constraint.custom.constraint_value) + return bitrate, bidir, ob_width + @metered_subclass_method(METRICS_POOL) def SetEndpoint( self, endpoints : List[Tuple[str, str, Optional[str]]], connection_uuid : Optional[str] = None @@ -45,9 +59,8 @@ class OpticalTfsServiceHandler(_ServiceHandler): if len(endpoints) < 2: return [] service_uuid = self.__service.service_id.service_uuid.uuid - settings = self.__settings_handler.get('/settings') - json_settings : Dict = {} if settings is None else settings.value - bitrate = json_settings['bitrate'] + service_name = self.__service.name + bitrate, bidir, ob_width = self._get_constraints() results = [] try: @@ -64,10 +77,15 @@ class OpticalTfsServiceHandler(_ServiceHandler): controller = src_controller json_config_rule = json_config_rule_set('/services/service[{:s}]'.format(service_uuid), { - 'uuid' : service_uuid, - 'src_node' : src_endpoint_uuid, - 'dst_node' : dst_endpoint_uuid, - 'bitrate' : bitrate + 'service_uuid' : service_uuid, + 'service_name' : service_name, + 'src_device_uuid' : src_device_uuid, + 'src_endpoint_uuid': src_endpoint_uuid, + 'dst_device_uuid' : dst_device_uuid, + 'dst_endpoint_uuid': dst_endpoint_uuid, + 'bitrate' : bitrate, + 'bidir' : bidir, + 'ob_width' : ob_width, }) del controller.device_config.config_rules[:] controller.device_config.config_rules.append(ConfigRule(**json_config_rule)) @@ -91,7 +109,7 @@ class OpticalTfsServiceHandler(_ServiceHandler): settings = self.__settings_handler.get('/settings') json_settings : Dict = {} if settings is None else settings.value flow_id = json_settings['flow_id'] - bitrate = json_settings['bitrate'] + bitrate, bidir, ob_width = self._get_constraints() results = [] try: @@ -107,12 +125,16 @@ class OpticalTfsServiceHandler(_ServiceHandler): controller = src_controller - json_config_rule = json_config_rule_set('/services/service[{:s}]'.format(service_uuid), { - 'uuid' : service_uuid, - 'flow_id' : flow_id, - 'src_node' : src_endpoint_uuid, - 'dst_node' : dst_endpoint_uuid, - 'bitrate' : bitrate + json_config_rule = json_config_rule_delete('/services/service[{:s}]'.format(service_uuid), { + 'flow_id' : flow_id, + 'service_uuid' : service_uuid, + 'src_device_uuid' : src_device_uuid, + 'src_endpoint_uuid': src_endpoint_uuid, + 'dst_device_uuid' : dst_device_uuid, + 'dst_endpoint_uuid': dst_endpoint_uuid, + 'bitrate' : bitrate, + 'bidir' : bidir, + 'ob_width' : ob_width, }) del controller.device_config.config_rules[:]