Пример #1
0
def _json_layer3(load_traffic=False, view=None):
    topology_without_metadata = vlan.build_layer3_graph((
        'prefix__vlan__net_type',
        'gwportprefix__prefix__vlan__net_type',
    ))

    vlans_map = _get_vlans_map_layer3(topology_without_metadata)

    graph = build_netmap_layer3_graph(topology_without_metadata, load_traffic,
                                      view)

    def get_edge_from_meta(meta):
        edges = next(iter(meta['metadata'].values()))
        first = next(iter(edges))
        return first.u.netbox, first.v.netbox

    result = {
        'vlans': [vlan_to_json(prefix.vlan) for prefix in vlans_map],
        'nodes':
        _get_nodes(node_to_json_layer3, graph),
        'links': [
            edge_to_json_layer3(get_edge_from_meta(meta), meta)
            for u, v, meta in graph.edges_iter(data=True)
        ]
    }
    return result
Пример #2
0
    def test_layer3_prefix_is_added_between_a_and_b(self):
        nx_meta = self.netmap_graph.get_edge_data(self.a, self.b)
        edge_json_metadata = metadata.edge_to_json_layer3((self.a, self.b),
            nx_meta
        )

        self.assertEqual(1, len(edge_json_metadata['edges']))
        self.assertEqual(u'158.38.0.0/30',
                         edge_json_metadata['edges'][2111][0]['prefix']['net_address'])
Пример #3
0
    def test_layer3_prefix_is_added_between_a_and_b(self):
        nx_meta = self.netmap_graph.get_edge_data(self.a, self.b)
        edge_json_metadata = metadata.edge_to_json_layer3((self.a, self.b),
                                                          nx_meta)

        self.assertEqual(1, len(edge_json_metadata['edges']))
        self.assertEqual(
            u'158.38.0.0/30',
            edge_json_metadata['edges'][2111][0]['prefix']['net_address'])
Пример #4
0
    def test_layer3_v4_and_v6_prefixes_added_between_a_and_c(self):
        edge_json_metadata = metadata.edge_to_json_layer3((self.a, self.b),
            self.netmap_graph.get_edge_data(self.a, self.c)
        )

        self.assertEqual(1, len(edge_json_metadata['edges']))
        self.assertEqual(2, len(edge_json_metadata['edges'][2112]))
        expected_prefixes = (u'feed:dead:cafe:babe::/64', u'158.38.0.4/30')
        for i, prefix in enumerate(expected_prefixes):
            self.assertEqual(edge_json_metadata['edges'][2112][i]['prefix']['net_address'], prefix)
Пример #5
0
    def test_layer3_v4_and_v6_prefixes_added_between_a_and_c(self):
        edge_json_metadata = metadata.edge_to_json_layer3(
            (self.a, self.b), self.netmap_graph.get_edge_data(self.a, self.c))

        self.assertEqual(1, len(edge_json_metadata['edges']))
        self.assertEqual(2, len(edge_json_metadata['edges'][2112]))
        expected_prefixes = (u'158.38.0.4/30', u'feed:dead:cafe:babe::/64')
        for i, prefix in enumerate(expected_prefixes):
            self.assertEqual(
                edge_json_metadata['edges'][2112][i]['prefix']['net_address'],
                prefix)
Пример #6
0
def _json_layer3(load_traffic=False, view=None):
    _LOGGER.debug("build_netmap_layer3_graph() start")
    topology_without_metadata = vlan.build_layer3_graph(
        ('prefix__vlan__net_type', 'gwportprefix__prefix__vlan__net_type',))
    _LOGGER.debug("build_netmap_layer3_graph() topology graph done")

    vlans_map = _get_vlans_map_layer3(topology_without_metadata)
    _LOGGER.debug("build_netmap_layer2_graph() vlan mappings done")

    graph = build_netmap_layer3_graph(topology_without_metadata, load_traffic,
                                      view)
    return {
        'vlans': [vlan_to_json(prefix.vlan) for prefix in vlans_map],
        'nodes': _get_nodes(node_to_json_layer3, graph),
        'links': [edge_to_json_layer3((node_a, node_b), nx_metadata) for
                  node_a, node_b, nx_metadata in graph.edges_iter(data=True)]
    }
Пример #7
0
def _json_layer3(load_traffic=False, view=None):
    topology_without_metadata = vlan.build_layer3_graph((
        'prefix__vlan__net_type',
        'gwportprefix__prefix__vlan__net_type',
    ))

    vlans_map = _get_vlans_map_layer3(topology_without_metadata)

    graph = build_netmap_layer3_graph(topology_without_metadata, load_traffic,
                                      view)
    result = {
        'vlans': [vlan_to_json(prefix.vlan) for prefix in vlans_map],
        'nodes':
        _get_nodes(node_to_json_layer3, graph),
        'links': [
            edge_to_json_layer3((node_a, node_b), nx_metadata)
            for node_a, node_b, nx_metadata in graph.edges_iter(data=True)
        ]
    }
    return result