Esempio n. 1
0
    def initialize_graph(self):
        # Se ainda não conhece os switches, pega do controlador LLDP
        if not self.switches:
            lldp = self._lldp
            lldp.close()
            app_manager.unregister_app(lldp)
            # Desabilita o controlador LLDP após não precisar mais dele

            # Obtém os dados do controlador LLDP para gerar a topologia
            switches = []
            for dp in lldp.dps.itervalues():
                switches.append(lldp._get_switch(dp.id))
            self.logger.info("%s The following switches were found: %s", timestamp(), [s.dp.id for s in switches])
            self.switches = switches
            self.links = lldp.links
            self.logger.info("%s The following %s links were found: %s", timestamp(), len(self.links), [(l.src.dpid, l.dst.dpid)  for l in self.links])

        # Define os switches como nodos do grafo
        switch_list = self.switches
        if self.status == RED:
            switch_list = filter(lambda s: s.dp.id not in self.what_to_disable, switch_list)
        switches=[switch.dp.id for switch in switch_list]
        self.net.add_nodes_from(switches)

        # Define os links entre os switches como ligações entre os nodos do
        # grafo, dando prioridade para os links para switches com dpid maior
        links_list = self.links
        if self.status == RED:
            links_list = filter(lambda l: l.src.dpid not in self.what_to_disable, links_list)
            links_list = filter(lambda l: l.dst.dpid not in self.what_to_disable, links_list)
        links=[(link.src.dpid,link.dst.dpid,{'port':link.src.port_no, "priority":len(switches)-link.dst.dpid+1}) for link in links_list]
        self.net.add_edges_from(links)
Esempio n. 2
0
    def Traveling_critical_link(self, srcip, dstip, critical_nodes,
                                critical_links):
        #critical_links:[(sw,port),(sw,port)]
        #store
        switch_dof = {}
        src_location = self.get_host_location(srcip)
        dst_location = self.get_host_location(dstip)

        if src_location:
            src_sw = src_location[0]
        if dst_location:
            dst_sw = dst_location[0]

        switches = []
        ports = []
        cri_links = critical_links
        for node in cri_links:
            switches.append(node[0])
            ports.append(node[1])
        sw_link_ports = (ports[0], ports[1])
        if self.link_to_port[(switches[0], switches[1])] != sw_link_ports:
            self.logger.info(
                "These two switches are not connected by these two ports")
        else:
            distance_table = {
            }  #{cri_node1:{cri_node2:dis1,cir_node3:dis2,...cri_noden:disn}}
            path_table = {}  #{sw1:{sw2:[node,node]},sw2:{}}
            for critical_node in switches:
                result = self.dijkstra(self.graph, critical_node)
                path_table[critical_node] = result[1][critical_node]
                distance_table[critical_node] = result[0]
            # store the information of src_sw and dst_sw
            src_sw_result = self.dijkstra(self.graph, src_sw)
            path_table[src_sw] = src_sw_result[1][src_sw]
            distance_table[src_sw] = src_sw_result[0]
            dst_sw_result = self.dijkstra(self.graph, dst_sw)
            path_table[dst_sw] = dst_sw_result[1][dst_sw]
            distance_table[dst_sw] = dst_sw_result[0]
            distance_a = distance_table[src_sw][switches[0]]
            path_a = path_table[src_sw][switches[0]]
            path_a.insert(0, src_sw)
            for node in path_a:
                switch_dof[node] = "TOWARDS " + str(path_a[-1])
            switch_dof[path_a[-1]] = "FIXED_FORWARD " + str(switches[1])
            distance_b = distance_table[switches[1]][dst_sw]
            path_b = path_table[switches[1]][dst_sw]
            path_b.insert(0, switches[1])
            for node in path_b:
                switch_dof[node] = "TOWARDS " + str(dst_sw)
            switch_dof[dst_sw] = "FIXED_FORWARD"
            full_path = path_a + path_b
            total_distance = distance_a + distance_b + distance_table[
                switches[0]][switches[1]]
            print "total_distance is ", total_distance
            print switch_dof
            return switch_dof
