Exemplo n.º 1
0
    def _generate_path(self, topo, src_mac, dst_mac, src_port,
                       dst_port, src_dpid, dst_dpid):
        """Generate path method."""
        net = nx.DiGraph(data=topo)
        net.add_node(src_mac)
        net.add_node(dst_mac)
        net.add_edge(int(src_dpid), src_mac, {'port': int(src_port)})
        net.add_edge(src_mac, int(src_dpid))
        net.add_edge(int(dst_dpid), dst_mac, {'port': int(dst_port)})
        net.add_edge(dst_mac, int(dst_dpid))

        target_path = None
        try:
            path = nx.shortest_path(net, src_mac, dst_mac)
            path2 = nx.shortest_path(net, src_mac, dst_mac)
            path2.pop()
            path2.pop(0)
            list_load = check_switch_load(path2, data_collection.switch_stat, constant.load_limitation)
            if len(list_load) > 0:
                # print 'lui', list_load
                all_paths = nx.all_simple_paths(net, src_mac, dst_mac)
                path_list = list(all_paths)
                target_path_index, target_path_cost = calculate_least_cost_path(path_list, data_collection.switch_stat, net)
                target_path = path_list[target_path_index]
            else:
                target_path = path
            print 'tarrr', target_path
        except Exception:
            target_path = None
        return target_path
Exemplo n.º 2
0
    def _generate_path(self, topo, src_mac, dst_mac, src_port, dst_port,
                       src_dpid, dst_dpid):
        """Generate path method."""
        net = nx.DiGraph(data=topo)
        net.add_node(src_mac)
        net.add_node(dst_mac)
        net.add_edge(int(src_dpid), src_mac, {'port': int(src_port)})
        net.add_edge(src_mac, int(src_dpid))
        net.add_edge(int(dst_dpid), dst_mac, {'port': int(dst_port)})
        net.add_edge(dst_mac, int(dst_dpid))

        target_path = None
        try:
            path = nx.shortest_path(net, src_mac, dst_mac)
            path2 = nx.shortest_path(net, src_mac, dst_mac)
            path2.pop()
            path2.pop(0)
            list_load = check_switch_load(path2, data_collection.switch_stat,
                                          constant.load_limitation)
            if len(list_load) > 0:
                # print 'lui', list_load
                all_paths = nx.all_simple_paths(net, src_mac, dst_mac)
                path_list = list(all_paths)
                target_path_index, target_path_cost = calculate_least_cost_path(
                    path_list, data_collection.switch_stat, net)
                target_path = path_list[target_path_index]
            else:
                target_path = path
            print 'tarrr', target_path
        except Exception:
            target_path = None
        return target_path
Exemplo n.º 3
0
    def _adjustment_handler(self, flow_list, dpid):
        weight = self.sw_stat.get(dpid)
        load = 0
        if weight is not None:
            if weight.get('load') is not None:
                load = max(weight.get('load'))
        for key_tuples in flow_list.keys():
            flow = data_collection.flow_list.get(key_tuples)
            # check_for_limit(flow, key_tuples)

            # for new adjustment flow
            src = data_collection.member_list.get(flow.src_mac)
            kk = (str(src.datapath.id) + flow.src_mac + flow.dst_mac +
                  flow.src_ip + flow.dst_ip + str(flow.ip_proto) +
                  str(flow.src_port) + str(flow.dst_port))

            ff = data_collection.flow_list.get(kk)
            if ff is not None:
                if ff.r_limited >= 1:
                    flow.r_limited = ff.r_limited

            if flow is not None and flow.r_limited == 0:
                print 'key', key_tuples
                print 'flow_rate & load', flow.rate, load
                flow.r_limited = 1
                switch_list = get_switch(self.topology_api_app, None)
                for sw in switch_list:
                    sw_flow_tuple = (str(sw.dp.id) +
                                     flow.src_mac + flow.dst_mac +
                                     flow.src_ip + flow.dst_ip +
                                     str(flow.ip_proto) +
                                     str(flow.src_port) + str(flow.dst_port))

                    print 'tu', sw_flow_tuple
                    flow_l = data_collection.flow_list.get(sw_flow_tuple)
                    if flow_l is not None:
                        flow_l.r_limited = 1

                if load <= self.load:
                    break
                # elif self.load - flow.rate <= 0:
                #     continue
                else:

                    group = data_collection.group_list.get('whole')
                    topo = group.topology
                    net = nx.DiGraph(data=topo)
                    net.add_node(flow.src_mac)
                    net.add_node(flow.dst_mac)
                    src = data_collection.member_list.get(flow.src_mac)
                    dst = data_collection.member_list.get(flow.dst_mac)
                    net.add_edge(int(src.datapath.id), flow.src_mac,
                                 {'port': int(src.port)})
                    net.add_edge(flow.src_mac, int(src.datapath.id))
                    net.add_edge(int(dst.datapath.id), flow.dst_mac,
                                 {'port': int(dst.port)})
                    net.add_edge(flow.dst_mac, int(dst.datapath.id))
                    all_paths = nx.all_simple_paths(net, flow.src_mac,
                                                    flow.dst_mac)
                    path_list = list(all_paths)
                    target_path_index, target_path_cost = calculate_least_cost_path(path_list, self.sw_stat, net)

                    valid_adjust = 1
                    for node in path_list[target_path_index]:
                        index = path_list[target_path_index].index(node)
                        if index > 1 and index < len(path_list[target_path_index])-2:
                            load_tar = self.sw_stat.get(node).get('load')
                            print 'load_v', (max(load_tar) + flow.rate), self.load
                            if (max(load_tar) + flow.rate) > self.load:
                                valid_adjust = 0
                    print 'valid_adjust', valid_adjust
                    if valid_adjust == 1:
                        #if (target_path_cost + flow.rate) < (load - flow.rate):
                        src_m = data_collection.member_list.get(flow.src_mac)
                        dst_m = data_collection.member_list.get(flow.dst_mac)
                        if src_m.datapath.id != dpid and dst_m.datapath.id != dpid:
                            load = load - flow.rate

                        target_path = path_list[target_path_index]

                        for node in target_path:
                            index = target_path.index(node)
                            if index != 0 and index != len(target_path)-1:
                                switches = get_switch(self.topology_api_app, node)
                                target_path[index] = switches[0].dp
                                if index > 1 and index < len(target_path)-2:
                                    cot = self.sw_stat.get(node).get('load')
                                    cot[0] = cot[0]+flow.rate
                                    cot[1] = cot[1]+flow.rate

                        print 't', target_path
                        flow_adjust(net, target_path, flow)