Loading src/simap_connector/service/simap_updater/SimapUpdater.py +97 −2 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ import logging, queue, threading from typing import Any, Optional from typing import Any, Optional, Set from common.DeviceTypes import DeviceTypeEnum from common.proto.context_pb2 import DeviceEvent, Empty, LinkEvent, TopologyEvent from common.tools.grpc.BaseEventCollector import BaseEventCollector Loading Loading @@ -51,6 +51,18 @@ class EventDispatcher(BaseEventDispatcher): ) self._simap_client = SimapClient(self._restconf_client) self._skipped_devices : Set[str] = set() def _add_skipped_device(self, device) -> None: self._skipped_devices.add(device.device_id.device_uuid.uuid) self._skipped_devices.add(device.name) def _remove_skipped_device(self, device) -> None: self._skipped_devices.discard(device.device_id.device_uuid.uuid) self._skipped_devices.discard(device.name) def dispatch(self, event : Any) -> None: MSG = 'Unexpected Event: {:s}' Loading Loading @@ -117,6 +129,7 @@ class EventDispatcher(BaseEventDispatcher): DeviceTypeEnum.TERAFLOWSDN_CONTROLLER.value, } if device_type in SKIPPED_DEVICE_TYPES: self._add_skipped_device(device) MSG = ( 'DeviceEvent({:s}) skipped, is of a skipped device type. ' 'SIMAP should be updated by him: {:s}' Loading @@ -128,6 +141,7 @@ class EventDispatcher(BaseEventDispatcher): device_controller_uuid = device.controller_id.device_uuid.uuid if len(device_controller_uuid) > 0: self._add_skipped_device(device) MSG = ( 'DeviceEvent({:s}) skipped, is a remotely-managed device. ' 'SIMAP should be populated by remote controller: {:s}' Loading @@ -139,6 +153,7 @@ class EventDispatcher(BaseEventDispatcher): topology_uuid, endpoint_names = get_device_endpoint(device) if topology_uuid is None: self._add_skipped_device(device) MSG = 'DeviceEvent({:s}) skipped, no endpoints to identify topology: {:s}' str_device_event = grpc_message_to_json_string(device_event) str_device = grpc_message_to_json_string(device) Loading @@ -153,6 +168,7 @@ class EventDispatcher(BaseEventDispatcher): device_name = device.name te_topo.node(device_name).create(termination_point_ids=endpoint_names) self._remove_skipped_device(device) MSG = 'Device Created: {:s}' LOGGER.info(MSG.format(grpc_message_to_json_string(device_event))) Loading @@ -173,6 +189,7 @@ class EventDispatcher(BaseEventDispatcher): DeviceTypeEnum.TERAFLOWSDN_CONTROLLER.value, } if device_type in SKIPPED_DEVICE_TYPES: self._add_skipped_device(device) MSG = ( 'DeviceEvent({:s}) skipped, is of a skipped device type. ' 'SIMAP should be updated by him: {:s}' Loading @@ -184,6 +201,7 @@ class EventDispatcher(BaseEventDispatcher): device_controller_uuid = device.controller_id.device_uuid.uuid if len(device_controller_uuid) > 0: self._add_skipped_device(device) MSG = ( 'DeviceEvent({:s}) skipped, is a remotely-managed device. ' 'SIMAP should be updated by remote controller: {:s}' Loading @@ -195,6 +213,7 @@ class EventDispatcher(BaseEventDispatcher): topology_uuid, endpoint_names = get_device_endpoint(device) if topology_uuid is None: self._add_skipped_device(device) MSG = 'DeviceEvent({:s}) skipped, no endpoints to identify topology: {:s}' str_device_event = grpc_message_to_json_string(device_event) str_device = grpc_message_to_json_string(device) Loading @@ -214,6 +233,8 @@ class EventDispatcher(BaseEventDispatcher): for endpoint_name in endpoint_names: te_device.termination_point(endpoint_name).update() self._remove_skipped_device(device) MSG = 'Device Updated: {:s}' LOGGER.info(MSG.format(grpc_message_to_json_string(device_event))) Loading @@ -233,6 +254,7 @@ class EventDispatcher(BaseEventDispatcher): DeviceTypeEnum.TERAFLOWSDN_CONTROLLER.value, } if device_type in SKIPPED_DEVICE_TYPES: self._add_skipped_device(device) MSG = ( 'DeviceEvent({:s}) skipped, is of a skipped device type. ' 'SIMAP should be updated by him: {:s}' Loading @@ -244,6 +266,7 @@ class EventDispatcher(BaseEventDispatcher): device_controller_uuid = device.controller_id.device_uuid.uuid if len(device_controller_uuid) > 0: self._add_skipped_device(device) MSG = ( 'DeviceEvent({:s}) skipped, is a remotely-managed device. ' 'SIMAP should be updated by remote controller: {:s}' Loading Loading @@ -274,6 +297,7 @@ class EventDispatcher(BaseEventDispatcher): te_device.delete() self._remove_skipped_device(device) self._object_cache.delete(CachedEntities.DEVICE, device_uuid) self._object_cache.delete(CachedEntities.DEVICE, device_name) Loading Loading @@ -308,6 +332,28 @@ class EventDispatcher(BaseEventDispatcher): dst_device = self._object_cache.get(CachedEntities.DEVICE, endpoint_uuids[1][0], auto_retrieve=False) dst_endpoint = self._object_cache.get(CachedEntities.ENDPOINT, *(endpoint_uuids[1]), auto_retrieve=False) # Skip links that connect two management endpoints if src_endpoint is not None and dst_endpoint is not None: if str(src_endpoint.name).lower() == 'mgmt' and str(dst_endpoint.name).lower() == 'mgmt': MSG = 'LinkEvent({:s}) skipped, connects two management endpoints: {:s}' str_link_event = grpc_message_to_json_string(link_event) str_link = grpc_message_to_json_string(link) LOGGER.warning(MSG.format(str_link_event, str_link)) return # Skip links that connect to devices previously marked as skipped src_uuid = src_device.device_id.device_uuid.uuid dst_uuid = dst_device.device_id.device_uuid.uuid src_name = src_device.name dst_name = dst_device.name if (src_uuid in self._skipped_devices or src_name in self._skipped_devices or dst_uuid in self._skipped_devices or dst_name in self._skipped_devices): MSG = 'LinkEvent({:s}) skipped, connects to skipped device(s): {:s}' str_link_event = grpc_message_to_json_string(link_event) str_link = grpc_message_to_json_string(link) LOGGER.warning(MSG.format(str_link_event, str_link)) return try: if src_device is None: MSG = 'Device({:s}) not found in cache' Loading Loading @@ -357,6 +403,28 @@ class EventDispatcher(BaseEventDispatcher): dst_device = self._object_cache.get(CachedEntities.DEVICE, endpoint_uuids[1][0], auto_retrieve=False) dst_endpoint = self._object_cache.get(CachedEntities.ENDPOINT, *(endpoint_uuids[1]), auto_retrieve=False) # Skip links that connect two management endpoints if src_endpoint is not None and dst_endpoint is not None: if str(src_endpoint.name).lower() == 'mgmt' and str(dst_endpoint.name).lower() == 'mgmt': MSG = 'LinkEvent({:s}) skipped, connects two management endpoints: {:s}' str_link_event = grpc_message_to_json_string(link_event) str_link = grpc_message_to_json_string(link) LOGGER.warning(MSG.format(str_link_event, str_link)) return # Skip links that connect to devices previously marked as skipped src_uuid = src_device.device_id.device_uuid.uuid dst_uuid = dst_device.device_id.device_uuid.uuid src_name = src_device.name dst_name = dst_device.name if (src_uuid in self._skipped_devices or src_name in self._skipped_devices or dst_uuid in self._skipped_devices or dst_name in self._skipped_devices): MSG = 'LinkEvent({:s}) skipped, connects to skipped device(s): {:s}' str_link_event = grpc_message_to_json_string(link_event) str_link = grpc_message_to_json_string(link) LOGGER.warning(MSG.format(str_link_event, str_link)) return try: if src_device is None: MSG = 'Device({:s}) not found in cache' Loading Loading @@ -388,13 +456,40 @@ class EventDispatcher(BaseEventDispatcher): link = self._object_cache.get(CachedEntities.LINK, link_uuid) link_name = link.name topology_uuid, _ = get_link_endpoint(link) topology_uuid, endpoint_uuids = get_link_endpoint(link) topology = self._object_cache.get(CachedEntities.TOPOLOGY, topology_uuid) topology_name = topology.name te_topo = self._simap_client.network(topology_name) te_topo.update() src_device = self._object_cache.get(CachedEntities.DEVICE, endpoint_uuids[0][0], auto_retrieve=False) src_endpoint = self._object_cache.get(CachedEntities.ENDPOINT, *(endpoint_uuids[0]), auto_retrieve=False) dst_device = self._object_cache.get(CachedEntities.DEVICE, endpoint_uuids[1][0], auto_retrieve=False) dst_endpoint = self._object_cache.get(CachedEntities.ENDPOINT, *(endpoint_uuids[1]), auto_retrieve=False) # Skip links that connect two management endpoints if src_endpoint is not None and dst_endpoint is not None: if str(src_endpoint.name).lower() == 'mgmt' and str(dst_endpoint.name).lower() == 'mgmt': MSG = 'LinkEvent({:s}) skipped, connects two management endpoints: {:s}' str_link_event = grpc_message_to_json_string(link_event) str_link = grpc_message_to_json_string(link) LOGGER.warning(MSG.format(str_link_event, str_link)) return # Skip links that connect to devices previously marked as skipped src_uuid = src_device.device_id.device_uuid.uuid dst_uuid = dst_device.device_id.device_uuid.uuid src_name = src_device.name dst_name = dst_device.name if (src_uuid in self._skipped_devices or src_name in self._skipped_devices or dst_uuid in self._skipped_devices or dst_name in self._skipped_devices): MSG = 'LinkEvent({:s}) skipped, connects to skipped device(s): {:s}' str_link_event = grpc_message_to_json_string(link_event) str_link = grpc_message_to_json_string(link) LOGGER.warning(MSG.format(str_link_event, str_link)) return te_link = te_topo.link(link_name) te_link.delete() Loading Loading
src/simap_connector/service/simap_updater/SimapUpdater.py +97 −2 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ import logging, queue, threading from typing import Any, Optional from typing import Any, Optional, Set from common.DeviceTypes import DeviceTypeEnum from common.proto.context_pb2 import DeviceEvent, Empty, LinkEvent, TopologyEvent from common.tools.grpc.BaseEventCollector import BaseEventCollector Loading Loading @@ -51,6 +51,18 @@ class EventDispatcher(BaseEventDispatcher): ) self._simap_client = SimapClient(self._restconf_client) self._skipped_devices : Set[str] = set() def _add_skipped_device(self, device) -> None: self._skipped_devices.add(device.device_id.device_uuid.uuid) self._skipped_devices.add(device.name) def _remove_skipped_device(self, device) -> None: self._skipped_devices.discard(device.device_id.device_uuid.uuid) self._skipped_devices.discard(device.name) def dispatch(self, event : Any) -> None: MSG = 'Unexpected Event: {:s}' Loading Loading @@ -117,6 +129,7 @@ class EventDispatcher(BaseEventDispatcher): DeviceTypeEnum.TERAFLOWSDN_CONTROLLER.value, } if device_type in SKIPPED_DEVICE_TYPES: self._add_skipped_device(device) MSG = ( 'DeviceEvent({:s}) skipped, is of a skipped device type. ' 'SIMAP should be updated by him: {:s}' Loading @@ -128,6 +141,7 @@ class EventDispatcher(BaseEventDispatcher): device_controller_uuid = device.controller_id.device_uuid.uuid if len(device_controller_uuid) > 0: self._add_skipped_device(device) MSG = ( 'DeviceEvent({:s}) skipped, is a remotely-managed device. ' 'SIMAP should be populated by remote controller: {:s}' Loading @@ -139,6 +153,7 @@ class EventDispatcher(BaseEventDispatcher): topology_uuid, endpoint_names = get_device_endpoint(device) if topology_uuid is None: self._add_skipped_device(device) MSG = 'DeviceEvent({:s}) skipped, no endpoints to identify topology: {:s}' str_device_event = grpc_message_to_json_string(device_event) str_device = grpc_message_to_json_string(device) Loading @@ -153,6 +168,7 @@ class EventDispatcher(BaseEventDispatcher): device_name = device.name te_topo.node(device_name).create(termination_point_ids=endpoint_names) self._remove_skipped_device(device) MSG = 'Device Created: {:s}' LOGGER.info(MSG.format(grpc_message_to_json_string(device_event))) Loading @@ -173,6 +189,7 @@ class EventDispatcher(BaseEventDispatcher): DeviceTypeEnum.TERAFLOWSDN_CONTROLLER.value, } if device_type in SKIPPED_DEVICE_TYPES: self._add_skipped_device(device) MSG = ( 'DeviceEvent({:s}) skipped, is of a skipped device type. ' 'SIMAP should be updated by him: {:s}' Loading @@ -184,6 +201,7 @@ class EventDispatcher(BaseEventDispatcher): device_controller_uuid = device.controller_id.device_uuid.uuid if len(device_controller_uuid) > 0: self._add_skipped_device(device) MSG = ( 'DeviceEvent({:s}) skipped, is a remotely-managed device. ' 'SIMAP should be updated by remote controller: {:s}' Loading @@ -195,6 +213,7 @@ class EventDispatcher(BaseEventDispatcher): topology_uuid, endpoint_names = get_device_endpoint(device) if topology_uuid is None: self._add_skipped_device(device) MSG = 'DeviceEvent({:s}) skipped, no endpoints to identify topology: {:s}' str_device_event = grpc_message_to_json_string(device_event) str_device = grpc_message_to_json_string(device) Loading @@ -214,6 +233,8 @@ class EventDispatcher(BaseEventDispatcher): for endpoint_name in endpoint_names: te_device.termination_point(endpoint_name).update() self._remove_skipped_device(device) MSG = 'Device Updated: {:s}' LOGGER.info(MSG.format(grpc_message_to_json_string(device_event))) Loading @@ -233,6 +254,7 @@ class EventDispatcher(BaseEventDispatcher): DeviceTypeEnum.TERAFLOWSDN_CONTROLLER.value, } if device_type in SKIPPED_DEVICE_TYPES: self._add_skipped_device(device) MSG = ( 'DeviceEvent({:s}) skipped, is of a skipped device type. ' 'SIMAP should be updated by him: {:s}' Loading @@ -244,6 +266,7 @@ class EventDispatcher(BaseEventDispatcher): device_controller_uuid = device.controller_id.device_uuid.uuid if len(device_controller_uuid) > 0: self._add_skipped_device(device) MSG = ( 'DeviceEvent({:s}) skipped, is a remotely-managed device. ' 'SIMAP should be updated by remote controller: {:s}' Loading Loading @@ -274,6 +297,7 @@ class EventDispatcher(BaseEventDispatcher): te_device.delete() self._remove_skipped_device(device) self._object_cache.delete(CachedEntities.DEVICE, device_uuid) self._object_cache.delete(CachedEntities.DEVICE, device_name) Loading Loading @@ -308,6 +332,28 @@ class EventDispatcher(BaseEventDispatcher): dst_device = self._object_cache.get(CachedEntities.DEVICE, endpoint_uuids[1][0], auto_retrieve=False) dst_endpoint = self._object_cache.get(CachedEntities.ENDPOINT, *(endpoint_uuids[1]), auto_retrieve=False) # Skip links that connect two management endpoints if src_endpoint is not None and dst_endpoint is not None: if str(src_endpoint.name).lower() == 'mgmt' and str(dst_endpoint.name).lower() == 'mgmt': MSG = 'LinkEvent({:s}) skipped, connects two management endpoints: {:s}' str_link_event = grpc_message_to_json_string(link_event) str_link = grpc_message_to_json_string(link) LOGGER.warning(MSG.format(str_link_event, str_link)) return # Skip links that connect to devices previously marked as skipped src_uuid = src_device.device_id.device_uuid.uuid dst_uuid = dst_device.device_id.device_uuid.uuid src_name = src_device.name dst_name = dst_device.name if (src_uuid in self._skipped_devices or src_name in self._skipped_devices or dst_uuid in self._skipped_devices or dst_name in self._skipped_devices): MSG = 'LinkEvent({:s}) skipped, connects to skipped device(s): {:s}' str_link_event = grpc_message_to_json_string(link_event) str_link = grpc_message_to_json_string(link) LOGGER.warning(MSG.format(str_link_event, str_link)) return try: if src_device is None: MSG = 'Device({:s}) not found in cache' Loading Loading @@ -357,6 +403,28 @@ class EventDispatcher(BaseEventDispatcher): dst_device = self._object_cache.get(CachedEntities.DEVICE, endpoint_uuids[1][0], auto_retrieve=False) dst_endpoint = self._object_cache.get(CachedEntities.ENDPOINT, *(endpoint_uuids[1]), auto_retrieve=False) # Skip links that connect two management endpoints if src_endpoint is not None and dst_endpoint is not None: if str(src_endpoint.name).lower() == 'mgmt' and str(dst_endpoint.name).lower() == 'mgmt': MSG = 'LinkEvent({:s}) skipped, connects two management endpoints: {:s}' str_link_event = grpc_message_to_json_string(link_event) str_link = grpc_message_to_json_string(link) LOGGER.warning(MSG.format(str_link_event, str_link)) return # Skip links that connect to devices previously marked as skipped src_uuid = src_device.device_id.device_uuid.uuid dst_uuid = dst_device.device_id.device_uuid.uuid src_name = src_device.name dst_name = dst_device.name if (src_uuid in self._skipped_devices or src_name in self._skipped_devices or dst_uuid in self._skipped_devices or dst_name in self._skipped_devices): MSG = 'LinkEvent({:s}) skipped, connects to skipped device(s): {:s}' str_link_event = grpc_message_to_json_string(link_event) str_link = grpc_message_to_json_string(link) LOGGER.warning(MSG.format(str_link_event, str_link)) return try: if src_device is None: MSG = 'Device({:s}) not found in cache' Loading Loading @@ -388,13 +456,40 @@ class EventDispatcher(BaseEventDispatcher): link = self._object_cache.get(CachedEntities.LINK, link_uuid) link_name = link.name topology_uuid, _ = get_link_endpoint(link) topology_uuid, endpoint_uuids = get_link_endpoint(link) topology = self._object_cache.get(CachedEntities.TOPOLOGY, topology_uuid) topology_name = topology.name te_topo = self._simap_client.network(topology_name) te_topo.update() src_device = self._object_cache.get(CachedEntities.DEVICE, endpoint_uuids[0][0], auto_retrieve=False) src_endpoint = self._object_cache.get(CachedEntities.ENDPOINT, *(endpoint_uuids[0]), auto_retrieve=False) dst_device = self._object_cache.get(CachedEntities.DEVICE, endpoint_uuids[1][0], auto_retrieve=False) dst_endpoint = self._object_cache.get(CachedEntities.ENDPOINT, *(endpoint_uuids[1]), auto_retrieve=False) # Skip links that connect two management endpoints if src_endpoint is not None and dst_endpoint is not None: if str(src_endpoint.name).lower() == 'mgmt' and str(dst_endpoint.name).lower() == 'mgmt': MSG = 'LinkEvent({:s}) skipped, connects two management endpoints: {:s}' str_link_event = grpc_message_to_json_string(link_event) str_link = grpc_message_to_json_string(link) LOGGER.warning(MSG.format(str_link_event, str_link)) return # Skip links that connect to devices previously marked as skipped src_uuid = src_device.device_id.device_uuid.uuid dst_uuid = dst_device.device_id.device_uuid.uuid src_name = src_device.name dst_name = dst_device.name if (src_uuid in self._skipped_devices or src_name in self._skipped_devices or dst_uuid in self._skipped_devices or dst_name in self._skipped_devices): MSG = 'LinkEvent({:s}) skipped, connects to skipped device(s): {:s}' str_link_event = grpc_message_to_json_string(link_event) str_link = grpc_message_to_json_string(link) LOGGER.warning(MSG.format(str_link_event, str_link)) return te_link = te_topo.link(link_name) te_link.delete() Loading