def setUp(self):
        super(TopologyLayer2TestCase, self).setUp()

        self.model_id = 1
        self.nav_graph = nx.MultiDiGraph()

        self.a = a = self._netbox_factory('a')
        self.b = b = self._netbox_factory('b')
        self.c = c = self._netbox_factory('c')
        self.d = d = self._netbox_factory('d')

        self.a1 = a1 = self._interface_factory('a1', a)
        self.a2 = a2 = self._interface_factory('a2', a)
        self.a3 = a3 = self._interface_factory('a3', a)
        self.b1 = b1 = self._interface_factory('b1', b)
        self.b2 = b2 = self._interface_factory('b2', b)
        self.c3 = c3 = self._interface_factory('c3', c)
        self.c4 = c4 = self._interface_factory('c4', c)
        self.d4 = d4 = self._interface_factory('d4', d)

        self._add_edge(self.nav_graph, a1.netbox, a1, b1.netbox, b1)
        self._add_edge(self.nav_graph, b1.netbox, b1, a1.netbox, a1)
        self._add_edge(self.nav_graph, a2.netbox, a2, b2.netbox, b2)
        self._add_edge(self.nav_graph, b2.netbox, b2, a2.netbox, a2)
        self._add_edge(self.nav_graph, a3.netbox, a3, c3.netbox, c3)
        self._add_edge(self.nav_graph, d4.netbox, d4, c4.netbox, c4)

        self.vlan__a1_b1 = a_vlan_between_a1_and_b1 = SwPortVlan(
            id=self._next_id(), interface=self.a1, vlan=Vlan(id=201, vlan=2))

        self.vlans = patch.object(topology, '_get_vlans_map_layer2',
                                  return_value=(
            {
                self.a1: [a_vlan_between_a1_and_b1],
                self.b1: [a_vlan_between_a1_and_b1],
                self.a2: [],
                self.b2: [],
                self.a3: [],
                self.c3: []
            },
            {
                self.a: {201: a_vlan_between_a1_and_b1},
                self.b: {201: a_vlan_between_a1_and_b1},
                self.c: {}
            }))
        self.vlans.start()

        self.build_l2 = patch.object(vlan, 'build_layer2_graph', return_value=self.nav_graph)
        self.build_l2.start()

        bar = vlan.build_layer2_graph()
        #foo = topology._get_vlans_map_layer2(bar)

        vlan_by_interfaces, vlan_by_netbox = topology._get_vlans_map_layer2(self.nav_graph)

        self.netmap_graph = topology.build_netmap_layer2_graph(
                        vlan.build_layer2_graph(),
                        vlan_by_interfaces,
                        vlan_by_netbox,
                        None)
Beispiel #2
0
def _json_layer2(load_traffic=False, view=None):
    topology_without_metadata = vlan.build_layer2_graph((
        'to_interface__netbox',
        'to_interface__netbox__room',
        'to_netbox__room',
        'netbox__room',
        'to_interface__netbox__room__location',
        'to_netbox__room__location',
        'netbox__room__location',
    ))

    vlan_by_interface, vlan_by_netbox = _get_vlans_map_layer2(
        topology_without_metadata)

    graph = build_netmap_layer2_graph(topology_without_metadata,
                                      vlan_by_interface, vlan_by_netbox,
                                      load_traffic, view)

    def get_edge_from_meta(meta):
        edge = meta['metadata'][0]
        return edge.u.netbox, edge.v.netbox

    result = {
        'vlans':
        get_vlan_lookup_json(vlan_by_interface),
        'nodes':
        _get_nodes(node_to_json_layer2, graph),
        'links': [
            edge_to_json_layer2(get_edge_from_meta(meta), meta)
            for u, v, meta in graph.edges_iter(data=True)
        ]
    }
    return result
Beispiel #3
0
def _json_layer2(load_traffic=False, view=None):
    topology_without_metadata = vlan.build_layer2_graph((
        'to_interface__netbox',
        'to_interface__netbox__room',
        'to_netbox__room',
        'netbox__room',
        'to_interface__netbox__room__location',
        'to_netbox__room__location',
        'netbox__room__location',
    ))

    vlan_by_interface, vlan_by_netbox = _get_vlans_map_layer2(
        topology_without_metadata)

    graph = build_netmap_layer2_graph(topology_without_metadata,
                                      vlan_by_interface, vlan_by_netbox,
                                      load_traffic, view)

    result = {
        'vlans':
        get_vlan_lookup_json(vlan_by_interface),
        'nodes':
        _get_nodes(node_to_json_layer2, graph),
        'links': [
            edge_to_json_layer2((node_a, node_b), nx_metadata)
            for node_a, node_b, nx_metadata in graph.edges_iter(data=True)
        ]
    }
    return result
Beispiel #4
0
def find_affected_but_not_down(netbox_going_down, netboxes):
    """Mark affected but not down because of redundancy boxes"""
    graph = build_layer2_graph()
    if not graph.has_node(netbox_going_down):
        return [netbox_going_down]
    graph.remove_node(netbox_going_down)
    masters = find_uplink_nodes(netbox_going_down)
    redundant = []
    for netbox in netboxes:
        if netbox_going_down == netbox:
            continue
        if any(nx.has_path(graph, master, netbox) for master in masters):
            redundant.append(netbox)

    return redundant
