diff --git a/src/common/Constants.py b/src/common/Constants.py index 21ac64a00037c7fc2d03d07fa7c6ad17197947ce..a5dca46a29d5d1a416aa135419c2bdf962c7753c 100644 --- a/src/common/Constants.py +++ b/src/common/Constants.py @@ -135,3 +135,14 @@ DEFAULT_SERVICE_HTTP_BASEURLS = { ServiceNameEnum.NBI .value : None, ServiceNameEnum.WEBUI.value : None, } + + +def OpticalServiceType(value): + if value == "multi_granular": + return 1 + elif value == "flexi_grid": + return 2 + elif value == "pmp": + return 3 + else: + return 1 diff --git a/src/opticalcontroller/OpticalController.py b/src/opticalcontroller/OpticalController.py index 9b0c330ece52f0264ef480aadf92875a79d27a73..4c211f9789f802da00ccfc6a3bce3cac35000a98 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////') -@optical.route('/AddLightpath///') +#@optical.route('/AddLightpath///') +@optical.route('/AddLightpath////') @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 82bd9c2326b5ad78d6487f025a47b3599b67c239..b111ea93da0b253f1f056d4cbabff213562a7e58 100644 --- a/src/opticalcontroller/RSA.py +++ b/src/opticalcontroller/RSA.py @@ -307,8 +307,7 @@ class RSA(): if 'used' in fib: fib['used'] = False #fib[band].keys().sort() - #set_link_update(fib,link,test="restoration") - + #set_link_update(fib,link,test="restoration") def restore_optical_band(self, optical_band_id, slots, band): @@ -316,13 +315,8 @@ class RSA(): self.optical_bands[optical_band_id][band][str(i)] = 1 #self.optical_bands[optical_band_id][band].append(int(i)) - #self.optical_bands[optical_band_id][band].sort() - - - - + #self.optical_bands[optical_band_id][band].sort() - def restore_optical_band_2(self, optical_band_id, slots, band ,links): print(f"example of band { band}") print(f"example of slots {slots}") @@ -362,11 +356,7 @@ class RSA(): self.restore_link_2(fib, slots, band, link=link) if debug: print(fib[band]) - - - - if o_b_id is not None: - + if o_b_id is not None: if debug: print("restoring OB") print(f"invoking restore_optical_band o_b_id: {o_b_id} , slots {slots} , band {band} ") @@ -413,8 +403,6 @@ class RSA(): def del_band(self, flow, o_b_id = None): print(f"delete band {flow} ") - - flows = flow["flows"] band = None #slots = flow["slots"] @@ -430,13 +418,17 @@ class RSA(): links= self.optical_bands[o_b_id]["links"] band = self.optical_bands[o_b_id]["band_type"] n_slots =self.optical_bands[o_b_id]["n_slots"] - if n_slots > 0: - #slots=[i+1 for i in range(n_slots)] - for key in self.optical_bands[o_b_id][band].keys(): - slots.append(int(key)) - slots.sort() - - + if isinstance(n_slots, str): + if n_slots == "full_band": + for key in self.optical_bands[o_b_id][band].keys(): + slots.append(int(key)) + slots.sort() + elif isinstance(n_slots, int): + if n_slots > 0: + #slots=[i+1 for i in range(n_slots)] + for key in self.optical_bands[o_b_id][band].keys(): + slots.append(int(key)) + slots.sort() for l in links: if debug: print(l) @@ -593,18 +585,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 +744,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 fb4537925d5a287e32e2f0ad63a8fcf5d3244989..0e8ae981f4af59df512f741a49513dc90eaf7d24 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 ) @@ -287,6 +287,7 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): dst = devs[1] bidir = None ob_band = None + oc_type = 1 bitrate = 100 for constraint in service.service_constraints: if "bandwidth" in constraint.custom.constraint_type: @@ -295,11 +296,19 @@ 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.debug('[optical] reply_json[{:s}]={:s}'.format(str(type(reply_json)), str(reply_json))) optical_band_txt = "" @@ -406,37 +415,44 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): dst = get_device_name_from_uuid(devices, devs[1]) bitrate = 100 bidir = 0 + oc_type = 1 for constraint in service.service_constraints: if "bandwidth" in constraint.custom.constraint_type: bitrate = int(float(constraint.custom.constraint_value)) - break + if "type" in constraint.custom.constraint_type: + oc_type = OpticalServiceType(str(constraint.custom.constraint_value)) + ''' if service.service_constraints: bitrate = int(float( service.service_constraints[0].custom.constraint_value - )) - if len(service.service_config.config_rules) > 0: - c_rules_dict = json.loads( - service.service_config.config_rules[0].custom.resource_value) - ob_id=None - flow_id=None - if "ob_id" in c_rules_dict: - ob_id = c_rules_dict["ob_id"] - if ("flow_id" in c_rules_dict): - flow_id = c_rules_dict["flow_id"] - #if ("ob_id" in c_rules_dict): - # ob_id = c_rules_dict["ob_id"] - params['bitrate'] = bitrate - params['dst' ] = dst - params['src' ] = src - params['ob_id' ] = ob_id - params['flow_id'] = flow_id - params['bidir' ] = bidir - + )) + ''' + #multi-granular + if oc_type == 1: + if len(service.service_config.config_rules) > 0: + c_rules_dict = json.loads( + service.service_config.config_rules[0].custom.resource_value + ) + ob_id = None + flow_id = None + if "ob_id" in c_rules_dict: + ob_id = c_rules_dict["ob_id"] + if ("flow_id" in c_rules_dict): + flow_id = c_rules_dict["flow_id"] + #if ("ob_id" in c_rules_dict): + # ob_id = c_rules_dict["ob_id"] + params['bitrate'] = bitrate + params['dst' ] = dst + params['src' ] = src + params['ob_id' ] = ob_id + params['flow_id'] = flow_id + params['bidir' ] = bidir - tasks_scheduler = TasksScheduler(self.service_handler_factory) - tasks_scheduler.compose_from_optical_service(service, params=params, is_delete=True) - tasks_scheduler.execute_all() - return Empty() + + tasks_scheduler = TasksScheduler(self.service_handler_factory) + tasks_scheduler.compose_from_optical_service(service, params=params, is_delete=True) + tasks_scheduler.execute_all() + return Empty() # Normal service # Feed TaskScheduler with this service and the sub-services and sub-connections related to this service. diff --git a/src/service/service/tools/OpticalTools.py b/src/service/service/tools/OpticalTools.py index bc5ea725875992c5a661ebbf34841c2e1656815a..8f03f0338e9b998557166d6f88c279cee3978dff 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: