| ... | ... | @@ -26,6 +26,8 @@ from common.proto.context_pb2 import ( | 
| 
 | 
 | 
    Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList)
 | 
| 
 | 
 | 
from common.proto.context_pb2_grpc import ContextServiceServicer
 | 
| 
 | 
 | 
from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string
 | 
| 
 | 
 | 
from common.tools.object_factory.Device import json_device_id
 | 
| 
 | 
 | 
from common.tools.object_factory.Link import json_link_id
 | 
| 
 | 
 | 
from .InMemoryObjectDatabase import InMemoryObjectDatabase
 | 
| 
 | 
 | 
from .MockMessageBroker import (
 | 
| 
 | 
 | 
    TOPIC_CONNECTION, TOPIC_CONTEXT, TOPIC_DEVICE, TOPIC_LINK, TOPIC_SERVICE, TOPIC_SLICE, TOPIC_TOPOLOGY,
 | 
| ... | ... | @@ -143,17 +145,60 @@ class MockServicerImpl_Context(ContextServiceServicer): | 
| 
 | 
 | 
 | 
| 
 | 
 | 
    def SetTopology(self, request: Topology, context : grpc.ServicerContext) -> TopologyId:
 | 
| 
 | 
 | 
        LOGGER.debug('[SetTopology] request={:s}'.format(grpc_message_to_json_string(request)))
 | 
| 
 | 
 | 
        container_name = 'topology[{:s}]'.format(str(request.topology_id.context_id.context_uuid.uuid))
 | 
| 
 | 
 | 
        context_uuid = str(request.topology_id.context_id.context_uuid.uuid)
 | 
| 
 | 
 | 
        container_name = 'topology[{:s}]'.format(context_uuid)
 | 
| 
 | 
 | 
        topology_uuid = request.topology_id.topology_uuid.uuid
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
        if self.obj_db.has_entry(container_name, topology_uuid):
 | 
| 
 | 
 | 
            # merge device_ids and link_ids from database and request, and update request
 | 
| 
 | 
 | 
            db_topology = self.obj_db.get_entry(container_name, topology_uuid, context)
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
            device_uuids = set()
 | 
| 
 | 
 | 
            for device_id in request.device_ids: device_uuids.add(device_id.device_uuid.uuid)
 | 
| 
 | 
 | 
            for device_id in db_topology.device_ids: device_uuids.add(device_id.device_uuid.uuid)
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
            link_uuids = set()
 | 
| 
 | 
 | 
            for link_id in request.link_ids: link_uuids.add(link_id.link_uuid.uuid)
 | 
| 
 | 
 | 
            for link_id in db_topology.link_ids: link_uuids.add(link_id.link_uuid.uuid)
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
            rw_request = Topology()
 | 
| 
 | 
 | 
            rw_request.CopyFrom(request)
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
            del rw_request.device_ids[:]
 | 
| 
 | 
 | 
            for device_uuid in sorted(device_uuids):
 | 
| 
 | 
 | 
                rw_request.device_ids.append(DeviceId(**json_device_id(device_uuid)))
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
            del rw_request.link_ids[:]
 | 
| 
 | 
 | 
            for link_uuid in sorted(link_uuids):
 | 
| 
 | 
 | 
                rw_request.link_ids.append(LinkId(**json_link_id(link_uuid)))
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
            request = rw_request
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
        reply,_ = self._set(request, container_name, topology_uuid, 'topology_id', TOPIC_TOPOLOGY)
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
        context_ = self.obj_db.get_entry('context', context_uuid, context)
 | 
| 
 | 
 | 
        for _topology_id in context_.topology_ids:
 | 
| 
 | 
 | 
            if _topology_id.topology_uuid.uuid == topology_uuid: break
 | 
| 
 | 
 | 
        else:
 | 
| 
 | 
 | 
            # topology not found, add it
 | 
| 
 | 
 | 
            context_.topology_ids.add().topology_uuid.uuid = topology_uuid
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
        LOGGER.debug('[SetTopology] reply={:s}'.format(grpc_message_to_json_string(reply)))
 | 
| 
 | 
 | 
        return reply
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
    def RemoveTopology(self, request: TopologyId, context : grpc.ServicerContext) -> Empty:
 | 
| 
 | 
 | 
        LOGGER.debug('[RemoveTopology] request={:s}'.format(grpc_message_to_json_string(request)))
 | 
| 
 | 
 | 
        container_name = 'topology[{:s}]'.format(str(request.context_id.context_uuid.uuid))
 | 
| 
 | 
 | 
        context_uuid = str(request.context_id.context_uuid.uuid)
 | 
| 
 | 
 | 
        container_name = 'topology[{:s}]'.format(context_uuid)
 | 
| 
 | 
 | 
        topology_uuid = request.topology_uuid.uuid
 | 
| 
 | 
 | 
        reply = self._del(request, container_name, topology_uuid, 'topology_id', TOPIC_TOPOLOGY, context)
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
        context_ = self.obj_db.get_entry('context', context_uuid, context)
 | 
| 
 | 
 | 
        for _topology_id in context_.topology_ids:
 | 
| 
 | 
 | 
            if _topology_id.topology_uuid.uuid == topology_uuid:
 | 
| 
 | 
 | 
                context_.topology_ids.remove(_topology_id)
 | 
| 
 | 
 | 
                break
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
        LOGGER.debug('[RemoveTopology] reply={:s}'.format(grpc_message_to_json_string(reply)))
 | 
| 
 | 
 | 
        return reply
 | 
| 
 | 
 | 
 | 
| ... | ... | @@ -368,17 +413,34 @@ class MockServicerImpl_Context(ContextServiceServicer): | 
| 
 | 
 | 
 | 
| 
 | 
 | 
    def SetSlice(self, request: Slice, context : grpc.ServicerContext) -> SliceId:
 | 
| 
 | 
 | 
        LOGGER.debug('[SetSlice] request={:s}'.format(grpc_message_to_json_string(request)))
 | 
| 
 | 
 | 
        container_name = 'slice[{:s}]'.format(str(request.slice_id.context_id.context_uuid.uuid))
 | 
| 
 | 
 | 
        context_uuid = str(request.slice_id.context_id.context_uuid.uuid)
 | 
| 
 | 
 | 
        container_name = 'slice[{:s}]'.format(context_uuid)
 | 
| 
 | 
 | 
        slice_uuid = request.slice_id.slice_uuid.uuid
 | 
| 
 | 
 | 
        reply,_ = self._set(request, container_name, slice_uuid, 'slice_id', TOPIC_SLICE)
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
        context_ = self.obj_db.get_entry('context', context_uuid, context)
 | 
| 
 | 
 | 
        for _slice_id in context_.slice_ids:
 | 
| 
 | 
 | 
            if _slice_id.slice_uuid.uuid == slice_uuid: break
 | 
| 
 | 
 | 
        else:
 | 
| 
 | 
 | 
            # slice not found, add it
 | 
| 
 | 
 | 
            context_.slice_ids.add().slice_uuid.uuid = slice_uuid
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
        LOGGER.debug('[SetSlice] reply={:s}'.format(grpc_message_to_json_string(reply)))
 | 
| 
 | 
 | 
        return reply
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
    def RemoveSlice(self, request: SliceId, context : grpc.ServicerContext) -> Empty:
 | 
| 
 | 
 | 
        LOGGER.debug('[RemoveSlice] request={:s}'.format(grpc_message_to_json_string(request)))
 | 
| 
 | 
 | 
        container_name = 'slice[{:s}]'.format(str(request.context_id.context_uuid.uuid))
 | 
| 
 | 
 | 
        context_uuid = str(request.context_id.context_uuid.uuid)
 | 
| 
 | 
 | 
        container_name = 'slice[{:s}]'.format(context_uuid)
 | 
| 
 | 
 | 
        slice_uuid = request.slice_uuid.uuid
 | 
| 
 | 
 | 
        reply = self._del(request, container_name, slice_uuid, 'slice_id', TOPIC_SLICE, context)
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
        context_ = self.obj_db.get_entry('context', context_uuid, context)
 | 
| 
 | 
 | 
        for _slice_id in context_.slice_ids:
 | 
| 
 | 
 | 
            if _slice_id.slice_uuid.uuid == slice_uuid:
 | 
| 
 | 
 | 
                context_.slice_ids.remove(_slice_id)
 | 
| 
 | 
 | 
                break
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
        LOGGER.debug('[RemoveSlice] reply={:s}'.format(grpc_message_to_json_string(reply)))
 | 
| 
 | 
 | 
        return reply
 | 
| 
 | 
 | 
 | 
| ... | ... | @@ -443,17 +505,34 @@ class MockServicerImpl_Context(ContextServiceServicer): | 
| 
 | 
 | 
 | 
| 
 | 
 | 
    def SetService(self, request: Service, context : grpc.ServicerContext) -> ServiceId:
 | 
| 
 | 
 | 
        LOGGER.debug('[SetService] request={:s}'.format(grpc_message_to_json_string(request)))
 | 
| 
 | 
 | 
        container_name = 'service[{:s}]'.format(str(request.service_id.context_id.context_uuid.uuid))
 | 
| 
 | 
 | 
        context_uuid = str(request.service_id.context_id.context_uuid.uuid)
 | 
| 
 | 
 | 
        container_name = 'service[{:s}]'.format(context_uuid)
 | 
| 
 | 
 | 
        service_uuid = request.service_id.service_uuid.uuid
 | 
| 
 | 
 | 
        reply,_ = self._set(request, container_name, service_uuid, 'service_id', TOPIC_SERVICE)
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
        context_ = self.obj_db.get_entry('context', context_uuid, context)
 | 
| 
 | 
 | 
        for _service_id in context_.service_ids:
 | 
| 
 | 
 | 
            if _service_id.service_uuid.uuid == service_uuid: break
 | 
| 
 | 
 | 
        else:
 | 
| 
 | 
 | 
            # service not found, add it
 | 
| 
 | 
 | 
            context_.service_ids.add().service_uuid.uuid = service_uuid
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
        LOGGER.debug('[SetService] reply={:s}'.format(grpc_message_to_json_string(reply)))
 | 
| 
 | 
 | 
        return reply
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
    def RemoveService(self, request: ServiceId, context : grpc.ServicerContext) -> Empty:
 | 
| 
 | 
 | 
        LOGGER.debug('[RemoveService] request={:s}'.format(grpc_message_to_json_string(request)))
 | 
| 
 | 
 | 
        container_name = 'service[{:s}]'.format(str(request.context_id.context_uuid.uuid))
 | 
| 
 | 
 | 
        context_uuid = str(request.context_id.context_uuid.uuid)
 | 
| 
 | 
 | 
        container_name = 'service[{:s}]'.format(context_uuid)
 | 
| 
 | 
 | 
        service_uuid = request.service_uuid.uuid
 | 
| 
 | 
 | 
        reply = self._del(request, container_name, service_uuid, 'service_id', TOPIC_SERVICE, context)
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
        context_ = self.obj_db.get_entry('context', context_uuid, context)
 | 
| 
 | 
 | 
        for _service_id in context_.service_ids:
 | 
| 
 | 
 | 
            if _service_id.service_uuid.uuid == service_uuid:
 | 
| 
 | 
 | 
                context_.service_ids.remove(_service_id)
 | 
| 
 | 
 | 
                break
 | 
| 
 | 
 | 
 | 
| 
 | 
 | 
        LOGGER.debug('[RemoveService] reply={:s}'.format(grpc_message_to_json_string(reply)))
 | 
| 
 | 
 | 
        return reply
 | 
| 
 | 
 | 
 | 
| ... | ... |  |