From 78b2795eb8ca4872bffefd6805c9b7e9e7942da8 Mon Sep 17 00:00:00 2001 From: sgambelluri <andrea.sgambelluri@cnit.it> Date: Tue, 22 Apr 2025 14:28:55 +0200 Subject: [PATCH] flexigrid deployment of an optical connection --- src/common/Constants.py | 11 +++++++++ src/opticalcontroller/OpticalController.py | 4 ++-- src/opticalcontroller/RSA.py | 20 ++++++---------- .../service/ServiceServiceServicerImpl.py | 24 ++++++++++++++----- src/service/service/tools/OpticalTools.py | 20 +++++++++++++++- 5 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/common/Constants.py b/src/common/Constants.py index 4d4dcacf5..b873b351c 100644 --- a/src/common/Constants.py +++ b/src/common/Constants.py @@ -131,3 +131,14 @@ DEFAULT_SERVICE_HTTP_BASEURLS = { ServiceNameEnum.NBI .value : None, ServiceNameEnum.WEBUI.value : None, } + + +def OpticalServiceType(value): + if value == "multi_granular": + return 1 + elif value == "flex_grid": + return 2 + elif value == "pmp": + return 3 + else: + return 1 \ No newline at end of file diff --git a/src/opticalcontroller/OpticalController.py b/src/opticalcontroller/OpticalController.py index effa153af..e859e3ba1 100644 --- a/src/opticalcontroller/OpticalController.py +++ b/src/opticalcontroller/OpticalController.py @@ -43,8 +43,8 @@ def index(): return render_template('index.html') -#@optical.route('/AddLightpath/<string:src>/<string:dst>/<int:bitrate>/<int:bidir>') -@optical.route('/AddLightpath/<string:src>/<string:dst>/<int:bitrate>') +#@optical.route('/AddLightpath/<string:src>/<string:dst>/<int:bitrate>') +@optical.route('/AddLightpath/<string:src>/<string:dst>/<int:bitrate>/<int:bidir>') @optical.response(200, 'Success') @optical.response(404, 'Error, not found') class AddLightpath(Resource): diff --git a/src/opticalcontroller/RSA.py b/src/opticalcontroller/RSA.py index 39b5772df..f5c8bbc69 100644 --- a/src/opticalcontroller/RSA.py +++ b/src/opticalcontroller/RSA.py @@ -593,18 +593,6 @@ class RSA(): self.get_fibers_forward(links, slots, band) if bidir: self.get_fibers_backward(links, slots, band) - ''' - fibers_f = self.get_fibers_forward(links, slots, band) - - fibers_b = [] - if bidir: - fibers_b = self.get_fibers_backward(links, fibers_f, slots, band) - if debug: - print("forward") - print(fibers_f) - print("backward") - print(fibers_b) - ''' add = links[0] drop = links[-1] inport = "0" @@ -764,7 +752,13 @@ class RSA(): return t_flows, band, slots, {}, {} def rsa_computation(self, src, dst, rate, bidir): - self.flow_id += 1 + if self.flow_id == 0: + self.flow_id += 1 + else: + if (self.db_flows[self.flow_id]["bidir"] == 1): + self.flow_id += 2 + else: + self.flow_id += 1 self.db_flows[self.flow_id] = {} self.db_flows[self.flow_id]["flow_id"] = self.flow_id self.db_flows[self.flow_id]["src"] = src diff --git a/src/service/service/ServiceServiceServicerImpl.py b/src/service/service/ServiceServiceServicerImpl.py index a316c70c4..300e5a6fe 100644 --- a/src/service/service/ServiceServiceServicerImpl.py +++ b/src/service/service/ServiceServiceServicerImpl.py @@ -30,7 +30,7 @@ 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 common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Topology import json_topology_id -from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME +from common.Constants import OpticalServiceType, DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME from common.Settings import ( is_deployed_e2e_orch, is_deployed_optical, is_deployed_te ) @@ -43,7 +43,7 @@ from .service_handler_api.ServiceHandlerFactory import ServiceHandlerFactory from .task_scheduler.TaskScheduler import TasksScheduler from .tools.GeodesicDistance import gps_distance from .tools.OpticalTools import ( - add_lightpath, delete_lightpath, adapt_reply, get_device_name_from_uuid, + add_flex_lightpath, add_lightpath, delete_lightpath, adapt_reply, get_device_name_from_uuid, get_optical_band, refresh_opticalcontroller, DelFlexLightpath , extend_optical_band ) @@ -276,13 +276,17 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): ports = [] for endpoint_id in service.service_endpoint_ids: endpoint_device_uuid = endpoint_id.device_id.device_uuid.uuid - endpoint_device_name = device_names[endpoint_device_uuid] + if "." in endpoint_device_uuid: + endpoint_device_name = endpoint_device_uuid + else: + endpoint_device_name = device_names[endpoint_device_uuid] devs.append(endpoint_device_name) ports.append(endpoint_id.endpoint_uuid.uuid) src = devs[0] dst = devs[1] bidir = None ob_band = None + oc_type = "multi-granular" bitrate = 100 for constraint in service.service_constraints: if "bandwidth" in constraint.custom.constraint_type: @@ -291,10 +295,18 @@ 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 "type" in constraint.custom.constraint_type: + oc_type = OpticalServiceType(str(constraint.custom.constraint_value)) + + reply_txt = "" # to get the reply form the optical module - reply_txt = add_lightpath(src, dst, bitrate, bidir, ob_band) - + #multi-granular + if oc_type == 1: + reply_txt = add_flex_lightpath(src, dst, bitrate, bidir, ob_band) + elif oc_type == 2: + reply_txt = add_lightpath(src, dst, bitrate, bidir) + else: + reply_txt = add_flex_lightpath(src, dst, bitrate, bidir, ob_band) # reply with 2 transponders and 2 roadms reply_json = json.loads(reply_txt) LOGGER.info('[optical] reply_json[{:s}]={:s}'.format(str(type(reply_json)), str(reply_json))) diff --git a/src/service/service/tools/OpticalTools.py b/src/service/service/tools/OpticalTools.py index 10787ca1d..ded45b63a 100644 --- a/src/service/service/tools/OpticalTools.py +++ b/src/service/service/tools/OpticalTools.py @@ -120,7 +120,7 @@ def refresh_opticalcontroller(topology_id : dict): log.debug(f"GetTopology Response {res}") -def add_lightpath(src, dst, bitrate, bidir, ob_band) -> str: +def add_flex_lightpath(src, dst, bitrate, bidir, ob_band) -> str: if not TESTING: urlx = "" headers = {"Content-Type": "application/json"} @@ -142,6 +142,24 @@ def add_lightpath(src, dst, bitrate, bidir, ob_band) -> str: if bidir == 0: return reply_uni_txt return reply_bid_txt + +def add_lightpath(src, dst, bitrate, bidir) -> str: + if not TESTING: + urlx = "" + headers = {"Content-Type": "application/json"} + base_url = get_optical_controller_base_url() + if bidir is None: + bidir = 1 + urlx = "{:s}/AddLightpath/{:s}/{:s}/{:s}/{:s}".format(base_url, src, dst, str(bitrate), str(bidir)) + r = requests.put(urlx, headers=headers) + print(f"addpathlight {r}") + reply = r.text + return reply + else: + if bidir is not None: + if bidir == 0: + return reply_uni_txt + return reply_bid_txt def get_optical_band(idx) -> str: -- GitLab