Skip to content
Snippets Groups Projects
Commit 0d94bcd1 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch 'fix/release-2' into 'develop'

Improvements in Device component

See merge request !52
parents 438a93f9 676b2913
No related branches found
No related tags found
2 merge requests!54Release 2.0.0,!52Improvements in Device component
...@@ -12,9 +12,6 @@ ...@@ -12,9 +12,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# RFC 8466 - L2VPN Service Model (L2SM)
# Ref: https://datatracker.ietf.org/doc/html/rfc8466
from typing import Optional from typing import Optional
from common.proto.context_pb2 import EndPointId from common.proto.context_pb2 import EndPointId
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
import grpc, logging import grpc, logging
from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method
from common.method_wrappers.ServiceExceptions import NotFoundException, OperationFailedException 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 import MonitoringSettings
from common.proto.device_pb2_grpc import DeviceServiceServicer from common.proto.device_pb2_grpc import DeviceServiceServicer
from common.tools.context_queries.Device import get_device from common.tools.context_queries.Device import get_device
...@@ -27,7 +28,7 @@ from .driver_api.DriverInstanceCache import DriverInstanceCache, get_driver ...@@ -27,7 +28,7 @@ from .driver_api.DriverInstanceCache import DriverInstanceCache, get_driver
from .monitoring.MonitoringLoops import MonitoringLoops from .monitoring.MonitoringLoops import MonitoringLoops
from .Tools import ( from .Tools import (
check_connect_rules, check_no_endpoints, compute_rules_to_add_delete, configure_rules, deconfigure_rules, 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__) LOGGER = logging.getLogger(__name__)
...@@ -112,6 +113,15 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): ...@@ -112,6 +113,15 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
msg = ERROR_MISSING_DRIVER.format(str(device_uuid)) msg = ERROR_MISSING_DRIVER.format(str(device_uuid))
raise OperationFailedException('ConfigureDevice', extra_details=msg) 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: if request.device_operational_status != DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_UNDEFINED:
device.device_operational_status = request.device_operational_status device.device_operational_status = request.device_operational_status
......
...@@ -271,3 +271,29 @@ def unsubscribe_kpi(request : MonitoringSettings, driver : _Driver, monitoring_l ...@@ -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 #monitoring_loops.remove_device(device_uuid) # Do not remove; one monitoring_loop/device used by multiple requests
return errors 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment