Commit a8c7843a authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Common - Context Queries:

- Improved InterDomain queries
- Cleaned up code
parent 33265c97
Loading
Loading
Loading
Loading
+55 −50
Original line number Diff line number Diff line
@@ -33,28 +33,33 @@ DATACENTER_DEVICE_TYPES = {DeviceTypeEnum.DATACENTER, DeviceTypeEnum.EMULATED_DA

def get_local_device_uuids(context_client : ContextClient) -> Set[str]:
    topologies = context_client.ListTopologies(ADMIN_CONTEXT_ID)
    topologies = {topology.topology_id.topology_uuid.uuid : topology for topology in topologies.topologies}
    LOGGER.debug('[get_local_device_uuids] topologies.keys()={:s}'.format(str(topologies.keys())))

    local_topology_uuids = set(topologies.keys())
    local_topology_uuids.discard(INTERDOMAIN_TOPOLOGY_NAME)
    local_topologies = dict()
    for topology in topologies.topologies:
        topology_uuid = topology.topology_id.topology_uuid.uuid
        if topology_uuid == INTERDOMAIN_TOPOLOGY_NAME: continue
        topology_name = topology.name
        if topology_name == INTERDOMAIN_TOPOLOGY_NAME: continue
        local_topologies[topology_uuid] = topology
    LOGGER.debug('[get_local_device_uuids] local_topologies={:s}'.format(str(local_topologies)))

    local_topology_uuids = set(local_topologies.keys())
    LOGGER.debug('[get_local_device_uuids] local_topology_uuids={:s}'.format(str(local_topology_uuids)))

    # Add topology names except DEFAULT_TOPOLOGY_NAME and INTERDOMAIN_TOPOLOGY_NAME; they are abstracted as a
    # local device in inter-domain and the name of the topology is used as abstract device name
    # Add physical devices in the local topologies
    local_device_uuids = set()
    for topology_uuid,topology in local_topologies.items():
        if topology_uuid == DEFAULT_TOPOLOGY_NAME: continue
        topology_name = topology.name
        if topology_name == DEFAULT_TOPOLOGY_NAME: continue
        #local_device_uuids.add(topology_uuid)

    # add topology names except DEFAULT_TOPOLOGY_NAME and INTERDOMAIN_TOPOLOGY_NAME; they are abstracted as a
    # local device in inter-domain and the name of the topology is used as abstract device name
    for local_topology_uuid in local_topology_uuids:
        if local_topology_uuid == DEFAULT_TOPOLOGY_NAME: continue
        local_device_uuids.add(local_topology_uuid)

    # add physical devices in the local topologies
    for local_topology_uuid in local_topology_uuids:
        topology_device_ids = topologies[local_topology_uuid].device_ids
        topology_device_uuids = {device_id.device_uuid.uuid for device_id in topology_device_ids}
        LOGGER.debug('[get_local_device_uuids] [loop] local_topology_uuid={:s} topology_device_uuids={:s}'.format(
            str(local_topology_uuid), str(topology_device_uuids)))
        local_device_uuids.update(topology_device_uuids)
        device_uuids = {device_id.device_uuid.uuid for device_id in topology.device_ids}
        LOGGER.debug('[get_local_device_uuids] [loop] topology_uuid={:s} device_uuids={:s}'.format(
            str(topology_uuid), str(device_uuids)))
        local_device_uuids.update(device_uuids)

    LOGGER.debug('[get_local_device_uuids] local_device_uuids={:s}'.format(str(local_device_uuids)))
    return local_device_uuids
@@ -74,16 +79,16 @@ def get_interdomain_device_uuids(context_client : ContextClient) -> Set[str]:
    LOGGER.debug('[get_interdomain_device_uuids] interdomain_device_uuids={:s}'.format(str(interdomain_device_uuids)))
    return interdomain_device_uuids

def get_local_domain_devices(context_client : ContextClient) -> List[Device]:
    local_device_uuids = get_local_device_uuids(context_client)
    all_devices = context_client.ListDevices(Empty())
    local_domain_devices = list()
    for device in all_devices.devices:
        if not device_type_is_network(device.device_type): continue
        device_uuid = device.device_id.device_uuid.uuid
        if device_uuid not in local_device_uuids: continue
        local_domain_devices.append(device)
    return local_domain_devices
#def get_local_domain_devices(context_client : ContextClient) -> List[Device]:
#    local_device_uuids = get_local_device_uuids(context_client)
#    all_devices = context_client.ListDevices(Empty())
#    local_domain_devices = list()
#    for device in all_devices.devices:
#        if not device_type_is_network(device.device_type): continue
#        device_uuid = device.device_id.device_uuid.uuid
#        if device_uuid not in local_device_uuids: continue
#        local_domain_devices.append(device)
#    return local_domain_devices

def is_inter_domain(context_client : ContextClient, endpoint_ids : List[EndPointId]) -> bool:
    interdomain_device_uuids = get_interdomain_device_uuids(context_client)
@@ -102,22 +107,22 @@ def is_inter_domain(context_client : ContextClient, endpoint_ids : List[EndPoint
    LOGGER.debug('[is_inter_domain] is_inter_domain={:s}'.format(str(is_inter_domain_)))
    return is_inter_domain_

def is_multi_domain(context_client : ContextClient, endpoint_ids : List[EndPointId]) -> bool:
    local_device_uuids = get_local_device_uuids(context_client)
    LOGGER.debug('[is_multi_domain] local_device_uuids={:s}'.format(str(local_device_uuids)))
    remote_endpoint_ids = [
        endpoint_id
        for endpoint_id in endpoint_ids
        if endpoint_id.device_id.device_uuid.uuid not in local_device_uuids
    ]
    str_remote_endpoint_ids = [
        (endpoint_id.device_id.device_uuid.uuid, endpoint_id.endpoint_uuid.uuid)
        for endpoint_id in remote_endpoint_ids
    ]
    LOGGER.debug('[is_multi_domain] remote_endpoint_ids={:s}'.format(str(str_remote_endpoint_ids)))
    is_multi_domain_ = len(remote_endpoint_ids) > 0
    LOGGER.debug('[is_multi_domain] is_multi_domain={:s}'.format(str(is_multi_domain_)))
    return is_multi_domain_
#def is_multi_domain(context_client : ContextClient, endpoint_ids : List[EndPointId]) -> bool:
#    local_device_uuids = get_local_device_uuids(context_client)
#    LOGGER.debug('[is_multi_domain] local_device_uuids={:s}'.format(str(local_device_uuids)))
#    remote_endpoint_ids = [
#        endpoint_id
#        for endpoint_id in endpoint_ids
#        if endpoint_id.device_id.device_uuid.uuid not in local_device_uuids
#    ]
#    str_remote_endpoint_ids = [
#        (endpoint_id.device_id.device_uuid.uuid, endpoint_id.endpoint_uuid.uuid)
#        for endpoint_id in remote_endpoint_ids
#    ]
#    LOGGER.debug('[is_multi_domain] remote_endpoint_ids={:s}'.format(str(str_remote_endpoint_ids)))
#    is_multi_domain_ = len(remote_endpoint_ids) > 0
#    LOGGER.debug('[is_multi_domain] is_multi_domain={:s}'.format(str(is_multi_domain_)))
#    return is_multi_domain_

def compute_interdomain_path(
    pathcomp_client : PathCompClient, slice_ : Slice
@@ -149,7 +154,7 @@ def compute_interdomain_path(
    service = next(iter([
        service
        for service in pathcomp_rep.services
        if service.service_id == pathcomp_req_svc.service_id
        if service.service_id.service_uuid.uuid == pathcomp_req_svc.service_id.service_uuid.uuid
    ]), None)
    if service is None:
        str_service_id = grpc_message_to_json_string(pathcomp_req_svc.service_id)
@@ -158,7 +163,7 @@ def compute_interdomain_path(
    connection = next(iter([
        connection
        for connection in pathcomp_rep.connections
        if connection.service_id == pathcomp_req_svc.service_id
        if connection.service_id.service_uuid.uuid == pathcomp_req_svc.service_id.service_uuid.uuid
    ]), None)
    if connection is None:
        str_service_id = grpc_message_to_json_string(pathcomp_req_svc.service_id)
@@ -222,11 +227,11 @@ def compute_traversed_domains(
    local_device_uuids = get_local_device_uuids(context_client)
    LOGGER.debug('[compute_traversed_domains] local_device_uuids={:s}'.format(str(local_device_uuids)))

    interdomain_devices = get_devices_in_topology(context_client, ADMIN_CONTEXT_ID, INTERDOMAIN_TOPOLOGY_NAME)
    interdomain_devices = {
        device.device_id.device_uuid.uuid : device
        for device in interdomain_devices
    }
    #interdomain_devices = get_devices_in_topology(context_client, ADMIN_CONTEXT_ID, INTERDOMAIN_TOPOLOGY_NAME)
    #interdomain_devices = {
    #    device.device_id.device_uuid.uuid : device
    #    for device in interdomain_devices
    #}

    devices_to_domains = get_device_to_domain_map(context_client)
    LOGGER.debug('[compute_traversed_domains] devices_to_domains={:s}'.format(str(devices_to_domains)))