Skip to content
Snippets Groups Projects
Commit a36f8613 authored by Carlos Natalino Da Silva's avatar Carlos Natalino Da Silva
Browse files

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

parent 2f5fe7ea
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!97Optical cybersecurity scenario
......@@ -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,
......
# 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
......
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment