Commit 016525ee authored by Andrea Sgambelluri's avatar Andrea Sgambelluri
Browse files

working version with optical-band extensions

parent d68868c7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ MANIFEST
#  Usually these files are written by a python script from a template
#  before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
.manifest/
*.spec

# Installer logs
+1 −1
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ 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=""
+4 −2
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ class DelFLightpath(Resource):
                    rsa.db_flows[flow_id]["is_active"] = False
                    rsa.optical_bands[ob_id]["served_lightpaths"].remove(flow_id)
                    if debug:
                        print(links_dict)
                        print(rsa.links_dict)
                    return "flow {} deleted".format(flow_id), 200
                else:
                    return "flow {} not matching".format(flow_id), 404
@@ -253,6 +253,8 @@ class GetTopology(Resource):
                    #print(f"refresh_optical controller node_dict  {node_dict}") 
      
                rsa = RSA(node_dict, links_dict)
                if debug:
                    print(rsa.init_link_slots2(testing))
            
            
                return  "ok" ,200
+119 −24
Original line number Diff line number Diff line
@@ -248,17 +248,21 @@ class RSA():
        return c_sts, l_sts, s_sts

    def update_link(self, fib, slots, band):
        print(fib)
        #print(fib)
        for i in slots:
            fib[band][str(i)] = 0
        if 'used' in fib:
            fib['used'] = True
        print(fib)
        #print(fib)

    def update_optical_band(self, optical_band_id, slots, band):
        for i in slots:
            self.optical_bands[optical_band_id][band][str(i)] = 0

    def augment_optical_band(self, optical_band_id, slots, band):
        for i in slots:
            self.optical_bands[optical_band_id][band][str(i)] = 1

    def restore_link(self, fib, slots, band):
        for i in slots:
            fib[band][str(i)] = 1
@@ -423,7 +427,7 @@ class RSA():
    #function invoked for lightpaths and OB
    def select_slots_and_ports(self, links, n_slots, c, l, s, bidir):
        if debug:
            print(self.links_dict)
            print (links, n_slots, c, l, s, bidir, self.c_slot_number, self.l_slot_number, self.s_slot_number)
        band, slots = slot_selection(c, l, s, n_slots, self.c_slot_number, self.l_slot_number, self.s_slot_number)
        if debug:
            print (band, slots)
@@ -431,8 +435,7 @@ class RSA():
            print("No slots available in the three bands")
            #return None, None, None, {}, {}
            return None, None, None, {}, {}
        if debug:
            print(band, slots)
        
        self.get_fibers_forward(links, slots, band)
        if bidir:
            self.get_fibers_backward(links, slots, band)
@@ -629,7 +632,7 @@ class RSA():
        if len(c_slots) > 0 or len(l_slots) > 0 or len(s_slots) > 0:
            flow_list, band_range, slots, fiber_f, fiber_b = self.select_slots_and_ports(links, num_slots, c_slots,
                                                                                         l_slots, s_slots, bidir)
            f0, band = freqency_converter(band_range, slots)
            f0, band = frequency_converter(band_range, slots)
            if debug:
                print(f0, band)
            print("INFO: RSA completed for normal wavelenght connection")
@@ -739,22 +742,9 @@ class RSA():
            print(s_slots)
        if len(c_slots) > 0 or len(l_slots) > 0 or len(s_slots) > 0:
            flow_list, band_range, slots, fiber_f, fiber_b = self.select_slots_and_ports(links, num_slots, c_slots, l_slots, s_slots, bidir)
            f0, band = freqency_converter(band_range, slots)
            if debug:
                print(flow_list, band_range, slots, fiber_f, fiber_b)
            '''

            flow_list_b = {}
            rev_path = path.copy()
            rev_path.reverse()
            rev_links = reverse_links(links)
            if bidir:
                for dev_x in flow_list.keys():
                    flow_list_b[dev_x] = {}
                    flow_list_b[dev_x]["f"] = flow_list[dev_x]["b"]
                    del flow_list[dev_x]["b"]
                    rev_path = path.copy()
            '''
            f0, band = frequency_converter(band_range, slots)
            if debug:
                print(f0, band)
            print("INFO: RSA completed for optical band")
@@ -906,7 +896,7 @@ class RSA():
                                                                                                            c_slots,
                                                                                                            l_slots, s_slots, bidir,
                                                                                                            ob_id)
                            f0, band = freqency_converter(band_range, slots)
                            f0, band = frequency_converter(band_range, slots)
                            if debug:
                                print(f0, band)
                            print("INFO: RSA completed for Flex Lightpath with OB already in place")