Esempio n. 3
0
    def Traveling_critical_link(self, srcip, dstip, critical_nodes, critical_links):
        # critical_links:[(sw,port),(sw,port)]
        # store
        switch_dof = {}
        src_location = self.get_host_location(srcip)
        dst_location = self.get_host_location(dstip)

        if src_location:
            src_sw = src_location[0]
        if dst_location:
            dst_sw = dst_location[0]

        switches = []
        ports = []
        cri_links = critical_links
        for node in cri_links:
            switches.append(node[0])
            ports.append(node[1])
        sw_link_ports = (ports[0], ports[1])
        if self.link_to_port[(switches[0], switches[1])] != sw_link_ports:
            self.logger.info("These two switches are not connected by these two ports")
        else:
            distance_table = {}  # {cri_node1:{cri_node2:dis1,cir_node3:dis2,...cri_noden:disn}}
            path_table = {}  # {sw1:{sw2:[node,node]},sw2:{}}
            for critical_node in switches:
                result = self.dijkstra(self.graph, critical_node)
                path_table[critical_node] = result[1][critical_node]
                distance_table[critical_node] = result[0]
            # store the information of src_sw and dst_sw
            src_sw_result = self.dijkstra(self.graph, src_sw)
            path_table[src_sw] = src_sw_result[1][src_sw]
            distance_table[src_sw] = src_sw_result[0]
            dst_sw_result = self.dijkstra(self.graph, dst_sw)
            path_table[dst_sw] = dst_sw_result[1][dst_sw]
            distance_table[dst_sw] = dst_sw_result[0]
            distance_a = distance_table[src_sw][switches[0]]
            path_a = path_table[src_sw][switches[0]]
            path_a.insert(0, src_sw)
            for node in path_a:
                switch_dof[node] = "TOWARDS " + str(path_a[-1])
            switch_dof[path_a[-1]] = "FIXED_FORWARD " + str(switches[1])
            distance_b = distance_table[switches[1]][dst_sw]
            path_b = path_table[switches[1]][dst_sw]
            path_b.insert(0, switches[1])
            for node in path_b:
                switch_dof[node] = "TOWARDS " + str(dst_sw)
            switch_dof[dst_sw] = "FIXED_FORWARD"
            full_path = path_a + path_b
            total_distance = distance_a + distance_b + distance_table[switches[0]][switches[1]]
            print "total_distance is ", total_distance
            print switch_dof
            return switch_dof
Esempio n. 4
0
    def _switch_enter_handler(self, ev):
        switch = ev.switch.dp
        if switch.id not in switches:
            switches.append(switch.id)
            self.datapath_list[switch.id] = switch
            # req = ofp_parser.OFPPortDescStatsRequest(switch)
            # switch.send_msg(req)

        if switches:
            (ifname, agent) = getIfInfo(collector)
            logging.getLogger("requests").setLevel(logging.WARNING)
            logging.getLogger("urllib3").setLevel(logging.WARNING)
            init_sflow(ifname, collector, 10, 10)
Esempio n. 5
0
 def generate_cri_node(self, num):
     if num == 0:
         return []
     else:
         information = []
         switches = []
         i = 0
         while i < num:
             index = random.randrange(0, 26)
             if self.total_switches[index] not in switches:
                 switches.append(self.total_switches[index])
                 information.append({1: self.total_switches[index]})
                 i += 1
             else:
                 index = random.randrange(0, 26)
     return information
Esempio n. 6
0
 def generate_cri_node(self, num):
     if num == 0:
         return []
     else:
         information = []
         switches = []
         i = 0
         while i < num:
             index = random.randrange(0, 26)
             if self.total_switches[index] not in switches:
                 switches.append(self.total_switches[index])
                 information.append({1: self.total_switches[index]})
                 i += 1
             else:
                 index = random.randrange(0, 26)
     return information
Esempio n. 7
0
 def _switch_enter_handler(self, ev):
     switch = ev.switch.dp
     if switch.id not in switches:
         switches.append(switch.id)
         self.datapath_list[switch.id] = switch
 def getAllDatapaths(self):
     """ Returns a list of all switch objects """
     switches = list()
     for i in get_all_switch(self):
         switches.append(i)
     return switches
Esempio n. 9
0
 def _switch_enter_handler(self, ev):
     switch = ev.switch.dp
     if switch.id not in switches:
         switches.append(switch.id)
         self.datapath_list[switch.id] = switch
         hub.spawn(self.monitor_link_controller, switch)