diff --git a/src/opticalcontroller/OpticalController.py b/src/opticalcontroller/OpticalController.py index d78494d9ba676160c2931f52bec10a6c9d2984af..d7b589b4307995e9f93a4ede804567d99501a3c1 100644 --- a/src/opticalcontroller/OpticalController.py +++ b/src/opticalcontroller/OpticalController.py @@ -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}") @@ -109,7 +110,8 @@ class DelFLightpath(Resource): ob_id = flow["parent_opt_band"] rsa.del_flow(flow, ob_id) rsa.db_flows[flow_id]["is_active"] = False - rsa.optical_bands[ob_id]["served_lightpaths"].remove(flow_id) + 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"] # rsa.optical_bands[rev_ob_id]["served_lightpaths"].remove(flow_id) @@ -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 diff --git a/src/opticalcontroller/RSA.py b/src/opticalcontroller/RSA.py index 0ceb23475b4f50ddf9e5e4c2eb052f16a1943617..0401c2535f71c69e4948b981ccc043f1cc51cccd 100644 --- a/src/opticalcontroller/RSA.py +++ b/src/opticalcontroller/RSA.py @@ -390,7 +390,97 @@ class RSA(): # 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_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] @@ -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) diff --git a/src/service/service/ServiceServiceServicerImpl.py b/src/service/service/ServiceServiceServicerImpl.py index f036ad8f6e8be40ec7b34f2a4604d5d770346f5b..dbda6ce6d7bd15220c987fa501a70b1148af1efe 100644 --- a/src/service/service/ServiceServiceServicerImpl.py +++ b/src/service/service/ServiceServiceServicerImpl.py @@ -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) @@ -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) @@ -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() diff --git a/src/service/service/task_scheduler/TaskScheduler.py b/src/service/service/task_scheduler/TaskScheduler.py index 17b48d14d25ee1bd2d0168c634845c4d99943a01..dc231778a541315836df5c46353be926371d055d 100644 --- a/src/service/service/task_scheduler/TaskScheduler.py +++ b/src/service/service/task_scheduler/TaskScheduler.py @@ -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 @@ -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 @@ -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 @@ -198,15 +201,24 @@ class TasksScheduler: except queue.Empty: 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) self._add_service_to_executor_cache(item) diff --git a/src/service/service/tools/OpticalTools.py b/src/service/service/tools/OpticalTools.py index 0e59d5c43780fe3a0e3fff3fcf51172436a692da..c7c0e76c456deb2371ff984b1dbe629f4532fea2 100644 --- a/src/service/service/tools/OpticalTools.py +++ b/src/service/service/tools/OpticalTools.py @@ -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) diff --git a/src/tests/ofc24/get_topology.sh b/src/tests/ofc24/get_bands.sh similarity index 100% rename from src/tests/ofc24/get_topology.sh rename to src/tests/ofc24/get_bands.sh diff --git a/src/tests/ofc24/get_lightpath.sh b/src/tests/ofc24/get_lightpath.sh new file mode 100644 index 0000000000000000000000000000000000000000..f5c7206e756a05138d5ec054ca1e6298b88cde5d --- /dev/null +++ b/src/tests/ofc24/get_lightpath.sh @@ -0,0 +1,11 @@ +#!/bin/bash +ip=$(sudo kubectl get all --all-namespaces | grep service/opticalcontrollerservice | awk '{print $4}') + +#echo $ip + +#push=$(curl -X GET "http://$ip:10060/OpticalTFS/GetTopology/admin/admin") + + +links=$(curl -X GET "http://$ip:10060/OpticalTFS/GetLightpaths") + +echo $links \ No newline at end of file diff --git a/src/tests/ofc24/get_links.sh b/src/tests/ofc24/get_links.sh new file mode 100644 index 0000000000000000000000000000000000000000..2799934ad8d927e40607c3285cc2ff447d4e48d7 --- /dev/null +++ b/src/tests/ofc24/get_links.sh @@ -0,0 +1,11 @@ +#!/bin/bash +ip=$(sudo kubectl get all --all-namespaces | grep service/opticalcontrollerservice | awk '{print $4}') + +#echo $ip + +#push=$(curl -X GET "http://$ip:10060/OpticalTFS/GetTopology/admin/admin") + + +links=$(curl -X GET "http://$ip:10060/OpticalTFS/GetLinks") + +echo $links \ No newline at end of file