Commit 4f78cbf1 authored by Andrea Sgambelluri's avatar Andrea Sgambelluri
Browse files

bugfix on the alien media channels

parent ea4be004
Loading
Loading
Loading
Loading
+104 −4
Original line number Diff line number Diff line
@@ -1586,9 +1586,11 @@ class RSA():
        print(f"INFO: Reconfiguring connection {flow_idx}")
        if flow_idx not in self.db_flows.keys():
            print(f"ERROR: key not present {flow_idx}")
        else:
            print(self.db_flows[flow_idx])
            return None, 0
        #self.db_flows[flow_idx] = {}
        op = self.db_flows[flow_idx]["op-mode"]
        if op is None:
            return self.alien_reconfig(flow_idx)
        src = self.db_flows[flow_idx]["src"]
        dst = self.db_flows[flow_idx]["dst"]
        rate = self.db_flows[flow_idx]["bitrate"]
@@ -1598,14 +1600,12 @@ class RSA():
        slots_init = self.db_flows[flow_idx]["slots"] 
        fiber_f = self.db_flows[flow_idx]["fiber_forward"]
        fiber_b = self.db_flows[flow_idx]["fiber_backward"]
        op = self.db_flows[flow_idx]["op-mode"]
        num_slots = self.db_flows[flow_idx]["n_slots"]
        links = self.db_flows[flow_idx]["links"]
        path = self.db_flows[flow_idx]["path"]
        band = self.db_flows[flow_idx]["band"]
        f0 = self.db_flows[flow_idx]["freq"]
        ob_idx = self.db_flows[flow_idx]["parent_opt_band"]
        
        r1 = ""
        r2 = ""
        if len(links) == 2:
@@ -1691,6 +1691,106 @@ class RSA():
            return None, 0


    def alien_reconfig(self, flow_idx):
        print(f"INFO: Reconfiguring alien connection {flow_idx}")
        if flow_idx not in self.db_flows.keys():
            print(f"ERROR: key not present {flow_idx}")
            return None, 0
        op = self.db_flows[flow_idx]["op-mode"]
        src = self.db_flows[flow_idx]["src"]
        dst = self.db_flows[flow_idx]["dst"]
        rate = self.db_flows[flow_idx]["bitrate"]
        bidir = self.db_flows[flow_idx]["bidir"]
        flow_list = self.db_flows[flow_idx]["flows"]
        band_type = self.db_flows[flow_idx]["band_type"]
        slots_init = self.db_flows[flow_idx]["slots"] 
        fiber_f = self.db_flows[flow_idx]["fiber_forward"]
        fiber_b = self.db_flows[flow_idx]["fiber_backward"]
        num_slots = self.db_flows[flow_idx]["n_slots"]
        links = self.db_flows[flow_idx]["links"]
        path = self.db_flows[flow_idx]["path"]
        band = self.db_flows[flow_idx]["band"]
        f0 = self.db_flows[flow_idx]["freq"]
        ob_idx = self.db_flows[flow_idx]["parent_opt_band"]
        existing_ob = self.get_optical_bands(src, dst)
        if len(existing_ob) > 0:
            print("INFO: Trying to move connection to an existing OB")
            #first checking in existing OB
            for ob_id in existing_ob:
                if ob_id == ob_idx:
                    continue
                if not band_type in self.optical_bands[ob_id].keys():
                    continue                
                if "is_active" in self.optical_bands[ob_id].keys():
                    is_active = self.optical_bands[ob_id]["is_active"]
                    if not is_active:
                        continue
                c_slots, l_slots, s_slots = self.get_alien_slots(ob_id, num_slots)
                if debug:
                    print("OFC26 available slots pre")
                    print(c_slots)
                    print(l_slots)
                    print(s_slots)
                if band_type == "c_slots":
                    l_slots =[]
                    s_slots = []
                elif band_type == "l_slots":
                    c_slots = []
                    s_slots = []
                elif band_type == "s_slots":
                    c_slots = []
                    l_slots =[]
                if debug:
                    print("OFC26 available slots after reset due to band")
                    print(c_slots)
                    print(l_slots)
                    print(s_slots)
                s_port = flow_list[src]["f"]["in"]
                d_port = flow_list[dst]["f"]["out"]
                #{'MGON1': {'f': {'in': 'port-25-in', 'out': 'port-9-out'}, 'b': {}}, 'MGON3': {'f': {'in': 'port-1-in', 'out': 'port-25-out'}, 'b': {}}}
                
                if len(c_slots) >= num_slots or len(l_slots) >= num_slots or len(s_slots) >= num_slots:
                    flow_list, band_range, slots, fiber_f, fiber_b = self.alien_select_slots_and_ports_fs(s_port, d_port, num_slots,
                                                                                                    c_slots, l_slots, s_slots, bidir,
                                                                                                    ob_id)
                    f0, band = frequency_converter(band_range, slots)

                    if debug:
                        print(f0, band)
                    print("INFO: RSA completed for alien Flex Lightpath with OB already in place")
                    if flow_list is None:
                        continue
                    slots_i = []
                    for i in slots:
                        slots_i.append(int(i))
                    self.db_flows[flow_idx]["flows"] = flow_list
                    self.db_flows[flow_idx]["band_type"] = band_range
                    self.db_flows[flow_idx]["slots"] = slots_i
                    self.db_flows[flow_idx]["fiber_forward"] = fiber_f
                    self.db_flows[flow_idx]["fiber_backward"] = fiber_b
                    #self.db_flows[flow_idx]["op-mode"] = op
                    self.db_flows[flow_idx]["n_slots"] = num_slots
                    #self.db_flows[flow_idx]["links"] = temp_links2
                    #self.db_flows[flow_idx]["path"] = temp_path
                    self.db_flows[flow_idx]["band"] = band
                    self.db_flows[flow_idx]["freq"] = f0
                    self.db_flows[flow_idx]["is_active"] = True
                    self.db_flows[flow_idx]["parent_opt_band"] = ob_id
                    self.db_flows[flow_idx]["new_optical_band"] = 0
                    self.optical_bands[ob_id]["served_lightpaths"].append(flow_idx)
                    '''
                    if bidir:
                        rev_ob_id = self.optical_bands[ob_id]["reverse_optical_band_id"]
                        self.optical_bands[rev_ob_id]["served_lightpaths"].append(flow_id)
                    '''
                    self.move_flow(flow_idx, slots_init, band_type, links, bidir, ob_idx)
                    return flow_idx, ob_id
                else:
                    continue
            print("not enough slots")
            return None, 0
            
                        
    def extend_optical_band(self, ob_id, band=None):
        ob = self.optical_bands[ob_id]
        links = ob["links"]