From 52e1c8ae4420e79252e4f83c5b73e47547d23287 Mon Sep 17 00:00:00 2001 From: gifrerenom Date: Wed, 1 Feb 2023 14:13:38 +0000 Subject: [PATCH 1/2] Common Tools - gRPC: - removed useless comment --- src/common/tools/grpc/EndPointIds.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/common/tools/grpc/EndPointIds.py b/src/common/tools/grpc/EndPointIds.py index b3830d4c8..e4c67ee32 100644 --- a/src/common/tools/grpc/EndPointIds.py +++ b/src/common/tools/grpc/EndPointIds.py @@ -12,9 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# RFC 8466 - L2VPN Service Model (L2SM) -# Ref: https://datatracker.ietf.org/doc/html/rfc8466 - from typing import Optional from common.proto.context_pb2 import EndPointId -- GitLab From fe234b87a7f02278e0cb37c4fde05e8fd84b6327 Mon Sep 17 00:00:00 2001 From: gifrerenom Date: Wed, 1 Feb 2023 14:53:36 +0000 Subject: [PATCH 2/2] Device component: - Added logic to update endpoints manually for P4 devices --- .../service/DeviceServiceServicerImpl.py | 14 ++++++++-- src/device/service/Tools.py | 26 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/device/service/DeviceServiceServicerImpl.py b/src/device/service/DeviceServiceServicerImpl.py index 5cabaea76..1cf7c264e 100644 --- a/src/device/service/DeviceServiceServicerImpl.py +++ b/src/device/service/DeviceServiceServicerImpl.py @@ -15,7 +15,8 @@ import grpc, logging from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method from common.method_wrappers.ServiceExceptions import NotFoundException, OperationFailedException -from common.proto.context_pb2 import Device, DeviceConfig, DeviceId, DeviceOperationalStatusEnum, Empty +from common.proto.context_pb2 import ( + Device, DeviceConfig, DeviceDriverEnum, DeviceId, DeviceOperationalStatusEnum, Empty) from common.proto.device_pb2 import MonitoringSettings from common.proto.device_pb2_grpc import DeviceServiceServicer from common.tools.context_queries.Device import get_device @@ -27,7 +28,7 @@ from .driver_api.DriverInstanceCache import DriverInstanceCache, get_driver from .monitoring.MonitoringLoops import MonitoringLoops from .Tools import ( check_connect_rules, check_no_endpoints, compute_rules_to_add_delete, configure_rules, deconfigure_rules, - populate_config_rules, populate_endpoint_monitoring_resources, populate_endpoints, populate_initial_config_rules, subscribe_kpi, unsubscribe_kpi) + populate_config_rules, populate_endpoint_monitoring_resources, populate_endpoints, populate_initial_config_rules, subscribe_kpi, unsubscribe_kpi, update_endpoints) LOGGER = logging.getLogger(__name__) @@ -112,6 +113,15 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): msg = ERROR_MISSING_DRIVER.format(str(device_uuid)) raise OperationFailedException('ConfigureDevice', extra_details=msg) + if DeviceDriverEnum.DEVICEDRIVER_P4 in device.device_drivers: + # P4 Driver, by now, has no means to retrieve endpoints + # We allow defining the endpoints manually + update_endpoints(request, device) + + # Update endpoints to get UUIDs + device_id = context_client.SetDevice(device) + device = context_client.GetDevice(device_id) + if request.device_operational_status != DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_UNDEFINED: device.device_operational_status = request.device_operational_status diff --git a/src/device/service/Tools.py b/src/device/service/Tools.py index 05610e1d2..5c15958ad 100644 --- a/src/device/service/Tools.py +++ b/src/device/service/Tools.py @@ -269,3 +269,29 @@ def unsubscribe_kpi(request : MonitoringSettings, driver : _Driver, monitoring_l #monitoring_loops.remove_device(device_uuid) # Do not remove; one monitoring_loop/device used by multiple requests return errors + +def update_endpoints(src_device : Device, dst_device : Device) -> None: + for src_endpoint in src_device.device_endpoints: + src_device_uuid = src_endpoint.endpoint_id.device_id.device_uuid.uuid + src_endpoint_uuid = src_endpoint.endpoint_id.endpoint_uuid.uuid + src_context_uuid = src_endpoint.endpoint_id.topology_id.context_id.context_uuid.uuid + src_topology_uuid = src_endpoint.endpoint_id.topology_id.topology_uuid.uuid + + for dst_endpoint in dst_device.device_endpoints: + dst_endpoint_id = dst_endpoint.endpoint_id + if src_endpoint_uuid not in {dst_endpoint_id.endpoint_uuid.uuid, dst_endpoint.name}: continue + if src_device_uuid != dst_endpoint_id.device_id.device_uuid.uuid: continue + + dst_topology_id = dst_endpoint_id.topology_id + if len(src_topology_uuid) > 0 and src_topology_uuid != dst_topology_id.topology_uuid.uuid: continue + if len(src_context_uuid) > 0 and src_context_uuid != dst_topology_id.context_id.context_uuid.uuid: continue + break # found, do nothing + else: + # not found, add it + dst_endpoint = dst_device.device_endpoints.add() # pylint: disable=no-member + dst_endpoint_id = dst_endpoint.endpoint_id + dst_endpoint_id.endpoint_uuid.uuid = src_endpoint_uuid + dst_endpoint_id.device_id.device_uuid.uuid = src_device_uuid + dst_topology_id = dst_endpoint_id.topology_id + if len(src_topology_uuid) > 0: dst_topology_id.topology_uuid.uuid = src_topology_uuid + if len(src_context_uuid) > 0: dst_topology_id.context_id.context_uuid.uuid = src_context_uuid -- GitLab