Loading src/opticalcontroller/RSA.py +20 −16 Original line number Diff line number Diff line Loading @@ -69,27 +69,31 @@ class RSA(): return "{},{},{}".format(self.c_slot_number, self.l_slot_number, self.s_slot_number) def init_link_slots2(self): def initialize_band_slots(fib: dict, band_name: str, width: int) -> int: band_slots = fib.get(band_name) if not band_slots: return 0 fib[band_name] = {str(slot_index): 1 for slot_index in range(width)} return width if full_links: print("2026 initialize full spectrum") for l in self.links_dict["optical_links"]: fib = l["optical_details"] #fib = self.links_dict[l]["fibers"][f] if len(fib["c_slots"]) > 0: for c in range(0, Nc): fib["c_slots"][str(c)] = 1 if len(fib["l_slots"]) > 0: for c in range(0, Nl): fib["l_slots"][str(c)] = 1 if len(fib["s_slots"]) > 0: for c in range(0, Ns): fib["s_slots"][str(c)] = 1 self.c_slot_number = initialize_band_slots(fib, "c_slots", Nc) self.l_slot_number = initialize_band_slots(fib, "l_slots", Nl) self.s_slot_number = initialize_band_slots(fib, "s_slots", Ns) if debug: print(fib) if self.c_slot_number == 0 and self.l_slot_number == 0 and self.s_slot_number == 0: for l1 in self.links_dict["optical_links"]: fib1 = l1["optical_details"] self.c_slot_number = len(fib1["c_slots"].keys()) self.l_slot_number = len(fib1["l_slots"].keys()) self.s_slot_number = len(fib1["s_slots"].keys()) self.c_slot_number = len(fib1.get("c_slots", {}).keys()) self.l_slot_number = len(fib1.get("l_slots", {}).keys()) self.s_slot_number = len(fib1.get("s_slots", {}).keys()) break return "{},{},{}".format(self.c_slot_number, self.l_slot_number, self.s_slot_number) Loading src/opticalcontroller/tools.py +25 −16 Original line number Diff line number Diff line Loading @@ -149,27 +149,36 @@ def get_slot_frequency(b, n): def get_side_slots_on_link(link, val, old_slots): #link = l["optical_details"][band] x = list(old_slots.keys()) y = list(link.keys()) keys = str_list_to_int(x) keys.sort() #print("AAAA") #print(link, val, old_slots, keys) #print(x) starting_slot = keys[-1] current_slots = str_list_to_int(list(old_slots.keys())) if isinstance(old_slots, dict) else sorted([ int(slot) for slot in old_slots ]) available_slots = str_list_to_int(list(link.keys())) if len(current_slots) == 0 or len(available_slots) == 0: return [], 0 starting_slot = current_slots[-1] + 1 num = 0 res = [] #print(starting_slot) for slot_id in range(starting_slot, len(y)): if link[y[slot_id]] == 1: for slot_id in available_slots: if slot_id < starting_slot: continue expected_slot = starting_slot + num if slot_id != expected_slot: return res, 0 if link[str(slot_id)] == 1: num += 1 res.append(int(y[slot_id])) res.append(slot_id) else: return res, 0 if num == val or slot_id == len(y) - 1: if num == val or slot_id == available_slots[-1]: return res, num return res, 0 def frequency_converter(b, slots): l = len(slots) Loading Loading @@ -305,7 +314,8 @@ 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] if (len(key_list) < 20): corrected_slots=correct_slot(optical_bands[optical_band_id][band]) band_width = Nc if band == "c_slots" else Nl if band == "l_slots" else Ns corrected_slots=correct_slot(optical_bands[optical_band_id][band], width=band_width) fib={} fib['c_slots']=link['optical_details']['c_slots'] Loading Loading @@ -362,4 +372,3 @@ def set_link_update (fib:dict,link:dict,test="updating"): print (f"setOpticalLink {err}") Loading
src/opticalcontroller/RSA.py +20 −16 Original line number Diff line number Diff line Loading @@ -69,27 +69,31 @@ class RSA(): return "{},{},{}".format(self.c_slot_number, self.l_slot_number, self.s_slot_number) def init_link_slots2(self): def initialize_band_slots(fib: dict, band_name: str, width: int) -> int: band_slots = fib.get(band_name) if not band_slots: return 0 fib[band_name] = {str(slot_index): 1 for slot_index in range(width)} return width if full_links: print("2026 initialize full spectrum") for l in self.links_dict["optical_links"]: fib = l["optical_details"] #fib = self.links_dict[l]["fibers"][f] if len(fib["c_slots"]) > 0: for c in range(0, Nc): fib["c_slots"][str(c)] = 1 if len(fib["l_slots"]) > 0: for c in range(0, Nl): fib["l_slots"][str(c)] = 1 if len(fib["s_slots"]) > 0: for c in range(0, Ns): fib["s_slots"][str(c)] = 1 self.c_slot_number = initialize_band_slots(fib, "c_slots", Nc) self.l_slot_number = initialize_band_slots(fib, "l_slots", Nl) self.s_slot_number = initialize_band_slots(fib, "s_slots", Ns) if debug: print(fib) if self.c_slot_number == 0 and self.l_slot_number == 0 and self.s_slot_number == 0: for l1 in self.links_dict["optical_links"]: fib1 = l1["optical_details"] self.c_slot_number = len(fib1["c_slots"].keys()) self.l_slot_number = len(fib1["l_slots"].keys()) self.s_slot_number = len(fib1["s_slots"].keys()) self.c_slot_number = len(fib1.get("c_slots", {}).keys()) self.l_slot_number = len(fib1.get("l_slots", {}).keys()) self.s_slot_number = len(fib1.get("s_slots", {}).keys()) break return "{},{},{}".format(self.c_slot_number, self.l_slot_number, self.s_slot_number) Loading
src/opticalcontroller/tools.py +25 −16 Original line number Diff line number Diff line Loading @@ -149,27 +149,36 @@ def get_slot_frequency(b, n): def get_side_slots_on_link(link, val, old_slots): #link = l["optical_details"][band] x = list(old_slots.keys()) y = list(link.keys()) keys = str_list_to_int(x) keys.sort() #print("AAAA") #print(link, val, old_slots, keys) #print(x) starting_slot = keys[-1] current_slots = str_list_to_int(list(old_slots.keys())) if isinstance(old_slots, dict) else sorted([ int(slot) for slot in old_slots ]) available_slots = str_list_to_int(list(link.keys())) if len(current_slots) == 0 or len(available_slots) == 0: return [], 0 starting_slot = current_slots[-1] + 1 num = 0 res = [] #print(starting_slot) for slot_id in range(starting_slot, len(y)): if link[y[slot_id]] == 1: for slot_id in available_slots: if slot_id < starting_slot: continue expected_slot = starting_slot + num if slot_id != expected_slot: return res, 0 if link[str(slot_id)] == 1: num += 1 res.append(int(y[slot_id])) res.append(slot_id) else: return res, 0 if num == val or slot_id == len(y) - 1: if num == val or slot_id == available_slots[-1]: return res, num return res, 0 def frequency_converter(b, slots): l = len(slots) Loading Loading @@ -305,7 +314,8 @@ 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] if (len(key_list) < 20): corrected_slots=correct_slot(optical_bands[optical_band_id][band]) band_width = Nc if band == "c_slots" else Nl if band == "l_slots" else Ns corrected_slots=correct_slot(optical_bands[optical_band_id][band], width=band_width) fib={} fib['c_slots']=link['optical_details']['c_slots'] Loading Loading @@ -362,4 +372,3 @@ def set_link_update (fib:dict,link:dict,test="updating"): print (f"setOpticalLink {err}")