diff --git a/src/common/tools/grpc/EndPointIds.py b/src/common/tools/grpc/EndPointIds.py index b3830d4c809bb6dc065e58bc8af0f1ad56c610f4..e4c67ee32f8e78c5d0f6429a460ea385f3861095 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 diff --git a/src/device/service/DeviceServiceServicerImpl.py b/src/device/service/DeviceServiceServicerImpl.py index 5cabaea76972a799341541ce01ebc38628e834f5..1cf7c264ed4ad89ca58f7aa98696ba130af143b2 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 11a2e49b8e9da03efbceb730cae2a3cd9d10f0b5..e4abd557ce5a8142866977e2b8c884b22f164a00 100644 --- a/src/device/service/Tools.py +++ b/src/device/service/Tools.py @@ -271,3 +271,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