def do_layer2_detection(): """Detect and update layer 2 topology""" candidates = build_candidate_graph_from_db() aggregates = get_aggregate_mapping(include_stacks=True) reducer = AdjacencyReducer(candidates, aggregates) reducer.reduce() links = reducer.get_single_edges_from_ports() update_layer2_topology(links)
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
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)
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
def do_layer2_detection(): """Detect and update layer 2 topology""" reducer = AdjacencyReducer(build_candidate_graph_from_db()) reducer.reduce() links = reducer.get_single_edges_from_ports() update_layer2_topology(links)