Skip to content
Snippets Groups Projects
RSA.py 53.2 KiB
Newer Older
  • Learn to ignore specific revisions
  •         self.db_flows[self.flow_id]["dst"] = dst
            self.db_flows[self.flow_id]["bitrate"] = rate
            self.db_flows[self.flow_id]["bidir"] = bidir
    
            if band is None:
                temp_links2 = []
                temp_path = []
                src_links = get_links_from_node(self.links_dict, src)
                dst_links = get_links_to_node(self.links_dict, dst)
                if len(src_links.keys()) >= 1:
                    temp_links2.append(list(src_links.keys())[0])
                if len(dst_links.keys()) >= 1:
                    temp_links2.append(list(dst_links.keys())[0])
    
                if len(temp_links2) == 2:
                    [t_src, roadm_src] = temp_links2[0].split('-')
                    [roadm_dst, t_dst] = temp_links2[1].split('-')
                    temp_path.append(t_src)
                    temp_path.append(roadm_src)
                    temp_path.append(roadm_dst)
                    temp_path.append(t_dst)
                    existing_ob = self.get_optical_bands(roadm_src, roadm_dst)
    
                    if len(existing_ob) > 0:
                        print("INFO: Evaluating existing OB  {}".format(existing_ob))
                        #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)
                            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)
                            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"] = 0
                                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("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:
                print("INFO: optical-band width specified")
            #if no OB I create a new one
            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)
            if debug:
                print(c_slots)
                print(l_slots)
                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_fs(temp_links, num_slots, c_slots,
                                                                                                l_slots, s_slots, bidir, optical_band_id)
    
                f0, band = frequency_converter(band_range, slots)
    
                if debug:
                    print(f0, band)
                print("INFO: RSA completed for FLex Lightpath with new OB")
                if flow_list is None:
                    self.null_values(self.flow_id)
                    return self.flow_id, optical_band_id
                slots_i = []
                for i in slots:
                    slots_i.append(int(i))
    
                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_links
                self.db_flows[self.flow_id]["path"] = 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"] = optical_band_id
                self.db_flows[self.flow_id]["new_optical_band"] = 1
                self.optical_bands[optical_band_id]["served_lightpaths"].append(self.flow_id)
                '''
                if bidir:
                    rev_ob_id = self.optical_bands[optical_band_id]["reverse_optical_band_id"]
                    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)