diff --git a/src/common/Constants.py b/src/common/Constants.py index 480e2a2313c22074a0a9c1297b2d794f36cdbc9d..c5a49746eeeaf163b067e359853b4d0594d69ab7 100644 --- a/src/common/Constants.py +++ b/src/common/Constants.py @@ -61,18 +61,21 @@ class ServiceNameEnum(Enum): # Default gRPC service ports DEFAULT_SERVICE_GRPC_PORTS = { - ServiceNameEnum.CONTEXT .value : 1010, - ServiceNameEnum.DEVICE .value : 2020, - ServiceNameEnum.SERVICE .value : 3030, - ServiceNameEnum.SLICE .value : 4040, - ServiceNameEnum.AUTOMATION .value : 5050, - ServiceNameEnum.POLICY .value : 6060, - ServiceNameEnum.MONITORING .value : 7070, - ServiceNameEnum.DLT .value : 8080, - ServiceNameEnum.COMPUTE .value : 9090, - ServiceNameEnum.CYBERSECURITY.value : 10000, - ServiceNameEnum.INTERDOMAIN .value : 10010, - ServiceNameEnum.PATHCOMP .value : 10020, + ServiceNameEnum.CONTEXT .value : 1010, + ServiceNameEnum.DEVICE .value : 2020, + ServiceNameEnum.SERVICE .value : 3030, + ServiceNameEnum.SLICE .value : 4040, + ServiceNameEnum.AUTOMATION .value : 5050, + ServiceNameEnum.POLICY .value : 6060, + ServiceNameEnum.MONITORING .value : 7070, + ServiceNameEnum.DLT .value : 8080, + ServiceNameEnum.COMPUTE .value : 9090, + ServiceNameEnum.DBSCANSERVING .value : 10008, + ServiceNameEnum.OPTICALATTACKDETECTOR .value : 10006, + ServiceNameEnum.OPTICALATTACKMITIGATOR .value : 10007, + ServiceNameEnum.OPTICALATTACKMANAGER .value : 10005, + ServiceNameEnum.INTERDOMAIN .value : 10010, + ServiceNameEnum.PATHCOMP .value : 10020, # Used for test and debugging only ServiceNameEnum.DLT_GATEWAY .value : 50051, diff --git a/src/dbscanserving/client/DbscanServingClient.py b/src/dbscanserving/client/DbscanServingClient.py index c8944f90a96cb9a77942d87835b1a32fc714738f..15081ab3a0fce2c23838e4a00d0e0e56f91f474b 100644 --- a/src/dbscanserving/client/DbscanServingClient.py +++ b/src/dbscanserving/client/DbscanServingClient.py @@ -1,4 +1,4 @@ -# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,10 +15,11 @@ import grpc, logging from typing import Counter +from common.Constants import ServiceNameEnum +from common.Settings import get_service_host, get_service_port_grpc +from common.tools.client.RetryDecorator import delay_exponential, retry from common.proto.dbscanserving_pb2 import DetectionRequest, DetectionResponse from common.proto.dbscanserving_pb2_grpc import DetectorStub -from common.Settings import get_setting -from common.tools.client.RetryDecorator import delay_exponential, retry LOGGER = logging.getLogger(__name__) MAX_RETRIES = 15 @@ -32,10 +33,9 @@ RETRY_DECORATOR = retry( class DbscanServingClient: def __init__(self, host=None, port=None): - if not host: - host = get_setting("DBSCANSERVINGSERVICE_SERVICE_HOST") - if not port: - port = get_setting("DBSCANSERVINGSERVICE_SERVICE_PORT_GRPC") + if not host: host = get_service_host(ServiceNameEnum.DBSCANSERVING) + if not port: port = get_service_port_grpc(ServiceNameEnum.DBSCANSERVING) + self.endpoint = "{:s}:{:s}".format(str(host), str(port)) LOGGER.debug("Creating channel to {:s}...".format(str(self.endpoint))) self.channel = None diff --git a/src/opticalattackdetector/client/OpticalAttackDetectorClient.py b/src/opticalattackdetector/client/OpticalAttackDetectorClient.py index eb84e5155c13ed38b20496c98dc3c6f695bbe988..50f303b5d08beb86b3101154179951566cba372c 100644 --- a/src/opticalattackdetector/client/OpticalAttackDetectorClient.py +++ b/src/opticalattackdetector/client/OpticalAttackDetectorClient.py @@ -12,16 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging - -import grpc +import grpc, logging +from common.Constants import ServiceNameEnum +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.context_pb2 import Empty from common.proto.optical_attack_detector_pb2_grpc import \ OpticalAttackDetectorServiceStub -from common.Settings import get_setting -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 @@ -35,14 +34,8 @@ RETRY_DECORATOR = retry( class OpticalAttackDetectorClient: def __init__(self, host=None, port=None): - if not host: - host = get_setting( - "OPTICALATTACKDETECTORSERVICE_SERVICE_HOST", default="DBSCANSERVING" - ) - if not port: - port = get_setting( - "OPTICALATTACKDETECTORSERVICE_SERVICE_PORT_GRPC", default=10007 - ) + if not host: host = get_service_host(ServiceNameEnum.OPTICALATTACKDETECTOR) + if not port: port = get_service_port_grpc(ServiceNameEnum.OPTICALATTACKDETECTOR) self.endpoint = "{:s}:{:s}".format(str(host), str(port)) LOGGER.debug("Creating channel to {:s}...".format(str(self.endpoint))) self.channel = None diff --git a/src/opticalattackmitigator/client/OpticalAttackMitigatorClient.py b/src/opticalattackmitigator/client/OpticalAttackMitigatorClient.py index 214c82eefc9cfe8177b598431c15b10038a935f7..6851d349231dd2b428245b3ef91c09ce36191ffa 100644 --- a/src/opticalattackmitigator/client/OpticalAttackMitigatorClient.py +++ b/src/opticalattackmitigator/client/OpticalAttackMitigatorClient.py @@ -12,16 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging - -import grpc +import grpc, logging +from common.Constants import ServiceNameEnum +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.optical_attack_mitigator_pb2 import (AttackDescription, AttackResponse) from common.proto.optical_attack_mitigator_pb2_grpc import AttackMitigatorStub -from common.Settings import get_setting -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 @@ -35,14 +34,8 @@ RETRY_DECORATOR = retry( class OpticalAttackMitigatorClient: def __init__(self, host=None, port=None): - if not host: - host = get_setting( - "OPTICALATTACKMITIGATORSERVICE_SERVICE_HOST", default="DBSCANSERVING" - ) - if not port: - port = get_setting( - "OPTICALATTACKMITIGATORSERVICE_SERVICE_PORT_GRPC", default=10007 - ) + if not host: host = get_service_host(ServiceNameEnum.OPTICALATTACKMITIGATOR) + if not port: port = get_service_port_grpc(ServiceNameEnum.OPTICALATTACKMITIGATOR) self.endpoint = "{:s}:{:s}".format(str(host), str(port)) LOGGER.debug("Creating channel to {:s}...".format(str(self.endpoint))) self.channel = None