Skip to content
Snippets Groups Projects
Commit e0a8039a authored by delacal's avatar delacal
Browse files

Merge branch 'develop' into feat/l3-components

parents a8344a6d cc8afab9
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!93Updated L3 components + scalability
Showing
with 93 additions and 60 deletions
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
...@@ -22,13 +22,14 @@ from common.proto.device_pb2_grpc import DeviceServiceServicer ...@@ -22,13 +22,14 @@ 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
from common.tools.mutex_queues.MutexQueues import MutexQueues from common.tools.mutex_queues.MutexQueues import MutexQueues
from context.client.ContextClient import ContextClient from context.client.ContextClient import ContextClient
from device.service.Errors import ERROR_MISSING_DRIVER, ERROR_MISSING_KPI
from .driver_api._Driver import _Driver from .driver_api._Driver import _Driver
from .driver_api.DriverInstanceCache import DriverInstanceCache, get_driver from .driver_api.DriverInstanceCache import DriverInstanceCache, get_driver
from .monitoring.MonitoringLoops import MonitoringLoops from .monitoring.MonitoringLoops import MonitoringLoops
from .ErrorMessages import ERROR_MISSING_DRIVER, ERROR_MISSING_KPI
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, update_endpoints) 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__)
...@@ -108,9 +109,9 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): ...@@ -108,9 +109,9 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
if device is None: if device is None:
raise NotFoundException('Device', device_uuid, extra_details='loading in ConfigureDevice') raise NotFoundException('Device', device_uuid, extra_details='loading in ConfigureDevice')
driver : _Driver = self.driver_instance_cache.get(device_uuid) driver : _Driver = get_driver(self.driver_instance_cache, device)
if driver is None: if driver is None:
msg = ERROR_MISSING_DRIVER.format(str(device_uuid)) msg = ERROR_MISSING_DRIVER.format(device_uuid=str(device_uuid))
raise OperationFailedException('ConfigureDevice', extra_details=msg) raise OperationFailedException('ConfigureDevice', extra_details=msg)
if DeviceDriverEnum.DEVICEDRIVER_P4 in device.device_drivers: if DeviceDriverEnum.DEVICEDRIVER_P4 in device.device_drivers:
...@@ -152,6 +153,11 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): ...@@ -152,6 +153,11 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
self.mutex_queues.wait_my_turn(device_uuid) self.mutex_queues.wait_my_turn(device_uuid)
try: try:
context_client = ContextClient() context_client = ContextClient()
device = get_device(context_client, device_uuid, rw_copy=False)
if device is None:
raise NotFoundException('Device', device_uuid, extra_details='loading in DeleteDevice')
device_uuid = device.device_id.device_uuid.uuid
self.monitoring_loops.remove_device(device_uuid) self.monitoring_loops.remove_device(device_uuid)
self.driver_instance_cache.delete(device_uuid) self.driver_instance_cache.delete(device_uuid)
context_client.RemoveDevice(request) context_client.RemoveDevice(request)
...@@ -165,9 +171,14 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): ...@@ -165,9 +171,14 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
self.mutex_queues.wait_my_turn(device_uuid) self.mutex_queues.wait_my_turn(device_uuid)
try: try:
driver : _Driver = self.driver_instance_cache.get(device_uuid) context_client = ContextClient()
device = get_device(context_client, device_uuid, rw_copy=False)
if device is None:
raise NotFoundException('Device', device_uuid, extra_details='loading in DeleteDevice')
driver : _Driver = get_driver(self.driver_instance_cache, device)
if driver is None: if driver is None:
msg = ERROR_MISSING_DRIVER.format(str(device_uuid)) msg = ERROR_MISSING_DRIVER.format(device_uuid=str(device_uuid))
raise OperationFailedException('GetInitialConfig', extra_details=msg) raise OperationFailedException('GetInitialConfig', extra_details=msg)
device_config = DeviceConfig() device_config = DeviceConfig()
...@@ -193,15 +204,20 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): ...@@ -193,15 +204,20 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
kpi_uuid = request.kpi_id.kpi_id.uuid kpi_uuid = request.kpi_id.kpi_id.uuid
kpi_details = self.monitoring_loops.get_kpi_by_uuid(kpi_uuid) kpi_details = self.monitoring_loops.get_kpi_by_uuid(kpi_uuid)
if kpi_details is None: if kpi_details is None:
msg = ERROR_MISSING_KPI.format(str(kpi_uuid)) msg = ERROR_MISSING_KPI.format(kpi_uuid=str(kpi_uuid))
raise OperationFailedException('MonitorDeviceKpi', extra_details=msg) raise OperationFailedException('MonitorDeviceKpi', extra_details=msg)
device_uuid = kpi_details[0] device_uuid = kpi_details[0]
self.mutex_queues.wait_my_turn(device_uuid) self.mutex_queues.wait_my_turn(device_uuid)
try: try:
driver : _Driver = self.driver_instance_cache.get(device_uuid) context_client = ContextClient()
device = get_device(context_client, device_uuid, rw_copy=False)
if device is None:
raise NotFoundException('Device', device_uuid, extra_details='loading in DeleteDevice')
driver : _Driver = get_driver(self.driver_instance_cache, device)
if driver is None: if driver is None:
msg = ERROR_MISSING_DRIVER.format(str(device_uuid)) msg = ERROR_MISSING_DRIVER.format(device_uuid=str(device_uuid))
raise OperationFailedException('MonitorDeviceKpi', extra_details=msg) raise OperationFailedException('MonitorDeviceKpi', extra_details=msg)
errors = manage_kpi_method(request, driver, self.monitoring_loops) errors = manage_kpi_method(request, driver, self.monitoring_loops)
......
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
_DEVICE_ID = 'DeviceId({device_uuid:s})'
_ENDPOINT_ID = 'EndpointId({endpoint_uuid:s})'
_ENDPOINT_DATA = 'EndpointId({endpoint_data:s})'
_KPI = 'Kpi({kpi_uuid:s})'
_DEVICE_ENDPOINT_ID = _DEVICE_ID + '/' + _ENDPOINT_ID
_RESOURCE_KEY = 'Resource(key={resource_key:s})'
_RESOURCE_KEY_VALUE = 'Resource(key={resource_key:s}, value={resource_value:s})'
_SUBSCRIPTION = 'Subscription(key={subscr_key:s}, duration={subscr_duration:s}, interval={subscr_interval:s})'
_SAMPLE_TYPE = 'SampleType({sample_type_id:s}/{sample_type_name:s})'
_ERROR = 'Error({error:s})'
ERROR_MISSING_DRIVER = _DEVICE_ID + ' has not been added to this Device instance'
ERROR_MISSING_KPI = _KPI + ' not found'
ERROR_BAD_ENDPOINT = _DEVICE_ID + ': GetConfig retrieved malformed ' + _ENDPOINT_DATA
ERROR_GET = _DEVICE_ID + ': Unable to Get ' + _RESOURCE_KEY + '; ' + _ERROR
ERROR_GET_INIT = _DEVICE_ID + ': Unable to Get Initial ' + _RESOURCE_KEY + '; ' + _ERROR
ERROR_DELETE = _DEVICE_ID + ': Unable to Delete ' + _RESOURCE_KEY_VALUE + '; ' + _ERROR
ERROR_SET = _DEVICE_ID + ': Unable to Set ' + _RESOURCE_KEY_VALUE + '; ' + _ERROR
ERROR_SAMPLETYPE = _DEVICE_ENDPOINT_ID + ': ' + _SAMPLE_TYPE + ' not supported'
ERROR_SUBSCRIBE = _DEVICE_ID + ': Unable to Subscribe ' + _SUBSCRIPTION + '; ' + _ERROR
ERROR_UNSUBSCRIBE = _DEVICE_ID + ': Unable to Unsubscribe ' + _SUBSCRIPTION + '; ' + _ERROR
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ERROR_MISSING_DRIVER = 'Device({:s}) has not been added to this Device instance'
ERROR_MISSING_KPI = 'Kpi({:s}) not found'
ERROR_BAD_ENDPOINT = 'Device({:s}): GetConfig retrieved malformed Endpoint({:s})'
ERROR_GET = 'Device({:s}): Unable to Get resource(key={:s}); error({:s})'
ERROR_GET_INIT = 'Device({:s}): Unable to Get Initial resource(key={:s}); error({:s})'
ERROR_DELETE = 'Device({:s}): Unable to Delete resource(key={:s}, value={:s}); error({:s})'
ERROR_SET = 'Device({:s}): Unable to Set resource(key={:s}, value={:s}); error({:s})'
ERROR_SAMPLETYPE = 'Device({:s})/EndPoint({:s}): SampleType({:s}/{:s}) not supported'
ERROR_SUBSCRIBE = 'Device({:s}): Unable to Subscribe subscription(key={:s}, duration={:s}, interval={:s}); '+\
'error({:s})'
ERROR_UNSUBSCRIBE = 'Device({:s}): Unable to Unsubscribe subscription(key={:s}, duration={:s}, interval={:s}); '+\
'error({:s})'
...@@ -23,9 +23,10 @@ from common.tools.grpc.ConfigRules import update_config_rule_custom ...@@ -23,9 +23,10 @@ from common.tools.grpc.ConfigRules import update_config_rule_custom
from common.tools.grpc.Tools import grpc_message_to_json from common.tools.grpc.Tools import grpc_message_to_json
from .driver_api._Driver import _Driver, RESOURCE_ENDPOINTS from .driver_api._Driver import _Driver, RESOURCE_ENDPOINTS
from .monitoring.MonitoringLoops import MonitoringLoops from .monitoring.MonitoringLoops import MonitoringLoops
from .Errors import ( from .ErrorMessages import (
ERROR_BAD_ENDPOINT, ERROR_DELETE, ERROR_GET, ERROR_GET_INIT, ERROR_MISSING_KPI, ERROR_SAMPLETYPE, ERROR_SET, ERROR_BAD_ENDPOINT, ERROR_DELETE, ERROR_GET, ERROR_GET_INIT, ERROR_MISSING_KPI, ERROR_SAMPLETYPE, ERROR_SET,
ERROR_SUBSCRIBE, ERROR_UNSUBSCRIBE) ERROR_SUBSCRIBE, ERROR_UNSUBSCRIBE
)
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
...@@ -85,12 +86,13 @@ def populate_endpoints(device : Device, driver : _Driver, monitoring_loops : Mon ...@@ -85,12 +86,13 @@ def populate_endpoints(device : Device, driver : _Driver, monitoring_loops : Mon
errors : List[str] = list() errors : List[str] = list()
for endpoint in results_getconfig: for endpoint in results_getconfig:
if len(endpoint) != 2: if len(endpoint) != 2:
errors.append(ERROR_BAD_ENDPOINT.format(device_uuid, str(endpoint))) errors.append(ERROR_BAD_ENDPOINT.format(device_uuid=device_uuid, endpoint_data=str(endpoint)))
continue continue
resource_key, resource_value = endpoint resource_key, resource_value = endpoint
if isinstance(resource_value, Exception): if isinstance(resource_value, Exception):
errors.append(ERROR_GET.format(device_uuid, str(resource_key), str(resource_value))) errors.append(ERROR_GET.format(
device_uuid=device_uuid, resource_key=str(resource_key), error=str(resource_value)))
continue continue
if resource_value is None: if resource_value is None:
continue continue
...@@ -134,7 +136,9 @@ def _raw_config_rules_to_grpc( ...@@ -134,7 +136,9 @@ def _raw_config_rules_to_grpc(
for resource_key, resource_value in raw_config_rules: for resource_key, resource_value in raw_config_rules:
if isinstance(resource_value, Exception): if isinstance(resource_value, Exception):
errors.append(error_template.format(device_uuid, str(resource_key), str(resource_value))) errors.append(error_template.format(
device_uuid=device_uuid, resource_key=str(resource_key), resource_value=str(resource_value),
error=str(resource_value)))
continue continue
if resource_value is None: continue if resource_value is None: continue
...@@ -226,7 +230,8 @@ def subscribe_kpi(request : MonitoringSettings, driver : _Driver, monitoring_loo ...@@ -226,7 +230,8 @@ def subscribe_kpi(request : MonitoringSettings, driver : _Driver, monitoring_loo
if resource_key is None: if resource_key is None:
kpi_sample_type_name = KpiSampleType.Name(kpi_sample_type).upper().replace('KPISAMPLETYPE_', '') kpi_sample_type_name = KpiSampleType.Name(kpi_sample_type).upper().replace('KPISAMPLETYPE_', '')
MSG = ERROR_SAMPLETYPE.format( MSG = ERROR_SAMPLETYPE.format(
str(device_uuid), str(endpoint_uuid), str(kpi_sample_type), str(kpi_sample_type_name) device_uuid=str(device_uuid), endpoint_uuid=str(endpoint_uuid), sample_type_id=str(kpi_sample_type),
sample_type_name=str(kpi_sample_type_name)
) )
LOGGER.warning('{:s} Supported Device-Endpoint-KpiSampleType items: {:s}'.format( LOGGER.warning('{:s} Supported Device-Endpoint-KpiSampleType items: {:s}'.format(
MSG, str(monitoring_loops.get_all_resource_keys()))) MSG, str(monitoring_loops.get_all_resource_keys())))
...@@ -242,7 +247,8 @@ def subscribe_kpi(request : MonitoringSettings, driver : _Driver, monitoring_loo ...@@ -242,7 +247,8 @@ def subscribe_kpi(request : MonitoringSettings, driver : _Driver, monitoring_loo
for (resource_key, duration, interval), result in zip(resources_to_subscribe, results_subscribestate): for (resource_key, duration, interval), result in zip(resources_to_subscribe, results_subscribestate):
if isinstance(result, Exception): if isinstance(result, Exception):
errors.append(ERROR_SUBSCRIBE.format( errors.append(ERROR_SUBSCRIBE.format(
str(device_uuid), str(resource_key), str(duration), str(interval), str(result) device_uuid=str(device_uuid), subscr_key=str(resource_key), subscr_duration=str(duration),
subscr_interval=str(interval), error=str(result)
)) ))
continue continue
...@@ -256,7 +262,7 @@ def unsubscribe_kpi(request : MonitoringSettings, driver : _Driver, monitoring_l ...@@ -256,7 +262,7 @@ def unsubscribe_kpi(request : MonitoringSettings, driver : _Driver, monitoring_l
kpi_details = monitoring_loops.get_kpi_by_uuid(kpi_uuid) kpi_details = monitoring_loops.get_kpi_by_uuid(kpi_uuid)
if kpi_details is None: if kpi_details is None:
return [ERROR_MISSING_KPI.format(str(kpi_uuid))] return [ERROR_MISSING_KPI.format(kpi_uuid=str(kpi_uuid))]
device_uuid, resource_key, sampling_duration, sampling_interval = kpi_details device_uuid, resource_key, sampling_duration, sampling_interval = kpi_details
...@@ -267,7 +273,9 @@ def unsubscribe_kpi(request : MonitoringSettings, driver : _Driver, monitoring_l ...@@ -267,7 +273,9 @@ def unsubscribe_kpi(request : MonitoringSettings, driver : _Driver, monitoring_l
for (resource_key, duration, interval), result in zip(resources_to_unsubscribe, results_unsubscribestate): for (resource_key, duration, interval), result in zip(resources_to_unsubscribe, results_unsubscribestate):
if isinstance(result, Exception): if isinstance(result, Exception):
errors.append(ERROR_UNSUBSCRIBE.format( errors.append(ERROR_UNSUBSCRIBE.format(
device_uuid, str(resource_key), str(duration), str(interval), str(result))) device_uuid=str(device_uuid), subscr_key=str(resource_key), subscr_duration=str(duration),
subscr_interval=str(interval), error=str(result)
))
continue continue
monitoring_loops.remove_kpi(kpi_uuid) monitoring_loops.remove_kpi(kpi_uuid)
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
/* /*
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) * Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
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