Commit 719df434 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Service & PathComp components:

- Corrected logic to select service handlers
- Code cleanup
parent b09c880b
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -70,11 +70,6 @@ def get_device_controller_uuid(
) -> Optional[str]:
    controller_uuid = device.controller_id.device_uuid.uuid
    if len(controller_uuid) > 0: return controller_uuid
    #for config_rule in device.device_config.config_rules:
    #    if config_rule.WhichOneof('config_rule') != 'custom': continue
    #    if config_rule.custom.resource_key != '_controller': continue
    #    device_controller_id = json.loads(config_rule.custom.resource_value)
    #    return device_controller_id['uuid']
    return None

def _map_device_type(device : Device) -> DeviceTypeEnum:
+33 −21
Original line number Diff line number Diff line
@@ -52,6 +52,22 @@ class CacheableObjectType(Enum):
    SERVICE    = 'service'
    QKD_APP    = 'qkd-app'

CONTROLLER_DEVICE_TYPES = {
    DeviceTypeEnum.EMULATED_IP_SDN_CONTROLLER,
    DeviceTypeEnum.EMULATED_MICROWAVE_RADIO_SYSTEM,
    DeviceTypeEnum.EMULATED_OPEN_LINE_SYSTEM,
    DeviceTypeEnum.IETF_SLICE,
    DeviceTypeEnum.IP_SDN_CONTROLLER,
    DeviceTypeEnum.MICROWAVE_RADIO_SYSTEM,
    DeviceTypeEnum.OPEN_LINE_SYSTEM,
    DeviceTypeEnum.OPENFLOW_RYU_CONTROLLER,
    DeviceTypeEnum.TERAFLOWSDN_CONTROLLER,
}
EXPANSION_CONTROLLER_DEVICE_TYPES = {
    DeviceTypeEnum.IETF_SLICE,
    DeviceTypeEnum.OPENFLOW_RYU_CONTROLLER,
}

class TaskExecutor:
    def __init__(self, service_handler_factory : ServiceHandlerFactory) -> None:
        self._service_handler_factory = service_handler_factory
@@ -255,16 +271,6 @@ class TaskExecutor:
        return service_handler_class.check_media_channel(connection_uuid)

    def get_device_controller(self, device : Device) -> Optional[Device]:
        #json_controller = None
        #for config_rule in device.device_config.config_rules:
        #    if config_rule.WhichOneof('config_rule') != 'custom': continue
        #    if config_rule.custom.resource_key != '_controller': continue
        #    json_controller = json.loads(config_rule.custom.resource_value)
        #    break

        #if json_controller is None: return None

        #controller_uuid = json_controller['uuid']
        controller_uuid = device.controller_id.device_uuid.uuid
        if len(controller_uuid) == 0: return None
        controller = self.get_device(DeviceId(**json_device_id(controller_uuid)))
@@ -276,6 +282,7 @@ class TaskExecutor:
        self, connection : Connection, exclude_managed_by_controller : bool = False
    ) -> Dict[DeviceTypeEnum, Dict[str, Device]]:
        devices : Dict[DeviceTypeEnum, Dict[str, Device]] = dict()
        controllers : Dict[DeviceTypeEnum, Dict[str, Device]] = dict()
        for endpoint_id in connection.path_hops_endpoint_ids:
            device = self.get_device(endpoint_id.device_id)
            device_uuid = endpoint_id.device_id.device_uuid.uuid
@@ -284,6 +291,9 @@ class TaskExecutor:
            controller = self.get_device_controller(device)
            if controller is None:
                device_type = DeviceTypeEnum._value2member_map_[device.device_type]
                if device_type in CONTROLLER_DEVICE_TYPES:
                    controllers.setdefault(device_type, dict())[device_uuid] = device
                else:
                    devices.setdefault(device_type, dict())[device_uuid] = device
            else:
                # ===== Ryu original test ========================================================================
@@ -300,17 +310,19 @@ class TaskExecutor:

                if not exclude_managed_by_controller:
                    # Controller device types for those underlying path is needed by service handler
                    CONTROLLER_DEVICE_TYPES = {
                        DeviceTypeEnum.IETF_SLICE, DeviceTypeEnum.OPENFLOW_RYU_CONTROLLER
                    }
                    controller_device_type_enum = DeviceTypeEnum._value2member_map_[controller.device_type]
                    if controller_device_type_enum in CONTROLLER_DEVICE_TYPES:
                        devices.setdefault(controller_device_type_enum, dict())[device_uuid] = device
                    else:
                    device_type = DeviceTypeEnum._value2member_map_[controller.device_type]
                    if device_type not in EXPANSION_CONTROLLER_DEVICE_TYPES:
                        device_type = DeviceTypeEnum._value2member_map_[device.device_type]
                    devices.setdefault(device_type, dict())[device_uuid] = device
                
                device_type = DeviceTypeEnum._value2member_map_[controller.device_type]
                devices.setdefault(device_type, dict())[controller.device_id.device_uuid.uuid] = controller
                controllers.setdefault(device_type, dict())[controller.device_id.device_uuid.uuid] = controller
        
        LOGGER.debug('[get_devices_from_connection] devices = {:s}'.format(str(devices)))
        LOGGER.debug('[get_devices_from_connection] controllers = {:s}'.format(str(controllers)))
        if len(devices) == 0 and len(controllers) > 0:
            return controllers
        else:
            return devices

    # ----- Service-related methods ------------------------------------------------------------------------------------