From dc073cb01748516f0932a75f4242b680c999ce5c Mon Sep 17 00:00:00 2001 From: Carlos Manso Date: Tue, 3 Oct 2023 12:48:51 +0200 Subject: [PATCH 1/6] initial base plugin --- .../drivers/flexscale/FlexScaleDriver.py | 123 ++++++++++++++++++ src/device/service/drivers/flexscale/Tools.py | 31 +++++ .../service/drivers/flexscale/__init__.py | 20 +++ 3 files changed, 174 insertions(+) create mode 100644 src/device/service/drivers/flexscale/FlexScaleDriver.py create mode 100644 src/device/service/drivers/flexscale/Tools.py create mode 100644 src/device/service/drivers/flexscale/__init__.py diff --git a/src/device/service/drivers/flexscale/FlexScaleDriver.py b/src/device/service/drivers/flexscale/FlexScaleDriver.py new file mode 100644 index 000000000..f512a7923 --- /dev/null +++ b/src/device/service/drivers/flexscale/FlexScaleDriver.py @@ -0,0 +1,123 @@ +# 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. + +import logging, requests, threading +from requests.auth import HTTPBasicAuth +from typing import Any, Iterator, List, Optional, Tuple, Union +from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method +from common.type_checkers.Checkers import chk_string, chk_type +from device.service.driver_api._Driver import _Driver +from . import ALL_RESOURCE_KEYS +from .Tools import find_key + +LOGGER = logging.getLogger(__name__) + +DRIVER_NAME = 'flexscale' +METRICS_POOL = MetricsPool('Device', 'Driver', labels={'driver': DRIVER_NAME}) + +class FlexScaleDriver(_Driver): + def __init__(self, address: str, port: int, **settings) -> None: + super().__init__(DRIVER_NAME, address, port, **settings) + self.__lock = threading.Lock() + self.__started = threading.Event() + self.__terminate = threading.Event() + username = self.settings.get('username') + password = self.settings.get('password') + self.__auth = HTTPBasicAuth(username, password) if username is not None and password is not None else None + scheme = self.settings.get('scheme', 'http') + self.__flexscale_root = '{:s}://{:s}:{:d}'.format(scheme, self.address, int(self.port)) + self.__timeout = int(self.settings.get('timeout', 120)) + + def Connect(self) -> bool: + url = self.__flexscale_root + '/TODO' # TODO + with self.__lock: + if self.__started.is_set(): return True + try: + requests.get(url, timeout=self.__timeout, verify=False, auth=self.__auth) + except requests.exceptions.Timeout: + LOGGER.exception('Timeout connecting {:s}'.format(str(self.__tapi_root))) + return False + except Exception: # pylint: disable=broad-except + LOGGER.exception('Exception connecting {:s}'.format(str(self.__tapi_root))) + return False + else: + self.__started.set() + return True + + def Disconnect(self) -> bool: + with self.__lock: + self.__terminate.set() + return True + + @metered_subclass_method(METRICS_POOL) + def GetInitialConfig(self) -> List[Tuple[str, Any]]: + with self.__lock: + return [] + + @metered_subclass_method(METRICS_POOL) + def GetConfig(self, resource_keys : List[str] = []) -> List[Tuple[str, Union[Any, None, Exception]]]: + chk_type('resources', resource_keys, list) + results = [] + with self.__lock: + if len(resource_keys) == 0: resource_keys = ALL_RESOURCE_KEYS + for i, resource_key in enumerate(resource_keys): + str_resource_name = 'resource_key[#{:d}]'.format(i) + chk_string(str_resource_name, resource_key, allow_empty=False) + # TODO results.extend(config_getter( + # self.__tapi_root, resource_key, timeout=self.__timeout, auth=self.__auth)) + return results + + @metered_subclass_method(METRICS_POOL) + def SetConfig(self, resources: List[Tuple[str, Any]]) -> List[Union[bool, Exception]]: + results = [] + if len(resources) == 0: + return results + with self.__lock: + for resource in resources: + LOGGER.info('resource = {:s}'.format(str(resource))) + + # data = create_connectivity_service( TODO + # self.__tapi_root, uuid, input_sip, output_sip, direction, capacity_value, capacity_unit, + # layer_protocol_name, layer_protocol_qualifier, timeout=self.__timeout, auth=self.__auth) + data = None + results.extend(data) + return results + + @metered_subclass_method(METRICS_POOL) + def DeleteConfig(self, resources: List[Tuple[str, Any]]) -> List[Union[bool, Exception]]: + results = [] + if len(resources) == 0: return results + with self.__lock: + for resource in resources: + LOGGER.info('resource = {:s}'.format(str(resource))) + uuid = find_key(resource, 'uuid') + # results.extend(delete_connectivity_service( TODO + # self.__tapi_root, uuid, timeout=self.__timeout, auth=self.__auth)) + return results + + @metered_subclass_method(METRICS_POOL) + def SubscribeState(self, subscriptions : List[Tuple[str, float, float]]) -> List[Union[bool, Exception]]: + # TODO: TAPI does not support monitoring by now + return [False for _ in subscriptions] + + @metered_subclass_method(METRICS_POOL) + def UnsubscribeState(self, subscriptions : List[Tuple[str, float, float]]) -> List[Union[bool, Exception]]: + # TODO: TAPI does not support monitoring by now + return [False for _ in subscriptions] + + def GetState( + self, blocking=False, terminate : Optional[threading.Event] = None + ) -> Iterator[Tuple[float, str, Any]]: + # TODO: TAPI does not support monitoring by now + return [] diff --git a/src/device/service/drivers/flexscale/Tools.py b/src/device/service/drivers/flexscale/Tools.py new file mode 100644 index 000000000..49a01b267 --- /dev/null +++ b/src/device/service/drivers/flexscale/Tools.py @@ -0,0 +1,31 @@ +# 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. + +import json, logging, operator, requests +from requests.auth import HTTPBasicAuth +from typing import Optional +from device.service.driver_api._Driver import RESOURCE_ENDPOINTS, RESOURCE_SERVICES + +LOGGER = logging.getLogger(__name__) + +HTTP_OK_CODES = { + 200, # OK + 201, # Created + 202, # Accepted + 204, # No Content +} + +def find_key(resource, key): + return json.loads(resource[1])[key] + diff --git a/src/device/service/drivers/flexscale/__init__.py b/src/device/service/drivers/flexscale/__init__.py new file mode 100644 index 000000000..d5073c330 --- /dev/null +++ b/src/device/service/drivers/flexscale/__init__.py @@ -0,0 +1,20 @@ +# 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. + +from device.service.driver_api._Driver import RESOURCE_ENDPOINTS, RESOURCE_SERVICES + +ALL_RESOURCE_KEYS = [ + RESOURCE_ENDPOINTS, + RESOURCE_SERVICES, +] -- GitLab From c3e310512ab442499998891af7c41f83167e6e02 Mon Sep 17 00:00:00 2001 From: Carlos Manso Date: Mon, 23 Oct 2023 12:38:28 +0200 Subject: [PATCH 2/6] Update --- manifests/e2eorchestratorservice.yaml | 96 ++++++++++ my_deploy.sh | 6 +- proto/context.proto | 1 + proto/e2eorchestrator.proto | 39 ++++ scripts/show_logs_e2eorchestrator.sh | 27 +++ src/common/Constants.py | 2 + .../drivers/flexscale/FlexScaleDriver.py | 47 +++-- src/device/service/drivers/flexscale/Tools.py | 119 +++++++++++- src/e2eorchestrator/.gitlab-ci.yml | 38 ++++ src/e2eorchestrator/Config.py | 13 ++ src/e2eorchestrator/Dockerfile | 84 +++++++++ src/e2eorchestrator/__init__.py | 13 ++ .../client/E2EOrchestratorServiceClient.py | 68 +++++++ src/e2eorchestrator/client/__init__.py | 13 ++ src/e2eorchestrator/requirements.in | 15 ++ .../service/E2EOrchestratorService.py | 35 ++++ .../E2EOrchestratorServiceServicerImpl.py | 89 +++++++++ src/e2eorchestrator/service/__init__.py | 13 ++ src/e2eorchestrator/service/__main__.py | 80 ++++++++ src/service/Dockerfile | 1 + .../service/ServiceServiceServicerImpl.py | 29 +++ .../2e2_orch/E2EOrchServiceHandler.py | 176 ++++++++++++++++++ .../service_handlers/2e2_orch/__init__.py | 14 ++ .../MockFlexscaleOptCtrl.py | 73 ++++++++ .../tools/mock_flexscale_opt_ctrl/data.py | 98 ++++++++++ .../tools/mock_flexscale_opt_ctrl/run.sh | 16 ++ .../tools/mock_flexscale_opt_ctrl/test_mw.py | 84 +++++++++ 27 files changed, 1267 insertions(+), 22 deletions(-) create mode 100644 manifests/e2eorchestratorservice.yaml create mode 100644 proto/e2eorchestrator.proto create mode 100755 scripts/show_logs_e2eorchestrator.sh create mode 100644 src/e2eorchestrator/.gitlab-ci.yml create mode 100644 src/e2eorchestrator/Config.py create mode 100644 src/e2eorchestrator/Dockerfile create mode 100644 src/e2eorchestrator/__init__.py create mode 100644 src/e2eorchestrator/client/E2EOrchestratorServiceClient.py create mode 100644 src/e2eorchestrator/client/__init__.py create mode 100644 src/e2eorchestrator/requirements.in create mode 100644 src/e2eorchestrator/service/E2EOrchestratorService.py create mode 100644 src/e2eorchestrator/service/E2EOrchestratorServiceServicerImpl.py create mode 100644 src/e2eorchestrator/service/__init__.py create mode 100644 src/e2eorchestrator/service/__main__.py create mode 100644 src/service/service/service_handlers/2e2_orch/E2EOrchServiceHandler.py create mode 100644 src/service/service/service_handlers/2e2_orch/__init__.py create mode 100644 src/tests/tools/mock_flexscale_opt_ctrl/MockFlexscaleOptCtrl.py create mode 100644 src/tests/tools/mock_flexscale_opt_ctrl/data.py create mode 100755 src/tests/tools/mock_flexscale_opt_ctrl/run.sh create mode 100644 src/tests/tools/mock_flexscale_opt_ctrl/test_mw.py diff --git a/manifests/e2eorchestratorservice.yaml b/manifests/e2eorchestratorservice.yaml new file mode 100644 index 000000000..ba2e4fabd --- /dev/null +++ b/manifests/e2eorchestratorservice.yaml @@ -0,0 +1,96 @@ +# 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. + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: e2eorchestratorservice +spec: + selector: + matchLabels: + app: e2eorchestratorservice + template: + metadata: + labels: + app: e2eorchestratorservice + spec: + terminationGracePeriodSeconds: 5 + containers: + - name: server + image: labs.etsi.org:5050/tfs/controller/e2eorchestrator:latest + imagePullPolicy: Always + ports: + - containerPort: 10040 + - containerPort: 9192 + env: + - name: LOG_LEVEL + value: "INFO" + - name: REDIS_PASSWORD + valueFrom: + secretKeyRef: + name: redis-secrets + key: REDIS_PASSWORD + readinessProbe: + exec: + command: ["/bin/grpc_health_probe", "-addr=:10009"] + livenessProbe: + exec: + command: ["/bin/grpc_health_probe", "-addr=:10009"] + resources: + requests: + cpu: 250m + memory: 128Mi + limits: + cpu: 1000m + memory: 1024Mi +--- +apiVersion: v1 +kind: Service +metadata: + name: e2eorchestratorservice + labels: + app: e2eorchestratorservice +spec: + type: ClusterIP + selector: + app: e2eorchestratorservice + ports: + - name: grpc + port: 10040 + targetPort: 10040 + - name: metrics + port: 9192 + targetPort: 9192 +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: e2eorchestratorservice-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: e2eorchestratorservice + minReplicas: 1 + maxReplicas: 20 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 80 + #behavior: + # scaleDown: + # stabilizationWindowSeconds: 30 diff --git a/my_deploy.sh b/my_deploy.sh index 888fc9890..358ddcf08 100755 --- a/my_deploy.sh +++ b/my_deploy.sh @@ -37,6 +37,10 @@ export TFS_COMPONENTS="context device pathcomp service slice compute webui load_ # Uncomment to activate TE #export TFS_COMPONENTS="${TFS_COMPONENTS} te" +# Uncomment to activate E2EOrchestrator +export TFS_COMPONENTS="${TFS_COMPONENTS} e2eorchestrator" + + # Set the tag you want to use for your images. export TFS_IMAGE_TAG="dev" @@ -102,7 +106,7 @@ export NATS_EXT_PORT_CLIENT="4222" export NATS_EXT_PORT_HTTP="8222" # Disable flag for re-deploying NATS from scratch. -export NATS_REDEPLOY="" +export NATS_REDEPLOY="YES" # ----- QuestDB ---------------------------------------------------------------- diff --git a/proto/context.proto b/proto/context.proto index 22e11bc68..4068bf1f8 100644 --- a/proto/context.proto +++ b/proto/context.proto @@ -279,6 +279,7 @@ enum ServiceTypeEnum { SERVICETYPE_L2NM = 2; SERVICETYPE_TAPI_CONNECTIVITY_SERVICE = 3; SERVICETYPE_TE = 4; + SERVICETYPE_E2E = 5; } enum ServiceStatusEnum { diff --git a/proto/e2eorchestrator.proto b/proto/e2eorchestrator.proto new file mode 100644 index 000000000..9eed8523e --- /dev/null +++ b/proto/e2eorchestrator.proto @@ -0,0 +1,39 @@ +// 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. + +// protocol buffers documentation: https://developers.google.com/protocol-buffers/docs/proto3 +syntax = "proto3"; +package orchestrator; + +import "context.proto"; + + +service E2EOrchestratorService { + rpc Compute(E2EOrchestratorRequest) returns (E2EOrchestratorReply) {} +} + +message E2EOrchestratorRequest { + context.Service service = 1; +} + +message E2EOrchestratorReply { + // Service requested completed with possible missing fields, and + // sub-services required for supporting requested service on the + // underlying layers. + repeated context.Service services = 1; + + // Connections supporting the requested service and sub-services + // required for the underlying layers. + repeated context.Connection connections = 2; +} \ No newline at end of file diff --git a/scripts/show_logs_e2eorchestrator.sh b/scripts/show_logs_e2eorchestrator.sh new file mode 100755 index 000000000..84951ed8d --- /dev/null +++ b/scripts/show_logs_e2eorchestrator.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# 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. + +######################################################################################################################## +# Define your deployment settings here +######################################################################################################################## + +# If not already set, set the name of the Kubernetes namespace to deploy to. +export TFS_K8S_NAMESPACE=${TFS_K8S_NAMESPACE:-"tfs"} + +######################################################################################################################## +# Automated steps start here +######################################################################################################################## + +kubectl --namespace $TFS_K8S_NAMESPACE logs deployment/e2eorchestratorservice -c server diff --git a/src/common/Constants.py b/src/common/Constants.py index 423f2558b..3bf294a50 100644 --- a/src/common/Constants.py +++ b/src/common/Constants.py @@ -57,6 +57,7 @@ class ServiceNameEnum(Enum): OPTICALATTACKMITIGATOR = 'opticalattackmitigator' CACHING = 'caching' TE = 'te' + E2EORCHESTRATOR = 'e2eorchestrator' # Used for test and debugging only DLT_GATEWAY = 'dltgateway' @@ -82,6 +83,7 @@ DEFAULT_SERVICE_GRPC_PORTS = { ServiceNameEnum.INTERDOMAIN .value : 10010, ServiceNameEnum.PATHCOMP .value : 10020, ServiceNameEnum.TE .value : 10030, + ServiceNameEnum.E2EORCHESTRATOR .value : 10040, # Used for test and debugging only ServiceNameEnum.DLT_GATEWAY .value : 50051, diff --git a/src/device/service/drivers/flexscale/FlexScaleDriver.py b/src/device/service/drivers/flexscale/FlexScaleDriver.py index f512a7923..1733f504d 100644 --- a/src/device/service/drivers/flexscale/FlexScaleDriver.py +++ b/src/device/service/drivers/flexscale/FlexScaleDriver.py @@ -12,20 +12,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging, requests, threading +import json, logging, requests, threading from requests.auth import HTTPBasicAuth from typing import Any, Iterator, List, Optional, Tuple, Union from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method from common.type_checkers.Checkers import chk_string, chk_type from device.service.driver_api._Driver import _Driver from . import ALL_RESOURCE_KEYS -from .Tools import find_key +from .Tools import find_key, add_lightpath, del_lightpath, get_lightpaths LOGGER = logging.getLogger(__name__) DRIVER_NAME = 'flexscale' METRICS_POOL = MetricsPool('Device', 'Driver', labels={'driver': DRIVER_NAME}) + class FlexScaleDriver(_Driver): def __init__(self, address: str, port: int, **settings) -> None: super().__init__(DRIVER_NAME, address, port, **settings) @@ -40,7 +41,7 @@ class FlexScaleDriver(_Driver): self.__timeout = int(self.settings.get('timeout', 120)) def Connect(self) -> bool: - url = self.__flexscale_root + '/TODO' # TODO + url = self.__flexscale_root + '/OpticalTFS/GetLightpaths' with self.__lock: if self.__started.is_set(): return True try: @@ -74,8 +75,8 @@ class FlexScaleDriver(_Driver): for i, resource_key in enumerate(resource_keys): str_resource_name = 'resource_key[#{:d}]'.format(i) chk_string(str_resource_name, resource_key, allow_empty=False) - # TODO results.extend(config_getter( - # self.__tapi_root, resource_key, timeout=self.__timeout, auth=self.__auth)) + results.extend(get_lightpaths( + self.__flexscale_root, resource_key, timeout=self.__timeout, auth=self.__auth)) return results @metered_subclass_method(METRICS_POOL) @@ -84,40 +85,48 @@ class FlexScaleDriver(_Driver): if len(resources) == 0: return results with self.__lock: - for resource in resources: + for _, resource in resources: LOGGER.info('resource = {:s}'.format(str(resource))) - # data = create_connectivity_service( TODO - # self.__tapi_root, uuid, input_sip, output_sip, direction, capacity_value, capacity_unit, - # layer_protocol_name, layer_protocol_qualifier, timeout=self.__timeout, auth=self.__auth) - data = None - results.extend(data) + src_node = find_key(resource, 'src_node') + dst_node = find_key(resource, 'dst_node') + bitrate = find_key(resource, 'bitrate') + + response = add_lightpath(self.__flexscale_root, src_node, dst_node, bitrate, + auth=self.__auth, timeout=self.__timeout) + results.extend(response) return results @metered_subclass_method(METRICS_POOL) def DeleteConfig(self, resources: List[Tuple[str, Any]]) -> List[Union[bool, Exception]]: results = [] - if len(resources) == 0: return results + if len(resources) == 0: + return results with self.__lock: - for resource in resources: + for _, resource in resources: LOGGER.info('resource = {:s}'.format(str(resource))) - uuid = find_key(resource, 'uuid') - # results.extend(delete_connectivity_service( TODO - # self.__tapi_root, uuid, timeout=self.__timeout, auth=self.__auth)) + flow_id = find_key(resource, 'flow_id') + src_node = find_key(resource, 'src_node') + dst_node = find_key(resource, 'dst_node') + bitrate = find_key(resource, 'bitrate') + + response = del_lightpath(self.__flexscale_root, flow_id, src_node, dst_node, bitrate) + results.extend(response) + return results @metered_subclass_method(METRICS_POOL) def SubscribeState(self, subscriptions : List[Tuple[str, float, float]]) -> List[Union[bool, Exception]]: - # TODO: TAPI does not support monitoring by now + # FlexScale does not support monitoring by now return [False for _ in subscriptions] @metered_subclass_method(METRICS_POOL) def UnsubscribeState(self, subscriptions : List[Tuple[str, float, float]]) -> List[Union[bool, Exception]]: - # TODO: TAPI does not support monitoring by now + # FlexScale does not support monitoring by now return [False for _ in subscriptions] def GetState( self, blocking=False, terminate : Optional[threading.Event] = None ) -> Iterator[Tuple[float, str, Any]]: - # TODO: TAPI does not support monitoring by now + # FlexScale does not support monitoring by now return [] diff --git a/src/device/service/drivers/flexscale/Tools.py b/src/device/service/drivers/flexscale/Tools.py index 49a01b267..15b60d765 100644 --- a/src/device/service/drivers/flexscale/Tools.py +++ b/src/device/service/drivers/flexscale/Tools.py @@ -26,6 +26,121 @@ HTTP_OK_CODES = { 204, # No Content } -def find_key(resource, key): - return json.loads(resource[1])[key] +def get_lightpaths(root_url : str, resource_key : str,auth : Optional[HTTPBasicAuth] = None, + timeout : Optional[int] = None): + headers = {'accept': 'application/json'} + url = '{:s}/OpticalTFS/GetLightpaths'.format(root_url) + result = [] + try: + response = requests.get(url, timeout=timeout, headers=headers, verify=False, auth=auth) + except requests.exceptions.Timeout: + LOGGER.exception('Timeout connecting {:s}'.format(url)) + return result + except Exception as e: # pylint: disable=broad-except + LOGGER.exception('Exception retrieving {:s}'.format(resource_key)) + result.append((resource_key, e)) + return result + + try: + flows = json.loads(response.content) + except Exception as e: # pylint: disable=broad-except + LOGGER.warning('Unable to decode reply: {:s}'.format(str(response.content))) + result.append((resource_key, e)) + return result + + # if resource_key == RESOURCE_ENDPOINTS: + for flow in flows: + flow_id = flow.get('flow_id') + source = flow.get('src') + destination = flow.get('dst') + bitrate = flow.get('bitrate') + # more TODO + + endpoint_url = '/flows/flow[{:s}]'.format(flow_id) + endpoint_data = {'flow_id': flow_id, 'src': source, 'dst': destination, 'bitrate': bitrate} + result.append((endpoint_url, endpoint_data)) + + return result + + +def add_lightpath(root_url, src_node, dst_node, bitrate, + auth : Optional[HTTPBasicAuth] = None, timeout : Optional[int] = None): + + headers = {'accept': 'application/json'} + url = '{:s}/OpticalTFS/AddLightpath/{:s}/{:s}/{:s}'.format(root_url, src_node, dst_node, bitrate) + + results = [] + try: + response = requests.put(url=url, timeout=timeout, headers=headers, verify=False, auth=auth) + results.extend(response) + LOGGER.info('Lightpath request: {:s} <-> {:s} with {:s} bitrate'.format( + str(src_node), str(dst_node), str(bitrate))) + LOGGER.info('Response: {:s}'.format(str(response))) + except Exception as e: # pylint: disable=broad-except + LOGGER.exception('Exception requesting Lightpath: {:s} <-> {:s} with {:s} bitrate'.format( + str(src_node), str(dst_node), str(bitrate))) + results.append(e) + else: + if response.status_code not in HTTP_OK_CODES: + msg = 'Could not create Lightpath(status_code={:s} reply={:s}' + LOGGER.error(msg.format(str(response.status_code), str(response))) + results.append(response.status_code in HTTP_OK_CODES) + + return results + + + +def del_lightpath(root_url, flow_id, src_node, dst_node, bitrate, + auth : Optional[HTTPBasicAuth] = None, timeout : Optional[int] = None): + url = '{:s}/OpticalTFS/DelLightpath/{:s}/{:s}/{:s}/{:s}'.format(root_url, flow_id, src_node, dst_node, bitrate) + headers = {'accept': 'application/json'} + + results = [] + + try: + response = requests.delete(url=url, timeout=timeout, headers=headers, verify=False, auth=auth) + except Exception as e: # pylint: disable=broad-except + LOGGER.exception('Exception deleting Lightpath(uuid={:s})'.format(str(flow_id))) + results.append(e) + else: + if response.status_code not in HTTP_OK_CODES: + msg = 'Could not delete Lightpath(flow_id={:s}). status_code={:s} reply={:s}' + LOGGER.error(msg.format(str(flow_id), str(response.status_code), str(response))) + results.append(response.status_code in HTTP_OK_CODES) + + return results + + +def get_topology(root_url : str, resource_key : str,auth : Optional[HTTPBasicAuth] = None, + timeout : Optional[int] = None): + headers = {'accept': 'application/json'} + url = '{:s}/OpticalTFS/GetLinks'.format(root_url) + + result = [] + try: + response = requests.get(url, timeout=timeout, headers=headers, verify=False, auth=auth) + except requests.exceptions.Timeout: + LOGGER.exception('Timeout connecting {:s}'.format(url)) + return result + except Exception as e: # pylint: disable=broad-except + LOGGER.exception('Exception retrieving {:s}'.format(resource_key)) + result.append((resource_key, e)) + return result + + try: + links = json.loads(response.content) + except Exception as e: # pylint: disable=broad-except + LOGGER.warning('Unable to decode reply: {:s}'.format(str(response.content))) + result.append((resource_key, e)) + return result + + # if resource_key == RESOURCE_ENDPOINTS: + for link in links: + # TODO + + # endpoint_url = '/flows/flow[{:s}]'.format(flow_id) + # endpoint_data = {'flow_id': flow_id, 'src': source, 'dst': destination, 'bitrate': bitrate} + # result.append((endpoint_url, endpoint_data)) + + return result diff --git a/src/e2eorchestrator/.gitlab-ci.yml b/src/e2eorchestrator/.gitlab-ci.yml new file mode 100644 index 000000000..a14a215af --- /dev/null +++ b/src/e2eorchestrator/.gitlab-ci.yml @@ -0,0 +1,38 @@ +# 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. + +# build, tag and push the Docker image to the gitlab registry +build e2eorchestrator: + variables: + IMAGE_NAME: 'e2eorchestrator' # name of the microservice + IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) + stage: build + before_script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + script: + - docker build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile . + - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" + - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" + after_script: + - docker images --filter="dangling=true" --quiet | xargs -r docker rmi + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' + - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"' + - changes: + - src/$IMAGE_NAME/**/*.{py,in,yml} + - src/$IMAGE_NAME/Dockerfile + - src/$IMAGE_NAME/tests/*.py + - src/$IMAGE_NAME/tests/Dockerfile + - manifests/${IMAGE_NAME}service.yaml + - .gitlab-ci.yml diff --git a/src/e2eorchestrator/Config.py b/src/e2eorchestrator/Config.py new file mode 100644 index 000000000..38d04994f --- /dev/null +++ b/src/e2eorchestrator/Config.py @@ -0,0 +1,13 @@ +# 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. diff --git a/src/e2eorchestrator/Dockerfile b/src/e2eorchestrator/Dockerfile new file mode 100644 index 000000000..52bd806f5 --- /dev/null +++ b/src/e2eorchestrator/Dockerfile @@ -0,0 +1,84 @@ +# 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. + +FROM python:3.9-slim + +# Install dependencies +RUN apt-get --yes --quiet --quiet update && \ + apt-get --yes --quiet --quiet install wget g++ && \ + rm -rf /var/lib/apt/lists/* + +# Set Python to show logs as they occur +ENV PYTHONUNBUFFERED=0 +ENV PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python + +# Download the gRPC health probe +RUN GRPC_HEALTH_PROBE_VERSION=v0.2.0 && \ + wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ + chmod +x /bin/grpc_health_probe + +# Creating a user for security reasons +RUN groupadd -r teraflow && useradd -u 1001 --no-log-init -r -m -g teraflow teraflow +USER teraflow + +# set working directory +RUN mkdir -p /home/teraflow/controller/common/ +WORKDIR /home/teraflow/controller + +# Get Python packages per module +ENV VIRTUAL_ENV=/home/teraflow/venv +RUN python3 -m venv ${VIRTUAL_ENV} +ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" + +# Get generic Python packages +RUN python3 -m pip install --upgrade pip +RUN python3 -m pip install --upgrade setuptools wheel +RUN python3 -m pip install --upgrade pip-tools + +# Get common Python packages +# Note: this step enables sharing the previous Docker build steps among all the Python components +COPY --chown=teraflow:teraflow common_requirements.in common_requirements.in +RUN pip-compile --quiet --output-file=common_requirements.txt common_requirements.in +RUN python3 -m pip install -r common_requirements.txt + +# Add common files into working directory +WORKDIR /home/teraflow/controller/common +COPY --chown=teraflow:teraflow src/common/. ./ +RUN rm -rf proto + +# Create proto sub-folder, copy .proto files, and generate Python code +RUN mkdir -p /home/teraflow/controller/common/proto +WORKDIR /home/teraflow/controller/common/proto +RUN touch __init__.py +COPY --chown=teraflow:teraflow proto/*.proto ./ +RUN python3 -m grpc_tools.protoc -I=. --python_out=. --grpc_python_out=. *.proto +RUN rm *.proto +RUN find . -type f -exec sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' {} \; + +# Create module sub-folders +RUN mkdir -p /home/teraflow/controller/e2eorchestrator +WORKDIR /home/teraflow/controller + +# Get Python packages per module +COPY --chown=teraflow:teraflow ./src/e2eorchestrator/requirements.in e2eorchestrator/requirements.in +# consider common and specific requirements to avoid inconsistencies with dependencies +RUN pip-compile --quiet --output-file=e2eorchestrator/requirements.txt e2eorchestrator/requirements.in common_requirements.in +RUN python3 -m pip install -r e2eorchestrator/requirements.txt + +# Add component files into working directory +COPY --chown=teraflow:teraflow ./src/context/. context +COPY --chown=teraflow:teraflow ./src/e2eorchestrator/. e2eorchestrator + +# Start the service +ENTRYPOINT ["python", "-m", "e2eorchestrator.service"] diff --git a/src/e2eorchestrator/__init__.py b/src/e2eorchestrator/__init__.py new file mode 100644 index 000000000..38d04994f --- /dev/null +++ b/src/e2eorchestrator/__init__.py @@ -0,0 +1,13 @@ +# 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. diff --git a/src/e2eorchestrator/client/E2EOrchestratorServiceClient.py b/src/e2eorchestrator/client/E2EOrchestratorServiceClient.py new file mode 100644 index 000000000..6efb0e3fc --- /dev/null +++ b/src/e2eorchestrator/client/E2EOrchestratorServiceClient.py @@ -0,0 +1,68 @@ +# 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. + +import logging + +import grpc + +from common.Constants import ServiceNameEnum +from common.proto.context_pb2 import Empty +from common.proto.e2eorchestrator_pb2_grpc import E2EOrchestratorServiceStub +from common.Settings import get_service_host, get_service_port_grpc +from common.tools.client.RetryDecorator import delay_exponential, retry +from common.tools.grpc.Tools import grpc_message_to_json + +LOGGER = logging.getLogger(__name__) +MAX_RETRIES = 15 +DELAY_FUNCTION = delay_exponential(initial=0.01, increment=2.0, maximum=5.0) +RETRY_DECORATOR = retry( + max_retries=MAX_RETRIES, + delay_function=DELAY_FUNCTION, + prepare_method_name="connect", +) + + +class E2EOrchestratorServiceClient: + def __init__(self, host=None, port=None): + if not host: + host = get_service_host(ServiceNameEnum.E2EORCHESTRATOR) + if not port: + port = get_service_port_grpc(ServiceNameEnum.E2EORCHESTRATOR) + self.endpoint = "{:s}:{:s}".format(str(host), str(port)) + LOGGER.debug("Creating channel to {:s}...".format(str(self.endpoint))) + self.channel = None + self.stub = None + self.connect() + LOGGER.debug("Channel created") + + def connect(self): + self.channel = grpc.insecure_channel(self.endpoint) + self.stub = E2EOrchestratorServiceStub(self.channel) + + def close(self): + if self.channel is not None: + self.channel.close() + self.channel = None + self.stub = None + + @RETRY_DECORATOR + def Compute(self, request: Empty) -> Empty: + LOGGER.debug( + "Compute request: {:s}".format(str(grpc_message_to_json(request))) + ) + response = self.stub.GetPath(request) + LOGGER.debug( + "Compute result: {:s}".format(str(grpc_message_to_json(response))) + ) + return response diff --git a/src/e2eorchestrator/client/__init__.py b/src/e2eorchestrator/client/__init__.py new file mode 100644 index 000000000..38d04994f --- /dev/null +++ b/src/e2eorchestrator/client/__init__.py @@ -0,0 +1,13 @@ +# 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. diff --git a/src/e2eorchestrator/requirements.in b/src/e2eorchestrator/requirements.in new file mode 100644 index 000000000..4c4720a2d --- /dev/null +++ b/src/e2eorchestrator/requirements.in @@ -0,0 +1,15 @@ +# 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. + +networkx \ No newline at end of file diff --git a/src/e2eorchestrator/service/E2EOrchestratorService.py b/src/e2eorchestrator/service/E2EOrchestratorService.py new file mode 100644 index 000000000..4d6125d4a --- /dev/null +++ b/src/e2eorchestrator/service/E2EOrchestratorService.py @@ -0,0 +1,35 @@ +# 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. + +import logging + +from common.Constants import ServiceNameEnum +from common.proto.e2eorchestrator_pb2_grpc import add_E2EOrchestratorServiceServicer_to_server +from common.Settings import get_service_port_grpc +from common.tools.service.GenericGrpcService import GenericGrpcService +from .E2EOrchestratorServiceServicerImpl import E2EOrchestratorServiceServicerImpl + +LOGGER = logging.getLogger(__name__) + + +class E2EOrchestratorService(GenericGrpcService): + def __init__(self, cls_name: str = __name__): + port = get_service_port_grpc(ServiceNameEnum.E2EORCHESTRATOR) + super().__init__(port, cls_name=cls_name) + self.e2eorchestrator_servicer = E2EOrchestratorServiceServicerImpl() + + def install_servicers(self): + add_E2EOrchestratorServiceServicer_to_server( + self.e2eorchestrator_servicer, self.server + ) diff --git a/src/e2eorchestrator/service/E2EOrchestratorServiceServicerImpl.py b/src/e2eorchestrator/service/E2EOrchestratorServiceServicerImpl.py new file mode 100644 index 000000000..8e5edfd63 --- /dev/null +++ b/src/e2eorchestrator/service/E2EOrchestratorServiceServicerImpl.py @@ -0,0 +1,89 @@ +# 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. + +import logging + +import networkx as nx +import grpc +import copy + +from common.Constants import ServiceNameEnum +from common.method_wrappers.Decorator import (MetricsPool, MetricTypeEnum, safe_and_metered_rpc_method) +from common.proto.e2eorchestrator_pb2 import E2EOrchestratorRequest, E2EOrchestratorReply +from common.proto.context_pb2 import Empty, Connection, EndPointId +from common.proto.e2eorchestrator_pb2_grpc import E2EOrchestratorServiceServicer +from context.client.ContextClient import ContextClient + + +LOGGER = logging.getLogger(__name__) + +METRICS_POOL = MetricsPool("E2EOrchestrator", "RPC") + +context_client: ContextClient = ContextClient() + + +class E2EOrchestratorServiceServicerImpl(E2EOrchestratorServiceServicer): + def __init__(self): + LOGGER.debug("Creating Servicer...") + LOGGER.debug("Servicer Created") + + @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) + def Compute(self, request: E2EOrchestratorRequest, context: grpc.ServicerContext) -> E2EOrchestratorReply: + + endpoints_ids = [] + for endpoint_id in request.service_endpoint_ids: + endpoints_ids.append(endpoint_id.endpoint_uuid.uuid) + + graph = nx.Graph() + + devices = context_client.ListDevices(Empty()).devices + + for device in devices: + endpoints_uuids = [endpoint.endpoint_uuid.uuid for endpoint in device.device_endpoints] + for ep in endpoints_uuids: + graph.add_node(ep) + + for ep in endpoints_uuids: + for ep_i in endpoints_uuids: + if ep == ep_i: + continue + graph.add_edge(ep. ep_i) + + links = context_client.ListLinks(Empty()).links + for link in links: + eps = [] + for endpoint_id in link.link_endpoint_ids: + eps.append(endpoint_id.endpoint_uuid.uuid) + graph.add_edge(eps[0], eps[1]) + + + shortest = nx.shortest_path(graph, endpoints_ids[0], endpoints_ids[1]) + + path = E2EOrchestratorReply() + path.services.append(copy.deepcopy(request.service)) + for i in len(shortest): + conn = Connection + conn.connection_id.connection_uuid.uuid = str(shortest[i*2]) + '_->_' + str(shortest[i*2+1]) + + ep0 = EndPointId + ep0.endpoint_uuid.uuid = ep + conn.path_hops_endpoint_ids.append(shortest[i*2]) + + ep1 = EndPointId + ep1.endpoint_uuid.uuid = ep + conn.path_hops_endpoint_ids.append(shortest[i*2+1]) + + path.connections.append(conn) + + return path diff --git a/src/e2eorchestrator/service/__init__.py b/src/e2eorchestrator/service/__init__.py new file mode 100644 index 000000000..38d04994f --- /dev/null +++ b/src/e2eorchestrator/service/__init__.py @@ -0,0 +1,13 @@ +# 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. diff --git a/src/e2eorchestrator/service/__main__.py b/src/e2eorchestrator/service/__main__.py new file mode 100644 index 000000000..a586543a7 --- /dev/null +++ b/src/e2eorchestrator/service/__main__.py @@ -0,0 +1,80 @@ +# 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. + +import logging +import signal +import sys +import threading + +from prometheus_client import start_http_server + +from common.Constants import ServiceNameEnum +from common.Settings import (ENVVAR_SUFIX_SERVICE_HOST, + ENVVAR_SUFIX_SERVICE_PORT_GRPC, get_env_var_name, + get_log_level, get_metrics_port, + wait_for_environment_variables) + +from .E2EOrchestratorService import E2EOrchestratorService + +terminate = threading.Event() +LOGGER = None + + +def signal_handler(signal, frame): # pylint: disable=redefined-outer-name + LOGGER.warning("Terminate signal received") + terminate.set() + + +def main(): + global LOGGER # pylint: disable=global-statement + + log_level = get_log_level() + logging.basicConfig(level=log_level) + LOGGER = logging.getLogger(__name__) + + wait_for_environment_variables( + [ + get_env_var_name(ServiceNameEnum.E2EORCHESTRATOR, ENVVAR_SUFIX_SERVICE_HOST), + get_env_var_name(ServiceNameEnum.E2EORCHESTRATOR, ENVVAR_SUFIX_SERVICE_PORT_GRPC), + ] + ) + + signal.signal(signal.SIGINT, signal_handler) + signal.signal(signal.SIGTERM, signal_handler) + + LOGGER.info("Starting...") + + # Start metrics server + metrics_port = get_metrics_port() + start_http_server(metrics_port) + + # Starting CentralizedCybersecurity service + grpc_service = E2EOrchestratorService() + grpc_service.start() + LOGGER.info("Started...") + # Wait for Ctrl+C or termination signal + + while not terminate.wait(timeout=1): + pass + + + LOGGER.info("Terminating...") + grpc_service.stop() + + LOGGER.info("Bye") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/src/service/Dockerfile b/src/service/Dockerfile index 5988374e0..23be900e6 100644 --- a/src/service/Dockerfile +++ b/src/service/Dockerfile @@ -66,6 +66,7 @@ COPY src/context/. context/ COPY src/device/. device/ COPY src/pathcomp/frontend/. pathcomp/frontend/ COPY src/service/. service/ +COPY src/e2eorchestrator/. e2eorchestrator/ # Start the service ENTRYPOINT ["python", "-m", "service.service"] diff --git a/src/service/service/ServiceServiceServicerImpl.py b/src/service/service/ServiceServiceServicerImpl.py index f79e3e5f3..20b6048af 100644 --- a/src/service/service/ServiceServiceServicerImpl.py +++ b/src/service/service/ServiceServiceServicerImpl.py @@ -21,10 +21,12 @@ from common.method_wrappers.ServiceExceptions import ( from common.proto.context_pb2 import ( Connection, Empty, Service, ServiceId, ServiceStatusEnum, ServiceTypeEnum, ConstraintActionEnum) from common.proto.pathcomp_pb2 import PathCompRequest +from common.proto.e2eorchestrator_pb2 import E2EOrchestratorRequest, E2EOrchestratorReply from common.proto.service_pb2_grpc import ServiceServiceServicer from common.tools.context_queries.Service import get_service_by_id from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string from context.client.ContextClient import ContextClient +from e2eorchestrator.client.E2EOrchestratorServiceClient import E2EOrchestratorServiceClient from pathcomp.frontend.client.PathCompClient import PathCompClient from service.service.tools.ConnectionToString import connection_to_string from service.client.TEServiceClient import TEServiceClient @@ -32,6 +34,7 @@ from .service_handler_api.ServiceHandlerFactory import ServiceHandlerFactory from .task_scheduler.TaskScheduler import TasksScheduler from .tools.GeodesicDistance import gps_distance + LOGGER = logging.getLogger(__name__) METRICS_POOL = MetricsPool('Service', 'RPC') @@ -153,6 +156,32 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): str_service_status = ServiceStatusEnum.Name(service_status.service_status) raise Exception(MSG.format(service_key, str_service_status)) + if service.service_type == ServiceTypeEnum.SERVICETYPE_E2E: + # End-to-End service: + service_id_with_uuids = context_client.SetService(request) + + service_with_uuids = get_service_by_id( + context_client, service_id_with_uuids, rw_copy=False, + include_config_rules=True, include_constraints=True, include_endpoint_ids=True) + + e2e_orch_request = E2EOrchestratorRequest() + e2e_orch_request.service.CopyFrom(service_with_uuids) + + e2e_orch_client = E2EOrchestratorServiceClient() + e2e_orch_reply = e2e_orch_client.Compute(e2e_orch_request) + + # Feed TaskScheduler with this end-to-end orchestrator reply. TaskScheduler identifies + # inter-dependencies among the services and connections retrieved and produces a + # schedule of tasks (an ordered list of tasks to be executed) to implement the + # requested create/update operation. + tasks_scheduler = TasksScheduler(self.service_handler_factory) + # e2e_orch_reply should be compatible with pathcomp_reply + # TODO: if we extend e2e_orch_reply, implement method TasksScheduler::compose_from_e2eorchreply() + tasks_scheduler.compose_from_pathcompreply(e2e_orch_reply, is_delete=False) + tasks_scheduler.execute_all() + return service_with_uuids.service_id + + # Normal service del service.service_endpoint_ids[:] # pylint: disable=no-member for endpoint_id in request.service_endpoint_ids: diff --git a/src/service/service/service_handlers/2e2_orch/E2EOrchServiceHandler.py b/src/service/service/service_handlers/2e2_orch/E2EOrchServiceHandler.py new file mode 100644 index 000000000..44272fee8 --- /dev/null +++ b/src/service/service/service_handlers/2e2_orch/E2EOrchServiceHandler.py @@ -0,0 +1,176 @@ +# 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. + +import json, logging +from typing import Any, Dict, List, Optional, Tuple, Union +from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method +from common.proto.context_pb2 import ConfigRule, DeviceId, Service +from common.tools.object_factory.ConfigRule import json_config_rule_delete, json_config_rule_set +from common.tools.object_factory.Device import json_device_id +from common.type_checkers.Checkers import chk_type +from service.service.service_handler_api.Tools import get_device_endpoint_uuids +from service.service.service_handler_api._ServiceHandler import _ServiceHandler +from service.service.service_handler_api.SettingsHandler import SettingsHandler +from service.service.task_scheduler.TaskExecutor import TaskExecutor + +LOGGER = logging.getLogger(__name__) + +METRICS_POOL = MetricsPool('Service', 'Handler', labels={'handler': 'e2e_orch'}) + +class E2EOrchServiceHandler(_ServiceHandler): + def __init__( # pylint: disable=super-init-not-called + self, service : Service, task_executor : TaskExecutor, **settings + ) -> None: + self.__service = service + self.__task_executor = task_executor + self.__settings_handler = SettingsHandler(service.service_config, **settings) + + @metered_subclass_method(METRICS_POOL) + def SetEndpoint( + self, endpoints : List[Tuple[str, str, Optional[str]]], connection_uuid : Optional[str] = None + ) -> List[Union[bool, Exception]]: + + chk_type('endpoints', endpoints, list) + if len(endpoints) < 2: return [] + + service_uuid = self.__service.service_id.service_uuid.uuid + settings = self.__settings_handler.get('/settings') + json_settings : Dict = {} if settings is None else settings.value + bitrate = json_settings.get('bitrate', 1000) + + results = [] + try: + src_device_uuid, src_endpoint_uuid = get_device_endpoint_uuids(endpoints[0]) + src_device = self.__task_executor.get_device(DeviceId(**json_device_id(src_device_uuid))) + src_controller = self.__task_executor.get_device_controller(src_device) + if src_controller is None: src_controller = src_device + + dst_device_uuid, dst_endpoint_uuid = get_device_endpoint_uuids(endpoints[-1]) + dst_device = self.__task_executor.get_device(DeviceId(**json_device_id(dst_device_uuid))) + dst_controller = self.__task_executor.get_device_controller(dst_device) + if dst_controller is None: dst_controller = dst_device + + controller = src_controller + + json_config_rule = json_config_rule_set('/services/service[{:s}]'.format(service_uuid), { + 'uuid' : service_uuid, + 'src_node' : src_endpoint_uuid, + 'dst_node' : dst_endpoint_uuid, + 'bitrate' : bitrate + }) + del controller.device_config.config_rules[:] + controller.device_config.config_rules.append(ConfigRule(**json_config_rule)) + self.__task_executor.configure_device(controller) + results.append(True) + except Exception as e: # pylint: disable=broad-except + LOGGER.exception('Unable to SetEndpoint for Service({:s})'.format(str(service_uuid))) + results.append(e) + + return results + + @metered_subclass_method(METRICS_POOL) + def DeleteEndpoint( + self, endpoints : List[Tuple[str, str, Optional[str]]], connection_uuid : Optional[str] = None + ) -> List[Union[bool, Exception]]: + + chk_type('endpoints', endpoints, list) + if len(endpoints) < 2: return [] + + service_uuid = self.__service.service_id.service_uuid.uuid + settings = self.__settings_handler.get('/settings') + json_settings : Dict = {} if settings is None else settings.value + flow_id = json_settings.get('flow_id', 100) + bitrate = json_settings.get('bitrate', 1000) + + results = [] + try: + src_device_uuid, src_endpoint_uuid = get_device_endpoint_uuids(endpoints[0]) + src_device = self.__task_executor.get_device(DeviceId(**json_device_id(src_device_uuid))) + src_controller = self.__task_executor.get_device_controller(src_device) + if src_controller is None: src_controller = src_device + + dst_device_uuid, dst_endpoint_uuid = get_device_endpoint_uuids(endpoints[1]) + dst_device = self.__task_executor.get_device(DeviceId(**json_device_id(dst_device_uuid))) + dst_controller = self.__task_executor.get_device_controller(dst_device) + if dst_controller is None: dst_controller = dst_device + + controller = src_controller + + json_config_rule = json_config_rule_set('/services/service[{:s}]'.format(service_uuid), { + 'uuid' : service_uuid, + 'flow_id' : flow_id, + 'src_node' : src_endpoint_uuid, + 'dst_node' : dst_endpoint_uuid, + 'bitrate' : bitrate + }) + + del controller.device_config.config_rules[:] + controller.device_config.config_rules.append(ConfigRule(**json_config_rule)) + self.__task_executor.configure_device(controller) + results.append(True) + except Exception as e: # pylint: disable=broad-except + LOGGER.exception('Unable to DeleteEndpoint for Service({:s})'.format(str(service_uuid))) + results.append(e) + + return results + + @metered_subclass_method(METRICS_POOL) + def SetConstraint(self, constraints : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]: + chk_type('constraints', constraints, list) + if len(constraints) == 0: return [] + + msg = '[SetConstraint] Method not implemented. Constraints({:s}) are being ignored.' + LOGGER.warning(msg.format(str(constraints))) + return [True for _ in range(len(constraints))] + + @metered_subclass_method(METRICS_POOL) + def DeleteConstraint(self, constraints : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]: + chk_type('constraints', constraints, list) + if len(constraints) == 0: return [] + + msg = '[DeleteConstraint] Method not implemented. Constraints({:s}) are being ignored.' + LOGGER.warning(msg.format(str(constraints))) + return [True for _ in range(len(constraints))] + + @metered_subclass_method(METRICS_POOL) + def SetConfig(self, resources : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]: + chk_type('resources', resources, list) + if len(resources) == 0: return [] + + results = [] + for resource in resources: + try: + resource_value = json.loads(resource[1]) + self.__settings_handler.set(resource[0], resource_value) + results.append(True) + except Exception as e: # pylint: disable=broad-except + LOGGER.exception('Unable to SetConfig({:s})'.format(str(resource))) + results.append(e) + + return results + + @metered_subclass_method(METRICS_POOL) + def DeleteConfig(self, resources : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]: + chk_type('resources', resources, list) + if len(resources) == 0: return [] + + results = [] + for resource in resources: + try: + self.__settings_handler.delete(resource[0]) + except Exception as e: # pylint: disable=broad-except + LOGGER.exception('Unable to DeleteConfig({:s})'.format(str(resource))) + results.append(e) + + return results diff --git a/src/service/service/service_handlers/2e2_orch/__init__.py b/src/service/service/service_handlers/2e2_orch/__init__.py new file mode 100644 index 000000000..1549d9811 --- /dev/null +++ b/src/service/service/service_handlers/2e2_orch/__init__.py @@ -0,0 +1,14 @@ +# 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. + diff --git a/src/tests/tools/mock_flexscale_opt_ctrl/MockFlexscaleOptCtrl.py b/src/tests/tools/mock_flexscale_opt_ctrl/MockFlexscaleOptCtrl.py new file mode 100644 index 000000000..09e1de995 --- /dev/null +++ b/src/tests/tools/mock_flexscale_opt_ctrl/MockFlexscaleOptCtrl.py @@ -0,0 +1,73 @@ +# 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. + + +import functools, logging, sys, time +from flask import Flask, jsonify, make_response, request +from flask_restful import Api, Resource +from data import ADDLIGHTPATH_REPLY + +BIND_ADDRESS = '0.0.0.0' +BIND_PORT = 8443 +BASE_URL = '/OpticalTFS' +STR_ENDPOINT = 'https://{:s}:{:s}{:s}'.format(str(BIND_ADDRESS), str(BIND_PORT), str(BASE_URL)) +LOG_LEVEL = logging.DEBUG + + +logging.basicConfig(level=LOG_LEVEL, format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s") +LOGGER = logging.getLogger(__name__) +logging.getLogger('werkzeug').setLevel(logging.WARNING) + +def log_request(logger : logging.Logger, response): + timestamp = time.strftime('[%Y-%b-%d %H:%M]') + logger.info('%s %s %s %s %s', timestamp, request.remote_addr, request.method, request.full_path, response.status) + return response + +class AddLightpath(Resource): + def put(self): + return make_response(jsonify(ADDLIGHTPATH_REPLY), 200) + +class DelLightpath(Resource): + def delete(self): + return make_response(jsonify({}), 200) + +class GetLightpaths(Resource): + def get(self): + return make_response(jsonify({}), 200) + +class GetLinks(Resource): + def get(self): + return make_response(jsonify({}), 200) + + +def main(): + LOGGER.info('Starting...') + + app = Flask(__name__) + app.after_request(functools.partial(log_request, LOGGER)) + + api = Api(app, prefix=BASE_URL) + api.add_resource(AddLightpath, '/AddLightpath///') + api.add_resource(DelLightpath, '/DelLightpath////') + api.add_resource(GetLightpaths, '/GetLightpaths') + api.add_resource(GetLinks, '/GetLinks') + + LOGGER.info('Listening on {:s}...'.format(str(STR_ENDPOINT))) + app.run(debug=True, host=BIND_ADDRESS, port=BIND_PORT) + + LOGGER.info('Bye') + return 0 + +if __name__ == '__main__': + sys.exit(main()) diff --git a/src/tests/tools/mock_flexscale_opt_ctrl/data.py b/src/tests/tools/mock_flexscale_opt_ctrl/data.py new file mode 100644 index 000000000..e89abeb3a --- /dev/null +++ b/src/tests/tools/mock_flexscale_opt_ctrl/data.py @@ -0,0 +1,98 @@ +# 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. + + +ADDLIGHTPATH_REPLY = """{ + "flow_id": 1, + "src": "t1", + "dst": "t2", + "bitrate": 100, + "bidir": 1, + "flows": { + "t1": [ + { + "in": 0, + "out": "1" + }, + { + "in": "1", + "out": 0 + } + ], + "r1": [ + { + "in": "101R", + "out": "1T" + }, + { + "in": "1R", + "out": "101T" + } + ], + "r2": [ + { + "in": "1R", + "out": "101T" + }, + { + "in": "101R", + "out": "1T" + } + ], + "t2": [ + { + "in": "1", + "out": 0 + }, + { + "in": 0, + "out": "1" + } + ] + }, + "band_type": "c_slots", + "slots": [ + 1, + 2, + 3, + 4 + ], + "fiber_forward": { + "t1-r1": "M1", + "r1-r2": "d1-1", + "r2-t2": "S1" + }, + "fiber_backward": { + "r1-t1": "S1", + "r2-r1": "d1-1", + "t2-r2": "M1" + }, + "op-mode": 1, + "n_slots": 4, + "links": [ + "t1-r1", + "r1-r2", + "r2-t2" + ], + "path": [ + "t1", + "r1", + "r2", + "t2" + ], + "band": 50, + "freq": 192031.25, + "is_active": true +} +""" diff --git a/src/tests/tools/mock_flexscale_opt_ctrl/run.sh b/src/tests/tools/mock_flexscale_opt_ctrl/run.sh new file mode 100755 index 000000000..183df7a03 --- /dev/null +++ b/src/tests/tools/mock_flexscale_opt_ctrl/run.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# 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. + +python MockFlexscaleOptCtrl.py diff --git a/src/tests/tools/mock_flexscale_opt_ctrl/test_mw.py b/src/tests/tools/mock_flexscale_opt_ctrl/test_mw.py new file mode 100644 index 000000000..0329d30ad --- /dev/null +++ b/src/tests/tools/mock_flexscale_opt_ctrl/test_mw.py @@ -0,0 +1,84 @@ +import json, logging, requests +from requests.auth import HTTPBasicAuth +from typing import Optional + +LOGGER = logging.getLogger(__name__) + +HTTP_OK_CODES = { + 200, # OK + 201, # Created + 202, # Accepted + 204, # No Content +} + +def create_connectivity_service( + root_url, uuid, node_id_src, tp_id_src, node_id_dst, tp_id_dst, vlan_id, + auth : Optional[HTTPBasicAuth] = None, timeout : Optional[int] = None +): + + url = '{:s}/nmswebs/restconf/data/ietf-eth-tran-service:etht-svc'.format(root_url) + headers = {'content-type': 'application/json'} + data = { + 'etht-svc-instances': [ + { + 'etht-svc-name': uuid, + 'etht-svc-type': 'ietf-eth-tran-types:p2p-svc', + 'etht-svc-end-points': [ + { + 'etht-svc-access-points': [ + {'access-node-id': node_id_src, 'access-ltp-id': tp_id_src, 'access-point-id': '1'} + ], + 'outer-tag': {'vlan-value': vlan_id, 'tag-type': 'ietf-eth-tran-types:classify-c-vlan'}, + 'etht-svc-end-point-name': '{:s}:{:s}'.format(str(node_id_src), str(tp_id_src)), + 'service-classification-type': 'ietf-eth-tran-types:vlan-classification' + }, + { + 'etht-svc-access-points': [ + {'access-node-id': node_id_dst, 'access-ltp-id': tp_id_dst, 'access-point-id': '2'} + ], + 'outer-tag': {'vlan-value': vlan_id, 'tag-type': 'ietf-eth-tran-types:classify-c-vlan'}, + 'etht-svc-end-point-name': '{:s}:{:s}'.format(str(node_id_dst), str(tp_id_dst)), + 'service-classification-type': 'ietf-eth-tran-types:vlan-classification' + } + ] + } + ] + } + results = [] + try: + LOGGER.info('Connectivity service {:s}: {:s}'.format(str(uuid), str(data))) + response = requests.post( + url=url, data=json.dumps(data), timeout=timeout, headers=headers, verify=False, auth=auth) + LOGGER.info('Microwave Driver response: {:s}'.format(str(response))) + except Exception as e: # pylint: disable=broad-except + LOGGER.exception('Exception creating ConnectivityService(uuid={:s}, data={:s})'.format(str(uuid), str(data))) + results.append(e) + else: + if response.status_code not in HTTP_OK_CODES: + msg = 'Could not create ConnectivityService(uuid={:s}, data={:s}). status_code={:s} reply={:s}' + LOGGER.error(msg.format(str(uuid), str(data), str(response.status_code), str(response))) + results.append(response.status_code in HTTP_OK_CODES) + return results + +def delete_connectivity_service(root_url, uuid, auth : Optional[HTTPBasicAuth] = None, timeout : Optional[int] = None): + url = '{:s}/nmswebs/restconf/data/ietf-eth-tran-service:etht-svc/etht-svc-instances={:s}' + url = url.format(root_url, uuid) + results = [] + try: + response = requests.delete(url=url, timeout=timeout, verify=False, auth=auth) + except Exception as e: # pylint: disable=broad-except + LOGGER.exception('Exception deleting ConnectivityService(uuid={:s})'.format(str(uuid))) + results.append(e) + else: + if response.status_code not in HTTP_OK_CODES: + msg = 'Could not delete ConnectivityService(uuid={:s}). status_code={:s} reply={:s}' + LOGGER.error(msg.format(str(uuid), str(response.status_code), str(response))) + results.append(response.status_code in HTTP_OK_CODES) + return results + +if __name__ == '__main__': + ROOT_URL = 'https://127.0.0.1:8443' + SERVICE_UUID = 'my-service' + + create_connectivity_service(ROOT_URL, SERVICE_UUID, '172.18.0.1', '1', '172.18.0.2', '2', 300) + delete_connectivity_service(ROOT_URL, SERVICE_UUID) -- GitLab From 2d7b16cad61375c3849cdb732ec721f3acf440b0 Mon Sep 17 00:00:00 2001 From: Carlos Manso Date: Fri, 1 Dec 2023 12:57:18 +0100 Subject: [PATCH 3/6] first functional version e2e_orchestrator --- manifests/e2eorchestratorservice.yaml | 4 +- proto/context.proto | 1 + .../database/models/enums/DeviceDriver.py | 1 + src/device/service/drivers/__init__.py | 10 ++++ .../drivers/flexscale/FlexScaleDriver.py | 29 ++++++++-- src/device/service/drivers/flexscale/Tools.py | 58 +++++++++++++++++-- .../drivers/ietf_l2vpn/TfsDebugApiClient.py | 2 + .../service_handler_api/FilterFields.py | 2 + .../service/service_handlers/__init__.py | 8 +++ .../E2EOrchestratorServiceHandler.py} | 4 +- .../{2e2_orch => e2e_orch}/__init__.py | 0 .../MockFlexscaleOptCtrl.py | 4 +- .../tools/mock_flexscale_opt_ctrl/data.py | 6 +- 13 files changed, 111 insertions(+), 18 deletions(-) rename src/service/service/service_handlers/{2e2_orch/E2EOrchServiceHandler.py => e2e_orch/E2EOrchestratorServiceHandler.py} (99%) rename src/service/service/service_handlers/{2e2_orch => e2e_orch}/__init__.py (100%) diff --git a/manifests/e2eorchestratorservice.yaml b/manifests/e2eorchestratorservice.yaml index ba2e4fabd..aefe554ce 100644 --- a/manifests/e2eorchestratorservice.yaml +++ b/manifests/e2eorchestratorservice.yaml @@ -43,10 +43,10 @@ spec: key: REDIS_PASSWORD readinessProbe: exec: - command: ["/bin/grpc_health_probe", "-addr=:10009"] + command: ["/bin/grpc_health_probe", "-addr=:10040"] livenessProbe: exec: - command: ["/bin/grpc_health_probe", "-addr=:10009"] + command: ["/bin/grpc_health_probe", "-addr=:10040"] resources: requests: cpu: 250m diff --git a/proto/context.proto b/proto/context.proto index 4068bf1f8..9c2bbea21 100644 --- a/proto/context.proto +++ b/proto/context.proto @@ -201,6 +201,7 @@ enum DeviceDriverEnum { DEVICEDRIVER_XR = 6; DEVICEDRIVER_IETF_L2VPN = 7; DEVICEDRIVER_GNMI_OPENCONFIG = 8; + DEVICEDRIVER_FLEXSCALE = 9; } enum DeviceOperationalStatusEnum { diff --git a/src/context/service/database/models/enums/DeviceDriver.py b/src/context/service/database/models/enums/DeviceDriver.py index 66635decc..f84833601 100644 --- a/src/context/service/database/models/enums/DeviceDriver.py +++ b/src/context/service/database/models/enums/DeviceDriver.py @@ -31,6 +31,7 @@ class ORM_DeviceDriverEnum(enum.Enum): XR = DeviceDriverEnum.DEVICEDRIVER_XR IETF_L2VPN = DeviceDriverEnum.DEVICEDRIVER_IETF_L2VPN GNMI_OPENCONFIG = DeviceDriverEnum.DEVICEDRIVER_GNMI_OPENCONFIG + FLEXSCALE = DeviceDriverEnum.DEVICEDRIVER_FLEXSCALE grpc_to_enum__device_driver = functools.partial( grpc_to_enum, DeviceDriverEnum, ORM_DeviceDriverEnum) diff --git a/src/device/service/drivers/__init__.py b/src/device/service/drivers/__init__.py index 0d85e8ff9..442acf839 100644 --- a/src/device/service/drivers/__init__.py +++ b/src/device/service/drivers/__init__.py @@ -148,3 +148,13 @@ if LOAD_ALL_DEVICE_DRIVERS: FilterFieldEnum.DRIVER : DeviceDriverEnum.DEVICEDRIVER_XR, } ])) + +if LOAD_ALL_DEVICE_DRIVERS: + from .flexscale.FlexScaleDriver import FlexScaleDriver # pylint: disable=wrong-import-position + DRIVERS.append( + (FlexScaleDriver, [ + { + FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.OPEN_LINE_SYSTEM, + FilterFieldEnum.DRIVER: DeviceDriverEnum.DEVICEDRIVER_FLEXSCALE, + } + ])) diff --git a/src/device/service/drivers/flexscale/FlexScaleDriver.py b/src/device/service/drivers/flexscale/FlexScaleDriver.py index 1733f504d..23a7bc006 100644 --- a/src/device/service/drivers/flexscale/FlexScaleDriver.py +++ b/src/device/service/drivers/flexscale/FlexScaleDriver.py @@ -20,6 +20,9 @@ from common.type_checkers.Checkers import chk_string, chk_type from device.service.driver_api._Driver import _Driver from . import ALL_RESOURCE_KEYS from .Tools import find_key, add_lightpath, del_lightpath, get_lightpaths +from device.service.driver_api._Driver import _Driver, RESOURCE_ENDPOINTS +from device.service.drivers.ietf_l2vpn.TfsDebugApiClient import TfsDebugApiClient +from device.service.driver_api.ImportTopologyEnum import ImportTopologyEnum, get_import_topology LOGGER = logging.getLogger(__name__) @@ -37,9 +40,19 @@ class FlexScaleDriver(_Driver): password = self.settings.get('password') self.__auth = HTTPBasicAuth(username, password) if username is not None and password is not None else None scheme = self.settings.get('scheme', 'http') + self.dac = TfsDebugApiClient(self.address, int(self.port), scheme=scheme, username=username, password=password) self.__flexscale_root = '{:s}://{:s}:{:d}'.format(scheme, self.address, int(self.port)) self.__timeout = int(self.settings.get('timeout', 120)) + # Options are: + # disabled --> just import endpoints as usual + # devices --> imports sub-devices but not links connecting them. + # (a remotely-controlled transport domain might exist between them) + # topology --> imports sub-devices and links connecting them. + # (not supported by XR driver) + self.__import_topology = get_import_topology(self.settings, default=ImportTopologyEnum.TOPOLOGY) + + def Connect(self) -> bool: url = self.__flexscale_root + '/OpticalTFS/GetLightpaths' with self.__lock: @@ -75,8 +88,13 @@ class FlexScaleDriver(_Driver): for i, resource_key in enumerate(resource_keys): str_resource_name = 'resource_key[#{:d}]'.format(i) chk_string(str_resource_name, resource_key, allow_empty=False) - results.extend(get_lightpaths( - self.__flexscale_root, resource_key, timeout=self.__timeout, auth=self.__auth)) + + if resource_key == RESOURCE_ENDPOINTS: + # return endpoints through debug-api and list-devices method + results.extend(self.dac.get_devices_endpoints(self.__import_topology)) + + # results.extend(get_lightpaths( + # self.__flexscale_root, resource_key, timeout=self.__timeout, auth=self.__auth)) return results @metered_subclass_method(METRICS_POOL) @@ -88,12 +106,13 @@ class FlexScaleDriver(_Driver): for _, resource in resources: LOGGER.info('resource = {:s}'.format(str(resource))) - src_node = find_key(resource, 'src_node') - dst_node = find_key(resource, 'dst_node') - bitrate = find_key(resource, 'bitrate') + src_node = '1' # find_key(resource, 'src_node') + dst_node = '2' # find_key(resource, 'dst_node') + bitrate = '3' # find_key(resource, 'bitrate') response = add_lightpath(self.__flexscale_root, src_node, dst_node, bitrate, auth=self.__auth, timeout=self.__timeout) + results.extend(response) return results diff --git a/src/device/service/drivers/flexscale/Tools.py b/src/device/service/drivers/flexscale/Tools.py index 15b60d765..1fffc2094 100644 --- a/src/device/service/drivers/flexscale/Tools.py +++ b/src/device/service/drivers/flexscale/Tools.py @@ -26,6 +26,9 @@ HTTP_OK_CODES = { 204, # No Content } +def find_key(resource, key): + return json.loads(resource[1])[key] + def get_lightpaths(root_url : str, resource_key : str,auth : Optional[HTTPBasicAuth] = None, timeout : Optional[int] = None): headers = {'accept': 'application/json'} @@ -68,14 +71,61 @@ def add_lightpath(root_url, src_node, dst_node, bitrate, auth : Optional[HTTPBasicAuth] = None, timeout : Optional[int] = None): headers = {'accept': 'application/json'} - url = '{:s}/OpticalTFS/AddLightpath/{:s}/{:s}/{:s}'.format(root_url, src_node, dst_node, bitrate) + # url = '{:s}/OpticalTFS/AddLightpath/{:s}/{:s}/{:s}'.format(root_url, src_node, dst_node, bitrate) results = [] try: - response = requests.put(url=url, timeout=timeout, headers=headers, verify=False, auth=auth) - results.extend(response) LOGGER.info('Lightpath request: {:s} <-> {:s} with {:s} bitrate'.format( str(src_node), str(dst_node), str(bitrate))) + + device1= 'T1' + ep1= 'ep1' + device2= 'T2' + ep2= 'ep2' + context_uuid = 'admin' + service_uuid = 'T1-T2_service' + + data = { + "services": [ + { + "service_id": { + "context_id": {"context_uuid": {"uuid": context_uuid}}, "service_uuid": {"uuid": service_uuid} + }, + "service_type": 5, + } + ] + } + url = '{:s}'.format(root_url) + '/context/{:s}/service/{:s}'.format(context_uuid, service_uuid) + response = requests.post(url=url, timeout=timeout, headers=headers, verify=False, auth=auth, data=json.dumps(data)).json() + + + data = { + "services": [ + { + "service_id": { + "context_id": {"context_uuid": {"uuid": "admin"}}, "service_uuid": {"uuid": "service_uuid"} + }, + "service_type": 5, + "service_status": {"service_status": 1}, + "service_endpoint_ids": [ + {"device_id":{"device_uuid":{"uuid":device1}},"endpoint_uuid":{"uuid":ep1}}, + {"device_id":{"device_uuid":{"uuid":device2}},"endpoint_uuid":{"uuid":ep2}} + ], + "service_config": {"config_rules": [ + {"action": 1, "custom": {"resource_key": "/settings", "resource_value": { + }} + } + ] + } + } + ] + } + url = '{:s}'.format(root_url) + '/context/{:s}/service/{:s}'.format(context_uuid, service_uuid) + response = requests.put(url=url, timeout=timeout, headers=headers, verify=False, auth=auth, data=json.dumps(data)) + + + #response = requests.put(url=url, timeout=timeout, headers=headers, verify=False, auth=auth) + results.append(response.json()) LOGGER.info('Response: {:s}'.format(str(response))) except Exception as e: # pylint: disable=broad-except LOGGER.exception('Exception requesting Lightpath: {:s} <-> {:s} with {:s} bitrate'.format( @@ -136,7 +186,7 @@ def get_topology(root_url : str, resource_key : str,auth : Optional[HTTPBasicAut return result # if resource_key == RESOURCE_ENDPOINTS: - for link in links: + #for link in links: # TODO # endpoint_url = '/flows/flow[{:s}]'.format(flow_id) diff --git a/src/device/service/drivers/ietf_l2vpn/TfsDebugApiClient.py b/src/device/service/drivers/ietf_l2vpn/TfsDebugApiClient.py index 2d3901695..24e91aa4c 100644 --- a/src/device/service/drivers/ietf_l2vpn/TfsDebugApiClient.py +++ b/src/device/service/drivers/ietf_l2vpn/TfsDebugApiClient.py @@ -44,6 +44,8 @@ MAPPING_DRIVER = { 'DEVICEDRIVER_XR' : 6, 'DEVICEDRIVER_IETF_L2VPN' : 7, 'DEVICEDRIVER_GNMI_OPENCONFIG' : 8, + 'DEVICEDRIVER_FLEXSCALE' : 9, + 'DEVICEDRIVER_OC' : 1, } MSG_ERROR = 'Could not retrieve devices in remote TeraFlowSDN instance({:s}). status_code={:s} reply={:s}' diff --git a/src/service/service/service_handler_api/FilterFields.py b/src/service/service/service_handler_api/FilterFields.py index 430e25938..35c45c996 100644 --- a/src/service/service/service_handler_api/FilterFields.py +++ b/src/service/service/service_handler_api/FilterFields.py @@ -25,6 +25,7 @@ SERVICE_TYPE_VALUES = { ServiceTypeEnum.SERVICETYPE_L2NM, ServiceTypeEnum.SERVICETYPE_TAPI_CONNECTIVITY_SERVICE, ServiceTypeEnum.SERVICETYPE_TE, + ServiceTypeEnum.SERVICETYPE_E2E, } DEVICE_DRIVER_VALUES = { @@ -37,6 +38,7 @@ DEVICE_DRIVER_VALUES = { DeviceDriverEnum.DEVICEDRIVER_XR, DeviceDriverEnum.DEVICEDRIVER_IETF_L2VPN, DeviceDriverEnum.DEVICEDRIVER_GNMI_OPENCONFIG, + DeviceDriverEnum.DEVICEDRIVER_FLEXSCALE, } # Map allowed filter fields to allowed values per Filter field. If no restriction (free text) None is specified diff --git a/src/service/service/service_handlers/__init__.py b/src/service/service/service_handlers/__init__.py index cb926e5b7..dd96db2af 100644 --- a/src/service/service/service_handlers/__init__.py +++ b/src/service/service/service_handlers/__init__.py @@ -24,6 +24,8 @@ from .microwave.MicrowaveServiceHandler import MicrowaveServiceHandler from .p4.p4_service_handler import P4ServiceHandler from .tapi_tapi.TapiServiceHandler import TapiServiceHandler from .tapi_xr.TapiXrServiceHandler import TapiXrServiceHandler +from .e2e_orch.E2EOrchestratorServiceHandler import E2EOrchestratorServiceHandler + SERVICE_HANDLERS = [ (L2NMEmulatedServiceHandler, [ @@ -86,4 +88,10 @@ SERVICE_HANDLERS = [ FilterFieldEnum.DEVICE_DRIVER : [DeviceDriverEnum.DEVICEDRIVER_IETF_L2VPN], } ]), + (E2EOrchestratorServiceHandler, [ + { + FilterFieldEnum.SERVICE_TYPE : ServiceTypeEnum.SERVICETYPE_E2E, + FilterFieldEnum.DEVICE_DRIVER : [DeviceDriverEnum.DEVICEDRIVER_FLEXSCALE], + } + ]), ] diff --git a/src/service/service/service_handlers/2e2_orch/E2EOrchServiceHandler.py b/src/service/service/service_handlers/e2e_orch/E2EOrchestratorServiceHandler.py similarity index 99% rename from src/service/service/service_handlers/2e2_orch/E2EOrchServiceHandler.py rename to src/service/service/service_handlers/e2e_orch/E2EOrchestratorServiceHandler.py index 44272fee8..5a068bb51 100644 --- a/src/service/service/service_handlers/2e2_orch/E2EOrchServiceHandler.py +++ b/src/service/service/service_handlers/e2e_orch/E2EOrchestratorServiceHandler.py @@ -16,7 +16,7 @@ import json, logging from typing import Any, Dict, List, Optional, Tuple, Union from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method from common.proto.context_pb2 import ConfigRule, DeviceId, Service -from common.tools.object_factory.ConfigRule import json_config_rule_delete, json_config_rule_set +from common.tools.object_factory.ConfigRule import json_config_rule_set from common.tools.object_factory.Device import json_device_id from common.type_checkers.Checkers import chk_type from service.service.service_handler_api.Tools import get_device_endpoint_uuids @@ -28,7 +28,7 @@ LOGGER = logging.getLogger(__name__) METRICS_POOL = MetricsPool('Service', 'Handler', labels={'handler': 'e2e_orch'}) -class E2EOrchServiceHandler(_ServiceHandler): +class E2EOrchestratorServiceHandler(_ServiceHandler): def __init__( # pylint: disable=super-init-not-called self, service : Service, task_executor : TaskExecutor, **settings ) -> None: diff --git a/src/service/service/service_handlers/2e2_orch/__init__.py b/src/service/service/service_handlers/e2e_orch/__init__.py similarity index 100% rename from src/service/service/service_handlers/2e2_orch/__init__.py rename to src/service/service/service_handlers/e2e_orch/__init__.py diff --git a/src/tests/tools/mock_flexscale_opt_ctrl/MockFlexscaleOptCtrl.py b/src/tests/tools/mock_flexscale_opt_ctrl/MockFlexscaleOptCtrl.py index 09e1de995..c4cc2b699 100644 --- a/src/tests/tools/mock_flexscale_opt_ctrl/MockFlexscaleOptCtrl.py +++ b/src/tests/tools/mock_flexscale_opt_ctrl/MockFlexscaleOptCtrl.py @@ -35,11 +35,11 @@ def log_request(logger : logging.Logger, response): return response class AddLightpath(Resource): - def put(self): + def put(self, src_node: str, dst_node: str, bitrate: int): return make_response(jsonify(ADDLIGHTPATH_REPLY), 200) class DelLightpath(Resource): - def delete(self): + def delete(self, flow_id: str, src_node: str, dst_node: str, bitrate: int): return make_response(jsonify({}), 200) class GetLightpaths(Resource): diff --git a/src/tests/tools/mock_flexscale_opt_ctrl/data.py b/src/tests/tools/mock_flexscale_opt_ctrl/data.py index e89abeb3a..20a034016 100644 --- a/src/tests/tools/mock_flexscale_opt_ctrl/data.py +++ b/src/tests/tools/mock_flexscale_opt_ctrl/data.py @@ -13,7 +13,7 @@ # limitations under the License. -ADDLIGHTPATH_REPLY = """{ +ADDLIGHTPATH_REPLY = { "flow_id": 1, "src": "t1", "dst": "t2", @@ -93,6 +93,6 @@ ADDLIGHTPATH_REPLY = """{ ], "band": 50, "freq": 192031.25, - "is_active": true + "is_active": True } -""" + -- GitLab From 921c17dc9ed471b030a487f9be8125a3955e4640 Mon Sep 17 00:00:00 2001 From: Carlos Manso Date: Wed, 13 Dec 2023 16:30:51 +0100 Subject: [PATCH 4/6] e2e orchestrator functional test 0.1 --- my_deploy.sh | 9 +- ...viceClient.py => E2EOrchestratorClient.py} | 11 +- .../E2EOrchestratorServiceServicerImpl.py | 32 ++- .../service/ServiceServiceServicerImpl.py | 4 +- src/tests/Fixtures.py | 15 ++ src/tests/e2e_orchestrator/__init__.py | 14 + src/tests/e2e_orchestrator/deploy_specs.sh | 154 +++++++++++ .../descriptors_emulated.json | 250 ++++++++++++++++++ src/tests/e2e_orchestrator/redeploy.sh | 18 ++ .../e2e_orchestrator/run_test_01_bootstrap.sh | 17 ++ .../run_test_02_compute_path.sh | 17 ++ .../e2e_orchestrator/run_test_03_cleanup.sh | 17 ++ src/tests/e2e_orchestrator/run_tests.sh | 20 ++ src/tests/e2e_orchestrator/tests/Fixtures.py | 13 + src/tests/e2e_orchestrator/tests/Objects.py | 60 +++++ src/tests/e2e_orchestrator/tests/__init__.py | 14 + .../tests/test_functional_bootstrap.py | 72 +++++ .../tests/test_functional_cleanup.py | 44 +++ .../tests/test_functional_compute_path.py | 65 +++++ 19 files changed, 822 insertions(+), 24 deletions(-) rename src/e2eorchestrator/client/{E2EOrchestratorServiceClient.py => E2EOrchestratorClient.py} (88%) create mode 100644 src/tests/e2e_orchestrator/__init__.py create mode 100755 src/tests/e2e_orchestrator/deploy_specs.sh create mode 100644 src/tests/e2e_orchestrator/descriptors_emulated.json create mode 100755 src/tests/e2e_orchestrator/redeploy.sh create mode 100755 src/tests/e2e_orchestrator/run_test_01_bootstrap.sh create mode 100755 src/tests/e2e_orchestrator/run_test_02_compute_path.sh create mode 100755 src/tests/e2e_orchestrator/run_test_03_cleanup.sh create mode 100755 src/tests/e2e_orchestrator/run_tests.sh create mode 100644 src/tests/e2e_orchestrator/tests/Fixtures.py create mode 100644 src/tests/e2e_orchestrator/tests/Objects.py create mode 100644 src/tests/e2e_orchestrator/tests/__init__.py create mode 100644 src/tests/e2e_orchestrator/tests/test_functional_bootstrap.py create mode 100644 src/tests/e2e_orchestrator/tests/test_functional_cleanup.py create mode 100644 src/tests/e2e_orchestrator/tests/test_functional_compute_path.py diff --git a/my_deploy.sh b/my_deploy.sh index 93db44e1f..73eb85fb5 100755 --- a/my_deploy.sh +++ b/my_deploy.sh @@ -43,6 +43,9 @@ export TFS_COMPONENTS="context device pathcomp service slice nbi webui load_gene # Uncomment to activate Forecaster #export TFS_COMPONENTS="${TFS_COMPONENTS} forecaster" +# Uncomment to activate E2E Orchestrator +#export TFS_COMPONENTS="${TFS_COMPONENTS} e2eorchestrator" + # Set the tag you want to use for your images. export TFS_IMAGE_TAG="dev" @@ -90,7 +93,7 @@ export CRDB_DATABASE="tfs" export CRDB_DEPLOY_MODE="single" # Disable flag for dropping database, if it exists. -export CRDB_DROP_DATABASE_IF_EXISTS="" +export CRDB_DROP_DATABASE_IF_EXISTS="YES" # Disable flag for re-deploying CockroachDB from scratch. export CRDB_REDEPLOY="" @@ -108,7 +111,7 @@ export NATS_EXT_PORT_CLIENT="4222" export NATS_EXT_PORT_HTTP="8222" # Disable flag for re-deploying NATS from scratch. -export NATS_REDEPLOY="YES" +export NATS_REDEPLOY="" # ----- QuestDB ---------------------------------------------------------------- @@ -138,7 +141,7 @@ export QDB_TABLE_MONITORING_KPIS="tfs_monitoring_kpis" export QDB_TABLE_SLICE_GROUPS="tfs_slice_groups" # Disable flag for dropping tables if they exist. -export QDB_DROP_TABLES_IF_EXIST="" +export QDB_DROP_TABLES_IF_EXIST="YES" # Disable flag for re-deploying QuestDB from scratch. export QDB_REDEPLOY="" diff --git a/src/e2eorchestrator/client/E2EOrchestratorServiceClient.py b/src/e2eorchestrator/client/E2EOrchestratorClient.py similarity index 88% rename from src/e2eorchestrator/client/E2EOrchestratorServiceClient.py rename to src/e2eorchestrator/client/E2EOrchestratorClient.py index 6efb0e3fc..10f183a51 100644 --- a/src/e2eorchestrator/client/E2EOrchestratorServiceClient.py +++ b/src/e2eorchestrator/client/E2EOrchestratorClient.py @@ -22,6 +22,7 @@ from common.proto.e2eorchestrator_pb2_grpc import E2EOrchestratorServiceStub from common.Settings import get_service_host, get_service_port_grpc from common.tools.client.RetryDecorator import delay_exponential, retry from common.tools.grpc.Tools import grpc_message_to_json +from common.proto.e2eorchestrator_pb2 import E2EOrchestratorRequest, E2EOrchestratorReply LOGGER = logging.getLogger(__name__) MAX_RETRIES = 15 @@ -33,7 +34,7 @@ RETRY_DECORATOR = retry( ) -class E2EOrchestratorServiceClient: +class E2EOrchestratorClient: def __init__(self, host=None, port=None): if not host: host = get_service_host(ServiceNameEnum.E2EORCHESTRATOR) @@ -57,12 +58,12 @@ class E2EOrchestratorServiceClient: self.stub = None @RETRY_DECORATOR - def Compute(self, request: Empty) -> Empty: - LOGGER.debug( + def Compute(self, request: E2EOrchestratorRequest) -> E2EOrchestratorReply: + LOGGER.info( "Compute request: {:s}".format(str(grpc_message_to_json(request))) ) - response = self.stub.GetPath(request) - LOGGER.debug( + response = self.stub.Compute(request) + LOGGER.info( "Compute result: {:s}".format(str(grpc_message_to_json(response))) ) return response diff --git a/src/e2eorchestrator/service/E2EOrchestratorServiceServicerImpl.py b/src/e2eorchestrator/service/E2EOrchestratorServiceServicerImpl.py index 8e5edfd63..d233f2e17 100644 --- a/src/e2eorchestrator/service/E2EOrchestratorServiceServicerImpl.py +++ b/src/e2eorchestrator/service/E2EOrchestratorServiceServicerImpl.py @@ -24,6 +24,7 @@ from common.proto.e2eorchestrator_pb2 import E2EOrchestratorRequest, E2EOrchestr from common.proto.context_pb2 import Empty, Connection, EndPointId from common.proto.e2eorchestrator_pb2_grpc import E2EOrchestratorServiceServicer from context.client.ContextClient import ContextClient +from context.service.database.uuids.EndPoint import endpoint_get_uuid LOGGER = logging.getLogger(__name__) @@ -40,17 +41,17 @@ class E2EOrchestratorServiceServicerImpl(E2EOrchestratorServiceServicer): @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) def Compute(self, request: E2EOrchestratorRequest, context: grpc.ServicerContext) -> E2EOrchestratorReply: - endpoints_ids = [] - for endpoint_id in request.service_endpoint_ids: - endpoints_ids.append(endpoint_id.endpoint_uuid.uuid) + for endpoint_id in request.service.service_endpoint_ids: + endpoints_ids.append(endpoint_get_uuid(endpoint_id)[2]) graph = nx.Graph() devices = context_client.ListDevices(Empty()).devices for device in devices: - endpoints_uuids = [endpoint.endpoint_uuid.uuid for endpoint in device.device_endpoints] + endpoints_uuids = [endpoint.endpoint_id.endpoint_uuid.uuid + for endpoint in device.device_endpoints] for ep in endpoints_uuids: graph.add_node(ep) @@ -58,7 +59,7 @@ class E2EOrchestratorServiceServicerImpl(E2EOrchestratorServiceServicer): for ep_i in endpoints_uuids: if ep == ep_i: continue - graph.add_edge(ep. ep_i) + graph.add_edge(ep, ep_i) links = context_client.ListLinks(Empty()).links for link in links: @@ -72,17 +73,20 @@ class E2EOrchestratorServiceServicerImpl(E2EOrchestratorServiceServicer): path = E2EOrchestratorReply() path.services.append(copy.deepcopy(request.service)) - for i in len(shortest): - conn = Connection - conn.connection_id.connection_uuid.uuid = str(shortest[i*2]) + '_->_' + str(shortest[i*2+1]) + for i in range(0, int(len(shortest)/2)): + conn = Connection() + ep_a_uuid = str(shortest[i*2]) + ep_z_uuid = str(shortest[i*2+1]) + + conn.connection_id.connection_uuid.uuid = str(ep_a_uuid) + '_->_' + str(ep_z_uuid) - ep0 = EndPointId - ep0.endpoint_uuid.uuid = ep - conn.path_hops_endpoint_ids.append(shortest[i*2]) + ep_a_id = EndPointId() + ep_a_id.endpoint_uuid.uuid = ep_a_uuid + conn.path_hops_endpoint_ids.append(ep_a_id) - ep1 = EndPointId - ep1.endpoint_uuid.uuid = ep - conn.path_hops_endpoint_ids.append(shortest[i*2+1]) + ep_z_id = EndPointId() + ep_z_id.endpoint_uuid.uuid = ep_z_uuid + conn.path_hops_endpoint_ids.append(ep_z_id) path.connections.append(conn) diff --git a/src/service/service/ServiceServiceServicerImpl.py b/src/service/service/ServiceServiceServicerImpl.py index 20b6048af..c5d305141 100644 --- a/src/service/service/ServiceServiceServicerImpl.py +++ b/src/service/service/ServiceServiceServicerImpl.py @@ -26,7 +26,7 @@ from common.proto.service_pb2_grpc import ServiceServiceServicer from common.tools.context_queries.Service import get_service_by_id from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string from context.client.ContextClient import ContextClient -from e2eorchestrator.client.E2EOrchestratorServiceClient import E2EOrchestratorServiceClient +from e2eorchestrator.client.E2EOrchestratorClient import E2EOrchestratorClient from pathcomp.frontend.client.PathCompClient import PathCompClient from service.service.tools.ConnectionToString import connection_to_string from service.client.TEServiceClient import TEServiceClient @@ -167,7 +167,7 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): e2e_orch_request = E2EOrchestratorRequest() e2e_orch_request.service.CopyFrom(service_with_uuids) - e2e_orch_client = E2EOrchestratorServiceClient() + e2e_orch_client = E2EOrchestratorClient() e2e_orch_reply = e2e_orch_client.Compute(e2e_orch_request) # Feed TaskScheduler with this end-to-end orchestrator reply. TaskScheduler identifies diff --git a/src/tests/Fixtures.py b/src/tests/Fixtures.py index ecb44a758..78a470b54 100644 --- a/src/tests/Fixtures.py +++ b/src/tests/Fixtures.py @@ -16,6 +16,15 @@ import pytest from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from monitoring.client.MonitoringClient import MonitoringClient +from e2eorchestrator.client.E2EOrchestratorClient import E2EOrchestratorClient +from service.client.ServiceClient import ServiceClient + + +@pytest.fixture(scope='session') +def service_client(): + _client = ServiceClient() + yield _client + _client.close() @pytest.fixture(scope='session') def context_client(): @@ -34,3 +43,9 @@ def monitoring_client(): _client = MonitoringClient() yield _client _client.close() + +@pytest.fixture(scope='session') +def e2eorchestrator_client(): + _client = E2EOrchestratorClient() + yield _client + _client.close() diff --git a/src/tests/e2e_orchestrator/__init__.py b/src/tests/e2e_orchestrator/__init__.py new file mode 100644 index 000000000..1549d9811 --- /dev/null +++ b/src/tests/e2e_orchestrator/__init__.py @@ -0,0 +1,14 @@ +# 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. + diff --git a/src/tests/e2e_orchestrator/deploy_specs.sh b/src/tests/e2e_orchestrator/deploy_specs.sh new file mode 100755 index 000000000..e93841917 --- /dev/null +++ b/src/tests/e2e_orchestrator/deploy_specs.sh @@ -0,0 +1,154 @@ +#!/bin/bash +# 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. + + +# ----- TeraFlowSDN ------------------------------------------------------------ + +# Set the URL of the internal MicroK8s Docker registry where the images will be uploaded to. +export TFS_REGISTRY_IMAGES="http://localhost:32000/tfs/" + +# Set the list of components, separated by spaces, you want to build images for, and deploy. +#export TFS_COMPONENTS="context device pathcomp service slice nbi webui load_generator" +export TFS_COMPONENTS="context device pathcomp service slice nbi webui" + +# Uncomment to activate Monitoring +# export TFS_COMPONENTS="${TFS_COMPONENTS} monitoring" + +# Uncomment to activate ZTP and Policy Manager +#export TFS_COMPONENTS="${TFS_COMPONENTS} ztp policy" +# export TFS_COMPONENTS="${TFS_COMPONENTS} ztp" + +# Uncomment to activate Optical CyberSecurity +#export TFS_COMPONENTS="${TFS_COMPONENTS} dbscanserving opticalattackmitigator opticalattackdetector opticalattackmanager" + +# Uncomment to activate L3 CyberSecurity +#export TFS_COMPONENTS="${TFS_COMPONENTS} l3_attackmitigator l3_centralizedattackdetector" + +# Uncomment to activate TE +#export TFS_COMPONENTS="${TFS_COMPONENTS} te" + +# Uncomment to activate E2E_Orchestrator +export TFS_COMPONENTS="${TFS_COMPONENTS} e2eorchestrator" + + + +# Set the tag you want to use for your images. +export TFS_IMAGE_TAG="dev" + +# Set the name of the Kubernetes namespace to deploy TFS to. +export TFS_K8S_NAMESPACE="tfs" + +# Set additional manifest files to be applied after the deployment +export TFS_EXTRA_MANIFESTS="manifests/nginx_ingress_http.yaml" + +# Uncomment to monitor performance of components +export TFS_EXTRA_MANIFESTS="${TFS_EXTRA_MANIFESTS} manifests/servicemonitors.yaml" + +# Uncomment when deploying Optical CyberSecurity +#export TFS_EXTRA_MANIFESTS="${TFS_EXTRA_MANIFESTS} manifests/cachingservice.yaml" + +# Set the new Grafana admin password +export TFS_GRAFANA_PASSWORD="admin123+" + +# Disable skip-build flag to rebuild the Docker images. +export TFS_SKIP_BUILD="" + + +# ----- CockroachDB ------------------------------------------------------------ + +# Set the namespace where CockroackDB will be deployed. +export CRDB_NAMESPACE="crdb" + +# Set the external port CockroackDB Postgre SQL interface will be exposed to. +export CRDB_EXT_PORT_SQL="26257" + +# Set the external port CockroackDB HTTP Mgmt GUI interface will be exposed to. +export CRDB_EXT_PORT_HTTP="8081" + +# Set the database username to be used by Context. +export CRDB_USERNAME="tfs" + +# Set the database user's password to be used by Context. +export CRDB_PASSWORD="tfs123" + +# Set the database name to be used by Context. +export CRDB_DATABASE="tfs" + +# Set CockroachDB installation mode to 'single'. This option is convenient for development and testing. +# See ./deploy/all.sh or ./deploy/crdb.sh for additional details +export CRDB_DEPLOY_MODE="single" + +# Disable flag for dropping database, if it exists. +export CRDB_DROP_DATABASE_IF_EXISTS="YES" + +# Disable flag for re-deploying CockroachDB from scratch. +export CRDB_REDEPLOY="" + + +# ----- NATS ------------------------------------------------------------------- + +# Set the namespace where NATS will be deployed. +export NATS_NAMESPACE="nats" + +# Set the external port NATS Client interface will be exposed to. +export NATS_EXT_PORT_CLIENT="4222" + +# Set the external port NATS HTTP Mgmt GUI interface will be exposed to. +export NATS_EXT_PORT_HTTP="8222" + +# Disable flag for re-deploying NATS from scratch. +export NATS_REDEPLOY="" + + +# ----- QuestDB ---------------------------------------------------------------- + +# Set the namespace where QuestDB will be deployed. +export QDB_NAMESPACE="qdb" + +# Set the external port QuestDB Postgre SQL interface will be exposed to. +export QDB_EXT_PORT_SQL="8812" + +# Set the external port QuestDB Influx Line Protocol interface will be exposed to. +export QDB_EXT_PORT_ILP="9009" + +# Set the external port QuestDB HTTP Mgmt GUI interface will be exposed to. +export QDB_EXT_PORT_HTTP="9000" + +# Set the database username to be used for QuestDB. +export QDB_USERNAME="admin" + +# Set the database user's password to be used for QuestDB. +export QDB_PASSWORD="quest" + +# Set the table name to be used by Monitoring for KPIs. +export QDB_TABLE_MONITORING_KPIS="tfs_monitoring_kpis" + +# Set the table name to be used by Slice for plotting groups. +export QDB_TABLE_SLICE_GROUPS="tfs_slice_groups" + +# Disable flag for dropping tables if they exist. +export QDB_DROP_TABLES_IF_EXIST="YES" + +# Disable flag for re-deploying QuestDB from scratch. +export QDB_REDEPLOY="" + + +# ----- K8s Observability ------------------------------------------------------ + +# Set the external port Prometheus Mgmt HTTP GUI interface will be exposed to. +export PROM_EXT_PORT_HTTP="9090" + +# Set the external port Grafana HTTP Dashboards will be exposed to. +export GRAF_EXT_PORT_HTTP="3000" diff --git a/src/tests/e2e_orchestrator/descriptors_emulated.json b/src/tests/e2e_orchestrator/descriptors_emulated.json new file mode 100644 index 000000000..a2918ace9 --- /dev/null +++ b/src/tests/e2e_orchestrator/descriptors_emulated.json @@ -0,0 +1,250 @@ +{ + "contexts": [ + { + "context_id": {"context_uuid": {"uuid": "admin"}}, + "topology_ids": [], "service_ids": [] + } + ], + "topologies": [ + { + "topology_id": { + "context_id": {"context_uuid": {"uuid": "admin"}}, + "topology_uuid": {"uuid": "admin"} + }, + "device_ids": [ + {"device_uuid": {"uuid": "R1"}}, + {"device_uuid": {"uuid": "R2"}}, + {"device_uuid": {"uuid": "T1"}}, + {"device_uuid": {"uuid": "T2"}}, + {"device_uuid": {"uuid": "M1"}}, + {"device_uuid": {"uuid": "M2"}} + ], + "link_ids": [ + {"link_uuid": {"uuid": "R1==T1"}}, + {"link_uuid": {"uuid": "T1==R1"}}, + {"link_uuid": {"uuid": "R2==T2"}}, + {"link_uuid": {"uuid": "T2==R2"}}, + + {"link_uuid": {"uuid": "T1==M1"}}, + {"link_uuid": {"uuid": "M1==T1"}}, + {"link_uuid": {"uuid": "T2==M2"}}, + {"link_uuid": {"uuid": "M2==T2"}}, + + {"link_uuid": {"uuid": "M1==M2"}}, + {"link_uuid": {"uuid": "M2==M1"}} + + + ] + } + ], + "devices": [ + { + "device_id": {"device_uuid": {"uuid": "R1"}}, "device_type": "emu-packet-router", "device_drivers": [0], + "device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [ + {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, + {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}}, + {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ + {"sample_types": [], "type": "copper", "uuid": "1/1"}, + {"sample_types": [], "type": "copper", "uuid": "1/2"}, + {"sample_types": [], "type": "copper", "uuid": "1/3"}, + {"sample_types": [], "type": "copper", "uuid": "1/4"}, + {"sample_types": [], "type": "copper", "uuid": "2/1"}, + {"sample_types": [], "type": "copper", "uuid": "2/2"}, + {"sample_types": [], "type": "copper", "uuid": "2/3"}, + {"sample_types": [], "type": "copper", "uuid": "2/4"}, + {"sample_types": [], "type": "copper", "uuid": "3/1"}, + {"sample_types": [], "type": "copper", "uuid": "3/2"}, + {"sample_types": [], "type": "copper", "uuid": "3/3"}, + {"sample_types": [], "type": "copper", "uuid": "3/4"} + ]}}} + ]} + }, + { + "device_id": {"device_uuid": {"uuid": "R2"}}, "device_type": "emu-packet-router", "device_drivers": [0], + "device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [ + {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, + {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}}, + {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ + {"sample_types": [], "type": "copper", "uuid": "1/1"}, + {"sample_types": [], "type": "copper", "uuid": "1/2"}, + {"sample_types": [], "type": "copper", "uuid": "1/3"}, + {"sample_types": [], "type": "copper", "uuid": "1/4"}, + {"sample_types": [], "type": "copper", "uuid": "2/1"}, + {"sample_types": [], "type": "copper", "uuid": "2/2"}, + {"sample_types": [], "type": "copper", "uuid": "2/3"}, + {"sample_types": [], "type": "copper", "uuid": "2/4"}, + {"sample_types": [], "type": "copper", "uuid": "3/1"}, + {"sample_types": [], "type": "copper", "uuid": "3/2"}, + {"sample_types": [], "type": "copper", "uuid": "3/3"}, + {"sample_types": [], "type": "copper", "uuid": "3/4"} + ]}}} + ]} + }, + { + "device_id": {"device_uuid": {"uuid": "T1"}}, "device_type": "emu-optical-transponder", "device_drivers": [0], + "device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [ + {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, + {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}}, + {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ + {"sample_types": [], "type": "copper", "uuid": "1/1"}, + {"sample_types": [], "type": "copper", "uuid": "1/2"}, + {"sample_types": [], "type": "copper", "uuid": "1/3"}, + {"sample_types": [], "type": "copper", "uuid": "1/4"}, + {"sample_types": [], "type": "copper", "uuid": "2/1"}, + {"sample_types": [], "type": "copper", "uuid": "2/2"}, + {"sample_types": [], "type": "copper", "uuid": "2/3"}, + {"sample_types": [], "type": "copper", "uuid": "2/4"}, + {"sample_types": [], "type": "copper", "uuid": "3/1"}, + {"sample_types": [], "type": "copper", "uuid": "3/2"}, + {"sample_types": [], "type": "copper", "uuid": "3/3"}, + {"sample_types": [], "type": "copper", "uuid": "3/4"} + ]}}} + ]} + }, + { + "device_id": {"device_uuid": {"uuid": "T2"}}, "device_type": "emu-optical-transponder", "device_drivers": [0], + "device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [ + {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, + {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}}, + {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ + {"sample_types": [], "type": "copper", "uuid": "1/1"}, + {"sample_types": [], "type": "copper", "uuid": "1/2"}, + {"sample_types": [], "type": "copper", "uuid": "1/3"}, + {"sample_types": [], "type": "copper", "uuid": "1/4"}, + {"sample_types": [], "type": "copper", "uuid": "2/1"}, + {"sample_types": [], "type": "copper", "uuid": "2/2"}, + {"sample_types": [], "type": "copper", "uuid": "2/3"}, + {"sample_types": [], "type": "copper", "uuid": "2/4"}, + {"sample_types": [], "type": "copper", "uuid": "3/1"}, + {"sample_types": [], "type": "copper", "uuid": "3/2"}, + {"sample_types": [], "type": "copper", "uuid": "3/3"}, + {"sample_types": [], "type": "copper", "uuid": "3/4"} + ]}}} + ]} + }, + + { + "device_id": {"device_uuid": {"uuid": "M1"}}, "device_type": "emu-optical-roadm", "device_drivers": [0], + "device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [ + {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, + {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}}, + {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ + {"sample_types": [], "type": "copper", "uuid": "1/1"}, + {"sample_types": [], "type": "copper", "uuid": "1/2"}, + {"sample_types": [], "type": "copper", "uuid": "1/3"}, + {"sample_types": [], "type": "copper", "uuid": "1/4"}, + {"sample_types": [], "type": "copper", "uuid": "2/1"}, + {"sample_types": [], "type": "copper", "uuid": "2/2"}, + {"sample_types": [], "type": "copper", "uuid": "2/3"}, + {"sample_types": [], "type": "copper", "uuid": "2/4"}, + {"sample_types": [], "type": "copper", "uuid": "3/1"}, + {"sample_types": [], "type": "copper", "uuid": "3/2"}, + {"sample_types": [], "type": "copper", "uuid": "3/3"}, + {"sample_types": [], "type": "copper", "uuid": "3/4"} + ]}}} + ]} + }, + + + { + "device_id": {"device_uuid": {"uuid": "M2"}}, "device_type": "emu-optical-roadm", "device_drivers": [0], + "device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [ + {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, + {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}}, + {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ + {"sample_types": [], "type": "copper", "uuid": "1/1"}, + {"sample_types": [], "type": "copper", "uuid": "1/2"}, + {"sample_types": [], "type": "copper", "uuid": "1/3"}, + {"sample_types": [], "type": "copper", "uuid": "1/4"}, + {"sample_types": [], "type": "copper", "uuid": "2/1"}, + {"sample_types": [], "type": "copper", "uuid": "2/2"}, + {"sample_types": [], "type": "copper", "uuid": "2/3"}, + {"sample_types": [], "type": "copper", "uuid": "2/4"}, + {"sample_types": [], "type": "copper", "uuid": "3/1"}, + {"sample_types": [], "type": "copper", "uuid": "3/2"}, + {"sample_types": [], "type": "copper", "uuid": "3/3"}, + {"sample_types": [], "type": "copper", "uuid": "3/4"} + ]}}} + ]} + } + + + ], + "links": [ + { + "link_id": {"link_uuid": {"uuid": "R1==T1"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "1/1"}}, + {"device_id": {"device_uuid": {"uuid": "T1"}}, "endpoint_uuid": {"uuid": "1/1"}} + ] + }, + { + "link_id": {"link_uuid": {"uuid": "T1==R1"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "T1"}}, "endpoint_uuid": {"uuid": "1/1"}}, + {"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "1/1"}} + ] + }, + { + "link_id": {"link_uuid": {"uuid": "R2==T2"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "1/2"}}, + {"device_id": {"device_uuid": {"uuid": "T2"}}, "endpoint_uuid": {"uuid": "1/2"}} + ] + }, + { + "link_id": {"link_uuid": {"uuid": "T2==R2"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "T2"}}, "endpoint_uuid": {"uuid": "1/2"}}, + {"device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "1/2"}} + ] + }, + + + { + "link_id": {"link_uuid": {"uuid": "T1==M1"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "T1"}}, "endpoint_uuid": {"uuid": "2/1"}}, + {"device_id": {"device_uuid": {"uuid": "M1"}}, "endpoint_uuid": {"uuid": "2/1"}} + ] + }, + { + "link_id": {"link_uuid": {"uuid": "M1==T1"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "M1"}}, "endpoint_uuid": {"uuid": "2/1"}}, + {"device_id": {"device_uuid": {"uuid": "T1"}}, "endpoint_uuid": {"uuid": "2/1"}} + ] + }, + + { + "link_id": {"link_uuid": {"uuid": "T2==M2"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "T2"}}, "endpoint_uuid": {"uuid": "2/2"}}, + {"device_id": {"device_uuid": {"uuid": "M2"}}, "endpoint_uuid": {"uuid": "2/2"}} + ] + }, + { + "link_id": {"link_uuid": {"uuid": "M2==T2"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "M2"}}, "endpoint_uuid": {"uuid": "2/2"}}, + {"device_id": {"device_uuid": {"uuid": "T2"}}, "endpoint_uuid": {"uuid": "2/2"}} + ] + }, + + { + "link_id": {"link_uuid": {"uuid": "M1==M2"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "M1"}}, "endpoint_uuid": {"uuid": "3/1"}}, + {"device_id": {"device_uuid": {"uuid": "M2"}}, "endpoint_uuid": {"uuid": "3/1"}} + ] + }, + { + "link_id": {"link_uuid": {"uuid": "M2==M1"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "M2"}}, "endpoint_uuid": {"uuid": "3/1"}}, + {"device_id": {"device_uuid": {"uuid": "M1"}}, "endpoint_uuid": {"uuid": "3/1"}} + ] + } + + ] +} \ No newline at end of file diff --git a/src/tests/e2e_orchestrator/redeploy.sh b/src/tests/e2e_orchestrator/redeploy.sh new file mode 100755 index 000000000..5e8519926 --- /dev/null +++ b/src/tests/e2e_orchestrator/redeploy.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# 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. + +source e2e_orchestrator/deploy_specs.sh +./deploy/all.sh +source tfs_runtime_env_vars.sh diff --git a/src/tests/e2e_orchestrator/run_test_01_bootstrap.sh b/src/tests/e2e_orchestrator/run_test_01_bootstrap.sh new file mode 100755 index 000000000..78c76def8 --- /dev/null +++ b/src/tests/e2e_orchestrator/run_test_01_bootstrap.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# 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. + +source tfs_runtime_env_vars.sh +pytest --verbose --log-level=INFO src/tests/e2e_orchestrator/tests/test_functional_bootstrap.py diff --git a/src/tests/e2e_orchestrator/run_test_02_compute_path.sh b/src/tests/e2e_orchestrator/run_test_02_compute_path.sh new file mode 100755 index 000000000..83191464a --- /dev/null +++ b/src/tests/e2e_orchestrator/run_test_02_compute_path.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# 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. + +source tfs_runtime_env_vars.sh +pytest --verbose --log-level=INFO src/tests/e2e_orchestrator/tests/test_functional_compute_path.py diff --git a/src/tests/e2e_orchestrator/run_test_03_cleanup.sh b/src/tests/e2e_orchestrator/run_test_03_cleanup.sh new file mode 100755 index 000000000..f3ab6c68d --- /dev/null +++ b/src/tests/e2e_orchestrator/run_test_03_cleanup.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# 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. + +source tfs_runtime_env_vars.sh +pytest --verbose --log-level=INFO src/tests/e2e_orchestrator/tests/test_functional_cleanup.py diff --git a/src/tests/e2e_orchestrator/run_tests.sh b/src/tests/e2e_orchestrator/run_tests.sh new file mode 100755 index 000000000..2c177259a --- /dev/null +++ b/src/tests/e2e_orchestrator/run_tests.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# 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. + +# Run functional tests +source tfs_runtime_env_vars.sh +pytest --verbose --log-level=INFO src/tests/e2e_orchestrator/tests/test_functional_bootstrap.py +pytest --verbose --log-level=INFO src/tests/e2e_orchestrator/tests/test_functional_compute_path.py +pytest --verbose --log-level=INFO src/tests/e2e_orchestrator/tests/test_functional_cleanup.py diff --git a/src/tests/e2e_orchestrator/tests/Fixtures.py b/src/tests/e2e_orchestrator/tests/Fixtures.py new file mode 100644 index 000000000..38d04994f --- /dev/null +++ b/src/tests/e2e_orchestrator/tests/Fixtures.py @@ -0,0 +1,13 @@ +# 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. diff --git a/src/tests/e2e_orchestrator/tests/Objects.py b/src/tests/e2e_orchestrator/tests/Objects.py new file mode 100644 index 000000000..1748efec9 --- /dev/null +++ b/src/tests/e2e_orchestrator/tests/Objects.py @@ -0,0 +1,60 @@ +# 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. + +import os +from typing import Dict, List, Tuple +from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME +from common.tools.object_factory.Context import json_context, json_context_id +from common.tools.object_factory.Device import ( + json_device_connect_rules, json_device_emulated_connect_rules, json_device_emulated_packet_router_disabled, + json_device_connect_rules, json_device_id, json_device_p4_disabled, + json_device_emulated_tapi_disabled, json_device_id, json_device_packetrouter_disabled, json_device_tapi_disabled) +from common.tools.object_factory.Service import ( + get_service_uuid, json_service_l3nm_planned,json_service_p4_planned) +from common.tools.object_factory.ConfigRule import ( + json_config_rule_set, json_config_rule_delete) +from common.tools.object_factory.EndPoint import json_endpoint, json_endpoint_ids, json_endpoints, json_endpoint_id +from common.tools.object_factory.EndPoint import json_endpoint_descriptor + + + +DEVICE_R1_UUID = 'R1' +DEVICE_R2_UUID = 'R2' + +DEVICE_R1_ID = json_device_id(DEVICE_R1_UUID) +DEVICE_R1_ENDPOINT_DEFS = [json_endpoint_descriptor('2/2', 'port')] +DEVICE_R2_ID = json_device_id(DEVICE_R2_UUID) +DEVICE_R2_ENDPOINT_DEFS = [json_endpoint_descriptor('2/2', 'port')] + +DEVICE_R1_ENDPOINTS = json_endpoints(DEVICE_R1_ID, DEVICE_R1_ENDPOINT_DEFS) +DEVICE_R2_ENDPOINTS = json_endpoints(DEVICE_R2_ID, DEVICE_R2_ENDPOINT_DEFS) + + +DEVICE_R1_ENDPOINT_IDS = json_endpoint_ids(DEVICE_R1_ID, DEVICE_R1_ENDPOINT_DEFS) +ENDPOINT_ID_R1 = DEVICE_R1_ENDPOINTS[0]['endpoint_id'] +DEVICE_R2_ENDPOINT_IDS = json_endpoint_ids(DEVICE_R2_ID, DEVICE_R2_ENDPOINT_DEFS) +ENDPOINT_ID_R2 = DEVICE_R2_ENDPOINTS[0]['endpoint_id'] + + +# ----- Service ---------------------------------------------------------------------------------------------------------- + + +SERVICE_R1_R2_UUID = get_service_uuid(ENDPOINT_ID_R1, ENDPOINT_ID_R2) +SERVICE_R1_R2 = json_service_p4_planned(SERVICE_R1_R2_UUID) +SERVICE_R1_R2_ENDPOINT_IDS = [DEVICE_R1_ENDPOINT_IDS[0], DEVICE_R2_ENDPOINT_IDS[0]] + + +SERVICES = [ + (SERVICE_R1_R2, SERVICE_R1_R2_ENDPOINT_IDS) +] diff --git a/src/tests/e2e_orchestrator/tests/__init__.py b/src/tests/e2e_orchestrator/tests/__init__.py new file mode 100644 index 000000000..1549d9811 --- /dev/null +++ b/src/tests/e2e_orchestrator/tests/__init__.py @@ -0,0 +1,14 @@ +# 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. + diff --git a/src/tests/e2e_orchestrator/tests/test_functional_bootstrap.py b/src/tests/e2e_orchestrator/tests/test_functional_bootstrap.py new file mode 100644 index 000000000..36c3b0918 --- /dev/null +++ b/src/tests/e2e_orchestrator/tests/test_functional_bootstrap.py @@ -0,0 +1,72 @@ +# 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. + +import logging, time +from common.Constants import DEFAULT_CONTEXT_NAME +from common.proto.context_pb2 import ContextId, DeviceOperationalStatusEnum, Empty +from common.proto.monitoring_pb2 import KpiDescriptorList +from common.tools.descriptor.Loader import DescriptorLoader, check_descriptor_load_results, validate_empty_scenario +from common.tools.object_factory.Context import json_context_id +from context.client.ContextClient import ContextClient +from device.client.DeviceClient import DeviceClient +from monitoring.client.MonitoringClient import MonitoringClient +from tests.Fixtures import context_client, device_client, monitoring_client # pylint: disable=unused-import + +LOGGER = logging.getLogger(__name__) +LOGGER.setLevel(logging.DEBUG) + +DESCRIPTOR_FILE = 'src/tests/e2e_orchestrator/descriptors_emulated.json' +ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_NAME)) + +def test_scenario_bootstrap( + context_client : ContextClient, # pylint: disable=redefined-outer-name + device_client : DeviceClient, # pylint: disable=redefined-outer-name +) -> None: + LOGGER.info(context_client) + validate_empty_scenario(context_client) + + descriptor_loader = DescriptorLoader( + descriptors_file=DESCRIPTOR_FILE, context_client=context_client, device_client=device_client) + results = descriptor_loader.process() + check_descriptor_load_results(results, descriptor_loader) + descriptor_loader.validate() + + # Verify the scenario has no services/slices + response = context_client.GetContext(ADMIN_CONTEXT_ID) + assert len(response.service_ids) == 0 + assert len(response.slice_ids) == 0 + +def test_scenario_devices_enabled( + context_client : ContextClient, # pylint: disable=redefined-outer-name +) -> None: + """ + This test validates that the devices are enabled. + """ + DEVICE_OP_STATUS_ENABLED = DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED + + num_devices = -1 + num_devices_enabled, num_retry = 0, 0 + while (num_devices != num_devices_enabled) and (num_retry < 1): + time.sleep(1.0) + response = context_client.ListDevices(Empty()) + num_devices = len(response.devices) + num_devices_enabled = 0 + for device in response.devices: + if device.device_operational_status != DEVICE_OP_STATUS_ENABLED: continue + num_devices_enabled += 1 + LOGGER.info('Num Devices enabled: {:d}/{:d}'.format(num_devices_enabled, num_devices)) + num_retry += 1 + assert num_devices_enabled == num_devices + + diff --git a/src/tests/e2e_orchestrator/tests/test_functional_cleanup.py b/src/tests/e2e_orchestrator/tests/test_functional_cleanup.py new file mode 100644 index 000000000..e661e177c --- /dev/null +++ b/src/tests/e2e_orchestrator/tests/test_functional_cleanup.py @@ -0,0 +1,44 @@ +# 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. + +import logging +from common.Constants import DEFAULT_CONTEXT_NAME +from common.proto.context_pb2 import ContextId +from common.tools.descriptor.Loader import DescriptorLoader, validate_empty_scenario +from common.tools.object_factory.Context import json_context_id +from context.client.ContextClient import ContextClient +from device.client.DeviceClient import DeviceClient +from tests.Fixtures import context_client, device_client # pylint: disable=unused-import + +LOGGER = logging.getLogger(__name__) +LOGGER.setLevel(logging.DEBUG) + +DESCRIPTOR_FILE = 'src/tests/e2e_orchestrator/descriptors_emulated.json' +ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_NAME)) + +def test_scenario_cleanup( + context_client : ContextClient, # pylint: disable=redefined-outer-name + device_client : DeviceClient, # pylint: disable=redefined-outer-name +) -> None: + # Verify the scenario has no services/slices + response = context_client.GetContext(ADMIN_CONTEXT_ID) + assert len(response.service_ids) == 0 + assert len(response.slice_ids) == 0 + + # Load descriptors and validate the base scenario + descriptor_loader = DescriptorLoader( + descriptors_file=DESCRIPTOR_FILE, context_client=context_client, device_client=device_client) + descriptor_loader.validate() + descriptor_loader.unload() + validate_empty_scenario(context_client) diff --git a/src/tests/e2e_orchestrator/tests/test_functional_compute_path.py b/src/tests/e2e_orchestrator/tests/test_functional_compute_path.py new file mode 100644 index 000000000..e95a325aa --- /dev/null +++ b/src/tests/e2e_orchestrator/tests/test_functional_compute_path.py @@ -0,0 +1,65 @@ +# 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. + +import logging, random +from common.Constants import DEFAULT_CONTEXT_NAME +from common.proto.context_pb2 import ContextId, Empty, ServiceTypeEnum, Service +from common.proto.e2eorchestrator_pb2 import E2EOrchestratorRequest +from common.proto.kpi_sample_types_pb2 import KpiSampleType +from common.tools.descriptor.Loader import DescriptorLoader +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 service.client.ServiceClient import ServiceClient +from tests.Fixtures import service_client, context_client, e2eorchestrator_client # pylint: disable=unused-import +from e2eorchestrator.client.E2EOrchestratorClient import E2EOrchestratorClient +from .Objects import SERVICES +import copy + +LOGGER = logging.getLogger(__name__) +LOGGER.setLevel(logging.DEBUG) + +DESCRIPTOR_FILE = 'src/tests/e2e_orchestrator/descriptors_emulated.json' +ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_NAME)) + + +def test_orchestration(service_client : ServiceClient, context_client : ContextClient, e2eorchestrator_client : E2EOrchestratorClient): # pylint: disable=redefined-outer-name + # Load descriptors and validate the base scenario + descriptor_loader = DescriptorLoader(descriptors_file=DESCRIPTOR_FILE, context_client=context_client) + descriptor_loader.validate() + + # Verify the scenario has no services/slices + response = context_client.GetContext(ADMIN_CONTEXT_ID) + assert len(response.service_ids) == 0 + assert len(response.slice_ids) == 0 + + # Create Connectivity Service + + + # ----- Create Services --------------------------------------------------------------- + for service, endpoints in SERVICES: + LOGGER.info(service) + # Insert Service (table entries) + service_uuid = service['service_id']['service_uuid']['uuid'] + print('Creating Service {:s}'.format(service_uuid)) + service_p4 = copy.deepcopy(service) + # service_client.CreateService(Service(**service_p4)) + LOGGER.info(type(service_p4)) + service_p4['service_endpoint_ids'].extend(endpoints) + # service_client.UpdateService(Service(**service_p4)) + request = E2EOrchestratorRequest() + request.service.MergeFrom(Service(**service_p4)) + reply = e2eorchestrator_client.Compute(request) + LOGGER.info(reply) + -- GitLab From 3374a8d65e64ff932507fce9d32814609907ce3e Mon Sep 17 00:00:00 2001 From: Carlos Manso Date: Fri, 15 Dec 2023 15:39:15 +0100 Subject: [PATCH 5/6] branch cleanup --- manifests/e2eorchestratorservice.yaml | 96 --- my_deploy.sh | 4 +- proto/context.proto | 613 ------------------ proto/e2eorchestrator.proto | 39 -- scripts/show_logs_e2eorchestrator.sh | 27 - src/common/Constants.py | 2 - src/e2eorchestrator/.gitlab-ci.yml | 38 -- src/e2eorchestrator/Config.py | 13 - src/e2eorchestrator/Dockerfile | 84 --- src/e2eorchestrator/__init__.py | 13 - .../client/E2EOrchestratorClient.py | 69 -- src/e2eorchestrator/client/__init__.py | 13 - src/e2eorchestrator/requirements.in | 15 - .../service/E2EOrchestratorService.py | 35 - .../E2EOrchestratorServiceServicerImpl.py | 93 --- src/e2eorchestrator/service/__init__.py | 13 - src/e2eorchestrator/service/__main__.py | 80 --- src/service/Dockerfile | 1 - .../service/ServiceServiceServicerImpl.py | 29 - .../service_handler_api/FilterFields.py | 1 - .../service/service_handlers/__init__.py | 6 - .../e2e_orch/E2EOrchestratorServiceHandler.py | 176 ----- .../service_handlers/e2e_orch/__init__.py | 14 - src/tests/Fixtures.py | 13 - src/tests/e2e_orchestrator/__init__.py | 14 - src/tests/e2e_orchestrator/deploy_specs.sh | 154 ----- .../descriptors_emulated.json | 250 ------- src/tests/e2e_orchestrator/redeploy.sh | 18 - .../e2e_orchestrator/run_test_01_bootstrap.sh | 17 - .../run_test_02_compute_path.sh | 17 - .../e2e_orchestrator/run_test_03_cleanup.sh | 17 - src/tests/e2e_orchestrator/run_tests.sh | 20 - src/tests/e2e_orchestrator/tests/Fixtures.py | 13 - src/tests/e2e_orchestrator/tests/Objects.py | 60 -- src/tests/e2e_orchestrator/tests/__init__.py | 14 - .../tests/test_functional_bootstrap.py | 72 -- .../tests/test_functional_cleanup.py | 44 -- .../tests/test_functional_compute_path.py | 65 -- 38 files changed, 2 insertions(+), 2260 deletions(-) delete mode 100644 manifests/e2eorchestratorservice.yaml delete mode 100644 proto/context.proto delete mode 100644 proto/e2eorchestrator.proto delete mode 100755 scripts/show_logs_e2eorchestrator.sh delete mode 100644 src/e2eorchestrator/.gitlab-ci.yml delete mode 100644 src/e2eorchestrator/Config.py delete mode 100644 src/e2eorchestrator/Dockerfile delete mode 100644 src/e2eorchestrator/__init__.py delete mode 100644 src/e2eorchestrator/client/E2EOrchestratorClient.py delete mode 100644 src/e2eorchestrator/client/__init__.py delete mode 100644 src/e2eorchestrator/requirements.in delete mode 100644 src/e2eorchestrator/service/E2EOrchestratorService.py delete mode 100644 src/e2eorchestrator/service/E2EOrchestratorServiceServicerImpl.py delete mode 100644 src/e2eorchestrator/service/__init__.py delete mode 100644 src/e2eorchestrator/service/__main__.py delete mode 100644 src/service/service/service_handlers/e2e_orch/E2EOrchestratorServiceHandler.py delete mode 100644 src/service/service/service_handlers/e2e_orch/__init__.py delete mode 100644 src/tests/e2e_orchestrator/__init__.py delete mode 100755 src/tests/e2e_orchestrator/deploy_specs.sh delete mode 100644 src/tests/e2e_orchestrator/descriptors_emulated.json delete mode 100755 src/tests/e2e_orchestrator/redeploy.sh delete mode 100755 src/tests/e2e_orchestrator/run_test_01_bootstrap.sh delete mode 100755 src/tests/e2e_orchestrator/run_test_02_compute_path.sh delete mode 100755 src/tests/e2e_orchestrator/run_test_03_cleanup.sh delete mode 100755 src/tests/e2e_orchestrator/run_tests.sh delete mode 100644 src/tests/e2e_orchestrator/tests/Fixtures.py delete mode 100644 src/tests/e2e_orchestrator/tests/Objects.py delete mode 100644 src/tests/e2e_orchestrator/tests/__init__.py delete mode 100644 src/tests/e2e_orchestrator/tests/test_functional_bootstrap.py delete mode 100644 src/tests/e2e_orchestrator/tests/test_functional_cleanup.py delete mode 100644 src/tests/e2e_orchestrator/tests/test_functional_compute_path.py diff --git a/manifests/e2eorchestratorservice.yaml b/manifests/e2eorchestratorservice.yaml deleted file mode 100644 index acefd44b9..000000000 --- a/manifests/e2eorchestratorservice.yaml +++ /dev/null @@ -1,96 +0,0 @@ -# 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. - -apiVersion: apps/v1 -kind: Deployment -metadata: - name: e2eorchestratorservice -spec: - selector: - matchLabels: - app: e2eorchestratorservice - template: - metadata: - labels: - app: e2eorchestratorservice - spec: - terminationGracePeriodSeconds: 5 - containers: - - name: server - image: labs.etsi.org:5050/tfs/controller/e2eorchestrator:latest - imagePullPolicy: Always - ports: - - containerPort: 10050 - - containerPort: 9192 - env: - - name: LOG_LEVEL - value: "INFO" - - name: REDIS_PASSWORD - valueFrom: - secretKeyRef: - name: redis-secrets - key: REDIS_PASSWORD - readinessProbe: - exec: - command: ["/bin/grpc_health_probe", "-addr=:10050"] - livenessProbe: - exec: - command: ["/bin/grpc_health_probe", "-addr=:10050"] - resources: - requests: - cpu: 250m - memory: 128Mi - limits: - cpu: 1000m - memory: 1024Mi ---- -apiVersion: v1 -kind: Service -metadata: - name: e2eorchestratorservice - labels: - app: e2eorchestratorservice -spec: - type: ClusterIP - selector: - app: e2eorchestratorservice - ports: - - name: grpc - port: 10050 - targetPort: 10050 - - name: metrics - port: 9192 - targetPort: 9192 ---- -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: e2eorchestratorservice-hpa -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: e2eorchestratorservice - minReplicas: 1 - maxReplicas: 20 - metrics: - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: 80 - #behavior: - # scaleDown: - # stabilizationWindowSeconds: 30 diff --git a/my_deploy.sh b/my_deploy.sh index 73eb85fb5..f1f2d580f 100755 --- a/my_deploy.sh +++ b/my_deploy.sh @@ -93,7 +93,7 @@ export CRDB_DATABASE="tfs" export CRDB_DEPLOY_MODE="single" # Disable flag for dropping database, if it exists. -export CRDB_DROP_DATABASE_IF_EXISTS="YES" +export CRDB_DROP_DATABASE_IF_EXISTS="" # Disable flag for re-deploying CockroachDB from scratch. export CRDB_REDEPLOY="" @@ -141,7 +141,7 @@ export QDB_TABLE_MONITORING_KPIS="tfs_monitoring_kpis" export QDB_TABLE_SLICE_GROUPS="tfs_slice_groups" # Disable flag for dropping tables if they exist. -export QDB_DROP_TABLES_IF_EXIST="YES" +export QDB_DROP_TABLES_IF_EXIST="" # Disable flag for re-deploying QuestDB from scratch. export QDB_REDEPLOY="" diff --git a/proto/context.proto b/proto/context.proto deleted file mode 100644 index 7570a4596..000000000 --- a/proto/context.proto +++ /dev/null @@ -1,613 +0,0 @@ -// 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. - -syntax = "proto3"; -package context; - -import "acl.proto"; -import "kpi_sample_types.proto"; - -service ContextService { - rpc ListContextIds (Empty ) returns ( ContextIdList ) {} - rpc ListContexts (Empty ) returns ( ContextList ) {} - rpc GetContext (ContextId ) returns ( Context ) {} - rpc SetContext (Context ) returns ( ContextId ) {} - rpc RemoveContext (ContextId ) returns ( Empty ) {} - rpc GetContextEvents (Empty ) returns (stream ContextEvent ) {} - - rpc ListTopologyIds (ContextId ) returns ( TopologyIdList ) {} - rpc ListTopologies (ContextId ) returns ( TopologyList ) {} - rpc GetTopology (TopologyId ) returns ( Topology ) {} - rpc GetTopologyDetails (TopologyId ) returns ( TopologyDetails ) {} - rpc SetTopology (Topology ) returns ( TopologyId ) {} - rpc RemoveTopology (TopologyId ) returns ( Empty ) {} - rpc GetTopologyEvents (Empty ) returns (stream TopologyEvent ) {} - - rpc ListDeviceIds (Empty ) returns ( DeviceIdList ) {} - rpc ListDevices (Empty ) returns ( DeviceList ) {} - rpc GetDevice (DeviceId ) returns ( Device ) {} - rpc SetDevice (Device ) returns ( DeviceId ) {} - rpc RemoveDevice (DeviceId ) returns ( Empty ) {} - rpc GetDeviceEvents (Empty ) returns (stream DeviceEvent ) {} - rpc SelectDevice (DeviceFilter ) returns ( DeviceList ) {} - rpc ListEndPointNames (EndPointIdList) returns ( EndPointNameList) {} - - rpc ListLinkIds (Empty ) returns ( LinkIdList ) {} - rpc ListLinks (Empty ) returns ( LinkList ) {} - rpc GetLink (LinkId ) returns ( Link ) {} - rpc SetLink (Link ) returns ( LinkId ) {} - rpc RemoveLink (LinkId ) returns ( Empty ) {} - rpc GetLinkEvents (Empty ) returns (stream LinkEvent ) {} - - rpc ListServiceIds (ContextId ) returns ( ServiceIdList ) {} - rpc ListServices (ContextId ) returns ( ServiceList ) {} - rpc GetService (ServiceId ) returns ( Service ) {} - rpc SetService (Service ) returns ( ServiceId ) {} - rpc UnsetService (Service ) returns ( ServiceId ) {} - rpc RemoveService (ServiceId ) returns ( Empty ) {} - rpc GetServiceEvents (Empty ) returns (stream ServiceEvent ) {} - rpc SelectService (ServiceFilter ) returns ( ServiceList ) {} - - rpc ListSliceIds (ContextId ) returns ( SliceIdList ) {} - rpc ListSlices (ContextId ) returns ( SliceList ) {} - rpc GetSlice (SliceId ) returns ( Slice ) {} - rpc SetSlice (Slice ) returns ( SliceId ) {} - rpc UnsetSlice (Slice ) returns ( SliceId ) {} - rpc RemoveSlice (SliceId ) returns ( Empty ) {} - rpc GetSliceEvents (Empty ) returns (stream SliceEvent ) {} - rpc SelectSlice (SliceFilter ) returns ( SliceList ) {} - - rpc ListConnectionIds (ServiceId ) returns ( ConnectionIdList) {} - rpc ListConnections (ServiceId ) returns ( ConnectionList ) {} - rpc GetConnection (ConnectionId ) returns ( Connection ) {} - rpc SetConnection (Connection ) returns ( ConnectionId ) {} - rpc RemoveConnection (ConnectionId ) returns ( Empty ) {} - rpc GetConnectionEvents(Empty ) returns (stream ConnectionEvent ) {} -} - -// ----- Generic ------------------------------------------------------------------------------------------------------- -message Empty {} - -message Uuid { - string uuid = 1; -} - -enum EventTypeEnum { - EVENTTYPE_UNDEFINED = 0; - EVENTTYPE_CREATE = 1; - EVENTTYPE_UPDATE = 2; - EVENTTYPE_REMOVE = 3; -} - -message Timestamp { - double timestamp = 1; -} - -message Event { - Timestamp timestamp = 1; - EventTypeEnum event_type = 2; -} - -// ----- Context ------------------------------------------------------------------------------------------------------- -message ContextId { - Uuid context_uuid = 1; -} - -message Context { - ContextId context_id = 1; - string name = 2; - repeated TopologyId topology_ids = 3; - repeated ServiceId service_ids = 4; - repeated SliceId slice_ids = 5; - TeraFlowController controller = 6; -} - -message ContextIdList { - repeated ContextId context_ids = 1; -} - -message ContextList { - repeated Context contexts = 1; -} - -message ContextEvent { - Event event = 1; - ContextId context_id = 2; -} - - -// ----- Topology ------------------------------------------------------------------------------------------------------ -message TopologyId { - ContextId context_id = 1; - Uuid topology_uuid = 2; -} - -message Topology { - TopologyId topology_id = 1; - string name = 2; - repeated DeviceId device_ids = 3; - repeated LinkId link_ids = 4; -} - -message TopologyDetails { - TopologyId topology_id = 1; - string name = 2; - repeated Device devices = 3; - repeated Link links = 4; -} - -message TopologyIdList { - repeated TopologyId topology_ids = 1; -} - -message TopologyList { - repeated Topology topologies = 1; -} - -message TopologyEvent { - Event event = 1; - TopologyId topology_id = 2; -} - - -// ----- Device -------------------------------------------------------------------------------------------------------- -message DeviceId { - Uuid device_uuid = 1; -} - -message Device { - DeviceId device_id = 1; - string name = 2; - string device_type = 3; - DeviceConfig device_config = 4; - DeviceOperationalStatusEnum device_operational_status = 5; - repeated DeviceDriverEnum device_drivers = 6; - repeated EndPoint device_endpoints = 7; - repeated Component components = 8; // Used for inventory - DeviceId controller_id = 9; // Identifier of node controlling the actual device -} - -message Component { //Defined previously to this section - Tested OK - Uuid component_uuid = 1; - string name = 2; - string type = 3; - - map attributes = 4; // dict[attr.name => json.dumps(attr.value)] - string parent = 5; -} - -message DeviceConfig { - repeated ConfigRule config_rules = 1; -} - -enum DeviceDriverEnum { - DEVICEDRIVER_UNDEFINED = 0; // also used for emulated - DEVICEDRIVER_OPENCONFIG = 1; - DEVICEDRIVER_TRANSPORT_API = 2; - DEVICEDRIVER_P4 = 3; - DEVICEDRIVER_IETF_NETWORK_TOPOLOGY = 4; - DEVICEDRIVER_ONF_TR_532 = 5; - DEVICEDRIVER_XR = 6; - DEVICEDRIVER_IETF_L2VPN = 7; - DEVICEDRIVER_GNMI_OPENCONFIG = 8; - DEVICEDRIVER_FLEXSCALE = 9; -} - -enum DeviceOperationalStatusEnum { - DEVICEOPERATIONALSTATUS_UNDEFINED = 0; - DEVICEOPERATIONALSTATUS_DISABLED = 1; - DEVICEOPERATIONALSTATUS_ENABLED = 2; -} - -message DeviceIdList { - repeated DeviceId device_ids = 1; -} - -message DeviceList { - repeated Device devices = 1; -} - -message DeviceFilter { - DeviceIdList device_ids = 1; - bool include_endpoints = 2; - bool include_config_rules = 3; - bool include_components = 4; -} - -message DeviceEvent { - Event event = 1; - DeviceId device_id = 2; - DeviceConfig device_config = 3; -} - - -// ----- Link ---------------------------------------------------------------------------------------------------------- -message LinkId { - Uuid link_uuid = 1; -} - -message LinkAttributes { - float total_capacity_gbps = 1; - float used_capacity_gbps = 2; -} - -message Link { - LinkId link_id = 1; - string name = 2; - repeated EndPointId link_endpoint_ids = 3; - LinkAttributes attributes = 4; -} - -message LinkIdList { - repeated LinkId link_ids = 1; -} - -message LinkList { - repeated Link links = 1; -} - -message LinkEvent { - Event event = 1; - LinkId link_id = 2; -} - - -// ----- Service ------------------------------------------------------------------------------------------------------- -message ServiceId { - ContextId context_id = 1; - Uuid service_uuid = 2; -} - -message Service { - ServiceId service_id = 1; - string name = 2; - ServiceTypeEnum service_type = 3; - repeated EndPointId service_endpoint_ids = 4; - repeated Constraint service_constraints = 5; - ServiceStatus service_status = 6; - ServiceConfig service_config = 7; - Timestamp timestamp = 8; -} - -enum ServiceTypeEnum { - SERVICETYPE_UNKNOWN = 0; - SERVICETYPE_L3NM = 1; - SERVICETYPE_L2NM = 2; - SERVICETYPE_TAPI_CONNECTIVITY_SERVICE = 3; - SERVICETYPE_TE = 4; - SERVICETYPE_E2E = 5; -} - -enum ServiceStatusEnum { - SERVICESTATUS_UNDEFINED = 0; - SERVICESTATUS_PLANNED = 1; - SERVICESTATUS_ACTIVE = 2; - SERVICESTATUS_UPDATING = 3; - SERVICESTATUS_PENDING_REMOVAL = 4; - SERVICESTATUS_SLA_VIOLATED = 5; -} - -message ServiceStatus { - ServiceStatusEnum service_status = 1; -} - -message ServiceConfig { - repeated ConfigRule config_rules = 1; -} - -message ServiceIdList { - repeated ServiceId service_ids = 1; -} - -message ServiceList { - repeated Service services = 1; -} - -message ServiceFilter { - ServiceIdList service_ids = 1; - bool include_endpoint_ids = 2; - bool include_constraints = 3; - bool include_config_rules = 4; -} - -message ServiceEvent { - Event event = 1; - ServiceId service_id = 2; -} - -// ----- Slice --------------------------------------------------------------------------------------------------------- -message SliceId { - ContextId context_id = 1; - Uuid slice_uuid = 2; -} - -message Slice { - SliceId slice_id = 1; - string name = 2; - repeated EndPointId slice_endpoint_ids = 3; - repeated Constraint slice_constraints = 4; - repeated ServiceId slice_service_ids = 5; - repeated SliceId slice_subslice_ids = 6; - SliceStatus slice_status = 7; - SliceConfig slice_config = 8; - SliceOwner slice_owner = 9; - Timestamp timestamp = 10; -} - -message SliceOwner { - Uuid owner_uuid = 1; - string owner_string = 2; -} - -enum SliceStatusEnum { - SLICESTATUS_UNDEFINED = 0; - SLICESTATUS_PLANNED = 1; - SLICESTATUS_INIT = 2; - SLICESTATUS_ACTIVE = 3; - SLICESTATUS_DEINIT = 4; - SLICESTATUS_SLA_VIOLATED = 5; -} - -message SliceStatus { - SliceStatusEnum slice_status = 1; -} - -message SliceConfig { - repeated ConfigRule config_rules = 1; -} - -message SliceIdList { - repeated SliceId slice_ids = 1; -} - -message SliceList { - repeated Slice slices = 1; -} - -message SliceFilter { - SliceIdList slice_ids = 1; - bool include_endpoint_ids = 2; - bool include_constraints = 3; - bool include_service_ids = 4; - bool include_subslice_ids = 5; - bool include_config_rules = 6; -} - -message SliceEvent { - Event event = 1; - SliceId slice_id = 2; -} - -// ----- Connection ---------------------------------------------------------------------------------------------------- -message ConnectionId { - Uuid connection_uuid = 1; -} - -message ConnectionSettings_L0 { - string lsp_symbolic_name = 1; -} - -message ConnectionSettings_L2 { - string src_mac_address = 1; - string dst_mac_address = 2; - uint32 ether_type = 3; - uint32 vlan_id = 4; - uint32 mpls_label = 5; - uint32 mpls_traffic_class = 6; -} - -message ConnectionSettings_L3 { - string src_ip_address = 1; - string dst_ip_address = 2; - uint32 dscp = 3; - uint32 protocol = 4; - uint32 ttl = 5; -} - -message ConnectionSettings_L4 { - uint32 src_port = 1; - uint32 dst_port = 2; - uint32 tcp_flags = 3; - uint32 ttl = 4; -} - -message ConnectionSettings { - ConnectionSettings_L0 l0 = 1; - ConnectionSettings_L2 l2 = 2; - ConnectionSettings_L3 l3 = 3; - ConnectionSettings_L4 l4 = 4; -} - -message Connection { - ConnectionId connection_id = 1; - ServiceId service_id = 2; - repeated EndPointId path_hops_endpoint_ids = 3; - repeated ServiceId sub_service_ids = 4; - ConnectionSettings settings = 5; -} - -message ConnectionIdList { - repeated ConnectionId connection_ids = 1; -} - -message ConnectionList { - repeated Connection connections = 1; -} - -message ConnectionEvent { - Event event = 1; - ConnectionId connection_id = 2; -} - - -// ----- Endpoint ------------------------------------------------------------------------------------------------------ -message EndPointId { - TopologyId topology_id = 1; - DeviceId device_id = 2; - Uuid endpoint_uuid = 3; -} - -message EndPoint { - EndPointId endpoint_id = 1; - string name = 2; - string endpoint_type = 3; - repeated kpi_sample_types.KpiSampleType kpi_sample_types = 4; - Location endpoint_location = 5; -} - -message EndPointName { - EndPointId endpoint_id = 1; - string device_name = 2; - string endpoint_name = 3; - string endpoint_type = 4; -} - -message EndPointIdList { - repeated EndPointId endpoint_ids = 1; -} - -message EndPointNameList { - repeated EndPointName endpoint_names = 1; -} - - -// ----- Configuration ------------------------------------------------------------------------------------------------- -enum ConfigActionEnum { - CONFIGACTION_UNDEFINED = 0; - CONFIGACTION_SET = 1; - CONFIGACTION_DELETE = 2; -} - -message ConfigRule_Custom { - string resource_key = 1; - string resource_value = 2; -} - -message ConfigRule_ACL { - EndPointId endpoint_id = 1; - acl.AclRuleSet rule_set = 2; -} - -message ConfigRule { - ConfigActionEnum action = 1; - oneof config_rule { - ConfigRule_Custom custom = 2; - ConfigRule_ACL acl = 3; - } -} - - -// ----- Constraint ---------------------------------------------------------------------------------------------------- -enum ConstraintActionEnum { - CONSTRAINTACTION_UNDEFINED = 0; - CONSTRAINTACTION_SET = 1; - CONSTRAINTACTION_DELETE = 2; -} - -message Constraint_Custom { - string constraint_type = 1; - string constraint_value = 2; -} - -message Constraint_Schedule { - float start_timestamp = 1; - float duration_days = 2; -} - -message GPS_Position { - float latitude = 1; - float longitude = 2; -} - -message Location { - oneof location { - string region = 1; - GPS_Position gps_position = 2; - } -} - -message Constraint_EndPointLocation { - EndPointId endpoint_id = 1; - Location location = 2; -} - -message Constraint_EndPointPriority { - EndPointId endpoint_id = 1; - uint32 priority = 2; -} - -message Constraint_SLA_Latency { - float e2e_latency_ms = 1; -} - -message Constraint_SLA_Capacity { - float capacity_gbps = 1; -} - -message Constraint_SLA_Availability { - uint32 num_disjoint_paths = 1; - bool all_active = 2; - float availability = 3; // 0.0 .. 100.0 percentage of availability -} - -enum IsolationLevelEnum { - NO_ISOLATION = 0; - PHYSICAL_ISOLATION = 1; - LOGICAL_ISOLATION = 2; - PROCESS_ISOLATION = 3; - PHYSICAL_MEMORY_ISOLATION = 4; - PHYSICAL_NETWORK_ISOLATION = 5; - VIRTUAL_RESOURCE_ISOLATION = 6; - NETWORK_FUNCTIONS_ISOLATION = 7; - SERVICE_ISOLATION = 8; -} - -message Constraint_SLA_Isolation_level { - repeated IsolationLevelEnum isolation_level = 1; -} - -message Constraint_Exclusions { - bool is_permanent = 1; - repeated DeviceId device_ids = 2; - repeated EndPointId endpoint_ids = 3; - repeated LinkId link_ids = 4; -} - -message Constraint { - ConstraintActionEnum action = 1; - oneof constraint { - Constraint_Custom custom = 2; - Constraint_Schedule schedule = 3; - Constraint_EndPointLocation endpoint_location = 4; - Constraint_EndPointPriority endpoint_priority = 5; - Constraint_SLA_Capacity sla_capacity = 6; - Constraint_SLA_Latency sla_latency = 7; - Constraint_SLA_Availability sla_availability = 8; - Constraint_SLA_Isolation_level sla_isolation = 9; - Constraint_Exclusions exclusions = 10; - } -} - - -// ----- Miscellaneous ------------------------------------------------------------------------------------------------- -message TeraFlowController { - ContextId context_id = 1; - string ip_address = 2; - uint32 port = 3; -} - -message AuthenticationResult { - ContextId context_id = 1; - bool authenticated = 2; -} diff --git a/proto/e2eorchestrator.proto b/proto/e2eorchestrator.proto deleted file mode 100644 index 9eed8523e..000000000 --- a/proto/e2eorchestrator.proto +++ /dev/null @@ -1,39 +0,0 @@ -// 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. - -// protocol buffers documentation: https://developers.google.com/protocol-buffers/docs/proto3 -syntax = "proto3"; -package orchestrator; - -import "context.proto"; - - -service E2EOrchestratorService { - rpc Compute(E2EOrchestratorRequest) returns (E2EOrchestratorReply) {} -} - -message E2EOrchestratorRequest { - context.Service service = 1; -} - -message E2EOrchestratorReply { - // Service requested completed with possible missing fields, and - // sub-services required for supporting requested service on the - // underlying layers. - repeated context.Service services = 1; - - // Connections supporting the requested service and sub-services - // required for the underlying layers. - repeated context.Connection connections = 2; -} \ No newline at end of file diff --git a/scripts/show_logs_e2eorchestrator.sh b/scripts/show_logs_e2eorchestrator.sh deleted file mode 100755 index 84951ed8d..000000000 --- a/scripts/show_logs_e2eorchestrator.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# 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. - -######################################################################################################################## -# Define your deployment settings here -######################################################################################################################## - -# If not already set, set the name of the Kubernetes namespace to deploy to. -export TFS_K8S_NAMESPACE=${TFS_K8S_NAMESPACE:-"tfs"} - -######################################################################################################################## -# Automated steps start here -######################################################################################################################## - -kubectl --namespace $TFS_K8S_NAMESPACE logs deployment/e2eorchestratorservice -c server diff --git a/src/common/Constants.py b/src/common/Constants.py index 30aa09b4c..79d5bb3b5 100644 --- a/src/common/Constants.py +++ b/src/common/Constants.py @@ -58,7 +58,6 @@ class ServiceNameEnum(Enum): CACHING = 'caching' TE = 'te' FORECASTER = 'forecaster' - E2EORCHESTRATOR = 'e2eorchestrator' # Used for test and debugging only DLT_GATEWAY = 'dltgateway' @@ -85,7 +84,6 @@ DEFAULT_SERVICE_GRPC_PORTS = { ServiceNameEnum.PATHCOMP .value : 10020, ServiceNameEnum.TE .value : 10030, ServiceNameEnum.FORECASTER .value : 10040, - ServiceNameEnum.E2EORCHESTRATOR .value : 10050, # Used for test and debugging only ServiceNameEnum.DLT_GATEWAY .value : 50051, diff --git a/src/e2eorchestrator/.gitlab-ci.yml b/src/e2eorchestrator/.gitlab-ci.yml deleted file mode 100644 index a14a215af..000000000 --- a/src/e2eorchestrator/.gitlab-ci.yml +++ /dev/null @@ -1,38 +0,0 @@ -# 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. - -# build, tag and push the Docker image to the gitlab registry -build e2eorchestrator: - variables: - IMAGE_NAME: 'e2eorchestrator' # name of the microservice - IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) - stage: build - before_script: - - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - script: - - docker build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile . - - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - after_script: - - docker images --filter="dangling=true" --quiet | xargs -r docker rmi - rules: - - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' - - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"' - - changes: - - src/$IMAGE_NAME/**/*.{py,in,yml} - - src/$IMAGE_NAME/Dockerfile - - src/$IMAGE_NAME/tests/*.py - - src/$IMAGE_NAME/tests/Dockerfile - - manifests/${IMAGE_NAME}service.yaml - - .gitlab-ci.yml diff --git a/src/e2eorchestrator/Config.py b/src/e2eorchestrator/Config.py deleted file mode 100644 index 38d04994f..000000000 --- a/src/e2eorchestrator/Config.py +++ /dev/null @@ -1,13 +0,0 @@ -# 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. diff --git a/src/e2eorchestrator/Dockerfile b/src/e2eorchestrator/Dockerfile deleted file mode 100644 index 52bd806f5..000000000 --- a/src/e2eorchestrator/Dockerfile +++ /dev/null @@ -1,84 +0,0 @@ -# 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. - -FROM python:3.9-slim - -# Install dependencies -RUN apt-get --yes --quiet --quiet update && \ - apt-get --yes --quiet --quiet install wget g++ && \ - rm -rf /var/lib/apt/lists/* - -# Set Python to show logs as they occur -ENV PYTHONUNBUFFERED=0 -ENV PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python - -# Download the gRPC health probe -RUN GRPC_HEALTH_PROBE_VERSION=v0.2.0 && \ - wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ - chmod +x /bin/grpc_health_probe - -# Creating a user for security reasons -RUN groupadd -r teraflow && useradd -u 1001 --no-log-init -r -m -g teraflow teraflow -USER teraflow - -# set working directory -RUN mkdir -p /home/teraflow/controller/common/ -WORKDIR /home/teraflow/controller - -# Get Python packages per module -ENV VIRTUAL_ENV=/home/teraflow/venv -RUN python3 -m venv ${VIRTUAL_ENV} -ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" - -# Get generic Python packages -RUN python3 -m pip install --upgrade pip -RUN python3 -m pip install --upgrade setuptools wheel -RUN python3 -m pip install --upgrade pip-tools - -# Get common Python packages -# Note: this step enables sharing the previous Docker build steps among all the Python components -COPY --chown=teraflow:teraflow common_requirements.in common_requirements.in -RUN pip-compile --quiet --output-file=common_requirements.txt common_requirements.in -RUN python3 -m pip install -r common_requirements.txt - -# Add common files into working directory -WORKDIR /home/teraflow/controller/common -COPY --chown=teraflow:teraflow src/common/. ./ -RUN rm -rf proto - -# Create proto sub-folder, copy .proto files, and generate Python code -RUN mkdir -p /home/teraflow/controller/common/proto -WORKDIR /home/teraflow/controller/common/proto -RUN touch __init__.py -COPY --chown=teraflow:teraflow proto/*.proto ./ -RUN python3 -m grpc_tools.protoc -I=. --python_out=. --grpc_python_out=. *.proto -RUN rm *.proto -RUN find . -type f -exec sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' {} \; - -# Create module sub-folders -RUN mkdir -p /home/teraflow/controller/e2eorchestrator -WORKDIR /home/teraflow/controller - -# Get Python packages per module -COPY --chown=teraflow:teraflow ./src/e2eorchestrator/requirements.in e2eorchestrator/requirements.in -# consider common and specific requirements to avoid inconsistencies with dependencies -RUN pip-compile --quiet --output-file=e2eorchestrator/requirements.txt e2eorchestrator/requirements.in common_requirements.in -RUN python3 -m pip install -r e2eorchestrator/requirements.txt - -# Add component files into working directory -COPY --chown=teraflow:teraflow ./src/context/. context -COPY --chown=teraflow:teraflow ./src/e2eorchestrator/. e2eorchestrator - -# Start the service -ENTRYPOINT ["python", "-m", "e2eorchestrator.service"] diff --git a/src/e2eorchestrator/__init__.py b/src/e2eorchestrator/__init__.py deleted file mode 100644 index 38d04994f..000000000 --- a/src/e2eorchestrator/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# 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. diff --git a/src/e2eorchestrator/client/E2EOrchestratorClient.py b/src/e2eorchestrator/client/E2EOrchestratorClient.py deleted file mode 100644 index 10f183a51..000000000 --- a/src/e2eorchestrator/client/E2EOrchestratorClient.py +++ /dev/null @@ -1,69 +0,0 @@ -# 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. - -import logging - -import grpc - -from common.Constants import ServiceNameEnum -from common.proto.context_pb2 import Empty -from common.proto.e2eorchestrator_pb2_grpc import E2EOrchestratorServiceStub -from common.Settings import get_service_host, get_service_port_grpc -from common.tools.client.RetryDecorator import delay_exponential, retry -from common.tools.grpc.Tools import grpc_message_to_json -from common.proto.e2eorchestrator_pb2 import E2EOrchestratorRequest, E2EOrchestratorReply - -LOGGER = logging.getLogger(__name__) -MAX_RETRIES = 15 -DELAY_FUNCTION = delay_exponential(initial=0.01, increment=2.0, maximum=5.0) -RETRY_DECORATOR = retry( - max_retries=MAX_RETRIES, - delay_function=DELAY_FUNCTION, - prepare_method_name="connect", -) - - -class E2EOrchestratorClient: - def __init__(self, host=None, port=None): - if not host: - host = get_service_host(ServiceNameEnum.E2EORCHESTRATOR) - if not port: - port = get_service_port_grpc(ServiceNameEnum.E2EORCHESTRATOR) - self.endpoint = "{:s}:{:s}".format(str(host), str(port)) - LOGGER.debug("Creating channel to {:s}...".format(str(self.endpoint))) - self.channel = None - self.stub = None - self.connect() - LOGGER.debug("Channel created") - - def connect(self): - self.channel = grpc.insecure_channel(self.endpoint) - self.stub = E2EOrchestratorServiceStub(self.channel) - - def close(self): - if self.channel is not None: - self.channel.close() - self.channel = None - self.stub = None - - @RETRY_DECORATOR - def Compute(self, request: E2EOrchestratorRequest) -> E2EOrchestratorReply: - LOGGER.info( - "Compute request: {:s}".format(str(grpc_message_to_json(request))) - ) - response = self.stub.Compute(request) - LOGGER.info( - "Compute result: {:s}".format(str(grpc_message_to_json(response))) - ) - return response diff --git a/src/e2eorchestrator/client/__init__.py b/src/e2eorchestrator/client/__init__.py deleted file mode 100644 index 38d04994f..000000000 --- a/src/e2eorchestrator/client/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# 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. diff --git a/src/e2eorchestrator/requirements.in b/src/e2eorchestrator/requirements.in deleted file mode 100644 index 4c4720a2d..000000000 --- a/src/e2eorchestrator/requirements.in +++ /dev/null @@ -1,15 +0,0 @@ -# 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. - -networkx \ No newline at end of file diff --git a/src/e2eorchestrator/service/E2EOrchestratorService.py b/src/e2eorchestrator/service/E2EOrchestratorService.py deleted file mode 100644 index 4d6125d4a..000000000 --- a/src/e2eorchestrator/service/E2EOrchestratorService.py +++ /dev/null @@ -1,35 +0,0 @@ -# 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. - -import logging - -from common.Constants import ServiceNameEnum -from common.proto.e2eorchestrator_pb2_grpc import add_E2EOrchestratorServiceServicer_to_server -from common.Settings import get_service_port_grpc -from common.tools.service.GenericGrpcService import GenericGrpcService -from .E2EOrchestratorServiceServicerImpl import E2EOrchestratorServiceServicerImpl - -LOGGER = logging.getLogger(__name__) - - -class E2EOrchestratorService(GenericGrpcService): - def __init__(self, cls_name: str = __name__): - port = get_service_port_grpc(ServiceNameEnum.E2EORCHESTRATOR) - super().__init__(port, cls_name=cls_name) - self.e2eorchestrator_servicer = E2EOrchestratorServiceServicerImpl() - - def install_servicers(self): - add_E2EOrchestratorServiceServicer_to_server( - self.e2eorchestrator_servicer, self.server - ) diff --git a/src/e2eorchestrator/service/E2EOrchestratorServiceServicerImpl.py b/src/e2eorchestrator/service/E2EOrchestratorServiceServicerImpl.py deleted file mode 100644 index d233f2e17..000000000 --- a/src/e2eorchestrator/service/E2EOrchestratorServiceServicerImpl.py +++ /dev/null @@ -1,93 +0,0 @@ -# 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. - -import logging - -import networkx as nx -import grpc -import copy - -from common.Constants import ServiceNameEnum -from common.method_wrappers.Decorator import (MetricsPool, MetricTypeEnum, safe_and_metered_rpc_method) -from common.proto.e2eorchestrator_pb2 import E2EOrchestratorRequest, E2EOrchestratorReply -from common.proto.context_pb2 import Empty, Connection, EndPointId -from common.proto.e2eorchestrator_pb2_grpc import E2EOrchestratorServiceServicer -from context.client.ContextClient import ContextClient -from context.service.database.uuids.EndPoint import endpoint_get_uuid - - -LOGGER = logging.getLogger(__name__) - -METRICS_POOL = MetricsPool("E2EOrchestrator", "RPC") - -context_client: ContextClient = ContextClient() - - -class E2EOrchestratorServiceServicerImpl(E2EOrchestratorServiceServicer): - def __init__(self): - LOGGER.debug("Creating Servicer...") - LOGGER.debug("Servicer Created") - - @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) - def Compute(self, request: E2EOrchestratorRequest, context: grpc.ServicerContext) -> E2EOrchestratorReply: - endpoints_ids = [] - for endpoint_id in request.service.service_endpoint_ids: - endpoints_ids.append(endpoint_get_uuid(endpoint_id)[2]) - - graph = nx.Graph() - - devices = context_client.ListDevices(Empty()).devices - - for device in devices: - endpoints_uuids = [endpoint.endpoint_id.endpoint_uuid.uuid - for endpoint in device.device_endpoints] - for ep in endpoints_uuids: - graph.add_node(ep) - - for ep in endpoints_uuids: - for ep_i in endpoints_uuids: - if ep == ep_i: - continue - graph.add_edge(ep, ep_i) - - links = context_client.ListLinks(Empty()).links - for link in links: - eps = [] - for endpoint_id in link.link_endpoint_ids: - eps.append(endpoint_id.endpoint_uuid.uuid) - graph.add_edge(eps[0], eps[1]) - - - shortest = nx.shortest_path(graph, endpoints_ids[0], endpoints_ids[1]) - - path = E2EOrchestratorReply() - path.services.append(copy.deepcopy(request.service)) - for i in range(0, int(len(shortest)/2)): - conn = Connection() - ep_a_uuid = str(shortest[i*2]) - ep_z_uuid = str(shortest[i*2+1]) - - conn.connection_id.connection_uuid.uuid = str(ep_a_uuid) + '_->_' + str(ep_z_uuid) - - ep_a_id = EndPointId() - ep_a_id.endpoint_uuid.uuid = ep_a_uuid - conn.path_hops_endpoint_ids.append(ep_a_id) - - ep_z_id = EndPointId() - ep_z_id.endpoint_uuid.uuid = ep_z_uuid - conn.path_hops_endpoint_ids.append(ep_z_id) - - path.connections.append(conn) - - return path diff --git a/src/e2eorchestrator/service/__init__.py b/src/e2eorchestrator/service/__init__.py deleted file mode 100644 index 38d04994f..000000000 --- a/src/e2eorchestrator/service/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# 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. diff --git a/src/e2eorchestrator/service/__main__.py b/src/e2eorchestrator/service/__main__.py deleted file mode 100644 index a586543a7..000000000 --- a/src/e2eorchestrator/service/__main__.py +++ /dev/null @@ -1,80 +0,0 @@ -# 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. - -import logging -import signal -import sys -import threading - -from prometheus_client import start_http_server - -from common.Constants import ServiceNameEnum -from common.Settings import (ENVVAR_SUFIX_SERVICE_HOST, - ENVVAR_SUFIX_SERVICE_PORT_GRPC, get_env_var_name, - get_log_level, get_metrics_port, - wait_for_environment_variables) - -from .E2EOrchestratorService import E2EOrchestratorService - -terminate = threading.Event() -LOGGER = None - - -def signal_handler(signal, frame): # pylint: disable=redefined-outer-name - LOGGER.warning("Terminate signal received") - terminate.set() - - -def main(): - global LOGGER # pylint: disable=global-statement - - log_level = get_log_level() - logging.basicConfig(level=log_level) - LOGGER = logging.getLogger(__name__) - - wait_for_environment_variables( - [ - get_env_var_name(ServiceNameEnum.E2EORCHESTRATOR, ENVVAR_SUFIX_SERVICE_HOST), - get_env_var_name(ServiceNameEnum.E2EORCHESTRATOR, ENVVAR_SUFIX_SERVICE_PORT_GRPC), - ] - ) - - signal.signal(signal.SIGINT, signal_handler) - signal.signal(signal.SIGTERM, signal_handler) - - LOGGER.info("Starting...") - - # Start metrics server - metrics_port = get_metrics_port() - start_http_server(metrics_port) - - # Starting CentralizedCybersecurity service - grpc_service = E2EOrchestratorService() - grpc_service.start() - LOGGER.info("Started...") - # Wait for Ctrl+C or termination signal - - while not terminate.wait(timeout=1): - pass - - - LOGGER.info("Terminating...") - grpc_service.stop() - - LOGGER.info("Bye") - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/src/service/Dockerfile b/src/service/Dockerfile index 3926770f8..fc431deca 100644 --- a/src/service/Dockerfile +++ b/src/service/Dockerfile @@ -66,7 +66,6 @@ COPY src/context/. context/ COPY src/device/. device/ COPY src/pathcomp/frontend/. pathcomp/frontend/ COPY src/service/. service/ -COPY src/e2eorchestrator/. e2eorchestrator/ # Start the service ENTRYPOINT ["python", "-m", "service.service"] diff --git a/src/service/service/ServiceServiceServicerImpl.py b/src/service/service/ServiceServiceServicerImpl.py index c5d305141..f79e3e5f3 100644 --- a/src/service/service/ServiceServiceServicerImpl.py +++ b/src/service/service/ServiceServiceServicerImpl.py @@ -21,12 +21,10 @@ from common.method_wrappers.ServiceExceptions import ( from common.proto.context_pb2 import ( Connection, Empty, Service, ServiceId, ServiceStatusEnum, ServiceTypeEnum, ConstraintActionEnum) from common.proto.pathcomp_pb2 import PathCompRequest -from common.proto.e2eorchestrator_pb2 import E2EOrchestratorRequest, E2EOrchestratorReply from common.proto.service_pb2_grpc import ServiceServiceServicer from common.tools.context_queries.Service import get_service_by_id from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string from context.client.ContextClient import ContextClient -from e2eorchestrator.client.E2EOrchestratorClient import E2EOrchestratorClient from pathcomp.frontend.client.PathCompClient import PathCompClient from service.service.tools.ConnectionToString import connection_to_string from service.client.TEServiceClient import TEServiceClient @@ -34,7 +32,6 @@ from .service_handler_api.ServiceHandlerFactory import ServiceHandlerFactory from .task_scheduler.TaskScheduler import TasksScheduler from .tools.GeodesicDistance import gps_distance - LOGGER = logging.getLogger(__name__) METRICS_POOL = MetricsPool('Service', 'RPC') @@ -156,32 +153,6 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): str_service_status = ServiceStatusEnum.Name(service_status.service_status) raise Exception(MSG.format(service_key, str_service_status)) - if service.service_type == ServiceTypeEnum.SERVICETYPE_E2E: - # End-to-End service: - service_id_with_uuids = context_client.SetService(request) - - service_with_uuids = get_service_by_id( - context_client, service_id_with_uuids, rw_copy=False, - include_config_rules=True, include_constraints=True, include_endpoint_ids=True) - - e2e_orch_request = E2EOrchestratorRequest() - e2e_orch_request.service.CopyFrom(service_with_uuids) - - e2e_orch_client = E2EOrchestratorClient() - e2e_orch_reply = e2e_orch_client.Compute(e2e_orch_request) - - # Feed TaskScheduler with this end-to-end orchestrator reply. TaskScheduler identifies - # inter-dependencies among the services and connections retrieved and produces a - # schedule of tasks (an ordered list of tasks to be executed) to implement the - # requested create/update operation. - tasks_scheduler = TasksScheduler(self.service_handler_factory) - # e2e_orch_reply should be compatible with pathcomp_reply - # TODO: if we extend e2e_orch_reply, implement method TasksScheduler::compose_from_e2eorchreply() - tasks_scheduler.compose_from_pathcompreply(e2e_orch_reply, is_delete=False) - tasks_scheduler.execute_all() - return service_with_uuids.service_id - - # Normal service del service.service_endpoint_ids[:] # pylint: disable=no-member for endpoint_id in request.service_endpoint_ids: diff --git a/src/service/service/service_handler_api/FilterFields.py b/src/service/service/service_handler_api/FilterFields.py index 35c45c996..f4a14a5a5 100644 --- a/src/service/service/service_handler_api/FilterFields.py +++ b/src/service/service/service_handler_api/FilterFields.py @@ -38,7 +38,6 @@ DEVICE_DRIVER_VALUES = { DeviceDriverEnum.DEVICEDRIVER_XR, DeviceDriverEnum.DEVICEDRIVER_IETF_L2VPN, DeviceDriverEnum.DEVICEDRIVER_GNMI_OPENCONFIG, - DeviceDriverEnum.DEVICEDRIVER_FLEXSCALE, } # Map allowed filter fields to allowed values per Filter field. If no restriction (free text) None is specified diff --git a/src/service/service/service_handlers/__init__.py b/src/service/service/service_handlers/__init__.py index dd96db2af..32df661a2 100644 --- a/src/service/service/service_handlers/__init__.py +++ b/src/service/service/service_handlers/__init__.py @@ -88,10 +88,4 @@ SERVICE_HANDLERS = [ FilterFieldEnum.DEVICE_DRIVER : [DeviceDriverEnum.DEVICEDRIVER_IETF_L2VPN], } ]), - (E2EOrchestratorServiceHandler, [ - { - FilterFieldEnum.SERVICE_TYPE : ServiceTypeEnum.SERVICETYPE_E2E, - FilterFieldEnum.DEVICE_DRIVER : [DeviceDriverEnum.DEVICEDRIVER_FLEXSCALE], - } - ]), ] diff --git a/src/service/service/service_handlers/e2e_orch/E2EOrchestratorServiceHandler.py b/src/service/service/service_handlers/e2e_orch/E2EOrchestratorServiceHandler.py deleted file mode 100644 index 5a068bb51..000000000 --- a/src/service/service/service_handlers/e2e_orch/E2EOrchestratorServiceHandler.py +++ /dev/null @@ -1,176 +0,0 @@ -# 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. - -import json, logging -from typing import Any, Dict, List, Optional, Tuple, Union -from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method -from common.proto.context_pb2 import ConfigRule, DeviceId, Service -from common.tools.object_factory.ConfigRule import json_config_rule_set -from common.tools.object_factory.Device import json_device_id -from common.type_checkers.Checkers import chk_type -from service.service.service_handler_api.Tools import get_device_endpoint_uuids -from service.service.service_handler_api._ServiceHandler import _ServiceHandler -from service.service.service_handler_api.SettingsHandler import SettingsHandler -from service.service.task_scheduler.TaskExecutor import TaskExecutor - -LOGGER = logging.getLogger(__name__) - -METRICS_POOL = MetricsPool('Service', 'Handler', labels={'handler': 'e2e_orch'}) - -class E2EOrchestratorServiceHandler(_ServiceHandler): - def __init__( # pylint: disable=super-init-not-called - self, service : Service, task_executor : TaskExecutor, **settings - ) -> None: - self.__service = service - self.__task_executor = task_executor - self.__settings_handler = SettingsHandler(service.service_config, **settings) - - @metered_subclass_method(METRICS_POOL) - def SetEndpoint( - self, endpoints : List[Tuple[str, str, Optional[str]]], connection_uuid : Optional[str] = None - ) -> List[Union[bool, Exception]]: - - chk_type('endpoints', endpoints, list) - if len(endpoints) < 2: return [] - - service_uuid = self.__service.service_id.service_uuid.uuid - settings = self.__settings_handler.get('/settings') - json_settings : Dict = {} if settings is None else settings.value - bitrate = json_settings.get('bitrate', 1000) - - results = [] - try: - src_device_uuid, src_endpoint_uuid = get_device_endpoint_uuids(endpoints[0]) - src_device = self.__task_executor.get_device(DeviceId(**json_device_id(src_device_uuid))) - src_controller = self.__task_executor.get_device_controller(src_device) - if src_controller is None: src_controller = src_device - - dst_device_uuid, dst_endpoint_uuid = get_device_endpoint_uuids(endpoints[-1]) - dst_device = self.__task_executor.get_device(DeviceId(**json_device_id(dst_device_uuid))) - dst_controller = self.__task_executor.get_device_controller(dst_device) - if dst_controller is None: dst_controller = dst_device - - controller = src_controller - - json_config_rule = json_config_rule_set('/services/service[{:s}]'.format(service_uuid), { - 'uuid' : service_uuid, - 'src_node' : src_endpoint_uuid, - 'dst_node' : dst_endpoint_uuid, - 'bitrate' : bitrate - }) - del controller.device_config.config_rules[:] - controller.device_config.config_rules.append(ConfigRule(**json_config_rule)) - self.__task_executor.configure_device(controller) - results.append(True) - except Exception as e: # pylint: disable=broad-except - LOGGER.exception('Unable to SetEndpoint for Service({:s})'.format(str(service_uuid))) - results.append(e) - - return results - - @metered_subclass_method(METRICS_POOL) - def DeleteEndpoint( - self, endpoints : List[Tuple[str, str, Optional[str]]], connection_uuid : Optional[str] = None - ) -> List[Union[bool, Exception]]: - - chk_type('endpoints', endpoints, list) - if len(endpoints) < 2: return [] - - service_uuid = self.__service.service_id.service_uuid.uuid - settings = self.__settings_handler.get('/settings') - json_settings : Dict = {} if settings is None else settings.value - flow_id = json_settings.get('flow_id', 100) - bitrate = json_settings.get('bitrate', 1000) - - results = [] - try: - src_device_uuid, src_endpoint_uuid = get_device_endpoint_uuids(endpoints[0]) - src_device = self.__task_executor.get_device(DeviceId(**json_device_id(src_device_uuid))) - src_controller = self.__task_executor.get_device_controller(src_device) - if src_controller is None: src_controller = src_device - - dst_device_uuid, dst_endpoint_uuid = get_device_endpoint_uuids(endpoints[1]) - dst_device = self.__task_executor.get_device(DeviceId(**json_device_id(dst_device_uuid))) - dst_controller = self.__task_executor.get_device_controller(dst_device) - if dst_controller is None: dst_controller = dst_device - - controller = src_controller - - json_config_rule = json_config_rule_set('/services/service[{:s}]'.format(service_uuid), { - 'uuid' : service_uuid, - 'flow_id' : flow_id, - 'src_node' : src_endpoint_uuid, - 'dst_node' : dst_endpoint_uuid, - 'bitrate' : bitrate - }) - - del controller.device_config.config_rules[:] - controller.device_config.config_rules.append(ConfigRule(**json_config_rule)) - self.__task_executor.configure_device(controller) - results.append(True) - except Exception as e: # pylint: disable=broad-except - LOGGER.exception('Unable to DeleteEndpoint for Service({:s})'.format(str(service_uuid))) - results.append(e) - - return results - - @metered_subclass_method(METRICS_POOL) - def SetConstraint(self, constraints : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]: - chk_type('constraints', constraints, list) - if len(constraints) == 0: return [] - - msg = '[SetConstraint] Method not implemented. Constraints({:s}) are being ignored.' - LOGGER.warning(msg.format(str(constraints))) - return [True for _ in range(len(constraints))] - - @metered_subclass_method(METRICS_POOL) - def DeleteConstraint(self, constraints : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]: - chk_type('constraints', constraints, list) - if len(constraints) == 0: return [] - - msg = '[DeleteConstraint] Method not implemented. Constraints({:s}) are being ignored.' - LOGGER.warning(msg.format(str(constraints))) - return [True for _ in range(len(constraints))] - - @metered_subclass_method(METRICS_POOL) - def SetConfig(self, resources : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]: - chk_type('resources', resources, list) - if len(resources) == 0: return [] - - results = [] - for resource in resources: - try: - resource_value = json.loads(resource[1]) - self.__settings_handler.set(resource[0], resource_value) - results.append(True) - except Exception as e: # pylint: disable=broad-except - LOGGER.exception('Unable to SetConfig({:s})'.format(str(resource))) - results.append(e) - - return results - - @metered_subclass_method(METRICS_POOL) - def DeleteConfig(self, resources : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]: - chk_type('resources', resources, list) - if len(resources) == 0: return [] - - results = [] - for resource in resources: - try: - self.__settings_handler.delete(resource[0]) - except Exception as e: # pylint: disable=broad-except - LOGGER.exception('Unable to DeleteConfig({:s})'.format(str(resource))) - results.append(e) - - return results diff --git a/src/service/service/service_handlers/e2e_orch/__init__.py b/src/service/service/service_handlers/e2e_orch/__init__.py deleted file mode 100644 index 1549d9811..000000000 --- a/src/service/service/service_handlers/e2e_orch/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - diff --git a/src/tests/Fixtures.py b/src/tests/Fixtures.py index 78a470b54..55ef90340 100644 --- a/src/tests/Fixtures.py +++ b/src/tests/Fixtures.py @@ -16,16 +16,8 @@ import pytest from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from monitoring.client.MonitoringClient import MonitoringClient -from e2eorchestrator.client.E2EOrchestratorClient import E2EOrchestratorClient -from service.client.ServiceClient import ServiceClient -@pytest.fixture(scope='session') -def service_client(): - _client = ServiceClient() - yield _client - _client.close() - @pytest.fixture(scope='session') def context_client(): _client = ContextClient() @@ -44,8 +36,3 @@ def monitoring_client(): yield _client _client.close() -@pytest.fixture(scope='session') -def e2eorchestrator_client(): - _client = E2EOrchestratorClient() - yield _client - _client.close() diff --git a/src/tests/e2e_orchestrator/__init__.py b/src/tests/e2e_orchestrator/__init__.py deleted file mode 100644 index 1549d9811..000000000 --- a/src/tests/e2e_orchestrator/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - diff --git a/src/tests/e2e_orchestrator/deploy_specs.sh b/src/tests/e2e_orchestrator/deploy_specs.sh deleted file mode 100755 index e93841917..000000000 --- a/src/tests/e2e_orchestrator/deploy_specs.sh +++ /dev/null @@ -1,154 +0,0 @@ -#!/bin/bash -# 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. - - -# ----- TeraFlowSDN ------------------------------------------------------------ - -# Set the URL of the internal MicroK8s Docker registry where the images will be uploaded to. -export TFS_REGISTRY_IMAGES="http://localhost:32000/tfs/" - -# Set the list of components, separated by spaces, you want to build images for, and deploy. -#export TFS_COMPONENTS="context device pathcomp service slice nbi webui load_generator" -export TFS_COMPONENTS="context device pathcomp service slice nbi webui" - -# Uncomment to activate Monitoring -# export TFS_COMPONENTS="${TFS_COMPONENTS} monitoring" - -# Uncomment to activate ZTP and Policy Manager -#export TFS_COMPONENTS="${TFS_COMPONENTS} ztp policy" -# export TFS_COMPONENTS="${TFS_COMPONENTS} ztp" - -# Uncomment to activate Optical CyberSecurity -#export TFS_COMPONENTS="${TFS_COMPONENTS} dbscanserving opticalattackmitigator opticalattackdetector opticalattackmanager" - -# Uncomment to activate L3 CyberSecurity -#export TFS_COMPONENTS="${TFS_COMPONENTS} l3_attackmitigator l3_centralizedattackdetector" - -# Uncomment to activate TE -#export TFS_COMPONENTS="${TFS_COMPONENTS} te" - -# Uncomment to activate E2E_Orchestrator -export TFS_COMPONENTS="${TFS_COMPONENTS} e2eorchestrator" - - - -# Set the tag you want to use for your images. -export TFS_IMAGE_TAG="dev" - -# Set the name of the Kubernetes namespace to deploy TFS to. -export TFS_K8S_NAMESPACE="tfs" - -# Set additional manifest files to be applied after the deployment -export TFS_EXTRA_MANIFESTS="manifests/nginx_ingress_http.yaml" - -# Uncomment to monitor performance of components -export TFS_EXTRA_MANIFESTS="${TFS_EXTRA_MANIFESTS} manifests/servicemonitors.yaml" - -# Uncomment when deploying Optical CyberSecurity -#export TFS_EXTRA_MANIFESTS="${TFS_EXTRA_MANIFESTS} manifests/cachingservice.yaml" - -# Set the new Grafana admin password -export TFS_GRAFANA_PASSWORD="admin123+" - -# Disable skip-build flag to rebuild the Docker images. -export TFS_SKIP_BUILD="" - - -# ----- CockroachDB ------------------------------------------------------------ - -# Set the namespace where CockroackDB will be deployed. -export CRDB_NAMESPACE="crdb" - -# Set the external port CockroackDB Postgre SQL interface will be exposed to. -export CRDB_EXT_PORT_SQL="26257" - -# Set the external port CockroackDB HTTP Mgmt GUI interface will be exposed to. -export CRDB_EXT_PORT_HTTP="8081" - -# Set the database username to be used by Context. -export CRDB_USERNAME="tfs" - -# Set the database user's password to be used by Context. -export CRDB_PASSWORD="tfs123" - -# Set the database name to be used by Context. -export CRDB_DATABASE="tfs" - -# Set CockroachDB installation mode to 'single'. This option is convenient for development and testing. -# See ./deploy/all.sh or ./deploy/crdb.sh for additional details -export CRDB_DEPLOY_MODE="single" - -# Disable flag for dropping database, if it exists. -export CRDB_DROP_DATABASE_IF_EXISTS="YES" - -# Disable flag for re-deploying CockroachDB from scratch. -export CRDB_REDEPLOY="" - - -# ----- NATS ------------------------------------------------------------------- - -# Set the namespace where NATS will be deployed. -export NATS_NAMESPACE="nats" - -# Set the external port NATS Client interface will be exposed to. -export NATS_EXT_PORT_CLIENT="4222" - -# Set the external port NATS HTTP Mgmt GUI interface will be exposed to. -export NATS_EXT_PORT_HTTP="8222" - -# Disable flag for re-deploying NATS from scratch. -export NATS_REDEPLOY="" - - -# ----- QuestDB ---------------------------------------------------------------- - -# Set the namespace where QuestDB will be deployed. -export QDB_NAMESPACE="qdb" - -# Set the external port QuestDB Postgre SQL interface will be exposed to. -export QDB_EXT_PORT_SQL="8812" - -# Set the external port QuestDB Influx Line Protocol interface will be exposed to. -export QDB_EXT_PORT_ILP="9009" - -# Set the external port QuestDB HTTP Mgmt GUI interface will be exposed to. -export QDB_EXT_PORT_HTTP="9000" - -# Set the database username to be used for QuestDB. -export QDB_USERNAME="admin" - -# Set the database user's password to be used for QuestDB. -export QDB_PASSWORD="quest" - -# Set the table name to be used by Monitoring for KPIs. -export QDB_TABLE_MONITORING_KPIS="tfs_monitoring_kpis" - -# Set the table name to be used by Slice for plotting groups. -export QDB_TABLE_SLICE_GROUPS="tfs_slice_groups" - -# Disable flag for dropping tables if they exist. -export QDB_DROP_TABLES_IF_EXIST="YES" - -# Disable flag for re-deploying QuestDB from scratch. -export QDB_REDEPLOY="" - - -# ----- K8s Observability ------------------------------------------------------ - -# Set the external port Prometheus Mgmt HTTP GUI interface will be exposed to. -export PROM_EXT_PORT_HTTP="9090" - -# Set the external port Grafana HTTP Dashboards will be exposed to. -export GRAF_EXT_PORT_HTTP="3000" diff --git a/src/tests/e2e_orchestrator/descriptors_emulated.json b/src/tests/e2e_orchestrator/descriptors_emulated.json deleted file mode 100644 index a2918ace9..000000000 --- a/src/tests/e2e_orchestrator/descriptors_emulated.json +++ /dev/null @@ -1,250 +0,0 @@ -{ - "contexts": [ - { - "context_id": {"context_uuid": {"uuid": "admin"}}, - "topology_ids": [], "service_ids": [] - } - ], - "topologies": [ - { - "topology_id": { - "context_id": {"context_uuid": {"uuid": "admin"}}, - "topology_uuid": {"uuid": "admin"} - }, - "device_ids": [ - {"device_uuid": {"uuid": "R1"}}, - {"device_uuid": {"uuid": "R2"}}, - {"device_uuid": {"uuid": "T1"}}, - {"device_uuid": {"uuid": "T2"}}, - {"device_uuid": {"uuid": "M1"}}, - {"device_uuid": {"uuid": "M2"}} - ], - "link_ids": [ - {"link_uuid": {"uuid": "R1==T1"}}, - {"link_uuid": {"uuid": "T1==R1"}}, - {"link_uuid": {"uuid": "R2==T2"}}, - {"link_uuid": {"uuid": "T2==R2"}}, - - {"link_uuid": {"uuid": "T1==M1"}}, - {"link_uuid": {"uuid": "M1==T1"}}, - {"link_uuid": {"uuid": "T2==M2"}}, - {"link_uuid": {"uuid": "M2==T2"}}, - - {"link_uuid": {"uuid": "M1==M2"}}, - {"link_uuid": {"uuid": "M2==M1"}} - - - ] - } - ], - "devices": [ - { - "device_id": {"device_uuid": {"uuid": "R1"}}, "device_type": "emu-packet-router", "device_drivers": [0], - "device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [ - {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, - {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}}, - {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ - {"sample_types": [], "type": "copper", "uuid": "1/1"}, - {"sample_types": [], "type": "copper", "uuid": "1/2"}, - {"sample_types": [], "type": "copper", "uuid": "1/3"}, - {"sample_types": [], "type": "copper", "uuid": "1/4"}, - {"sample_types": [], "type": "copper", "uuid": "2/1"}, - {"sample_types": [], "type": "copper", "uuid": "2/2"}, - {"sample_types": [], "type": "copper", "uuid": "2/3"}, - {"sample_types": [], "type": "copper", "uuid": "2/4"}, - {"sample_types": [], "type": "copper", "uuid": "3/1"}, - {"sample_types": [], "type": "copper", "uuid": "3/2"}, - {"sample_types": [], "type": "copper", "uuid": "3/3"}, - {"sample_types": [], "type": "copper", "uuid": "3/4"} - ]}}} - ]} - }, - { - "device_id": {"device_uuid": {"uuid": "R2"}}, "device_type": "emu-packet-router", "device_drivers": [0], - "device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [ - {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, - {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}}, - {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ - {"sample_types": [], "type": "copper", "uuid": "1/1"}, - {"sample_types": [], "type": "copper", "uuid": "1/2"}, - {"sample_types": [], "type": "copper", "uuid": "1/3"}, - {"sample_types": [], "type": "copper", "uuid": "1/4"}, - {"sample_types": [], "type": "copper", "uuid": "2/1"}, - {"sample_types": [], "type": "copper", "uuid": "2/2"}, - {"sample_types": [], "type": "copper", "uuid": "2/3"}, - {"sample_types": [], "type": "copper", "uuid": "2/4"}, - {"sample_types": [], "type": "copper", "uuid": "3/1"}, - {"sample_types": [], "type": "copper", "uuid": "3/2"}, - {"sample_types": [], "type": "copper", "uuid": "3/3"}, - {"sample_types": [], "type": "copper", "uuid": "3/4"} - ]}}} - ]} - }, - { - "device_id": {"device_uuid": {"uuid": "T1"}}, "device_type": "emu-optical-transponder", "device_drivers": [0], - "device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [ - {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, - {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}}, - {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ - {"sample_types": [], "type": "copper", "uuid": "1/1"}, - {"sample_types": [], "type": "copper", "uuid": "1/2"}, - {"sample_types": [], "type": "copper", "uuid": "1/3"}, - {"sample_types": [], "type": "copper", "uuid": "1/4"}, - {"sample_types": [], "type": "copper", "uuid": "2/1"}, - {"sample_types": [], "type": "copper", "uuid": "2/2"}, - {"sample_types": [], "type": "copper", "uuid": "2/3"}, - {"sample_types": [], "type": "copper", "uuid": "2/4"}, - {"sample_types": [], "type": "copper", "uuid": "3/1"}, - {"sample_types": [], "type": "copper", "uuid": "3/2"}, - {"sample_types": [], "type": "copper", "uuid": "3/3"}, - {"sample_types": [], "type": "copper", "uuid": "3/4"} - ]}}} - ]} - }, - { - "device_id": {"device_uuid": {"uuid": "T2"}}, "device_type": "emu-optical-transponder", "device_drivers": [0], - "device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [ - {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, - {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}}, - {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ - {"sample_types": [], "type": "copper", "uuid": "1/1"}, - {"sample_types": [], "type": "copper", "uuid": "1/2"}, - {"sample_types": [], "type": "copper", "uuid": "1/3"}, - {"sample_types": [], "type": "copper", "uuid": "1/4"}, - {"sample_types": [], "type": "copper", "uuid": "2/1"}, - {"sample_types": [], "type": "copper", "uuid": "2/2"}, - {"sample_types": [], "type": "copper", "uuid": "2/3"}, - {"sample_types": [], "type": "copper", "uuid": "2/4"}, - {"sample_types": [], "type": "copper", "uuid": "3/1"}, - {"sample_types": [], "type": "copper", "uuid": "3/2"}, - {"sample_types": [], "type": "copper", "uuid": "3/3"}, - {"sample_types": [], "type": "copper", "uuid": "3/4"} - ]}}} - ]} - }, - - { - "device_id": {"device_uuid": {"uuid": "M1"}}, "device_type": "emu-optical-roadm", "device_drivers": [0], - "device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [ - {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, - {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}}, - {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ - {"sample_types": [], "type": "copper", "uuid": "1/1"}, - {"sample_types": [], "type": "copper", "uuid": "1/2"}, - {"sample_types": [], "type": "copper", "uuid": "1/3"}, - {"sample_types": [], "type": "copper", "uuid": "1/4"}, - {"sample_types": [], "type": "copper", "uuid": "2/1"}, - {"sample_types": [], "type": "copper", "uuid": "2/2"}, - {"sample_types": [], "type": "copper", "uuid": "2/3"}, - {"sample_types": [], "type": "copper", "uuid": "2/4"}, - {"sample_types": [], "type": "copper", "uuid": "3/1"}, - {"sample_types": [], "type": "copper", "uuid": "3/2"}, - {"sample_types": [], "type": "copper", "uuid": "3/3"}, - {"sample_types": [], "type": "copper", "uuid": "3/4"} - ]}}} - ]} - }, - - - { - "device_id": {"device_uuid": {"uuid": "M2"}}, "device_type": "emu-optical-roadm", "device_drivers": [0], - "device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [ - {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, - {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}}, - {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ - {"sample_types": [], "type": "copper", "uuid": "1/1"}, - {"sample_types": [], "type": "copper", "uuid": "1/2"}, - {"sample_types": [], "type": "copper", "uuid": "1/3"}, - {"sample_types": [], "type": "copper", "uuid": "1/4"}, - {"sample_types": [], "type": "copper", "uuid": "2/1"}, - {"sample_types": [], "type": "copper", "uuid": "2/2"}, - {"sample_types": [], "type": "copper", "uuid": "2/3"}, - {"sample_types": [], "type": "copper", "uuid": "2/4"}, - {"sample_types": [], "type": "copper", "uuid": "3/1"}, - {"sample_types": [], "type": "copper", "uuid": "3/2"}, - {"sample_types": [], "type": "copper", "uuid": "3/3"}, - {"sample_types": [], "type": "copper", "uuid": "3/4"} - ]}}} - ]} - } - - - ], - "links": [ - { - "link_id": {"link_uuid": {"uuid": "R1==T1"}}, - "link_endpoint_ids": [ - {"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "1/1"}}, - {"device_id": {"device_uuid": {"uuid": "T1"}}, "endpoint_uuid": {"uuid": "1/1"}} - ] - }, - { - "link_id": {"link_uuid": {"uuid": "T1==R1"}}, - "link_endpoint_ids": [ - {"device_id": {"device_uuid": {"uuid": "T1"}}, "endpoint_uuid": {"uuid": "1/1"}}, - {"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "1/1"}} - ] - }, - { - "link_id": {"link_uuid": {"uuid": "R2==T2"}}, - "link_endpoint_ids": [ - {"device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "1/2"}}, - {"device_id": {"device_uuid": {"uuid": "T2"}}, "endpoint_uuid": {"uuid": "1/2"}} - ] - }, - { - "link_id": {"link_uuid": {"uuid": "T2==R2"}}, - "link_endpoint_ids": [ - {"device_id": {"device_uuid": {"uuid": "T2"}}, "endpoint_uuid": {"uuid": "1/2"}}, - {"device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "1/2"}} - ] - }, - - - { - "link_id": {"link_uuid": {"uuid": "T1==M1"}}, - "link_endpoint_ids": [ - {"device_id": {"device_uuid": {"uuid": "T1"}}, "endpoint_uuid": {"uuid": "2/1"}}, - {"device_id": {"device_uuid": {"uuid": "M1"}}, "endpoint_uuid": {"uuid": "2/1"}} - ] - }, - { - "link_id": {"link_uuid": {"uuid": "M1==T1"}}, - "link_endpoint_ids": [ - {"device_id": {"device_uuid": {"uuid": "M1"}}, "endpoint_uuid": {"uuid": "2/1"}}, - {"device_id": {"device_uuid": {"uuid": "T1"}}, "endpoint_uuid": {"uuid": "2/1"}} - ] - }, - - { - "link_id": {"link_uuid": {"uuid": "T2==M2"}}, - "link_endpoint_ids": [ - {"device_id": {"device_uuid": {"uuid": "T2"}}, "endpoint_uuid": {"uuid": "2/2"}}, - {"device_id": {"device_uuid": {"uuid": "M2"}}, "endpoint_uuid": {"uuid": "2/2"}} - ] - }, - { - "link_id": {"link_uuid": {"uuid": "M2==T2"}}, - "link_endpoint_ids": [ - {"device_id": {"device_uuid": {"uuid": "M2"}}, "endpoint_uuid": {"uuid": "2/2"}}, - {"device_id": {"device_uuid": {"uuid": "T2"}}, "endpoint_uuid": {"uuid": "2/2"}} - ] - }, - - { - "link_id": {"link_uuid": {"uuid": "M1==M2"}}, - "link_endpoint_ids": [ - {"device_id": {"device_uuid": {"uuid": "M1"}}, "endpoint_uuid": {"uuid": "3/1"}}, - {"device_id": {"device_uuid": {"uuid": "M2"}}, "endpoint_uuid": {"uuid": "3/1"}} - ] - }, - { - "link_id": {"link_uuid": {"uuid": "M2==M1"}}, - "link_endpoint_ids": [ - {"device_id": {"device_uuid": {"uuid": "M2"}}, "endpoint_uuid": {"uuid": "3/1"}}, - {"device_id": {"device_uuid": {"uuid": "M1"}}, "endpoint_uuid": {"uuid": "3/1"}} - ] - } - - ] -} \ No newline at end of file diff --git a/src/tests/e2e_orchestrator/redeploy.sh b/src/tests/e2e_orchestrator/redeploy.sh deleted file mode 100755 index 5e8519926..000000000 --- a/src/tests/e2e_orchestrator/redeploy.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# 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. - -source e2e_orchestrator/deploy_specs.sh -./deploy/all.sh -source tfs_runtime_env_vars.sh diff --git a/src/tests/e2e_orchestrator/run_test_01_bootstrap.sh b/src/tests/e2e_orchestrator/run_test_01_bootstrap.sh deleted file mode 100755 index 78c76def8..000000000 --- a/src/tests/e2e_orchestrator/run_test_01_bootstrap.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# 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. - -source tfs_runtime_env_vars.sh -pytest --verbose --log-level=INFO src/tests/e2e_orchestrator/tests/test_functional_bootstrap.py diff --git a/src/tests/e2e_orchestrator/run_test_02_compute_path.sh b/src/tests/e2e_orchestrator/run_test_02_compute_path.sh deleted file mode 100755 index 83191464a..000000000 --- a/src/tests/e2e_orchestrator/run_test_02_compute_path.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# 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. - -source tfs_runtime_env_vars.sh -pytest --verbose --log-level=INFO src/tests/e2e_orchestrator/tests/test_functional_compute_path.py diff --git a/src/tests/e2e_orchestrator/run_test_03_cleanup.sh b/src/tests/e2e_orchestrator/run_test_03_cleanup.sh deleted file mode 100755 index f3ab6c68d..000000000 --- a/src/tests/e2e_orchestrator/run_test_03_cleanup.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# 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. - -source tfs_runtime_env_vars.sh -pytest --verbose --log-level=INFO src/tests/e2e_orchestrator/tests/test_functional_cleanup.py diff --git a/src/tests/e2e_orchestrator/run_tests.sh b/src/tests/e2e_orchestrator/run_tests.sh deleted file mode 100755 index 2c177259a..000000000 --- a/src/tests/e2e_orchestrator/run_tests.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# 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. - -# Run functional tests -source tfs_runtime_env_vars.sh -pytest --verbose --log-level=INFO src/tests/e2e_orchestrator/tests/test_functional_bootstrap.py -pytest --verbose --log-level=INFO src/tests/e2e_orchestrator/tests/test_functional_compute_path.py -pytest --verbose --log-level=INFO src/tests/e2e_orchestrator/tests/test_functional_cleanup.py diff --git a/src/tests/e2e_orchestrator/tests/Fixtures.py b/src/tests/e2e_orchestrator/tests/Fixtures.py deleted file mode 100644 index 38d04994f..000000000 --- a/src/tests/e2e_orchestrator/tests/Fixtures.py +++ /dev/null @@ -1,13 +0,0 @@ -# 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. diff --git a/src/tests/e2e_orchestrator/tests/Objects.py b/src/tests/e2e_orchestrator/tests/Objects.py deleted file mode 100644 index 1748efec9..000000000 --- a/src/tests/e2e_orchestrator/tests/Objects.py +++ /dev/null @@ -1,60 +0,0 @@ -# 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. - -import os -from typing import Dict, List, Tuple -from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME -from common.tools.object_factory.Context import json_context, json_context_id -from common.tools.object_factory.Device import ( - json_device_connect_rules, json_device_emulated_connect_rules, json_device_emulated_packet_router_disabled, - json_device_connect_rules, json_device_id, json_device_p4_disabled, - json_device_emulated_tapi_disabled, json_device_id, json_device_packetrouter_disabled, json_device_tapi_disabled) -from common.tools.object_factory.Service import ( - get_service_uuid, json_service_l3nm_planned,json_service_p4_planned) -from common.tools.object_factory.ConfigRule import ( - json_config_rule_set, json_config_rule_delete) -from common.tools.object_factory.EndPoint import json_endpoint, json_endpoint_ids, json_endpoints, json_endpoint_id -from common.tools.object_factory.EndPoint import json_endpoint_descriptor - - - -DEVICE_R1_UUID = 'R1' -DEVICE_R2_UUID = 'R2' - -DEVICE_R1_ID = json_device_id(DEVICE_R1_UUID) -DEVICE_R1_ENDPOINT_DEFS = [json_endpoint_descriptor('2/2', 'port')] -DEVICE_R2_ID = json_device_id(DEVICE_R2_UUID) -DEVICE_R2_ENDPOINT_DEFS = [json_endpoint_descriptor('2/2', 'port')] - -DEVICE_R1_ENDPOINTS = json_endpoints(DEVICE_R1_ID, DEVICE_R1_ENDPOINT_DEFS) -DEVICE_R2_ENDPOINTS = json_endpoints(DEVICE_R2_ID, DEVICE_R2_ENDPOINT_DEFS) - - -DEVICE_R1_ENDPOINT_IDS = json_endpoint_ids(DEVICE_R1_ID, DEVICE_R1_ENDPOINT_DEFS) -ENDPOINT_ID_R1 = DEVICE_R1_ENDPOINTS[0]['endpoint_id'] -DEVICE_R2_ENDPOINT_IDS = json_endpoint_ids(DEVICE_R2_ID, DEVICE_R2_ENDPOINT_DEFS) -ENDPOINT_ID_R2 = DEVICE_R2_ENDPOINTS[0]['endpoint_id'] - - -# ----- Service ---------------------------------------------------------------------------------------------------------- - - -SERVICE_R1_R2_UUID = get_service_uuid(ENDPOINT_ID_R1, ENDPOINT_ID_R2) -SERVICE_R1_R2 = json_service_p4_planned(SERVICE_R1_R2_UUID) -SERVICE_R1_R2_ENDPOINT_IDS = [DEVICE_R1_ENDPOINT_IDS[0], DEVICE_R2_ENDPOINT_IDS[0]] - - -SERVICES = [ - (SERVICE_R1_R2, SERVICE_R1_R2_ENDPOINT_IDS) -] diff --git a/src/tests/e2e_orchestrator/tests/__init__.py b/src/tests/e2e_orchestrator/tests/__init__.py deleted file mode 100644 index 1549d9811..000000000 --- a/src/tests/e2e_orchestrator/tests/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - diff --git a/src/tests/e2e_orchestrator/tests/test_functional_bootstrap.py b/src/tests/e2e_orchestrator/tests/test_functional_bootstrap.py deleted file mode 100644 index 36c3b0918..000000000 --- a/src/tests/e2e_orchestrator/tests/test_functional_bootstrap.py +++ /dev/null @@ -1,72 +0,0 @@ -# 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. - -import logging, time -from common.Constants import DEFAULT_CONTEXT_NAME -from common.proto.context_pb2 import ContextId, DeviceOperationalStatusEnum, Empty -from common.proto.monitoring_pb2 import KpiDescriptorList -from common.tools.descriptor.Loader import DescriptorLoader, check_descriptor_load_results, validate_empty_scenario -from common.tools.object_factory.Context import json_context_id -from context.client.ContextClient import ContextClient -from device.client.DeviceClient import DeviceClient -from monitoring.client.MonitoringClient import MonitoringClient -from tests.Fixtures import context_client, device_client, monitoring_client # pylint: disable=unused-import - -LOGGER = logging.getLogger(__name__) -LOGGER.setLevel(logging.DEBUG) - -DESCRIPTOR_FILE = 'src/tests/e2e_orchestrator/descriptors_emulated.json' -ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_NAME)) - -def test_scenario_bootstrap( - context_client : ContextClient, # pylint: disable=redefined-outer-name - device_client : DeviceClient, # pylint: disable=redefined-outer-name -) -> None: - LOGGER.info(context_client) - validate_empty_scenario(context_client) - - descriptor_loader = DescriptorLoader( - descriptors_file=DESCRIPTOR_FILE, context_client=context_client, device_client=device_client) - results = descriptor_loader.process() - check_descriptor_load_results(results, descriptor_loader) - descriptor_loader.validate() - - # Verify the scenario has no services/slices - response = context_client.GetContext(ADMIN_CONTEXT_ID) - assert len(response.service_ids) == 0 - assert len(response.slice_ids) == 0 - -def test_scenario_devices_enabled( - context_client : ContextClient, # pylint: disable=redefined-outer-name -) -> None: - """ - This test validates that the devices are enabled. - """ - DEVICE_OP_STATUS_ENABLED = DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED - - num_devices = -1 - num_devices_enabled, num_retry = 0, 0 - while (num_devices != num_devices_enabled) and (num_retry < 1): - time.sleep(1.0) - response = context_client.ListDevices(Empty()) - num_devices = len(response.devices) - num_devices_enabled = 0 - for device in response.devices: - if device.device_operational_status != DEVICE_OP_STATUS_ENABLED: continue - num_devices_enabled += 1 - LOGGER.info('Num Devices enabled: {:d}/{:d}'.format(num_devices_enabled, num_devices)) - num_retry += 1 - assert num_devices_enabled == num_devices - - diff --git a/src/tests/e2e_orchestrator/tests/test_functional_cleanup.py b/src/tests/e2e_orchestrator/tests/test_functional_cleanup.py deleted file mode 100644 index e661e177c..000000000 --- a/src/tests/e2e_orchestrator/tests/test_functional_cleanup.py +++ /dev/null @@ -1,44 +0,0 @@ -# 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. - -import logging -from common.Constants import DEFAULT_CONTEXT_NAME -from common.proto.context_pb2 import ContextId -from common.tools.descriptor.Loader import DescriptorLoader, validate_empty_scenario -from common.tools.object_factory.Context import json_context_id -from context.client.ContextClient import ContextClient -from device.client.DeviceClient import DeviceClient -from tests.Fixtures import context_client, device_client # pylint: disable=unused-import - -LOGGER = logging.getLogger(__name__) -LOGGER.setLevel(logging.DEBUG) - -DESCRIPTOR_FILE = 'src/tests/e2e_orchestrator/descriptors_emulated.json' -ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_NAME)) - -def test_scenario_cleanup( - context_client : ContextClient, # pylint: disable=redefined-outer-name - device_client : DeviceClient, # pylint: disable=redefined-outer-name -) -> None: - # Verify the scenario has no services/slices - response = context_client.GetContext(ADMIN_CONTEXT_ID) - assert len(response.service_ids) == 0 - assert len(response.slice_ids) == 0 - - # Load descriptors and validate the base scenario - descriptor_loader = DescriptorLoader( - descriptors_file=DESCRIPTOR_FILE, context_client=context_client, device_client=device_client) - descriptor_loader.validate() - descriptor_loader.unload() - validate_empty_scenario(context_client) diff --git a/src/tests/e2e_orchestrator/tests/test_functional_compute_path.py b/src/tests/e2e_orchestrator/tests/test_functional_compute_path.py deleted file mode 100644 index e95a325aa..000000000 --- a/src/tests/e2e_orchestrator/tests/test_functional_compute_path.py +++ /dev/null @@ -1,65 +0,0 @@ -# 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. - -import logging, random -from common.Constants import DEFAULT_CONTEXT_NAME -from common.proto.context_pb2 import ContextId, Empty, ServiceTypeEnum, Service -from common.proto.e2eorchestrator_pb2 import E2EOrchestratorRequest -from common.proto.kpi_sample_types_pb2 import KpiSampleType -from common.tools.descriptor.Loader import DescriptorLoader -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 service.client.ServiceClient import ServiceClient -from tests.Fixtures import service_client, context_client, e2eorchestrator_client # pylint: disable=unused-import -from e2eorchestrator.client.E2EOrchestratorClient import E2EOrchestratorClient -from .Objects import SERVICES -import copy - -LOGGER = logging.getLogger(__name__) -LOGGER.setLevel(logging.DEBUG) - -DESCRIPTOR_FILE = 'src/tests/e2e_orchestrator/descriptors_emulated.json' -ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_NAME)) - - -def test_orchestration(service_client : ServiceClient, context_client : ContextClient, e2eorchestrator_client : E2EOrchestratorClient): # pylint: disable=redefined-outer-name - # Load descriptors and validate the base scenario - descriptor_loader = DescriptorLoader(descriptors_file=DESCRIPTOR_FILE, context_client=context_client) - descriptor_loader.validate() - - # Verify the scenario has no services/slices - response = context_client.GetContext(ADMIN_CONTEXT_ID) - assert len(response.service_ids) == 0 - assert len(response.slice_ids) == 0 - - # Create Connectivity Service - - - # ----- Create Services --------------------------------------------------------------- - for service, endpoints in SERVICES: - LOGGER.info(service) - # Insert Service (table entries) - service_uuid = service['service_id']['service_uuid']['uuid'] - print('Creating Service {:s}'.format(service_uuid)) - service_p4 = copy.deepcopy(service) - # service_client.CreateService(Service(**service_p4)) - LOGGER.info(type(service_p4)) - service_p4['service_endpoint_ids'].extend(endpoints) - # service_client.UpdateService(Service(**service_p4)) - request = E2EOrchestratorRequest() - request.service.MergeFrom(Service(**service_p4)) - reply = e2eorchestrator_client.Compute(request) - LOGGER.info(reply) - -- GitLab From f8d7deb154b3162d0899125100dc38e548f6e729 Mon Sep 17 00:00:00 2001 From: Carlos Manso Date: Thu, 21 Dec 2023 12:02:43 +0100 Subject: [PATCH 6/6] sbi_flexscale --- my_deploy.sh | 2 +- proto/context.proto | 611 ++++++++++++++++++ .../drivers/flexscale/FlexScaleDriver.py | 6 +- src/device/service/drivers/flexscale/Tools.py | 81 +-- .../drivers/ietf_l2vpn/TfsDebugApiClient.py | 1 - .../service/service_handlers/__init__.py | 1 - src/tests/Fixtures.py | 1 - .../tools/mock_flexscale_opt_ctrl/test_mw.py | 84 --- 8 files changed, 629 insertions(+), 158 deletions(-) create mode 100644 proto/context.proto delete mode 100644 src/tests/tools/mock_flexscale_opt_ctrl/test_mw.py diff --git a/my_deploy.sh b/my_deploy.sh index f1f2d580f..0fcb51f90 100755 --- a/my_deploy.sh +++ b/my_deploy.sh @@ -44,7 +44,7 @@ export TFS_COMPONENTS="context device pathcomp service slice nbi webui load_gene #export TFS_COMPONENTS="${TFS_COMPONENTS} forecaster" # Uncomment to activate E2E Orchestrator -#export TFS_COMPONENTS="${TFS_COMPONENTS} e2eorchestrator" +#export TFS_COMPONENTS="${TFS_COMPONENTS} e2e_orchestrator" # Set the tag you want to use for your images. export TFS_IMAGE_TAG="dev" diff --git a/proto/context.proto b/proto/context.proto new file mode 100644 index 000000000..3ccc13ab1 --- /dev/null +++ b/proto/context.proto @@ -0,0 +1,611 @@ +// 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. + +syntax = "proto3"; +package context; + +import "acl.proto"; +import "kpi_sample_types.proto"; + +service ContextService { + rpc ListContextIds (Empty ) returns ( ContextIdList ) {} + rpc ListContexts (Empty ) returns ( ContextList ) {} + rpc GetContext (ContextId ) returns ( Context ) {} + rpc SetContext (Context ) returns ( ContextId ) {} + rpc RemoveContext (ContextId ) returns ( Empty ) {} + rpc GetContextEvents (Empty ) returns (stream ContextEvent ) {} + + rpc ListTopologyIds (ContextId ) returns ( TopologyIdList ) {} + rpc ListTopologies (ContextId ) returns ( TopologyList ) {} + rpc GetTopology (TopologyId ) returns ( Topology ) {} + rpc GetTopologyDetails (TopologyId ) returns ( TopologyDetails ) {} + rpc SetTopology (Topology ) returns ( TopologyId ) {} + rpc RemoveTopology (TopologyId ) returns ( Empty ) {} + rpc GetTopologyEvents (Empty ) returns (stream TopologyEvent ) {} + + rpc ListDeviceIds (Empty ) returns ( DeviceIdList ) {} + rpc ListDevices (Empty ) returns ( DeviceList ) {} + rpc GetDevice (DeviceId ) returns ( Device ) {} + rpc SetDevice (Device ) returns ( DeviceId ) {} + rpc RemoveDevice (DeviceId ) returns ( Empty ) {} + rpc GetDeviceEvents (Empty ) returns (stream DeviceEvent ) {} + rpc SelectDevice (DeviceFilter ) returns ( DeviceList ) {} + rpc ListEndPointNames (EndPointIdList) returns ( EndPointNameList) {} + + rpc ListLinkIds (Empty ) returns ( LinkIdList ) {} + rpc ListLinks (Empty ) returns ( LinkList ) {} + rpc GetLink (LinkId ) returns ( Link ) {} + rpc SetLink (Link ) returns ( LinkId ) {} + rpc RemoveLink (LinkId ) returns ( Empty ) {} + rpc GetLinkEvents (Empty ) returns (stream LinkEvent ) {} + + rpc ListServiceIds (ContextId ) returns ( ServiceIdList ) {} + rpc ListServices (ContextId ) returns ( ServiceList ) {} + rpc GetService (ServiceId ) returns ( Service ) {} + rpc SetService (Service ) returns ( ServiceId ) {} + rpc UnsetService (Service ) returns ( ServiceId ) {} + rpc RemoveService (ServiceId ) returns ( Empty ) {} + rpc GetServiceEvents (Empty ) returns (stream ServiceEvent ) {} + rpc SelectService (ServiceFilter ) returns ( ServiceList ) {} + + rpc ListSliceIds (ContextId ) returns ( SliceIdList ) {} + rpc ListSlices (ContextId ) returns ( SliceList ) {} + rpc GetSlice (SliceId ) returns ( Slice ) {} + rpc SetSlice (Slice ) returns ( SliceId ) {} + rpc UnsetSlice (Slice ) returns ( SliceId ) {} + rpc RemoveSlice (SliceId ) returns ( Empty ) {} + rpc GetSliceEvents (Empty ) returns (stream SliceEvent ) {} + rpc SelectSlice (SliceFilter ) returns ( SliceList ) {} + + rpc ListConnectionIds (ServiceId ) returns ( ConnectionIdList) {} + rpc ListConnections (ServiceId ) returns ( ConnectionList ) {} + rpc GetConnection (ConnectionId ) returns ( Connection ) {} + rpc SetConnection (Connection ) returns ( ConnectionId ) {} + rpc RemoveConnection (ConnectionId ) returns ( Empty ) {} + rpc GetConnectionEvents(Empty ) returns (stream ConnectionEvent ) {} +} + +// ----- Generic ------------------------------------------------------------------------------------------------------- +message Empty {} + +message Uuid { + string uuid = 1; +} + +enum EventTypeEnum { + EVENTTYPE_UNDEFINED = 0; + EVENTTYPE_CREATE = 1; + EVENTTYPE_UPDATE = 2; + EVENTTYPE_REMOVE = 3; +} + +message Timestamp { + double timestamp = 1; +} + +message Event { + Timestamp timestamp = 1; + EventTypeEnum event_type = 2; +} + +// ----- Context ------------------------------------------------------------------------------------------------------- +message ContextId { + Uuid context_uuid = 1; +} + +message Context { + ContextId context_id = 1; + string name = 2; + repeated TopologyId topology_ids = 3; + repeated ServiceId service_ids = 4; + repeated SliceId slice_ids = 5; + TeraFlowController controller = 6; +} + +message ContextIdList { + repeated ContextId context_ids = 1; +} + +message ContextList { + repeated Context contexts = 1; +} + +message ContextEvent { + Event event = 1; + ContextId context_id = 2; +} + + +// ----- Topology ------------------------------------------------------------------------------------------------------ +message TopologyId { + ContextId context_id = 1; + Uuid topology_uuid = 2; +} + +message Topology { + TopologyId topology_id = 1; + string name = 2; + repeated DeviceId device_ids = 3; + repeated LinkId link_ids = 4; +} + +message TopologyDetails { + TopologyId topology_id = 1; + string name = 2; + repeated Device devices = 3; + repeated Link links = 4; +} + +message TopologyIdList { + repeated TopologyId topology_ids = 1; +} + +message TopologyList { + repeated Topology topologies = 1; +} + +message TopologyEvent { + Event event = 1; + TopologyId topology_id = 2; +} + + +// ----- Device -------------------------------------------------------------------------------------------------------- +message DeviceId { + Uuid device_uuid = 1; +} + +message Device { + DeviceId device_id = 1; + string name = 2; + string device_type = 3; + DeviceConfig device_config = 4; + DeviceOperationalStatusEnum device_operational_status = 5; + repeated DeviceDriverEnum device_drivers = 6; + repeated EndPoint device_endpoints = 7; + repeated Component components = 8; // Used for inventory + DeviceId controller_id = 9; // Identifier of node controlling the actual device +} + +message Component { //Defined previously to this section - Tested OK + Uuid component_uuid = 1; + string name = 2; + string type = 3; + + map attributes = 4; // dict[attr.name => json.dumps(attr.value)] + string parent = 5; +} + +message DeviceConfig { + repeated ConfigRule config_rules = 1; +} + +enum DeviceDriverEnum { + DEVICEDRIVER_UNDEFINED = 0; // also used for emulated + DEVICEDRIVER_OPENCONFIG = 1; + DEVICEDRIVER_TRANSPORT_API = 2; + DEVICEDRIVER_P4 = 3; + DEVICEDRIVER_IETF_NETWORK_TOPOLOGY = 4; + DEVICEDRIVER_ONF_TR_532 = 5; + DEVICEDRIVER_XR = 6; + DEVICEDRIVER_IETF_L2VPN = 7; + DEVICEDRIVER_GNMI_OPENCONFIG = 8; +} + +enum DeviceOperationalStatusEnum { + DEVICEOPERATIONALSTATUS_UNDEFINED = 0; + DEVICEOPERATIONALSTATUS_DISABLED = 1; + DEVICEOPERATIONALSTATUS_ENABLED = 2; +} + +message DeviceIdList { + repeated DeviceId device_ids = 1; +} + +message DeviceList { + repeated Device devices = 1; +} + +message DeviceFilter { + DeviceIdList device_ids = 1; + bool include_endpoints = 2; + bool include_config_rules = 3; + bool include_components = 4; +} + +message DeviceEvent { + Event event = 1; + DeviceId device_id = 2; + DeviceConfig device_config = 3; +} + + +// ----- Link ---------------------------------------------------------------------------------------------------------- +message LinkId { + Uuid link_uuid = 1; +} + +message LinkAttributes { + float total_capacity_gbps = 1; + float used_capacity_gbps = 2; +} + +message Link { + LinkId link_id = 1; + string name = 2; + repeated EndPointId link_endpoint_ids = 3; + LinkAttributes attributes = 4; +} + +message LinkIdList { + repeated LinkId link_ids = 1; +} + +message LinkList { + repeated Link links = 1; +} + +message LinkEvent { + Event event = 1; + LinkId link_id = 2; +} + + +// ----- Service ------------------------------------------------------------------------------------------------------- +message ServiceId { + ContextId context_id = 1; + Uuid service_uuid = 2; +} + +message Service { + ServiceId service_id = 1; + string name = 2; + ServiceTypeEnum service_type = 3; + repeated EndPointId service_endpoint_ids = 4; + repeated Constraint service_constraints = 5; + ServiceStatus service_status = 6; + ServiceConfig service_config = 7; + Timestamp timestamp = 8; +} + +enum ServiceTypeEnum { + SERVICETYPE_UNKNOWN = 0; + SERVICETYPE_L3NM = 1; + SERVICETYPE_L2NM = 2; + SERVICETYPE_TAPI_CONNECTIVITY_SERVICE = 3; + SERVICETYPE_TE = 4; +} + +enum ServiceStatusEnum { + SERVICESTATUS_UNDEFINED = 0; + SERVICESTATUS_PLANNED = 1; + SERVICESTATUS_ACTIVE = 2; + SERVICESTATUS_UPDATING = 3; + SERVICESTATUS_PENDING_REMOVAL = 4; + SERVICESTATUS_SLA_VIOLATED = 5; +} + +message ServiceStatus { + ServiceStatusEnum service_status = 1; +} + +message ServiceConfig { + repeated ConfigRule config_rules = 1; +} + +message ServiceIdList { + repeated ServiceId service_ids = 1; +} + +message ServiceList { + repeated Service services = 1; +} + +message ServiceFilter { + ServiceIdList service_ids = 1; + bool include_endpoint_ids = 2; + bool include_constraints = 3; + bool include_config_rules = 4; +} + +message ServiceEvent { + Event event = 1; + ServiceId service_id = 2; +} + +// ----- Slice --------------------------------------------------------------------------------------------------------- +message SliceId { + ContextId context_id = 1; + Uuid slice_uuid = 2; +} + +message Slice { + SliceId slice_id = 1; + string name = 2; + repeated EndPointId slice_endpoint_ids = 3; + repeated Constraint slice_constraints = 4; + repeated ServiceId slice_service_ids = 5; + repeated SliceId slice_subslice_ids = 6; + SliceStatus slice_status = 7; + SliceConfig slice_config = 8; + SliceOwner slice_owner = 9; + Timestamp timestamp = 10; +} + +message SliceOwner { + Uuid owner_uuid = 1; + string owner_string = 2; +} + +enum SliceStatusEnum { + SLICESTATUS_UNDEFINED = 0; + SLICESTATUS_PLANNED = 1; + SLICESTATUS_INIT = 2; + SLICESTATUS_ACTIVE = 3; + SLICESTATUS_DEINIT = 4; + SLICESTATUS_SLA_VIOLATED = 5; +} + +message SliceStatus { + SliceStatusEnum slice_status = 1; +} + +message SliceConfig { + repeated ConfigRule config_rules = 1; +} + +message SliceIdList { + repeated SliceId slice_ids = 1; +} + +message SliceList { + repeated Slice slices = 1; +} + +message SliceFilter { + SliceIdList slice_ids = 1; + bool include_endpoint_ids = 2; + bool include_constraints = 3; + bool include_service_ids = 4; + bool include_subslice_ids = 5; + bool include_config_rules = 6; +} + +message SliceEvent { + Event event = 1; + SliceId slice_id = 2; +} + +// ----- Connection ---------------------------------------------------------------------------------------------------- +message ConnectionId { + Uuid connection_uuid = 1; +} + +message ConnectionSettings_L0 { + string lsp_symbolic_name = 1; +} + +message ConnectionSettings_L2 { + string src_mac_address = 1; + string dst_mac_address = 2; + uint32 ether_type = 3; + uint32 vlan_id = 4; + uint32 mpls_label = 5; + uint32 mpls_traffic_class = 6; +} + +message ConnectionSettings_L3 { + string src_ip_address = 1; + string dst_ip_address = 2; + uint32 dscp = 3; + uint32 protocol = 4; + uint32 ttl = 5; +} + +message ConnectionSettings_L4 { + uint32 src_port = 1; + uint32 dst_port = 2; + uint32 tcp_flags = 3; + uint32 ttl = 4; +} + +message ConnectionSettings { + ConnectionSettings_L0 l0 = 1; + ConnectionSettings_L2 l2 = 2; + ConnectionSettings_L3 l3 = 3; + ConnectionSettings_L4 l4 = 4; +} + +message Connection { + ConnectionId connection_id = 1; + ServiceId service_id = 2; + repeated EndPointId path_hops_endpoint_ids = 3; + repeated ServiceId sub_service_ids = 4; + ConnectionSettings settings = 5; +} + +message ConnectionIdList { + repeated ConnectionId connection_ids = 1; +} + +message ConnectionList { + repeated Connection connections = 1; +} + +message ConnectionEvent { + Event event = 1; + ConnectionId connection_id = 2; +} + + +// ----- Endpoint ------------------------------------------------------------------------------------------------------ +message EndPointId { + TopologyId topology_id = 1; + DeviceId device_id = 2; + Uuid endpoint_uuid = 3; +} + +message EndPoint { + EndPointId endpoint_id = 1; + string name = 2; + string endpoint_type = 3; + repeated kpi_sample_types.KpiSampleType kpi_sample_types = 4; + Location endpoint_location = 5; +} + +message EndPointName { + EndPointId endpoint_id = 1; + string device_name = 2; + string endpoint_name = 3; + string endpoint_type = 4; +} + +message EndPointIdList { + repeated EndPointId endpoint_ids = 1; +} + +message EndPointNameList { + repeated EndPointName endpoint_names = 1; +} + + +// ----- Configuration ------------------------------------------------------------------------------------------------- +enum ConfigActionEnum { + CONFIGACTION_UNDEFINED = 0; + CONFIGACTION_SET = 1; + CONFIGACTION_DELETE = 2; +} + +message ConfigRule_Custom { + string resource_key = 1; + string resource_value = 2; +} + +message ConfigRule_ACL { + EndPointId endpoint_id = 1; + acl.AclRuleSet rule_set = 2; +} + +message ConfigRule { + ConfigActionEnum action = 1; + oneof config_rule { + ConfigRule_Custom custom = 2; + ConfigRule_ACL acl = 3; + } +} + + +// ----- Constraint ---------------------------------------------------------------------------------------------------- +enum ConstraintActionEnum { + CONSTRAINTACTION_UNDEFINED = 0; + CONSTRAINTACTION_SET = 1; + CONSTRAINTACTION_DELETE = 2; +} + +message Constraint_Custom { + string constraint_type = 1; + string constraint_value = 2; +} + +message Constraint_Schedule { + float start_timestamp = 1; + float duration_days = 2; +} + +message GPS_Position { + float latitude = 1; + float longitude = 2; +} + +message Location { + oneof location { + string region = 1; + GPS_Position gps_position = 2; + } +} + +message Constraint_EndPointLocation { + EndPointId endpoint_id = 1; + Location location = 2; +} + +message Constraint_EndPointPriority { + EndPointId endpoint_id = 1; + uint32 priority = 2; +} + +message Constraint_SLA_Latency { + float e2e_latency_ms = 1; +} + +message Constraint_SLA_Capacity { + float capacity_gbps = 1; +} + +message Constraint_SLA_Availability { + uint32 num_disjoint_paths = 1; + bool all_active = 2; + float availability = 3; // 0.0 .. 100.0 percentage of availability +} + +enum IsolationLevelEnum { + NO_ISOLATION = 0; + PHYSICAL_ISOLATION = 1; + LOGICAL_ISOLATION = 2; + PROCESS_ISOLATION = 3; + PHYSICAL_MEMORY_ISOLATION = 4; + PHYSICAL_NETWORK_ISOLATION = 5; + VIRTUAL_RESOURCE_ISOLATION = 6; + NETWORK_FUNCTIONS_ISOLATION = 7; + SERVICE_ISOLATION = 8; +} + +message Constraint_SLA_Isolation_level { + repeated IsolationLevelEnum isolation_level = 1; +} + +message Constraint_Exclusions { + bool is_permanent = 1; + repeated DeviceId device_ids = 2; + repeated EndPointId endpoint_ids = 3; + repeated LinkId link_ids = 4; +} + +message Constraint { + ConstraintActionEnum action = 1; + oneof constraint { + Constraint_Custom custom = 2; + Constraint_Schedule schedule = 3; + Constraint_EndPointLocation endpoint_location = 4; + Constraint_EndPointPriority endpoint_priority = 5; + Constraint_SLA_Capacity sla_capacity = 6; + Constraint_SLA_Latency sla_latency = 7; + Constraint_SLA_Availability sla_availability = 8; + Constraint_SLA_Isolation_level sla_isolation = 9; + Constraint_Exclusions exclusions = 10; + } +} + + +// ----- Miscellaneous ------------------------------------------------------------------------------------------------- +message TeraFlowController { + ContextId context_id = 1; + string ip_address = 2; + uint32 port = 3; +} + +message AuthenticationResult { + ContextId context_id = 1; + bool authenticated = 2; +} diff --git a/src/device/service/drivers/flexscale/FlexScaleDriver.py b/src/device/service/drivers/flexscale/FlexScaleDriver.py index 23a7bc006..f91ee1ceb 100644 --- a/src/device/service/drivers/flexscale/FlexScaleDriver.py +++ b/src/device/service/drivers/flexscale/FlexScaleDriver.py @@ -106,9 +106,9 @@ class FlexScaleDriver(_Driver): for _, resource in resources: LOGGER.info('resource = {:s}'.format(str(resource))) - src_node = '1' # find_key(resource, 'src_node') - dst_node = '2' # find_key(resource, 'dst_node') - bitrate = '3' # find_key(resource, 'bitrate') + src_node = find_key(resource, 'src_node') + dst_node = find_key(resource, 'dst_node') + bitrate = find_key(resource, 'bitrate') response = add_lightpath(self.__flexscale_root, src_node, dst_node, bitrate, auth=self.__auth, timeout=self.__timeout) diff --git a/src/device/service/drivers/flexscale/Tools.py b/src/device/service/drivers/flexscale/Tools.py index 1fffc2094..2f74f3657 100644 --- a/src/device/service/drivers/flexscale/Tools.py +++ b/src/device/service/drivers/flexscale/Tools.py @@ -12,10 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json, logging, operator, requests +import json, logging, requests from requests.auth import HTTPBasicAuth from typing import Optional -from device.service.driver_api._Driver import RESOURCE_ENDPOINTS, RESOURCE_SERVICES LOGGER = logging.getLogger(__name__) @@ -52,13 +51,11 @@ def get_lightpaths(root_url : str, resource_key : str,auth : Optional[HTTPBasicA result.append((resource_key, e)) return result - # if resource_key == RESOURCE_ENDPOINTS: for flow in flows: flow_id = flow.get('flow_id') source = flow.get('src') destination = flow.get('dst') bitrate = flow.get('bitrate') - # more TODO endpoint_url = '/flows/flow[{:s}]'.format(flow_id) endpoint_data = {'flow_id': flow_id, 'src': source, 'dst': destination, 'bitrate': bitrate} @@ -69,64 +66,19 @@ def get_lightpaths(root_url : str, resource_key : str,auth : Optional[HTTPBasicA def add_lightpath(root_url, src_node, dst_node, bitrate, auth : Optional[HTTPBasicAuth] = None, timeout : Optional[int] = None): - + headers = {'accept': 'application/json'} - # url = '{:s}/OpticalTFS/AddLightpath/{:s}/{:s}/{:s}'.format(root_url, src_node, dst_node, bitrate) + url = '{:s}/OpticalTFS/AddLightpath/{:s}/{:s}/{:s}'.format( + root_url, src_node, dst_node, bitrate) results = [] try: LOGGER.info('Lightpath request: {:s} <-> {:s} with {:s} bitrate'.format( str(src_node), str(dst_node), str(bitrate))) - - device1= 'T1' - ep1= 'ep1' - device2= 'T2' - ep2= 'ep2' - context_uuid = 'admin' - service_uuid = 'T1-T2_service' - - data = { - "services": [ - { - "service_id": { - "context_id": {"context_uuid": {"uuid": context_uuid}}, "service_uuid": {"uuid": service_uuid} - }, - "service_type": 5, - } - ] - } - url = '{:s}'.format(root_url) + '/context/{:s}/service/{:s}'.format(context_uuid, service_uuid) - response = requests.post(url=url, timeout=timeout, headers=headers, verify=False, auth=auth, data=json.dumps(data)).json() - - - data = { - "services": [ - { - "service_id": { - "context_id": {"context_uuid": {"uuid": "admin"}}, "service_uuid": {"uuid": "service_uuid"} - }, - "service_type": 5, - "service_status": {"service_status": 1}, - "service_endpoint_ids": [ - {"device_id":{"device_uuid":{"uuid":device1}},"endpoint_uuid":{"uuid":ep1}}, - {"device_id":{"device_uuid":{"uuid":device2}},"endpoint_uuid":{"uuid":ep2}} - ], - "service_config": {"config_rules": [ - {"action": 1, "custom": {"resource_key": "/settings", "resource_value": { - }} - } - ] - } - } - ] - } - url = '{:s}'.format(root_url) + '/context/{:s}/service/{:s}'.format(context_uuid, service_uuid) - response = requests.put(url=url, timeout=timeout, headers=headers, verify=False, auth=auth, data=json.dumps(data)) - - - #response = requests.put(url=url, timeout=timeout, headers=headers, verify=False, auth=auth) + response = requests.put(url=url, timeout=timeout, headers=headers, verify=False, auth=auth) results.append(response.json()) LOGGER.info('Response: {:s}'.format(str(response))) + except Exception as e: # pylint: disable=broad-except LOGGER.exception('Exception requesting Lightpath: {:s} <-> {:s} with {:s} bitrate'.format( str(src_node), str(dst_node), str(bitrate))) @@ -136,20 +88,22 @@ def add_lightpath(root_url, src_node, dst_node, bitrate, msg = 'Could not create Lightpath(status_code={:s} reply={:s}' LOGGER.error(msg.format(str(response.status_code), str(response))) results.append(response.status_code in HTTP_OK_CODES) - + return results def del_lightpath(root_url, flow_id, src_node, dst_node, bitrate, auth : Optional[HTTPBasicAuth] = None, timeout : Optional[int] = None): - url = '{:s}/OpticalTFS/DelLightpath/{:s}/{:s}/{:s}/{:s}'.format(root_url, flow_id, src_node, dst_node, bitrate) + url = '{:s}/OpticalTFS/DelLightpath/{:s}/{:s}/{:s}/{:s}'.format( + root_url, flow_id, src_node, dst_node, bitrate) headers = {'accept': 'application/json'} results = [] try: - response = requests.delete(url=url, timeout=timeout, headers=headers, verify=False, auth=auth) + response = requests.delete( + url=url, timeout=timeout, headers=headers, verify=False, auth=auth) except Exception as e: # pylint: disable=broad-except LOGGER.exception('Exception deleting Lightpath(uuid={:s})'.format(str(flow_id))) results.append(e) @@ -179,18 +133,11 @@ def get_topology(root_url : str, resource_key : str,auth : Optional[HTTPBasicAut return result try: - links = json.loads(response.content) + response = json.loads(response.content) except Exception as e: # pylint: disable=broad-except LOGGER.warning('Unable to decode reply: {:s}'.format(str(response.content))) result.append((resource_key, e)) return result - - # if resource_key == RESOURCE_ENDPOINTS: - #for link in links: - # TODO - - # endpoint_url = '/flows/flow[{:s}]'.format(flow_id) - # endpoint_data = {'flow_id': flow_id, 'src': source, 'dst': destination, 'bitrate': bitrate} - # result.append((endpoint_url, endpoint_data)) - + + result.append(response) return result diff --git a/src/device/service/drivers/ietf_l2vpn/TfsDebugApiClient.py b/src/device/service/drivers/ietf_l2vpn/TfsDebugApiClient.py index 24e91aa4c..06c55c5dc 100644 --- a/src/device/service/drivers/ietf_l2vpn/TfsDebugApiClient.py +++ b/src/device/service/drivers/ietf_l2vpn/TfsDebugApiClient.py @@ -45,7 +45,6 @@ MAPPING_DRIVER = { 'DEVICEDRIVER_IETF_L2VPN' : 7, 'DEVICEDRIVER_GNMI_OPENCONFIG' : 8, 'DEVICEDRIVER_FLEXSCALE' : 9, - 'DEVICEDRIVER_OC' : 1, } MSG_ERROR = 'Could not retrieve devices in remote TeraFlowSDN instance({:s}). status_code={:s} reply={:s}' diff --git a/src/service/service/service_handlers/__init__.py b/src/service/service/service_handlers/__init__.py index 32df661a2..48b5e694c 100644 --- a/src/service/service/service_handlers/__init__.py +++ b/src/service/service/service_handlers/__init__.py @@ -26,7 +26,6 @@ from .tapi_tapi.TapiServiceHandler import TapiServiceHandler from .tapi_xr.TapiXrServiceHandler import TapiXrServiceHandler from .e2e_orch.E2EOrchestratorServiceHandler import E2EOrchestratorServiceHandler - SERVICE_HANDLERS = [ (L2NMEmulatedServiceHandler, [ { diff --git a/src/tests/Fixtures.py b/src/tests/Fixtures.py index 55ef90340..842bd83f4 100644 --- a/src/tests/Fixtures.py +++ b/src/tests/Fixtures.py @@ -17,7 +17,6 @@ from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from monitoring.client.MonitoringClient import MonitoringClient - @pytest.fixture(scope='session') def context_client(): _client = ContextClient() diff --git a/src/tests/tools/mock_flexscale_opt_ctrl/test_mw.py b/src/tests/tools/mock_flexscale_opt_ctrl/test_mw.py deleted file mode 100644 index 0329d30ad..000000000 --- a/src/tests/tools/mock_flexscale_opt_ctrl/test_mw.py +++ /dev/null @@ -1,84 +0,0 @@ -import json, logging, requests -from requests.auth import HTTPBasicAuth -from typing import Optional - -LOGGER = logging.getLogger(__name__) - -HTTP_OK_CODES = { - 200, # OK - 201, # Created - 202, # Accepted - 204, # No Content -} - -def create_connectivity_service( - root_url, uuid, node_id_src, tp_id_src, node_id_dst, tp_id_dst, vlan_id, - auth : Optional[HTTPBasicAuth] = None, timeout : Optional[int] = None -): - - url = '{:s}/nmswebs/restconf/data/ietf-eth-tran-service:etht-svc'.format(root_url) - headers = {'content-type': 'application/json'} - data = { - 'etht-svc-instances': [ - { - 'etht-svc-name': uuid, - 'etht-svc-type': 'ietf-eth-tran-types:p2p-svc', - 'etht-svc-end-points': [ - { - 'etht-svc-access-points': [ - {'access-node-id': node_id_src, 'access-ltp-id': tp_id_src, 'access-point-id': '1'} - ], - 'outer-tag': {'vlan-value': vlan_id, 'tag-type': 'ietf-eth-tran-types:classify-c-vlan'}, - 'etht-svc-end-point-name': '{:s}:{:s}'.format(str(node_id_src), str(tp_id_src)), - 'service-classification-type': 'ietf-eth-tran-types:vlan-classification' - }, - { - 'etht-svc-access-points': [ - {'access-node-id': node_id_dst, 'access-ltp-id': tp_id_dst, 'access-point-id': '2'} - ], - 'outer-tag': {'vlan-value': vlan_id, 'tag-type': 'ietf-eth-tran-types:classify-c-vlan'}, - 'etht-svc-end-point-name': '{:s}:{:s}'.format(str(node_id_dst), str(tp_id_dst)), - 'service-classification-type': 'ietf-eth-tran-types:vlan-classification' - } - ] - } - ] - } - results = [] - try: - LOGGER.info('Connectivity service {:s}: {:s}'.format(str(uuid), str(data))) - response = requests.post( - url=url, data=json.dumps(data), timeout=timeout, headers=headers, verify=False, auth=auth) - LOGGER.info('Microwave Driver response: {:s}'.format(str(response))) - except Exception as e: # pylint: disable=broad-except - LOGGER.exception('Exception creating ConnectivityService(uuid={:s}, data={:s})'.format(str(uuid), str(data))) - results.append(e) - else: - if response.status_code not in HTTP_OK_CODES: - msg = 'Could not create ConnectivityService(uuid={:s}, data={:s}). status_code={:s} reply={:s}' - LOGGER.error(msg.format(str(uuid), str(data), str(response.status_code), str(response))) - results.append(response.status_code in HTTP_OK_CODES) - return results - -def delete_connectivity_service(root_url, uuid, auth : Optional[HTTPBasicAuth] = None, timeout : Optional[int] = None): - url = '{:s}/nmswebs/restconf/data/ietf-eth-tran-service:etht-svc/etht-svc-instances={:s}' - url = url.format(root_url, uuid) - results = [] - try: - response = requests.delete(url=url, timeout=timeout, verify=False, auth=auth) - except Exception as e: # pylint: disable=broad-except - LOGGER.exception('Exception deleting ConnectivityService(uuid={:s})'.format(str(uuid))) - results.append(e) - else: - if response.status_code not in HTTP_OK_CODES: - msg = 'Could not delete ConnectivityService(uuid={:s}). status_code={:s} reply={:s}' - LOGGER.error(msg.format(str(uuid), str(response.status_code), str(response))) - results.append(response.status_code in HTTP_OK_CODES) - return results - -if __name__ == '__main__': - ROOT_URL = 'https://127.0.0.1:8443' - SERVICE_UUID = 'my-service' - - create_connectivity_service(ROOT_URL, SERVICE_UUID, '172.18.0.1', '1', '172.18.0.2', '2', 300) - delete_connectivity_service(ROOT_URL, SERVICE_UUID) -- GitLab