Skip to content
Snippets Groups Projects
Commit c0a1c3c6 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Service component:

- Renamed device "manager" to device "controller"
- Extended TAPI Service Handler to support optional device controllers
- Fixed IETF L2VPN Service Handler delete to support optional device controllers
parent d9711a72
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!71OFC'23 + IETF L2VPN Device Driver + Device Controllers + Multiple small improvements
...@@ -55,16 +55,16 @@ class L2NM_IETFL2VPN_ServiceHandler(_ServiceHandler): ...@@ -55,16 +55,16 @@ class L2NM_IETFL2VPN_ServiceHandler(_ServiceHandler):
src_device_uuid, src_endpoint_uuid = get_device_endpoint_uuids(endpoints[0]) src_device_uuid, src_endpoint_uuid = get_device_endpoint_uuids(endpoints[0])
src_device = self.__task_executor.get_device(DeviceId(**json_device_id(src_device_uuid))) src_device = self.__task_executor.get_device(DeviceId(**json_device_id(src_device_uuid)))
src_endpoint = get_endpoint_matching(src_device, src_endpoint_uuid) src_endpoint = get_endpoint_matching(src_device, src_endpoint_uuid)
src_manager = self.__task_executor.get_device_manager(src_device) src_controller = self.__task_executor.get_device_controller(src_device)
dst_device_uuid, dst_endpoint_uuid = get_device_endpoint_uuids(endpoints[1]) dst_device_uuid, dst_endpoint_uuid = get_device_endpoint_uuids(endpoints[1])
dst_device = self.__task_executor.get_device(DeviceId(**json_device_id(dst_device_uuid))) dst_device = self.__task_executor.get_device(DeviceId(**json_device_id(dst_device_uuid)))
dst_endpoint = get_endpoint_matching(dst_device, dst_endpoint_uuid) dst_endpoint = get_endpoint_matching(dst_device, dst_endpoint_uuid)
dst_manager = self.__task_executor.get_device_manager(dst_device) dst_controller = self.__task_executor.get_device_controller(dst_device)
if src_manager.device_id.device_uuid.uuid != dst_manager.device_id.device_uuid.uuid: if src_controller.device_id.device_uuid.uuid != dst_controller.device_id.device_uuid.uuid:
raise Exception('Different Src-Dst devices not supported by now') raise Exception('Different Src-Dst devices not supported by now')
manager = src_manager controller = src_controller
json_config_rule = json_config_rule_set('/services/service[{:s}]'.format(service_uuid), { json_config_rule = json_config_rule_set('/services/service[{:s}]'.format(service_uuid), {
'uuid' : service_uuid, 'uuid' : service_uuid,
...@@ -75,9 +75,9 @@ class L2NM_IETFL2VPN_ServiceHandler(_ServiceHandler): ...@@ -75,9 +75,9 @@ class L2NM_IETFL2VPN_ServiceHandler(_ServiceHandler):
'encapsulation_type': encap_type, 'encapsulation_type': encap_type,
'vlan_id' : vlan_id, 'vlan_id' : vlan_id,
}) })
del manager.device_config.config_rules[:] del controller.device_config.config_rules[:]
manager.device_config.config_rules.append(ConfigRule(**json_config_rule)) controller.device_config.config_rules.append(ConfigRule(**json_config_rule))
self.__task_executor.configure_device(manager) self.__task_executor.configure_device(controller)
results.append(True) results.append(True)
except Exception as e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except
LOGGER.exception('Unable to SetEndpoint for Service({:s})'.format(str(service_uuid))) LOGGER.exception('Unable to SetEndpoint for Service({:s})'.format(str(service_uuid)))
...@@ -97,21 +97,24 @@ class L2NM_IETFL2VPN_ServiceHandler(_ServiceHandler): ...@@ -97,21 +97,24 @@ class L2NM_IETFL2VPN_ServiceHandler(_ServiceHandler):
results = [] results = []
try: try:
device_uuid_src, _ = get_device_endpoint_uuids(endpoints[0]) src_device_uuid, _ = get_device_endpoint_uuids(endpoints[0])
device_uuid_dst, _ = get_device_endpoint_uuids(endpoints[1]) src_device = self.__task_executor.get_device(DeviceId(**json_device_id(src_device_uuid)))
src_controller = self.__task_executor.get_device_controller(src_device)
if device_uuid_src != device_uuid_dst: dst_device_uuid, _ = get_device_endpoint_uuids(endpoints[1])
raise Exception('Different Src-Dst devices not supported by now') dst_device = self.__task_executor.get_device(DeviceId(**json_device_id(dst_device_uuid)))
device_uuid = device_uuid_src dst_controller = self.__task_executor.get_device_controller(dst_device)
device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) if src_controller.device_id.device_uuid.uuid != dst_controller.device_id.device_uuid.uuid:
raise Exception('Different Src-Dst devices not supported by now')
controller = src_controller
json_config_rule = json_config_rule_delete('/services/service[{:s}]'.format(service_uuid), { json_config_rule = json_config_rule_delete('/services/service[{:s}]'.format(service_uuid), {
'uuid': service_uuid 'uuid': service_uuid
}) })
del device_obj.device_config.config_rules[:] del controller.device_config.config_rules[:]
device_obj.device_config.config_rules.append(ConfigRule(**json_config_rule)) controller.device_config.config_rules.append(ConfigRule(**json_config_rule))
self.__task_executor.configure_device(device_obj) self.__task_executor.configure_device(controller)
results.append(True) results.append(True)
except Exception as e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except
LOGGER.exception('Unable to DeleteEndpoint for Service({:s})'.format(str(service_uuid))) LOGGER.exception('Unable to DeleteEndpoint for Service({:s})'.format(str(service_uuid)))
......
...@@ -19,7 +19,7 @@ from common.proto.context_pb2 import ConfigRule, DeviceId, Service ...@@ -19,7 +19,7 @@ from common.proto.context_pb2 import ConfigRule, DeviceId, Service
from common.tools.object_factory.ConfigRule import json_config_rule_delete, 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.tools.object_factory.Device import json_device_id
from common.type_checkers.Checkers import chk_type from common.type_checkers.Checkers import chk_type
from service.service.service_handler_api.Tools import get_device_endpoint_uuids from service.service.service_handler_api.Tools import get_device_endpoint_uuids, get_endpoint_matching
from service.service.service_handler_api._ServiceHandler import _ServiceHandler from service.service.service_handler_api._ServiceHandler import _ServiceHandler
from service.service.service_handler_api.SettingsHandler import SettingsHandler from service.service.service_handler_api.SettingsHandler import SettingsHandler
from service.service.task_scheduler.TaskExecutor import TaskExecutor from service.service.task_scheduler.TaskExecutor import TaskExecutor
...@@ -55,28 +55,35 @@ class TapiServiceHandler(_ServiceHandler): ...@@ -55,28 +55,35 @@ class TapiServiceHandler(_ServiceHandler):
results = [] results = []
try: try:
device_uuid_src, endpoint_uuid_src = get_device_endpoint_uuids(endpoints[0]) src_device_uuid, src_endpoint_uuid = get_device_endpoint_uuids(endpoints[0])
device_uuid_dst, endpoint_uuid_dst = get_device_endpoint_uuids(endpoints[1]) src_device = self.__task_executor.get_device(DeviceId(**json_device_id(src_device_uuid)))
src_endpoint = get_endpoint_matching(src_device, src_endpoint_uuid)
if device_uuid_src != device_uuid_dst: src_controller = self.__task_executor.get_device_controller(src_device)
if src_controller is None: src_controller = src_device
dst_device_uuid, dst_endpoint_uuid = get_device_endpoint_uuids(endpoints[1])
dst_device = self.__task_executor.get_device(DeviceId(**json_device_id(dst_device_uuid)))
dst_endpoint = get_endpoint_matching(dst_device, dst_endpoint_uuid)
dst_controller = self.__task_executor.get_device_controller(dst_device)
if dst_controller is None: dst_controller = dst_device
if src_controller.device_id.device_uuid.uuid != dst_controller.device_id.device_uuid.uuid:
raise Exception('Different Src-Dst devices not supported by now') raise Exception('Different Src-Dst devices not supported by now')
device_uuid = device_uuid_src controller = src_controller
device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid)))
json_config_rule = json_config_rule_set('/services/service[{:s}]'.format(service_uuid), { json_config_rule = json_config_rule_set('/services/service[{:s}]'.format(service_uuid), {
'uuid' : service_uuid, 'uuid' : service_uuid,
'input_sip' : endpoint_uuid_src, 'input_sip' : src_endpoint.name,
'output_sip' : endpoint_uuid_dst, 'output_sip' : dst_endpoint.name,
'capacity_unit' : capacity_unit, 'capacity_unit' : capacity_unit,
'capacity_value' : capacity_value, 'capacity_value' : capacity_value,
'layer_protocol_name' : layer_proto_name, 'layer_protocol_name' : layer_proto_name,
'layer_protocol_qualifier': layer_proto_qual, 'layer_protocol_qualifier': layer_proto_qual,
'direction' : direction, 'direction' : direction,
}) })
del device_obj.device_config.config_rules[:] del controller.device_config.config_rules[:]
device_obj.device_config.config_rules.append(ConfigRule(**json_config_rule)) controller.device_config.config_rules.append(ConfigRule(**json_config_rule))
self.__task_executor.configure_device(device_obj) self.__task_executor.configure_device(controller)
results.append(True) results.append(True)
except Exception as e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except
LOGGER.exception('Unable to SetEndpoint for Service({:s})'.format(str(service_uuid))) LOGGER.exception('Unable to SetEndpoint for Service({:s})'.format(str(service_uuid)))
...@@ -96,21 +103,26 @@ class TapiServiceHandler(_ServiceHandler): ...@@ -96,21 +103,26 @@ class TapiServiceHandler(_ServiceHandler):
results = [] results = []
try: try:
device_uuid_src, _ = get_device_endpoint_uuids(endpoints[0]) src_device_uuid, _ = get_device_endpoint_uuids(endpoints[0])
device_uuid_dst, _ = get_device_endpoint_uuids(endpoints[1]) src_device = self.__task_executor.get_device(DeviceId(**json_device_id(src_device_uuid)))
src_controller = self.__task_executor.get_device_controller(src_device)
if src_controller is None: src_controller = src_device
if device_uuid_src != device_uuid_dst: dst_device_uuid, _ = get_device_endpoint_uuids(endpoints[1])
raise Exception('Different Src-Dst devices not supported by now') dst_device = self.__task_executor.get_device(DeviceId(**json_device_id(dst_device_uuid)))
device_uuid = device_uuid_src dst_controller = self.__task_executor.get_device_controller(dst_device)
if dst_controller is None: dst_controller = dst_device
device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) if src_controller.device_id.device_uuid.uuid != dst_controller.device_id.device_uuid.uuid:
raise Exception('Different Src-Dst devices not supported by now')
controller = src_controller
json_config_rule = json_config_rule_delete('/services/service[{:s}]'.format(service_uuid), { json_config_rule = json_config_rule_delete('/services/service[{:s}]'.format(service_uuid), {
'uuid': service_uuid 'uuid': service_uuid
}) })
del device_obj.device_config.config_rules[:] del controller.device_config.config_rules[:]
device_obj.device_config.config_rules.append(ConfigRule(**json_config_rule)) controller.device_config.config_rules.append(ConfigRule(**json_config_rule))
self.__task_executor.configure_device(device_obj) self.__task_executor.configure_device(controller)
results.append(True) results.append(True)
except Exception as e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except
LOGGER.exception('Unable to DeleteEndpoint for Service({:s})'.format(str(service_uuid))) LOGGER.exception('Unable to DeleteEndpoint for Service({:s})'.format(str(service_uuid)))
......
...@@ -105,24 +105,24 @@ class TaskExecutor: ...@@ -105,24 +105,24 @@ class TaskExecutor:
self._device_client.ConfigureDevice(device) self._device_client.ConfigureDevice(device)
self._store_grpc_object(CacheableObjectType.DEVICE, device_key, device) self._store_grpc_object(CacheableObjectType.DEVICE, device_key, device)
def get_device_manager(self, device : Device) -> Optional[Device]: def get_device_controller(self, device : Device) -> Optional[Device]:
json_manager = None json_controller = None
for config_rule in device.device_config.config_rules: for config_rule in device.device_config.config_rules:
if config_rule.WhichOneof('config_rule') != 'custom': continue if config_rule.WhichOneof('config_rule') != 'custom': continue
if config_rule.custom.resource_key != '_manager': continue if config_rule.custom.resource_key != '_controller': continue
json_manager = json.loads(config_rule.custom.resource_value) json_controller = json.loads(config_rule.custom.resource_value)
break break
if json_manager is None: return None if json_controller is None: return None
manager_uuid = json_manager['uuid'] controller_uuid = json_controller['uuid']
manager = self.get_device(DeviceId(**json_device_id(manager_uuid))) controller = self.get_device(DeviceId(**json_device_id(controller_uuid)))
manager_uuid = manager.device_id.device_uuid.uuid controller_uuid = controller.device_id.device_uuid.uuid
if manager is None: raise Exception('Device({:s}) not found'.format(str(manager_uuid))) if controller is None: raise Exception('Device({:s}) not found'.format(str(controller_uuid)))
return manager return controller
def get_devices_from_connection( def get_devices_from_connection(
self, connection : Connection, exclude_managed : bool = False self, connection : Connection, exclude_managed_by_controller : bool = False
) -> Dict[str, Device]: ) -> Dict[str, Device]:
devices = dict() devices = dict()
for endpoint_id in connection.path_hops_endpoint_ids: for endpoint_id in connection.path_hops_endpoint_ids:
...@@ -130,13 +130,13 @@ class TaskExecutor: ...@@ -130,13 +130,13 @@ class TaskExecutor:
device_uuid = endpoint_id.device_id.device_uuid.uuid device_uuid = endpoint_id.device_id.device_uuid.uuid
if device is None: raise Exception('Device({:s}) not found'.format(str(device_uuid))) if device is None: raise Exception('Device({:s}) not found'.format(str(device_uuid)))
manager = self.get_device_manager(device) controller = self.get_device_controller(device)
if manager is None: if controller is None:
devices[device_uuid] = device devices[device_uuid] = device
else: else:
if not exclude_managed: if not exclude_managed_by_controller:
devices[device_uuid] = device devices[device_uuid] = device
devices[manager.device_id.device_uuid.uuid] = manager devices[controller.device_id.device_uuid.uuid] = controller
return devices return devices
# ----- Service-related methods ------------------------------------------------------------------------------------ # ----- Service-related methods ------------------------------------------------------------------------------------
...@@ -166,6 +166,6 @@ class TaskExecutor: ...@@ -166,6 +166,6 @@ class TaskExecutor:
def get_service_handler( def get_service_handler(
self, connection : Connection, service : Service, **service_handler_settings self, connection : Connection, service : Service, **service_handler_settings
) -> '_ServiceHandler': ) -> '_ServiceHandler':
connection_devices = self.get_devices_from_connection(connection, exclude_managed=True) connection_devices = self.get_devices_from_connection(connection, exclude_managed_by_controller=True)
service_handler_class = get_service_handler_class(self._service_handler_factory, service, connection_devices) service_handler_class = get_service_handler_class(self._service_handler_factory, service, connection_devices)
return service_handler_class(service, self, **service_handler_settings) return service_handler_class(service, self, **service_handler_settings)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment