Commit f2e40c3a authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Pre-merge code cleanup

parent e19f81b9
Loading
Loading
Loading
Loading
+1 −1
Changes for src/opticalcontroller/RSA_P2MP.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
# Copyright 2022-2026 ETSI SDG TeraFlowSDN (TFS) (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.
+1 −1
Changes for src/opticalcontroller/heuristicMST.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
# Copyright 2022-2026 ETSI SDG TeraFlowSDN (TFS) (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.
+1 −10
Changes for src/pathcomp/frontend/service/OpticalPathComp.py: 1 added line, 10 removed lines.
Original line number Diff line number Diff line
@@ -26,16 +26,7 @@ from .TopologyTools import get_device_with_driver

LOGGER = logging.getLogger(__name__)

# Auto-resolved via the same env-var/service-discovery convention every other
# TFS client uses -- falls back to the in-cluster DNS name
# "opticalcontrollerservice" and its default port (10060) when the
# OPTICALCONTROLLERSERVICE_SERVICE_HOST/_PORT env vars aren't set. This used
# to be a hardcoded LAN IP (10.30.7.65:31060, an external NodePort address)
# specific to one physical machine -- moving this demo to a different host/
# cluster silently broke PathComp's calls to OpticalController until someone
# edited this file by hand. NodePort access was also unnecessary here:
# PathComp runs inside the same cluster as OpticalController, so it should
# reach it via the in-cluster ClusterIP service, not an external NodePort.

def _optical_controller_base_url() -> str:
    host = get_service_host(ServiceNameEnum.OPTICALCONTROLLER)
    port = get_service_port_grpc(ServiceNameEnum.OPTICALCONTROLLER)
+13 −12
Changes for src/service/service/ServiceServiceServicerImpl.py: 13 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@ import grpc, json, logging, random, uuid
from typing import Dict, Optional
from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method
from common.method_wrappers.ServiceExceptions import (
    AlreadyExistsException, InvalidArgumentException, NotFoundException, NotImplementedException,
    OperationFailedException
    AlreadyExistsException, InvalidArgumentException, NotFoundException,
    NotImplementedException, OperationFailedException
)
from common.proto.context_pb2 import (
    Connection, ConstraintActionEnum, Empty, Service, ServiceId, ServiceStatusEnum,
@@ -43,10 +43,12 @@ from .service_handler_api.ServiceHandlerFactory import ServiceHandlerFactory
from .task_scheduler.TaskScheduler import TasksScheduler
from .tools.GeodesicDistance import gps_distance
from .tools.OpticalTools import (
    add_flex_lightpath, add_lightpath, delete_lightpath, adapt_reply, get_device_name_from_uuid,
    get_optical_band, refresh_opticalcontroller, refresh_opticalcontroller_pmp, DelFlexLightpath , extend_optical_band, adapt_reply_pmp,
    adapt_reply_pmp_simple, add_lightpath_pmp, add_lightpath_pmp_simple,  reconfig_flex_lightpath, adapt_reply_ob, add_alien_flex_lightpath,
    load_opticalcontroller_reply
    adapt_reply_ob, adapt_reply_pmp_simple, adapt_reply_pmp, adapt_reply,
    add_alien_flex_lightpath, add_flex_lightpath, add_lightpath_pmp_simple,
    add_lightpath_pmp, add_lightpath, delete_lightpath, DelFlexLightpath,
    extend_optical_band, get_device_name_from_uuid, get_optical_band,
    load_opticalcontroller_reply, reconfig_flex_lightpath,
    refresh_opticalcontroller_pmp, refresh_opticalcontroller,
)
from .tools.OpticalSpectrumReservation import parse_optical_spectrum_reservation_constraints

@@ -329,14 +331,13 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
                        bidir = int(constraint.custom.constraint_value)
                    elif "optical-band-width" in constraint.custom.constraint_type:
                        ob_band = int(constraint.custom.constraint_value)
                    elif "subcarriers_per_src" in constraint.custom.constraint_type or "subcarrier" in constraint.custom.constraint_type:
                    elif (
                        "subcarriers_per_src" in constraint.custom.constraint_type or
                        "subcarrier" in constraint.custom.constraint_type
                    ):
                        subcarrier_per_src = constraint.custom.constraint_value
                    elif "op_mode" in constraint.custom.constraint_type:
                        op_mode = constraint.custom.constraint_value
                    # elif "type" in constraint.custom.constraint_type:
                    #     logging.info(f"TEEEEEEEEEEEEEEST {constraint.custom.constraint_type}={constraint.custom.constraint_value}")
                    #     oc_type = OpticalServiceType(str(constraint.custom.constraint_value))
                    #     logging.info(f"TEEEEEEEEEEEEEEST {oc_type}")
                    elif "type" in constraint.custom.constraint_type:
                        logging.info(f"{constraint.custom.constraint_type}={constraint.custom.constraint_value}")
                        oc_type = OpticalServiceType(str(constraint.custom.constraint_value))
@@ -396,7 +397,7 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
                    reply_txt = add_flex_lightpath(
                        src, dst, bitrate, bidir, preferred, ob_band, dj_optical_band_id,
                        spectrum_reservation=spectrum_reservation)
                logging.info(f"TEEEEEEEEEEEEEEST {oc_type}")
                logging.info(f"oc_type={oc_type}")

            if isinstance(reply_txt, str):
                reply_json = json.loads(reply_txt)
+12 −12
Changes for src/service/service/tools/OpticalTools.py: 12 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@
# 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, json, logging, requests, uuid
from typing import Dict, List, Optional, Tuple, Union
@@ -39,8 +39,8 @@ from service.service.tools.replies import (
)
from common.method_wrappers.ServiceExceptions import OperationFailedException


LOGGER = logging.getLogger(__name__)
log = logging.getLogger(__name__)

TESTING = False

@@ -396,7 +396,7 @@ def add_lightpath_pmp(src, dst, bitrate, bidir, frequency, ob_band, subcarriers_
                # Parse the JSON response
                flow_data_converted = response.json()
                #flow_data_converted = response
                log.debug(f"Parsed flow_data_converted: {flow_data_converted}")
                LOGGER.debug(f"Parsed flow_data_converted: {flow_data_converted}")

                # Ensure the response contains the expected fields
                if not isinstance(flow_data_converted, dict):
@@ -707,7 +707,7 @@ def adapt_reply_pmp(devices, service, reply_json, context_id, topology_id, optic
        rules_ob.append(ConfigRule_Custom(resource_key="/settings-ob_{}".format(uuuid_x), resource_value=json.dumps(val_ob)))
        bidir_ob = ob["bidir"]
        for devxb in ob["flows"].keys():
            log.debug("optical-band device {}".format(devxb))
            LOGGER.debug("optical-band device {}".format(devxb))
            in_end_point_f = ob["flows"][devxb]["f"]["in"]
            out_end_point_f = ob["flows"][devxb]["f"]["out"]
            in_end_point_b = ob["flows"][devxb]["b"]["in"] if bidir_ob else "0"
@@ -720,7 +720,7 @@ def adapt_reply_pmp(devices, service, reply_json, context_id, topology_id, optic
                        end_point_b = EndPointId(topology_id=topo, device_id=DeviceId(device_uuid=Uuid(uuid=d_ob)), endpoint_uuid=Uuid(uuid=p_ob))
                        connection_ob.path_hops_endpoint_ids.add().CopyFrom(end_point_b)
                    else:
                        log.info("no map device port for device {} port {}".format(devxb, end_point))
                        LOGGER.info("no map device port for device {} port {}".format(devxb, end_point))

    # Handle main flow connections from the 'flows' section
    connection_f = add_connection_to_reply(opt_reply)
@@ -744,7 +744,7 @@ def adapt_reply_pmp(devices, service, reply_json, context_id, topology_id, optic
                            end_point = EndPointId(topology_id=topo, device_id=DeviceId(device_uuid=Uuid(uuid=d)), endpoint_uuid=Uuid(uuid=p))
                            connection_f.path_hops_endpoint_ids.add().CopyFrom(end_point)
                        else:
                            log.info("no map device port for device {} port {}".format(device_name, end_point))
                            LOGGER.info("no map device port for device {} port {}".format(device_name, end_point))

    # Handle main flow connections from the 'flows' section
    flow_data_list = []
@@ -814,7 +814,7 @@ def adapt_reply_pmp(devices, service, reply_json, context_id, topology_id, optic
            flow_data_list.append(flow_dict)

    else:
        log.error("No flows_per_link found in the response. Full response: %s", json.dumps(r, indent=2))
        LOGGER.error("No flows_per_link found in the response. Full response: %s", json.dumps(r, indent=2))
        raise OperationFailedException("No flows_per_link found in the response.")


@@ -900,7 +900,7 @@ def adapt_reply_pmp_simple(devices, service, reply_json, context_id, topology_id
        rules_ob.append(ConfigRule_Custom(resource_key="/settings-ob_{}".format(uuuid_x), resource_value=json.dumps(val_ob)))
        bidir_ob = ob["bidir"]
        for devxb in ob["flows"].keys():
            log.debug("optical-band device {}".format(devxb))
            LOGGER.debug("optical-band device {}".format(devxb))
            in_end_point_f = ob["flows"][devxb]["f"]["in"]
            out_end_point_f = ob["flows"][devxb]["f"]["out"]
            in_end_point_b = ob["flows"][devxb]["b"]["in"] if bidir_ob else "0"
@@ -913,7 +913,7 @@ def adapt_reply_pmp_simple(devices, service, reply_json, context_id, topology_id
                        end_point_b = EndPointId(topology_id=topo, device_id=DeviceId(device_uuid=Uuid(uuid=d_ob)), endpoint_uuid=Uuid(uuid=p_ob))
                        connection_ob.path_hops_endpoint_ids.add().CopyFrom(end_point_b)
                    else:
                        log.info("no map device port for device {} port {}".format(devxb, end_point))
                        LOGGER.info("no map device port for device {} port {}".format(devxb, end_point))

    # Handle main flow connections from the 'flows' section
    connection_f = add_connection_to_reply(opt_reply)
@@ -937,7 +937,7 @@ def adapt_reply_pmp_simple(devices, service, reply_json, context_id, topology_id
                            end_point = EndPointId(topology_id=topo, device_id=DeviceId(device_uuid=Uuid(uuid=d)), endpoint_uuid=Uuid(uuid=p))
                            connection_f.path_hops_endpoint_ids.add().CopyFrom(end_point)
                        else:
                            log.info("no map device port for device {} port {}".format(device_name, end_point))
                            LOGGER.info("no map device port for device {} port {}".format(device_name, end_point))

    # Handle main flow connections from the 'flows' section
    flow_data_list = []
@@ -1008,7 +1008,7 @@ def adapt_reply_pmp_simple(devices, service, reply_json, context_id, topology_id
            flow_data_list.append(flow_dict)

    else:
        log.error("No flows_per_link found in the response. Full response: %s", json.dumps(r, indent=2))
        LOGGER.error("No flows_per_link found in the response. Full response: %s", json.dumps(r, indent=2))
        raise OperationFailedException("No flows_per_link found in the response.")


@@ -1096,7 +1096,7 @@ def adapt_reply_ob(devices, service, reply_json, context_id, topology_id, optica
        }
        rules_ob.append(ConfigRule_Custom(resource_key="/settings-ob_{}".format(uuuid_x), resource_value=json.dumps(val_ob)))
        bidir_ob = ob["bidir"]
        # in case the service is built upon existed optical band , don't clacluate the endpoints of it
        # in case the service is built upon existed optical band, don't calculate the endpoints of it
        for devxb in ob["flows"].keys():
            LOGGER.debug("optical-band device {}".format(devxb))
            in_end_point_b = "0"