/
route_changes_direct.py
62 lines (49 loc) · 2.13 KB
/
route_changes_direct.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
import sys
import argparse
from collections import defaultdict
import reuter_util.bgp as bgp
def parse_arguments(args):
parser = argparse.ArgumentParser()
parser.add_argument("data", help="bgp data")
return parser.parse_args(args)
ANCHOR_EXPERIMENT_PAIRS = [('147.28.240.0/24', '147.28.241.0/24'),
('147.28.242.0/24', '147.28.244.0/24'),
('147.28.243.0/24', '147.28.245.0/24'),
('147.28.246.0/24', '147.28.247.0/24'),
('147.28.248.0/24', '147.28.249.0/24'),
('147.28.250.0/24', '147.28.251.0/24'),
('147.28.252.0/24', '147.28.253.0/24')
]
def main(args):
args = parse_arguments(args)
for pair in ANCHOR_EXPERIMENT_PAIRS:
anchor = pair[0]
experiment = pair[1]
print("Anchor: {0} ; Experiment: {1}".format(anchor, experiment))
anchor_direct_paths = defaultdict(int)
experiment_direct_paths = defaultdict(int)
monitors = set()
with open(args.data, 'r') as f:
for line in f:
line = line.split('|')
if not (line[0] == 'R' and line[1] == 'R'):
continue
prefix = line[7].rstrip()
as_path = line[9].rstrip()
peer_ip = line[6].rstrip()
peer_asn = line[5].rstrip()
monitor = (peer_asn, peer_ip)
monitors.add(monitor)
if len(as_path.split(' ')) == 2:
if prefix == anchor:
anchor_direct_paths[monitor] += 1
if prefix == experiment:
experiment_direct_paths[monitor] += 1
for monitor in monitors:
if monitor in anchor_direct_paths and monitor in experiment_direct_paths:
if anchor_direct_paths[monitor] != experiment_direct_paths[monitor]:
print(monitor[0] + '|' + monitor[1])
print("========================")
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))