@@ -941,6 +931,75 @@ class RSA():
                            return self.flow_id, ob_id
                        else:
                            print("not enough slots")
                            print("trying to extend OB {}".format(ob_id))
                            new_slots = self.extend_optical_band(ob_id, band=None)

                            if len(new_slots) > 0:
                                band_type = self.optical_bands[ob_id]["band_type"]
                                c_slots = []
                                l_slots = []
                                s_slots = []
                                if band_type == "c_slots":
                                    c_slots = new_slots
                                elif band_type == "l_slots":
                                    l_slots = new_slots
                                else:
                                    s_slots = new_slots
                                op, num_slots = map_rate_to_slot(rate)
                                if debug:
                                    print(temp_links2)
                                c_slots, l_slots, s_slots = self.get_slots(temp_links2, num_slots, ob_id)
                                if debug:
                                    print(c_slots)
                                    print(l_slots)
                                    print(s_slots)
                                #print(c_slots)
                                #print(l_slots)
                                #print(s_slots)
                                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.select_slots_and_ports_fs(
                                        temp_links2, 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 Flex Lightpath with OB already in place")
                                    if flow_list is None:
                                        self.null_values(self.flow_id)
                                        continue
                                    slots_i = []
                                    for i in slots:
                                        slots_i.append(int(i))
                                    # return links, path, flow_list, band_range, slots, fiber_f, fiber_b, op, num_slots, f0, band
                                    #        links, path, flows, bx, slots, fiber_f, fiber_b, op, n_slots, f0, band
                                    self.db_flows[self.flow_id]["flows"] = flow_list
                                    self.db_flows[self.flow_id]["band_type"] = band_range
                                    self.db_flows[self.flow_id]["slots"] = slots_i
                                    self.db_flows[self.flow_id]["fiber_forward"] = fiber_f
                                    self.db_flows[self.flow_id]["fiber_backward"] = fiber_b
                                    self.db_flows[self.flow_id]["op-mode"] = op
                                    self.db_flows[self.flow_id]["n_slots"] = num_slots
                                    self.db_flows[self.flow_id]["links"] = temp_links2
                                    self.db_flows[self.flow_id]["path"] = temp_path
                                    self.db_flows[self.flow_id]["band"] = band
                                    self.db_flows[self.flow_id]["freq"] = f0
                                    self.db_flows[self.flow_id]["is_active"] = True
                                    self.db_flows[self.flow_id]["parent_opt_band"] = ob_id
                                    self.db_flows[self.flow_id]["new_optical_band"] = 1
                                    #self.db_flows[self.flow_id]["new_optical_band"] = 2
                                    self.optical_bands[ob_id]["served_lightpaths"].append(self.flow_id)
                                    '''
                                    if bidir:
                                        rev_ob_id = self.optical_bands[ob_id]["reverse_optical_band_id"]
                                        self.optical_bands[rev_ob_id]["served_lightpaths"].append(self.flow_id)
                                    '''
                                    return self.flow_id, ob_id
                                else:
                                    print("it is not possible to allocate connection in extended OB {}".format(ob_id))
                                    

        if band is None:
            print("INFO: Not existing optical-band meeting the requirements")
        else:
@@ -949,8 +1008,6 @@ class RSA():
        links, path = self.compute_path(src, dst)
        optical_band_id, temp_links = self.create_optical_band(links, path, bidir, num_slots_ob)
        op, num_slots = map_rate_to_slot(rate)


        if debug:
            print(temp_links)
        c_slots, l_slots, s_slots = self.get_slots(temp_links, num_slots, optical_band_id)
@@ -961,7 +1018,7 @@ class RSA():
        if len(c_slots) > 0 or len(l_slots) > 0 or len(s_slots) > 0:
            flow_list, band_range, slots, fiber_f, fiber_b = self.select_slots_and_ports_fs(temp_links, num_slots, c_slots,
                                                                                            l_slots, s_slots, bidir, optical_band_id)
            f0, band = freqency_converter(band_range, slots)
            f0, band = frequency_converter(band_range, slots)
            if debug:
                print(f0, band)
            print("INFO: RSA completed for FLex Lightpath with new OB")
@@ -993,3 +1050,41 @@ class RSA():
                self.optical_bands[rev_ob_id]["served_lightpaths"].append(self.flow_id)
            '''
        return self.flow_id, optical_band_id

    def extend_optical_band(self, ob_id, band=None):
        ob = self.optical_bands[ob_id]
        links = ob["links"]
        old_band = ob["band"]
        band_type = ob["band_type"]
        f0 = ob["freq"]
        slots = ob[band_type]
        if band is None:
            num_slots_ob = map_band_to_slot(old_band/1000.0)
        else:
            num_slots_ob = map_band_to_slot(band)
        new_slots = []
        for l in links:
            link = self.get_link_by_name(l)
            fib = link["optical_details"][band_type]
            #s_slots = get_side_slots_on_link(link, band_type, num_slots_ob, slots)
            s_slots, s_num = get_side_slots_on_link(fib, num_slots_ob, slots)
            print("NEW SLOTS {}".format(s_slots))
            if len(new_slots) == 0:
                new_slots = s_slots
            else:
                if len(new_slots) < s_num:
                    new_slots = list_in_list(new_slots, s_slots)
        print("NEW SLOTS {}".format(new_slots))
        self.augment_optical_band(ob_id, new_slots, band_type)
        new_band = int(len(new_slots)*12.5*1000)
        print("{}, {},{},{} ".format(old_band, f0, len(new_slots), new_band))
        final_band = old_band + new_band
        final_f0 = int(f0 + new_band/2)
        print("{}, {}".format(final_band, final_f0))
        ob["band"] = final_band
        ob["freq"] = final_f0
        for link_x in links:
            link = self.get_link_by_name(link_x)
            fib = link["optical_details"]
            self.update_link(fib, new_slots, band_type)
        return new_slots
+26 −1
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ def str_list_to_int(str_list):
    int_list = []
    for i in str_list:
        int_list.append(int(i))
    int_list.sort()
    return int_list


@@ -110,7 +111,30 @@ def get_slot_frequency(b, n):
        return Fl + n * 12.5


def freqency_converter(b, slots):
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]
    num = 0
    res = []
    #print(starting_slot)
    for slot_id in range(starting_slot, len(y)):
        if link[y[slot_id]] == 1:
            num += 1
            res.append(int(y[slot_id]))
        else:
            return res, 0
        if num == val or slot_id == len(y) - 1:
            return res, num


def frequency_converter(b, slots):
    l = len(slots)
    if debug:
        print(slots)
@@ -183,6 +207,7 @@ def get_links_to_node(topology, node):

def slot_selection(c, l, s, n_slots, Nc, Nl, Ns):
    # First Fit
    
    if isinstance(n_slots, int):
        slot_c = n_slots
        slot_l = n_slots