def __init__(self, *args, **kwargs): super(SimpleSwitchRest13, self).__init__(*args, **kwargs) self.switches = {} wsgi = kwargs['wsgi'] wsgi.register(SimpleSwitchController, {simple_switch_instance_name: self}) self.graph = DirectedGraph()
def main(): g = DirectedGraph() g.updateNeighbor(1, 2) g.updateNeighbor(1, 3) g.updateNeighbor(1, 4) g.updateNeighbor(2, 5) g.updateNeighbor(2, 6) t = TopoSort(g.getGraph()) print(t.topologicalSort())
def update_topology(self): self.graph = DirectedGraph() switch_list = get_switch(self) for switch in switch_list: self.graph.add_node(SwitchNode(switch.dp.id, switch)) links_list = get_link(self) for link in links_list: self.graph.add_edge(link.src.dpid, link.dst.dpid) print(self.graph)
def __init__(self, *args, **kwargs): super(SimpleSwitchRest13, self).__init__(*args, **kwargs) self.switches = {} wsgi = kwargs['wsgi'] wsgi.register(SimpleSwitchController, {simple_switch_instance_name: self}) self.graph = DirectedGraph() self.forwarding_tables = [] self.mac_to_port = {} self.ip_to_mac = { "169.254.20.158": "b8:27:eb:17:0d:96", "169.254.173.130": "b8:27:eb:7f:7c:ea", "169.254.240.121": "b8:27:eb:81:61:47" } self.link_to_port = { (1, "169.254.20.158"): 2, (9, "169.254.173.130"): 16, (8, "169.254.240.121"): 2 }
G.addVertex('c') G.addVertex('d') G.addVertex('e') G.addEdge('a', 'b', 1) G.addEdge('a', 'c', 1) G.addEdge('b', 'd', 1) G.addEdge('b', 'e', 1) G.addEdge('c', 'd', 1) G.addEdge('c', 'e', 1) G.addEdge('d', 'e', 1) G.addEdge('e', 'a', 1) print has_cycle(G,G.getVertex('a')) #existence of a cycle in a directed graph DG = DirectedGraph() DG.addVertex('a') DG.addVertex('b') DG.addVertex('c') DG.addVertex('d') DG.addVertex('e') DG.addEdge('a', 'b', 1) DG.addEdge('b', 'c', 1) DG.addEdge('c', 'd', 1) DG.addEdge('e', 'a', 1) DG.addEdge('e', 'c', 1) print has_cycle(DG,DG.getVertex('a'))
G.addVertex('d') G.addVertex('e') G.addEdge('a', 'b', 1) G.addEdge('a', 'c', 1) G.addEdge('b', 'd', 1) G.addEdge('b', 'e', 1) G.addEdge('c', 'd', 1) G.addEdge('c', 'e', 1) G.addEdge('d', 'e', 1) G.addEdge('e', 'a', 1) topologicalSort(G) # topologicalSortedNodes = topologicalSort(G,G.getVertex('a')) DG = DirectedGraph() DG.addVertex('a') DG.addVertex('b') DG.addVertex('c') DG.addVertex('d') DG.addVertex('e') DG.addVertex('f') DG.addVertex('g') DG.addVertex('h') DG.addVertex('i') DG.addEdge('a', 'd', 1) DG.addEdge('b', 'd', 1) DG.addEdge('c', 'd', 1) DG.addEdge('d', 'g', 1) DG.addEdge('d', 'e', 1)
def __init__(self, *args, **kwargs): super(SimpleSwitch13, self).__init__(*args, **kwargs) self.graph = DirectedGraph()
def setUp(self): self.graph = DirectedGraph()