Edit on GitHub

bin.bgpgraph

 1import time
 2import networkx as nx
 3
 4import matplotlib.pyplot as plt
 5
 6
 7class BGPGraph:
 8    def __init__(self):
 9        self.graph = nx.Graph()
10        self.cpt = 0
11
12    def get(self, as_numbers=None, prefixes=None, match_type="more", countries=None):
13        pass
14
15    def filter_edge(self, n1, n2):
16        return not (self.graph[n1][n2]["prefix"] == self.del_prefix)
17
18    def update(self, record) -> bool:
19        """
20        Insert or delete paths in the graph.
21        Return true if graph changed.
22        """
23        return True
24        self.cpt += 1
25        if record["type"] == "A":
26            # Node attributes : prefix, time
27            nx.add_path(
28                self.graph,
29                record["path"].split(),
30                **{record["prefix"]: record["time"], "source": record["source"]}
31            )
32            nx.set_node_attributes(
33                self.graph, {record["source"]: {record["prefix"]: record["time"]}}
34            )
35        else:
36            # remove path
37            # check if edge has any prefix/ as ? if yes remove the edge
38            self.del_prefix = record["prefix"]
39
40            # for n, v in self.graph.nodes(data=True):
41            #    if self.graph.edges[record["prefix"]]:
42            #        del self.graph.edges[n][v]
43
44            # for self.graph.edges()
45            # view = nx.subgraph_view(self.graph, filter_edge=self.filter_edge)
46            # for e in view.edges():
47            #    print
48            # print(self.graph)
49            # print(view)
50            # nx.draw(view, with_labels=True, font_weight="bold")
51            # nx.draw_shell(view, with_labels=True, font_weight="bold")
52            # plt.show()
53            # time.sleep(10)
54
55        # Check if graph is updated
56
57        if self.cpt == 50:
58            nx.draw(self.graph, with_labels=True, font_weight="bold")
59            nx.draw_shell(self.graph, with_labels=True, font_weight="bold")
60            plt.show()
61            time.sleep(10)
62            exit(0)
63
64        return True
class BGPGraph:
 8class BGPGraph:
 9    def __init__(self):
10        self.graph = nx.Graph()
11        self.cpt = 0
12
13    def get(self, as_numbers=None, prefixes=None, match_type="more", countries=None):
14        pass
15
16    def filter_edge(self, n1, n2):
17        return not (self.graph[n1][n2]["prefix"] == self.del_prefix)
18
19    def update(self, record) -> bool:
20        """
21        Insert or delete paths in the graph.
22        Return true if graph changed.
23        """
24        return True
25        self.cpt += 1
26        if record["type"] == "A":
27            # Node attributes : prefix, time
28            nx.add_path(
29                self.graph,
30                record["path"].split(),
31                **{record["prefix"]: record["time"], "source": record["source"]}
32            )
33            nx.set_node_attributes(
34                self.graph, {record["source"]: {record["prefix"]: record["time"]}}
35            )
36        else:
37            # remove path
38            # check if edge has any prefix/ as ? if yes remove the edge
39            self.del_prefix = record["prefix"]
40
41            # for n, v in self.graph.nodes(data=True):
42            #    if self.graph.edges[record["prefix"]]:
43            #        del self.graph.edges[n][v]
44
45            # for self.graph.edges()
46            # view = nx.subgraph_view(self.graph, filter_edge=self.filter_edge)
47            # for e in view.edges():
48            #    print
49            # print(self.graph)
50            # print(view)
51            # nx.draw(view, with_labels=True, font_weight="bold")
52            # nx.draw_shell(view, with_labels=True, font_weight="bold")
53            # plt.show()
54            # time.sleep(10)
55
56        # Check if graph is updated
57
58        if self.cpt == 50:
59            nx.draw(self.graph, with_labels=True, font_weight="bold")
60            nx.draw_shell(self.graph, with_labels=True, font_weight="bold")
61            plt.show()
62            time.sleep(10)
63            exit(0)
64
65        return True
def get( self, as_numbers=None, prefixes=None, match_type='more', countries=None):
13    def get(self, as_numbers=None, prefixes=None, match_type="more", countries=None):
14        pass
def filter_edge(self, n1, n2):
16    def filter_edge(self, n1, n2):
17        return not (self.graph[n1][n2]["prefix"] == self.del_prefix)
def update(self, record) -> bool:
19    def update(self, record) -> bool:
20        """
21        Insert or delete paths in the graph.
22        Return true if graph changed.
23        """
24        return True
25        self.cpt += 1
26        if record["type"] == "A":
27            # Node attributes : prefix, time
28            nx.add_path(
29                self.graph,
30                record["path"].split(),
31                **{record["prefix"]: record["time"], "source": record["source"]}
32            )
33            nx.set_node_attributes(
34                self.graph, {record["source"]: {record["prefix"]: record["time"]}}
35            )
36        else:
37            # remove path
38            # check if edge has any prefix/ as ? if yes remove the edge
39            self.del_prefix = record["prefix"]
40
41            # for n, v in self.graph.nodes(data=True):
42            #    if self.graph.edges[record["prefix"]]:
43            #        del self.graph.edges[n][v]
44
45            # for self.graph.edges()
46            # view = nx.subgraph_view(self.graph, filter_edge=self.filter_edge)
47            # for e in view.edges():
48            #    print
49            # print(self.graph)
50            # print(view)
51            # nx.draw(view, with_labels=True, font_weight="bold")
52            # nx.draw_shell(view, with_labels=True, font_weight="bold")
53            # plt.show()
54            # time.sleep(10)
55
56        # Check if graph is updated
57
58        if self.cpt == 50:
59            nx.draw(self.graph, with_labels=True, font_weight="bold")
60            nx.draw_shell(self.graph, with_labels=True, font_weight="bold")
61            plt.show()
62            time.sleep(10)
63            exit(0)
64
65        return True

Insert or delete paths in the graph. Return true if graph changed.