Loading src/pathcomp/frontend/service/PathCompServiceServicerImpl.py +20 −5 Original line number Diff line number Diff line Loading @@ -13,13 +13,19 @@ # limitations under the License. import grpc, logging from common.proto.context_pb2 import Empty from common.Constants import DEFAULT_CONTEXT_UUID, INTERDOMAIN_TOPOLOGY_UUID from common.proto.context_pb2 import ContextId, Empty from common.proto.pathcomp_pb2 import PathCompReply, PathCompRequest from common.proto.pathcomp_pb2_grpc import PathCompServiceServicer from common.rpc_method_wrapper.Decorator import create_metrics, safe_and_metered_rpc_method from common.tools.context_queries.Device import get_devices_in_topology from common.tools.context_queries.Link import get_links_in_topology from common.tools.context_queries.InterDomain import is_multi_domain from common.tools.grpc.Tools import grpc_message_to_json_string from common.tools.object_factory.Context import json_context_id from context.client.ContextClient import ContextClient from pathcomp.frontend.service.algorithms.Factory import get_algorithm from pathcomp.frontend.service.algorithms.ShortestPathAlgorithm import ShortestPathAlgorithm LOGGER = logging.getLogger(__name__) Loading @@ -27,6 +33,8 @@ SERVICE_NAME = 'PathComp' METHOD_NAMES = ['Compute'] METRICS = create_metrics(SERVICE_NAME, METHOD_NAMES) ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_UUID)) class PathCompServiceServicerImpl(PathCompServiceServicer): def __init__(self) -> None: LOGGER.debug('Creating Servicer...') Loading @@ -38,11 +46,18 @@ class PathCompServiceServicerImpl(PathCompServiceServicer): context_client = ContextClient() # TODO: add filtering of devices and links if (len(request.services) == 1) and is_multi_domain(context_client, request.services[0].service_endpoint_ids): devices = get_devices_in_topology(context_client, ADMIN_CONTEXT_ID, INTERDOMAIN_TOPOLOGY_UUID) links = get_links_in_topology(context_client, ADMIN_CONTEXT_ID, INTERDOMAIN_TOPOLOGY_UUID) else: # TODO: improve filtering of devices and links # TODO: add contexts, topologies, and membership of devices/links in topologies devices = context_client.ListDevices(Empty()) links = context_client.ListLinks(Empty()) algorithm = get_algorithm(request) algorithm.add_devices(context_client.ListDevices(Empty())) algorithm.add_links(context_client.ListLinks(Empty())) algorithm.add_devices(devices) algorithm.add_links(links) algorithm.add_service_requests(request) #LOGGER.debug('device_list = {:s}' .format(str(algorithm.device_list ))) Loading src/pathcomp/frontend/service/algorithms/_Algorithm.py +7 −5 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ # limitations under the License. import json, logging, requests from typing import Dict, List, Optional, Tuple from typing import Dict, List, Optional, Tuple, Union from common.proto.context_pb2 import ( ConfigRule, Connection, Device, DeviceList, EndPointId, Link, LinkList, Service, ServiceStatusEnum, ServiceTypeEnum) Loading Loading @@ -46,8 +46,9 @@ class _Algorithm: self.service_list : List[Dict] = list() self.service_dict : Dict[Tuple[str, str], Tuple[Dict, Service]] = dict() def add_devices(self, grpc_devices : DeviceList) -> None: for grpc_device in grpc_devices.devices: def add_devices(self, grpc_devices : Union[List[Device], DeviceList]) -> None: if isinstance(grpc_devices, DeviceList): grpc_devices = grpc_devices.devices for grpc_device in grpc_devices: json_device = compose_device(grpc_device) self.device_list.append(json_device) Loading @@ -62,8 +63,9 @@ class _Algorithm: self.endpoint_dict[device_uuid] = device_endpoint_dict def add_links(self, grpc_links : LinkList) -> None: for grpc_link in grpc_links.links: def add_links(self, grpc_links : Union[List[Link], LinkList]) -> None: if isinstance(grpc_links, LinkList): grpc_links = grpc_links.links for grpc_link in grpc_links: json_link = compose_link(grpc_link) self.link_list.append(json_link) Loading src/pathcomp/frontend/service/algorithms/tools/ConstantsMappings.py +1 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ class DeviceLayerEnum(IntEnum): DEVICE_TYPE_TO_LAYER = { DeviceTypeEnum.EMULATED_DATACENTER.value : DeviceLayerEnum.APPLICATION_DEVICE, DeviceTypeEnum.DATACENTER.value : DeviceLayerEnum.APPLICATION_DEVICE, DeviceTypeEnum.NETWORK.value : DeviceLayerEnum.APPLICATION_DEVICE, DeviceTypeEnum.EMULATED_PACKET_ROUTER.value : DeviceLayerEnum.PACKET_DEVICE, DeviceTypeEnum.PACKET_ROUTER.value : DeviceLayerEnum.PACKET_DEVICE, Loading Loading
src/pathcomp/frontend/service/PathCompServiceServicerImpl.py +20 −5 Original line number Diff line number Diff line Loading @@ -13,13 +13,19 @@ # limitations under the License. import grpc, logging from common.proto.context_pb2 import Empty from common.Constants import DEFAULT_CONTEXT_UUID, INTERDOMAIN_TOPOLOGY_UUID from common.proto.context_pb2 import ContextId, Empty from common.proto.pathcomp_pb2 import PathCompReply, PathCompRequest from common.proto.pathcomp_pb2_grpc import PathCompServiceServicer from common.rpc_method_wrapper.Decorator import create_metrics, safe_and_metered_rpc_method from common.tools.context_queries.Device import get_devices_in_topology from common.tools.context_queries.Link import get_links_in_topology from common.tools.context_queries.InterDomain import is_multi_domain from common.tools.grpc.Tools import grpc_message_to_json_string from common.tools.object_factory.Context import json_context_id from context.client.ContextClient import ContextClient from pathcomp.frontend.service.algorithms.Factory import get_algorithm from pathcomp.frontend.service.algorithms.ShortestPathAlgorithm import ShortestPathAlgorithm LOGGER = logging.getLogger(__name__) Loading @@ -27,6 +33,8 @@ SERVICE_NAME = 'PathComp' METHOD_NAMES = ['Compute'] METRICS = create_metrics(SERVICE_NAME, METHOD_NAMES) ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_UUID)) class PathCompServiceServicerImpl(PathCompServiceServicer): def __init__(self) -> None: LOGGER.debug('Creating Servicer...') Loading @@ -38,11 +46,18 @@ class PathCompServiceServicerImpl(PathCompServiceServicer): context_client = ContextClient() # TODO: add filtering of devices and links if (len(request.services) == 1) and is_multi_domain(context_client, request.services[0].service_endpoint_ids): devices = get_devices_in_topology(context_client, ADMIN_CONTEXT_ID, INTERDOMAIN_TOPOLOGY_UUID) links = get_links_in_topology(context_client, ADMIN_CONTEXT_ID, INTERDOMAIN_TOPOLOGY_UUID) else: # TODO: improve filtering of devices and links # TODO: add contexts, topologies, and membership of devices/links in topologies devices = context_client.ListDevices(Empty()) links = context_client.ListLinks(Empty()) algorithm = get_algorithm(request) algorithm.add_devices(context_client.ListDevices(Empty())) algorithm.add_links(context_client.ListLinks(Empty())) algorithm.add_devices(devices) algorithm.add_links(links) algorithm.add_service_requests(request) #LOGGER.debug('device_list = {:s}' .format(str(algorithm.device_list ))) Loading
src/pathcomp/frontend/service/algorithms/_Algorithm.py +7 −5 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ # limitations under the License. import json, logging, requests from typing import Dict, List, Optional, Tuple from typing import Dict, List, Optional, Tuple, Union from common.proto.context_pb2 import ( ConfigRule, Connection, Device, DeviceList, EndPointId, Link, LinkList, Service, ServiceStatusEnum, ServiceTypeEnum) Loading Loading @@ -46,8 +46,9 @@ class _Algorithm: self.service_list : List[Dict] = list() self.service_dict : Dict[Tuple[str, str], Tuple[Dict, Service]] = dict() def add_devices(self, grpc_devices : DeviceList) -> None: for grpc_device in grpc_devices.devices: def add_devices(self, grpc_devices : Union[List[Device], DeviceList]) -> None: if isinstance(grpc_devices, DeviceList): grpc_devices = grpc_devices.devices for grpc_device in grpc_devices: json_device = compose_device(grpc_device) self.device_list.append(json_device) Loading @@ -62,8 +63,9 @@ class _Algorithm: self.endpoint_dict[device_uuid] = device_endpoint_dict def add_links(self, grpc_links : LinkList) -> None: for grpc_link in grpc_links.links: def add_links(self, grpc_links : Union[List[Link], LinkList]) -> None: if isinstance(grpc_links, LinkList): grpc_links = grpc_links.links for grpc_link in grpc_links: json_link = compose_link(grpc_link) self.link_list.append(json_link) Loading
src/pathcomp/frontend/service/algorithms/tools/ConstantsMappings.py +1 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ class DeviceLayerEnum(IntEnum): DEVICE_TYPE_TO_LAYER = { DeviceTypeEnum.EMULATED_DATACENTER.value : DeviceLayerEnum.APPLICATION_DEVICE, DeviceTypeEnum.DATACENTER.value : DeviceLayerEnum.APPLICATION_DEVICE, DeviceTypeEnum.NETWORK.value : DeviceLayerEnum.APPLICATION_DEVICE, DeviceTypeEnum.EMULATED_PACKET_ROUTER.value : DeviceLayerEnum.PACKET_DEVICE, DeviceTypeEnum.PACKET_ROUTER.value : DeviceLayerEnum.PACKET_DEVICE, Loading