Loading src/opticalcontroller/OpticalController.py +10 −5 Original line number Diff line number Diff line Loading @@ -93,11 +93,12 @@ class AddFlexLightpath(Resource): return "Error", 404 @optical.route('/DelFlexLightpath/<int:flow_id>/<string:src>/<string:dst>/<int:bitrate>/<int:o_band_id>') @optical.route('/DelFlexLightpath/<int:flow_id>/<string:src>/<string:dst>/<int:bitrate>/<int:o_band_id>/<string:delete_band>') @optical.response(200, 'Success') @optical.response(404, 'Error, not found') class DelFLightpath(Resource): @staticmethod def delete(flow_id, src, dst, bitrate, o_band_id): def delete(flow_id, src, dst, bitrate, o_band_id,delete_band): if flow_id in rsa.db_flows.keys(): flow = rsa.db_flows[flow_id] print(f"delete flexlightpath flow {flow}") Loading @@ -109,6 +110,7 @@ class DelFLightpath(Resource): ob_id = flow["parent_opt_band"] rsa.del_flow(flow, ob_id) rsa.db_flows[flow_id]["is_active"] = False if flow_id in rsa.optical_bands[ob_id]["served_lightpaths"].remove: rsa.optical_bands[ob_id]["served_lightpaths"].remove(flow_id) #if rsa.optical_bands[ob_id]["reverse_optical_band_id"] != 0: # rev_ob_id = rsa.optical_bands[ob_id]["reverse_optical_band_id"] Loading @@ -122,11 +124,14 @@ class DelFLightpath(Resource): else: if match1: ob_id = flow["parent_opt_band"] rsa.del_flow(flow, ob_id) rsa.del_handler(flow,flow_id,ob_id,delete_band) rsa.db_flows[flow_id]["is_active"] = False rsa.optical_bands[ob_id]["served_lightpaths"].remove(flow_id) if debug: print(rsa.links_dict) print(f"vor ob_id {ob_id} rsa.optical_bands {rsa.optical_bands[ob_id]}") print(f"rsa.links_dict {rsa.links_dict}") return "flow {} deleted".format(flow_id), 200 else: return "flow {} not matching".format(flow_id), 404 Loading src/opticalcontroller/RSA.py +95 −1 Original line number Diff line number Diff line Loading @@ -391,6 +391,96 @@ class RSA(): # self.restore_optical_band(rev_o_band_id, slots, band) return True def del_band(self, flow,flow_id, o_b_id = None): print(f"delete band {flow} ") flows = flow["flows"] band = None slots = flow["slots"] fiber_f = flow["fiber_forward"] fiber_b = flow["fiber_backward"] op = flow["op-mode"] n_slots = 0 path = flow["path"] bidir = flow["bidir"] links = [] if o_b_id is not None: 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 l in links: if debug: print(l) #link = self.links_dict[l] #f = fiber_f[l] #fib = link['fibers'][f] fib = self.get_link_by_name(l)["optical_details"] print(f"del_flow_fib {fib } and band {band}") print(f"del_flow { str_list_to_int(fib[band].keys())}") print(f"invoking restore_link_2 fib: {fib} , slots {slots} , band {band} ") self.restore_link(fib, slots, band) self.optical_bands[o_b_id]["is_active"]=False if flow_id in self.optical_bands[o_b_id]["served_lightpaths"]: self.optical_bands[o_b_id]["served_lightpaths"].remove(flow_id) if debug: print(fib[band]) 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} ") self.restore_optical_band(o_b_id, slots, band) #self.restore_optical_band_2(o_b_id, slots, band,links) if bidir: for l in links: r_l = reverse_link(l) if debug: print(r_l) # link = self.links_dict[l] # f = fiber_f[l] # fib = link['fibers'][f] fib = self.get_link_by_name(r_l)["optical_details"] if list_in_list(slots, str_list_to_int(fib[band].keys())): self.restore_link(fib, slots, band, link=l) if debug: print(fib[band]) ''' for rl in fiber_b.keys(): if debug: print(rl) print(fiber_b[rl]) #rlink = self.links_dict[rl] #rf = fiber_b[rl] #rfib = rlink['fibers'][rf] rfib = self.get_fiber_details(rl, fiber_b[rl]) if not list_in_list(slots, rfib[band]): self.restore_link(rfib, slots, band) if debug: print(rfib[band]) ''' #changed according to TFS development #if o_b_id is not None: # rev_o_band_id = self.optical_bands[o_b_id]["reverse_optical_band_id"] # self.restore_optical_band(rev_o_band_id, slots, band) return True def del_handler(self, flow,flow_id, o_b_id = None,delete_band=False): print(f" del_handler flow {flow} flow_id {flow_id} o_b_id {o_b_id} delete_band {delete_band}") if delete_band != 'False': print(f"delete band del_band") self.del_band(flow,flow_id,o_b_id=o_b_id) else : self.del_flow(flow,o_b_id=o_b_id) def get_fibers_forward(self, links, slots, band): fiber_list = {} add = links[0] Loading Loading @@ -940,6 +1030,10 @@ class RSA(): #first checking in existing OB ob_found = 0 for ob_id in existing_ob: if "is_active" in self.optical_bands[ob_id].keys(): is_active = self.optical_bands[ob_id]["is_active"] if not is_active: continue op, num_slots = map_rate_to_slot(rate) if debug: print(temp_links2) Loading src/service/service/ServiceServiceServicerImpl.py +18 −4 Original line number Diff line number Diff line Loading @@ -353,6 +353,13 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): return Empty() if service.service_type == ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY: params={ "src":None, "dst":None, "bitrate":None, 'ob_id':None, 'flow_id':None } devs = [] context_id_x = json_context_id(DEFAULT_CONTEXT_NAME) Loading @@ -370,8 +377,9 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): if "bandwidth" in constraint.custom.constraint_type: bitrate = int(float(constraint.custom.constraint_value)) break #bitrate = int( # float(service.service_constraints[0].custom.constraint_value)) 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) Loading @@ -383,10 +391,16 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): flow_id = c_rules_dict["flow_id"] #if ("ob_id" in c_rules_dict): # ob_id = c_rules_dict["ob_id"] reply = delete_lightpath(flow_id, src, dst, bitrate, ob_id) params['bitrate']=bitrate params['dst']=dst params['src']=src params['ob_id']=ob_id params['flow_id']=flow_id tasks_scheduler = TasksScheduler(self.service_handler_factory) tasks_scheduler.compose_from_optical_service(service, is_delete=True) tasks_scheduler.compose_from_optical_service(service, params=params,is_delete=True ) tasks_scheduler.execute_all() return Empty() Loading src/service/service/task_scheduler/TaskScheduler.py +19 −7 Original line number Diff line number Diff line Loading @@ -12,9 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. import graphlib, logging, queue, time import graphlib, logging, queue, time ,json from typing import TYPE_CHECKING, Dict, Tuple from common.proto.context_pb2 import Connection, ConnectionId, Service, ServiceId, ServiceStatusEnum,ConnectionList from common.proto.context_pb2 import (Connection, ConnectionId, Service , ServiceId, ServiceStatusEnum,ConnectionList ,DeviceList) from common.proto.pathcomp_pb2 import PathCompReply from common.tools.grpc.Tools import grpc_message_to_json_string from context.client.ContextClient import ContextClient Loading @@ -27,6 +29,7 @@ from .tasks.Task_ConnectionDeconfigure import Task_ConnectionDeconfigure from .tasks.Task_ServiceDelete import Task_ServiceDelete from .tasks.Task_ServiceSetStatus import Task_ServiceSetStatus from .TaskExecutor import CacheableObjectType, TaskExecutor from service.service.tools.OpticalTools import delete_lightpath if TYPE_CHECKING: from service.service.service_handler_api.ServiceHandlerFactory import ServiceHandlerFactory Loading Loading @@ -178,12 +181,12 @@ class TasksScheduler: connection_uuid = connection.connection_id.connection_uuid.uuid if class_service_handler is None: class_service_handler=self._executor.get_service_handler(connection, service,**service_handler_settings) LOGGER.info(f"checking media_channel for service {connection_uuid}") if class_service_handler.check_media_channel(connection_uuid): return True return False def compose_from_optical_service(self, service : Service, is_delete : bool = False) -> None: def compose_from_optical_service(self, service : Service,params:dict, is_delete : bool = False) -> None: t0 = time.time() include_service = self._optical_service_remove if is_delete else self._service_create include_connection = self._optical_connection_deconfigure if is_delete else self._connection_configure Loading @@ -200,12 +203,21 @@ class TasksScheduler: break if isinstance(item, Service): LOGGER.info(f"item instace is srevice") str_item_key = grpc_message_to_json_string(item.service_id) if str_item_key in explored_items: continue connections = self._context_client.ListConnections(item.service_id) has_media_channel=self.check_service_for_media_channel(connections=connections,item=item.service_id) LOGGER.info(f"checking if media_channel_existed {has_media_channel}") if len(service.service_config.config_rules) > 0: reply = delete_lightpath(params['flow_id'] , params['src'] ,params ['dst'] , params['bitrate'] , params['ob_id'] ,delete_band=not has_media_channel) include_service(item.service_id,has_media_channel=has_media_channel) Loading src/service/service/tools/OpticalTools.py +2 −2 Original line number Diff line number Diff line Loading @@ -127,10 +127,10 @@ def get_optical_band(idx) -> str: return optical_band_uni_txt def delete_lightpath(flow_id, src, dst, bitrate, ob_id) -> str: def delete_lightpath(flow_id, src, dst, bitrate, ob_id,delete_band) -> str: reply = "200" if not testing: urlx = "http://{}:{}/OpticalTFS/DelFlexLightpath/{}/{}/{}/{}/{}".format(OPTICAL_IP, OPTICAL_PORT, flow_id, src, dst, bitrate, ob_id) urlx = "http://{}:{}/OpticalTFS/DelFlexLightpath/{}/{}/{}/{}/{}/{}".format(OPTICAL_IP, OPTICAL_PORT, flow_id, src, dst, bitrate, ob_id,delete_band) headers = {"Content-Type": "application/json"} r = requests.delete(urlx, headers=headers) Loading Loading
src/opticalcontroller/OpticalController.py +10 −5 Original line number Diff line number Diff line Loading @@ -93,11 +93,12 @@ class AddFlexLightpath(Resource): return "Error", 404 @optical.route('/DelFlexLightpath/<int:flow_id>/<string:src>/<string:dst>/<int:bitrate>/<int:o_band_id>') @optical.route('/DelFlexLightpath/<int:flow_id>/<string:src>/<string:dst>/<int:bitrate>/<int:o_band_id>/<string:delete_band>') @optical.response(200, 'Success') @optical.response(404, 'Error, not found') class DelFLightpath(Resource): @staticmethod def delete(flow_id, src, dst, bitrate, o_band_id): def delete(flow_id, src, dst, bitrate, o_band_id,delete_band): if flow_id in rsa.db_flows.keys(): flow = rsa.db_flows[flow_id] print(f"delete flexlightpath flow {flow}") Loading @@ -109,6 +110,7 @@ class DelFLightpath(Resource): ob_id = flow["parent_opt_band"] rsa.del_flow(flow, ob_id) rsa.db_flows[flow_id]["is_active"] = False if flow_id in rsa.optical_bands[ob_id]["served_lightpaths"].remove: rsa.optical_bands[ob_id]["served_lightpaths"].remove(flow_id) #if rsa.optical_bands[ob_id]["reverse_optical_band_id"] != 0: # rev_ob_id = rsa.optical_bands[ob_id]["reverse_optical_band_id"] Loading @@ -122,11 +124,14 @@ class DelFLightpath(Resource): else: if match1: ob_id = flow["parent_opt_band"] rsa.del_flow(flow, ob_id) rsa.del_handler(flow,flow_id,ob_id,delete_band) rsa.db_flows[flow_id]["is_active"] = False rsa.optical_bands[ob_id]["served_lightpaths"].remove(flow_id) if debug: print(rsa.links_dict) print(f"vor ob_id {ob_id} rsa.optical_bands {rsa.optical_bands[ob_id]}") print(f"rsa.links_dict {rsa.links_dict}") return "flow {} deleted".format(flow_id), 200 else: return "flow {} not matching".format(flow_id), 404 Loading
src/opticalcontroller/RSA.py +95 −1 Original line number Diff line number Diff line Loading @@ -391,6 +391,96 @@ class RSA(): # self.restore_optical_band(rev_o_band_id, slots, band) return True def del_band(self, flow,flow_id, o_b_id = None): print(f"delete band {flow} ") flows = flow["flows"] band = None slots = flow["slots"] fiber_f = flow["fiber_forward"] fiber_b = flow["fiber_backward"] op = flow["op-mode"] n_slots = 0 path = flow["path"] bidir = flow["bidir"] links = [] if o_b_id is not None: 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 l in links: if debug: print(l) #link = self.links_dict[l] #f = fiber_f[l] #fib = link['fibers'][f] fib = self.get_link_by_name(l)["optical_details"] print(f"del_flow_fib {fib } and band {band}") print(f"del_flow { str_list_to_int(fib[band].keys())}") print(f"invoking restore_link_2 fib: {fib} , slots {slots} , band {band} ") self.restore_link(fib, slots, band) self.optical_bands[o_b_id]["is_active"]=False if flow_id in self.optical_bands[o_b_id]["served_lightpaths"]: self.optical_bands[o_b_id]["served_lightpaths"].remove(flow_id) if debug: print(fib[band]) 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} ") self.restore_optical_band(o_b_id, slots, band) #self.restore_optical_band_2(o_b_id, slots, band,links) if bidir: for l in links: r_l = reverse_link(l) if debug: print(r_l) # link = self.links_dict[l] # f = fiber_f[l] # fib = link['fibers'][f] fib = self.get_link_by_name(r_l)["optical_details"] if list_in_list(slots, str_list_to_int(fib[band].keys())): self.restore_link(fib, slots, band, link=l) if debug: print(fib[band]) ''' for rl in fiber_b.keys(): if debug: print(rl) print(fiber_b[rl]) #rlink = self.links_dict[rl] #rf = fiber_b[rl] #rfib = rlink['fibers'][rf] rfib = self.get_fiber_details(rl, fiber_b[rl]) if not list_in_list(slots, rfib[band]): self.restore_link(rfib, slots, band) if debug: print(rfib[band]) ''' #changed according to TFS development #if o_b_id is not None: # rev_o_band_id = self.optical_bands[o_b_id]["reverse_optical_band_id"] # self.restore_optical_band(rev_o_band_id, slots, band) return True def del_handler(self, flow,flow_id, o_b_id = None,delete_band=False): print(f" del_handler flow {flow} flow_id {flow_id} o_b_id {o_b_id} delete_band {delete_band}") if delete_band != 'False': print(f"delete band del_band") self.del_band(flow,flow_id,o_b_id=o_b_id) else : self.del_flow(flow,o_b_id=o_b_id) def get_fibers_forward(self, links, slots, band): fiber_list = {} add = links[0] Loading Loading @@ -940,6 +1030,10 @@ class RSA(): #first checking in existing OB ob_found = 0 for ob_id in existing_ob: if "is_active" in self.optical_bands[ob_id].keys(): is_active = self.optical_bands[ob_id]["is_active"] if not is_active: continue op, num_slots = map_rate_to_slot(rate) if debug: print(temp_links2) Loading
src/service/service/ServiceServiceServicerImpl.py +18 −4 Original line number Diff line number Diff line Loading @@ -353,6 +353,13 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): return Empty() if service.service_type == ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY: params={ "src":None, "dst":None, "bitrate":None, 'ob_id':None, 'flow_id':None } devs = [] context_id_x = json_context_id(DEFAULT_CONTEXT_NAME) Loading @@ -370,8 +377,9 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): if "bandwidth" in constraint.custom.constraint_type: bitrate = int(float(constraint.custom.constraint_value)) break #bitrate = int( # float(service.service_constraints[0].custom.constraint_value)) 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) Loading @@ -383,10 +391,16 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): flow_id = c_rules_dict["flow_id"] #if ("ob_id" in c_rules_dict): # ob_id = c_rules_dict["ob_id"] reply = delete_lightpath(flow_id, src, dst, bitrate, ob_id) params['bitrate']=bitrate params['dst']=dst params['src']=src params['ob_id']=ob_id params['flow_id']=flow_id tasks_scheduler = TasksScheduler(self.service_handler_factory) tasks_scheduler.compose_from_optical_service(service, is_delete=True) tasks_scheduler.compose_from_optical_service(service, params=params,is_delete=True ) tasks_scheduler.execute_all() return Empty() Loading
src/service/service/task_scheduler/TaskScheduler.py +19 −7 Original line number Diff line number Diff line Loading @@ -12,9 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. import graphlib, logging, queue, time import graphlib, logging, queue, time ,json from typing import TYPE_CHECKING, Dict, Tuple from common.proto.context_pb2 import Connection, ConnectionId, Service, ServiceId, ServiceStatusEnum,ConnectionList from common.proto.context_pb2 import (Connection, ConnectionId, Service , ServiceId, ServiceStatusEnum,ConnectionList ,DeviceList) from common.proto.pathcomp_pb2 import PathCompReply from common.tools.grpc.Tools import grpc_message_to_json_string from context.client.ContextClient import ContextClient Loading @@ -27,6 +29,7 @@ from .tasks.Task_ConnectionDeconfigure import Task_ConnectionDeconfigure from .tasks.Task_ServiceDelete import Task_ServiceDelete from .tasks.Task_ServiceSetStatus import Task_ServiceSetStatus from .TaskExecutor import CacheableObjectType, TaskExecutor from service.service.tools.OpticalTools import delete_lightpath if TYPE_CHECKING: from service.service.service_handler_api.ServiceHandlerFactory import ServiceHandlerFactory Loading Loading @@ -178,12 +181,12 @@ class TasksScheduler: connection_uuid = connection.connection_id.connection_uuid.uuid if class_service_handler is None: class_service_handler=self._executor.get_service_handler(connection, service,**service_handler_settings) LOGGER.info(f"checking media_channel for service {connection_uuid}") if class_service_handler.check_media_channel(connection_uuid): return True return False def compose_from_optical_service(self, service : Service, is_delete : bool = False) -> None: def compose_from_optical_service(self, service : Service,params:dict, is_delete : bool = False) -> None: t0 = time.time() include_service = self._optical_service_remove if is_delete else self._service_create include_connection = self._optical_connection_deconfigure if is_delete else self._connection_configure Loading @@ -200,12 +203,21 @@ class TasksScheduler: break if isinstance(item, Service): LOGGER.info(f"item instace is srevice") str_item_key = grpc_message_to_json_string(item.service_id) if str_item_key in explored_items: continue connections = self._context_client.ListConnections(item.service_id) has_media_channel=self.check_service_for_media_channel(connections=connections,item=item.service_id) LOGGER.info(f"checking if media_channel_existed {has_media_channel}") if len(service.service_config.config_rules) > 0: reply = delete_lightpath(params['flow_id'] , params['src'] ,params ['dst'] , params['bitrate'] , params['ob_id'] ,delete_band=not has_media_channel) include_service(item.service_id,has_media_channel=has_media_channel) Loading
src/service/service/tools/OpticalTools.py +2 −2 Original line number Diff line number Diff line Loading @@ -127,10 +127,10 @@ def get_optical_band(idx) -> str: return optical_band_uni_txt def delete_lightpath(flow_id, src, dst, bitrate, ob_id) -> str: def delete_lightpath(flow_id, src, dst, bitrate, ob_id,delete_band) -> str: reply = "200" if not testing: urlx = "http://{}:{}/OpticalTFS/DelFlexLightpath/{}/{}/{}/{}/{}".format(OPTICAL_IP, OPTICAL_PORT, flow_id, src, dst, bitrate, ob_id) urlx = "http://{}:{}/OpticalTFS/DelFlexLightpath/{}/{}/{}/{}/{}/{}".format(OPTICAL_IP, OPTICAL_PORT, flow_id, src, dst, bitrate, ob_id,delete_band) headers = {"Content-Type": "application/json"} r = requests.delete(urlx, headers=headers) Loading