diff --git a/my_deploy.sh b/my_deploy.sh index 7bb15dd968ff4876705e8fdc87103e723c5a74dd..c05da4c5f332adebe2d3943cdfc4d086bd675bf5 100755 --- a/my_deploy.sh +++ b/my_deploy.sh @@ -99,10 +99,10 @@ export CRDB_DATABASE="tfs" export CRDB_DEPLOY_MODE="single" # Disable flag for dropping database, if it exists. -export CRDB_DROP_DATABASE_IF_EXISTS="" +export CRDB_DROP_DATABASE_IF_EXISTS="YES" # Disable flag for re-deploying CockroachDB from scratch. -export CRDB_REDEPLOY="YES" +export CRDB_REDEPLOY="" # ----- NATS ------------------------------------------------------------------- diff --git a/src/common/tools/object_factory/OpticalLink.py b/src/common/tools/object_factory/OpticalLink.py index 2ec83b39bdf722df23cd88ab449780af8cf66107..d4d7a330ce67fa2690efe3a0d285a226e3e6e7c3 100644 --- a/src/common/tools/object_factory/OpticalLink.py +++ b/src/common/tools/object_factory/OpticalLink.py @@ -42,4 +42,34 @@ def order_dict (dct:dict)->dict: ordered_lst= order_list(lst) if (len(ordered_lst)>0): return list_to_dict (ordered_lst) - \ No newline at end of file + +def order_dict_v1 (dct:dict)->dict: + + lst = list() + for key,value in dct.items(): + lst.append((int(key),value)) + ordered_lst= order_list(lst) + if (len(ordered_lst)>0): + return list_to_dict (ordered_lst) + +def correct_slot (dic:dict): + ordered_dict= order_dict_v1(dic) + keys_list = list(ordered_dict.keys()) + + if (len(keys_list) < 20): + num_keys= [] + for i in keys_list: + num_keys.append(int(i)) + + if num_keys[-1] != 20 : + missed_keys=[] + diff= 20 - len(num_keys) + print(f"diff {diff}") + for i in range(diff+1): + missed_keys.append(num_keys[-1]+i) + print(f"missed_keys {missed_keys}") + for key in missed_keys : + ordered_dict[key]=1 + print(f"result {ordered_dict}") + return order_dict_v1(ordered_dict) + \ No newline at end of file diff --git a/src/context/service/database/OpticalLink.py b/src/context/service/database/OpticalLink.py index e4ffefd49cea9c6dfbba08102d1a9d2f414740c1..6c99450b96be2dd1f4769ed3ee0e273044dd5a79 100644 --- a/src/context/service/database/OpticalLink.py +++ b/src/context/service/database/OpticalLink.py @@ -129,14 +129,14 @@ def optical_link_set(db_engine : Engine, messagebroker : MessageBroker, request index_elements=[OpticalLinkModel.opticallink_uuid], set_=dict( updated_at = stmt.excluded.updated_at, - src_port =stmt.excluded.src_port, - dst_port =stmt.excluded.dst_port, - local_peer_port = stmt.excluded.local_peer_port, - remote_peer_port = stmt.excluded.remote_peer_port, - used = stmt.excluded.used , - c_slots = stmt.excluded.c_slots, - l_slots = stmt.excluded.l_slots, - s_slots = stmt.excluded.s_slots + src_port = stmt.excluded.src_port, + dst_port = stmt.excluded.dst_port, + local_peer_port = stmt.excluded.local_peer_port, + remote_peer_port = stmt.excluded.remote_peer_port, + used = stmt.excluded.used , + c_slots = stmt.excluded.c_slots, + l_slots = stmt.excluded.l_slots, + s_slots = stmt.excluded.s_slots ) ) stmt = stmt.returning(OpticalLinkModel.created_at, OpticalLinkModel.updated_at) diff --git a/src/context/service/database/Topology.py b/src/context/service/database/Topology.py index c20641116b91ce79ae00ee3e6df026ee6418c771..994197ed46c018baeeff41b02b83f41157f0bd80 100644 --- a/src/context/service/database/Topology.py +++ b/src/context/service/database/Topology.py @@ -84,7 +84,7 @@ def topology_get_details(db_engine : Engine, request : TopologyId) -> TopologyDe .options(selectinload(TopologyModel.topology_optical_links, TopologyOpticalLinkModel.optical_link, OpticalLinkModel.opticallink_endpoints))\ .filter_by(topology_uuid=topology_uuid).one_or_none() #.options(selectinload(DeviceModel.components))\ - LOGGER.info(f"optical_link from get_topology_details {obj.dump_details()['optical_links']} ") + return None if obj is None else obj.dump_details() obj = run_transaction(sessionmaker(bind=db_engine), callback) if obj is None: diff --git a/src/context/service/database/models/Slot.py b/src/context/service/database/models/Slot.py index cd2c273c982e19f6fc2c4db0703d98764dd95a3f..4daca913a72f803167ba52fa5d7d9abfca73390c 100644 --- a/src/context/service/database/models/Slot.py +++ b/src/context/service/database/models/Slot.py @@ -27,13 +27,13 @@ class SlotType(TypeDecorator): def process_bind_param(self, value, dialect): if value is not None: - logging.info(f"before ordering {value} ") + value =order_dict(value) - logging.info(f"after ordering {value} ") + bin_num="0b" for i,(key,val) in enumerate(value.items()): bin_num =bin_num + f"{val}" - logging.info(f"after ordering bin_num {bin_num} ") + int_num = int(bin_num,2) return int_num @@ -63,7 +63,7 @@ class C_Slot (SlotType): if (len(sliced_num) != 20) : for i in range(0,20 - len(sliced_num)): sliced_num='0'+sliced_num - logging.info(f"sliced_num {sliced_num}") + for i in range(len(sliced_num)): slot[str(self.start_point+i+1)]=int(sliced_num[i]) diff --git a/src/device/service/DeviceServiceServicerImpl.py b/src/device/service/DeviceServiceServicerImpl.py index 4483b9a3140c596809146bb0fbfa8d7cc80bd49e..b4d9a1c9d1fbb1574b23acee207c52ea7a084cb8 100644 --- a/src/device/service/DeviceServiceServicerImpl.py +++ b/src/device/service/DeviceServiceServicerImpl.py @@ -159,7 +159,7 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): # #endpoint.endpoint_id.device_id.CopyFrom(device.device_id) # pass - if 'opticalconfig' in new_optial_configs["new_optical_config"]: + if ('new_optical_config' in new_optial_configs and 'opticalconfig' in new_optial_configs["new_optical_config"]): context_client.SetOpticalConfig(new_optial_configs["new_optical_config"]['opticalconfig']) diff --git a/src/opticalcontroller/RSA.py b/src/opticalcontroller/RSA.py index f032682c86e3204dacedec3a20fd07b04dbb2310..dd693db0b098559552df4afaff922b65d3e0e9be 100644 --- a/src/opticalcontroller/RSA.py +++ b/src/opticalcontroller/RSA.py @@ -292,11 +292,31 @@ class RSA(): def restore_optical_band(self, optical_band_id, slots, band): + for i in slots: 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() + + + + + + def restore_optical_band_2(self, optical_band_id, slots, band ,links): + print(f"example of band { band}") + print(f"example of slots {slots}") + print(f"example of self.optical_bands_before { self.optical_bands}") + for i in slots: + self.optical_bands[optical_band_id][band][str(i)] = 1 + print(f"example of self.optical_bands_after { self.optical_bands}") + + link_name= self.optical_bands[optical_band_id]['links'][0] + link = self.get_link_by_name(link_name) + update_optical_band(optical_bands=self.optical_bands,optical_band_id=optical_band_id,band=band,link=link) + + def del_flow(self, flow, o_b_id = None): flows = flow["flows"] band = flow["band_type"] @@ -308,7 +328,7 @@ class RSA(): path = flow["path"] links = flow["links"] bidir = flow["bidir"] - + for l in links: if debug: print(l) @@ -316,15 +336,20 @@ class RSA(): #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())}") if not list_in_list(slots, str_list_to_int(fib[band].keys())): #self.restore_link(fib, slots, band) + print("invoking restore_link_2 from del_flow") self.restore_link_2(fib, slots, band,link=l) if debug: print(fib[band]) if o_b_id is not None: + if debug: print("restoring OB") - self.restore_optical_band(o_b_id, slots, 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) diff --git a/src/opticalcontroller/tools.py b/src/opticalcontroller/tools.py index 424d83f710904bdfa7b6b6996e6292a27d572aba..91dec7155ef7da67140d074e968660121bb0fd5c 100644 --- a/src/opticalcontroller/tools.py +++ b/src/opticalcontroller/tools.py @@ -3,6 +3,7 @@ from variables import * import json , logging from context.client.ContextClient import ContextClient from common.proto.context_pb2 import TopologyId , LinkId , OpticalLink , OpticalLinkDetails +from common.tools.object_factory.OpticalLink import correct_slot def common_slots(a, b): @@ -228,7 +229,30 @@ def slot_selection(c, l, s, n_slots, Nc, Nl, Ns): def handle_slot (slot_field, slot): for key,value in slot.items() : slot_field[key]=value + + + +def update_optical_band (optical_bands,optical_band_id,band,link): + key_list = optical_bands[optical_band_id][band].keys() + corrected_slots=optical_bands[optical_band_id][band] + print(f"band {band}") + print(f"corrected_slots_before {corrected_slots}") + if (len(key_list) < 20): + corrected_slots=correct_slot(optical_bands[optical_band_id][band]) + fib={} + print(f"corrected_slots_after {corrected_slots}") + fib['c_slots']=link['optical_details']['c_slots'] + fib['l_slots']=link['optical_details']['l_slots'] + fib['s_slots']=link['optical_details']['s_slots'] + + fib[band]=corrected_slots + fib["src_port"]=optical_bands[optical_band_id]['src_port'] + fib["dst_port"]=optical_bands[optical_band_id]['dst_port'] + fib["local_peer_port"]=link["optical_details"]["local_peer_port"] + fib["remote_peer_port"]=link["optical_details"]["remote_peer_port"] + set_link_update(fib,link,test=f"restoring_optical_band {link['link_id']}") + def set_link_update (fib:dict,link:dict,test="updating"): print(f"invoked from {test}") @@ -238,14 +262,25 @@ def set_link_update (fib:dict,link:dict,test="updating"): linkId.link_uuid.uuid=link["link_id"]["link_uuid"]["uuid"] optical_details = OpticalLinkDetails() optical_link.optical_details.length=0 - optical_link.optical_details.src_port=fib["src_port"] - optical_link.optical_details.dst_port=fib["dst_port"] - optical_link.optical_details.local_peer_port=fib['local_peer_port'] - optical_link.optical_details.remote_peer_port=fib['remote_peer_port'] + if "src_port" in fib : + optical_link.optical_details.src_port=fib["src_port"] + if "dst_port" in fib : + optical_link.optical_details.dst_port=fib["dst_port"] + if "local_peer_port" in fib : + optical_link.optical_details.local_peer_port=fib['local_peer_port'] + if "remote_peer_port" in fib: + optical_link.optical_details.remote_peer_port=fib['remote_peer_port'] + optical_link.optical_details.used=fib['used'] if 'used' in fib else False - handle_slot( optical_link.optical_details.c_slots,fib["c_slots"]) - handle_slot( optical_link.optical_details.s_slots,fib["s_slots"]) - handle_slot( optical_link.optical_details.l_slots,fib["l_slots"]) + if "c_slots" in fib : + + handle_slot( optical_link.optical_details.c_slots,fib["c_slots"]) + if "s_slots" in fib : + + handle_slot( optical_link.optical_details.s_slots,fib["s_slots"]) + if "l_slots" in fib : + + handle_slot( optical_link.optical_details.l_slots,fib["l_slots"]) optical_link.name=link['name'] @@ -258,3 +293,6 @@ def set_link_update (fib:dict,link:dict,test="updating"): ctx_client.SetOpticalLink(optical_link) except Exception as err: print (f"setOpticalLink {err}") + + + diff --git a/src/service/service/ServiceServiceServicerImpl.py b/src/service/service/ServiceServiceServicerImpl.py index f400de36b40863665691ea6f032f312ca7e9a145..239eca9aeb752675a2f03fc7474843d5355f351c 100644 --- a/src/service/service/ServiceServiceServicerImpl.py +++ b/src/service/service/ServiceServiceServicerImpl.py @@ -39,7 +39,8 @@ 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, get_optical_band,refresh_opticalcontroller + add_lightpath, delete_lightpath, adapt_reply, get_device_name_from_uuid, get_optical_band,refresh_opticalcontroller, + DelFlexLightpath ) @@ -370,9 +371,13 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): 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 + 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"] - reply = delete_lightpath(flow_id, src, dst, bitrate) + + reply = DelFlexLightpath(flow_id, src, dst, bitrate,ob_id) # 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 91ecb26ae7bf3b15e0ab0177ef6b1c38505be798..8927f252fab5acd3d0f2427f32d7ff6212430e69 100644 --- a/src/service/service/tools/OpticalTools.py +++ b/src/service/service/tools/OpticalTools.py @@ -137,6 +137,15 @@ def delete_lightpath(flow_id, src, dst, bitrate) -> str: reply = r.text return reply +def DelFlexLightpath (flow_id,src,dst,bitrate,o_band_id): + reply = "200" + if not testing: + urlx = "http://{}:{}/OpticalTFS/DelFlexLightpath/{}/{}/{}/{}/{}".format(OPTICAL_IP, OPTICAL_PORT, flow_id, src, dst, bitrate,o_band_id) + + headers = {"Content-Type": "application/json"} + r = requests.delete(urlx, headers=headers) + reply = r.text + return reply def get_lightpaths() -> str: urlx = "http://{}:{}/OpticalTFS/GetLightpaths".format(OPTICAL_IP, OPTICAL_PORT) diff --git a/src/webui/service/optical_link/routes.py b/src/webui/service/optical_link/routes.py index e9b8f18961120f5850976e48e1cefc9a56719222..8db38d479d104731fb60cfc4d2a41aa9e93eb709 100644 --- a/src/webui/service/optical_link/routes.py +++ b/src/webui/service/optical_link/routes.py @@ -73,6 +73,7 @@ def detail(link_uuid: str): s_slots= order_dict( link_obj.optical_details.s_slots) context_client.close() + return render_template('optical_link/detail.html',link=link_obj, device_names=device_names, endpoints_data=endpoints_data ,c_slots=c_slots,l_slots=l_slots,s_slots=s_slots)