Exemple #1
0
 def test_reduce_simple_tree_lldp(self):
     graph = nx.MultiDiGraph(name="simple tree lldp")
     graph.add_edge(self.router, self.router_port_a)
     graph.add_edge(self.router, self.router_port_b)
     graph.add_edge(self.switch_a, self.switch_port_a)
     graph.add_edge(self.switch_b, self.switch_port_b)
     graph.add_edge(self.switch_port_a, self.router_port_a, "lldp")
     graph.add_edge(self.switch_port_b, self.router_port_b, "lldp")
     graph.add_edge(self.router_port_a, self.switch_port_a, "lldp")
     graph.add_edge(self.router_port_b, self.switch_port_b, "lldp")
     reducer = AdjacencyReducer(graph)
     print("input:")
     print(reducer.format_connections())
     reducer.reduce()
     print("result:")
     print(reducer.format_connections())
     result = reducer.graph
     assert result.has_edge(self.switch_port_a, self.router_port_a)
     assert result.has_edge(self.switch_port_b, self.router_port_b)
     assert result.has_edge(self.router_port_a, self.switch_port_a)
     assert result.has_edge(self.router_port_b, self.switch_port_b)
     assert result.out_degree(self.switch_port_a) == 1
     assert result.out_degree(self.switch_port_b) == 1
     assert result.out_degree(self.router_port_a) == 1
     assert result.out_degree(self.router_port_b) == 1
Exemple #2
0
 def test_self_loop(self):
     graph = nx.MultiDiGraph(name="self loop")
     graph.add_edge(self.switch_a, self.switch_port_a)
     graph.add_edge(self.switch_port_a, self.switch_a, "cam")
     reducer = AdjacencyReducer(graph)
     print("input:")
     print(reducer.format_connections())
     reducer.reduce()
     print("result:")
     print(reducer.format_connections())
     result = reducer.graph
     assert not result.has_edge(self.switch_port_a, self.switch_a)
Exemple #3
0
 def test_no_return_path(self):
     graph = nx.MultiDiGraph()
     graph.add_edge(self.switch_a, self.switch_port_a)
     graph.add_edge(self.switch_b, self.switch_port_b)
     graph.add_edge(self.switch_port_a, self.switch_b, "cam")
     reducer = AdjacencyReducer(graph)
     print("input:")
     print(reducer.format_connections())
     reducer.reduce()
     print("result:")
     print(reducer.format_connections())
     result = reducer.graph
     assert result.has_edge(self.switch_port_a, self.switch_b)
     assert not result.has_edge(self.switch_port_b, self.switch_port_a)
     assert result.out_degree(self.switch_port_a) == 1
     assert self.switch_port_b not in result