Beispiel #5
0
def layer2_graph():
    """Layer2 graph"""
    graph = vlan.build_layer2_graph()

    netboxes = graph.nodes()

    connections = []

    for node, neighbours_dict in graph.adjacency_iter():
        for neighbour, keydict in neighbours_dict.items():
            for key, _ in keydict.items():
                # [from_netbox, to_netbox, to_interface]
                connections.append([node, neighbour, key])

    return netboxes, connections
Beispiel #6
0
def find_affected_but_not_down(netbox_going_down, netboxes):
    """Mark affected but not down because of redundancy boxes"""
    graph = build_layer2_graph()
    if not graph.has_node(netbox_going_down):
        return [netbox_going_down]
    graph.remove_node(netbox_going_down)
    masters = find_uplink_nodes(netbox_going_down)
    redundant = []
    for netbox in netboxes:
        if netbox_going_down == netbox:
            continue
        if any(nx.has_path(graph, master, netbox) for master in masters):
            redundant.append(netbox)

    return redundant
Beispiel #7
0
def layer2_graph():
    """Layer2 graph"""
    graph = vlan.build_layer2_graph()

    netboxes = graph.nodes()

    connections = []

    for node, neighbours_dict in graph.adjacency_iter():
        for neighbour, keydict in neighbours_dict.items():
            for key, _ in keydict.items():
                # [from_netbox, to_netbox, to_interface]
                connections.append([node, neighbour, key])

    return (netboxes, connections)
Beispiel #8
0
def _json_layer2(load_traffic=False, view=None):
    _LOGGER.debug("build_netmap_layer2_graph() start")
    topology_without_metadata = vlan.build_layer2_graph(
        (
        'to_interface__netbox', 'to_interface__netbox__room', 'to_netbox__room',
        'netbox__room', 'to_interface__netbox__room__location',
        'to_netbox__room__location', 'netbox__room__location'))
    _LOGGER.debug("build_netmap_layer2_graph() topology graph done")

    vlan_by_interface, vlan_by_netbox = _get_vlans_map_layer2(
        topology_without_metadata)
    _LOGGER.debug("build_netmap_layer2_graph() vlan mappings done")

    graph = build_netmap_layer2_graph(topology_without_metadata,
                                      vlan_by_interface, vlan_by_netbox,
                                      load_traffic, view)

    return {
        'vlans': get_vlan_lookup_json(vlan_by_interface),
        'nodes': _get_nodes(node_to_json_layer2, graph),
        'links': [edge_to_json_layer2((node_a, node_b), nx_metadata) for
                  node_a, node_b, nx_metadata in graph.edges_iter(data=True)]
    }
    def setUp(self):
        super(TopologyLayer2TestCase, self).setUp()

        self.model_id = 1
        self.nav_graph = nx.MultiDiGraph()

        self.a = a = self._netbox_factory('a')
        self.b = b = self._netbox_factory('b')
        self.c = c = self._netbox_factory('c')
        self.d = d = self._netbox_factory('d')

        self.a1 = a1 = self._interface_factory('a1', a)
        self.a2 = a2 = self._interface_factory('a2', a)
        self.a3 = a3 = self._interface_factory('a3', a)
        self.b1 = b1 = self._interface_factory('b1', b)
        self.b2 = b2 = self._interface_factory('b2', b)
        self.c3 = c3 = self._interface_factory('c3', c)
        self.c4 = c4 = self._interface_factory('c4', c)
        self.d4 = d4 = self._interface_factory('d4', d)

        self._add_edge(self.nav_graph, a1.netbox, a1, b1.netbox, b1)
        self._add_edge(self.nav_graph, b1.netbox, b1, a1.netbox, a1)
        self._add_edge(self.nav_graph, a2.netbox, a2, b2.netbox, b2)
        self._add_edge(self.nav_graph, b2.netbox, b2, a2.netbox, a2)
        self._add_edge(self.nav_graph, a3.netbox, a3, c3.netbox, c3)
        self._add_edge(self.nav_graph, d4.netbox, d4, c4.netbox, c4)

        self.vlan__a1_b1 = a_vlan_between_a1_and_b1 = SwPortVlan(
            id=self._next_id(), interface=self.a1, vlan=Vlan(id=201, vlan=2))

        self.vlans = patch.object(topology,
                                  '_get_vlans_map_layer2',
                                  return_value=({
                                      self.a1: [a_vlan_between_a1_and_b1],
                                      self.b1: [a_vlan_between_a1_and_b1],
                                      self.a2: [],
                                      self.b2: [],
                                      self.a3: [],
                                      self.c3: []
                                  }, {
                                      self.a: {
                                          201: a_vlan_between_a1_and_b1
                                      },
                                      self.b: {
                                          201: a_vlan_between_a1_and_b1
                                      },
                                      self.c: {}
                                  }))
        self.vlans.start()

        self.build_l2 = patch.object(vlan,
                                     'build_layer2_graph',
                                     return_value=self.nav_graph)
        self.build_l2.start()

        bar = vlan.build_layer2_graph()
        #foo = topology._get_vlans_map_layer2(bar)

        vlan_by_interfaces, vlan_by_netbox = topology._get_vlans_map_layer2(
            self.nav_graph)

        self.netmap_graph = topology.build_netmap_layer2_graph(
            vlan.build_layer2_graph(), vlan_by_interfaces, vlan_by_netbox,
            None)