Commit a36f8613 authored by Carlos Natalino's avatar Carlos Natalino
Browse files

Updating ports in the constants and using it in the clients.

parent 2f5fe7ea
Loading
Loading
Loading
Loading
+15 −12
Original line number Original line Diff line number Diff line
@@ -70,7 +70,10 @@ DEFAULT_SERVICE_GRPC_PORTS = {
    ServiceNameEnum.MONITORING             .value :  7070,
    ServiceNameEnum.MONITORING             .value :  7070,
    ServiceNameEnum.DLT                    .value :  8080,
    ServiceNameEnum.DLT                    .value :  8080,
    ServiceNameEnum.COMPUTE                .value :  9090,
    ServiceNameEnum.COMPUTE                .value :  9090,
    ServiceNameEnum.CYBERSECURITY.value : 10000,
    ServiceNameEnum.DBSCANSERVING          .value : 10008,
    ServiceNameEnum.OPTICALATTACKDETECTOR  .value : 10006,
    ServiceNameEnum.OPTICALATTACKMITIGATOR .value : 10007,
    ServiceNameEnum.OPTICALATTACKMANAGER   .value : 10005,
    ServiceNameEnum.INTERDOMAIN            .value : 10010,
    ServiceNameEnum.INTERDOMAIN            .value : 10010,
    ServiceNameEnum.PATHCOMP               .value : 10020,
    ServiceNameEnum.PATHCOMP               .value : 10020,


+7 −7
Original line number Original line Diff line number Diff line
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# you may not use this file except in compliance with the License.
@@ -15,10 +15,11 @@
import grpc, logging
import grpc, logging
from typing import Counter
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 import DetectionRequest, DetectionResponse
from common.proto.dbscanserving_pb2_grpc import DetectorStub
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__)
LOGGER = logging.getLogger(__name__)
MAX_RETRIES = 15
MAX_RETRIES = 15
@@ -32,10 +33,9 @@ RETRY_DECORATOR = retry(


class DbscanServingClient:
class DbscanServingClient:
    def __init__(self, host=None, port=None):
    def __init__(self, host=None, port=None):
        if not host:
        if not host: host = get_service_host(ServiceNameEnum.DBSCANSERVING)
            host = get_setting("DBSCANSERVINGSERVICE_SERVICE_HOST")
        if not port: port = get_service_port_grpc(ServiceNameEnum.DBSCANSERVING)
        if not port:

            port = get_setting("DBSCANSERVINGSERVICE_SERVICE_PORT_GRPC")
        self.endpoint = "{:s}:{:s}".format(str(host), str(port))
        self.endpoint = "{:s}:{:s}".format(str(host), str(port))
        LOGGER.debug("Creating channel to {:s}...".format(str(self.endpoint)))
        LOGGER.debug("Creating channel to {:s}...".format(str(self.endpoint)))
        self.channel = None
        self.channel = None
+7 −14
Original line number Original line Diff line number Diff line
@@ -12,16 +12,15 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.


import logging
import grpc, logging

import grpc


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.context_pb2 import Empty
from common.proto.optical_attack_detector_pb2_grpc import \
from common.proto.optical_attack_detector_pb2_grpc import \
    OpticalAttackDetectorServiceStub
    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__)
LOGGER = logging.getLogger(__name__)
MAX_RETRIES = 15
MAX_RETRIES = 15
@@ -35,14 +34,8 @@ RETRY_DECORATOR = retry(


class OpticalAttackDetectorClient:
class OpticalAttackDetectorClient:
    def __init__(self, host=None, port=None):
    def __init__(self, host=None, port=None):
        if not host:
        if not host: host = get_service_host(ServiceNameEnum.OPTICALATTACKDETECTOR)
            host = get_setting(
        if not port: port = get_service_port_grpc(ServiceNameEnum.OPTICALATTACKDETECTOR)
                "OPTICALATTACKDETECTORSERVICE_SERVICE_HOST", default="DBSCANSERVING"
            )
        if not port:
            port = get_setting(
                "OPTICALATTACKDETECTORSERVICE_SERVICE_PORT_GRPC", default=10007
            )
        self.endpoint = "{:s}:{:s}".format(str(host), str(port))
        self.endpoint = "{:s}:{:s}".format(str(host), str(port))
        LOGGER.debug("Creating channel to {:s}...".format(str(self.endpoint)))
        LOGGER.debug("Creating channel to {:s}...".format(str(self.endpoint)))
        self.channel = None
        self.channel = None
+7 −14
Original line number Original line Diff line number Diff line
@@ -12,16 +12,15 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.


import logging
import grpc, logging

import grpc


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,
from common.proto.optical_attack_mitigator_pb2 import (AttackDescription,
                                                       AttackResponse)
                                                       AttackResponse)
from common.proto.optical_attack_mitigator_pb2_grpc import AttackMitigatorStub
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__)
LOGGER = logging.getLogger(__name__)
MAX_RETRIES = 15
MAX_RETRIES = 15
@@ -35,14 +34,8 @@ RETRY_DECORATOR = retry(


class OpticalAttackMitigatorClient:
class OpticalAttackMitigatorClient:
    def __init__(self, host=None, port=None):
    def __init__(self, host=None, port=None):
        if not host:
        if not host: host = get_service_host(ServiceNameEnum.OPTICALATTACKMITIGATOR)
            host = get_setting(
        if not port: port = get_service_port_grpc(ServiceNameEnum.OPTICALATTACKMITIGATOR)
                "OPTICALATTACKMITIGATORSERVICE_SERVICE_HOST", default="DBSCANSERVING"
            )
        if not port:
            port = get_setting(
                "OPTICALATTACKMITIGATORSERVICE_SERVICE_PORT_GRPC", default=10007
            )
        self.endpoint = "{:s}:{:s}".format(str(host), str(port))
        self.endpoint = "{:s}:{:s}".format(str(host), str(port))
        LOGGER.debug("Creating channel to {:s}...".format(str(self.endpoint)))
        LOGGER.debug("Creating channel to {:s}...".format(str(self.endpoint)))
        self.channel = None
        self.channel = None