forked from PEERINGTestbed/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_routes.py
82 lines (71 loc) · 3.44 KB
/
parse_routes.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from collections import defaultdict
filename = "peers.csv"
with open(filename, 'r') as fp:
fp.readline()
ASset = set([line.split(',')[2] for line in fp])
with open(filename, 'r') as fp:
fp.readline()
sessiontoLine = {int(line.split(',')[-1].rstrip()):line.rstrip() for line in fp}
filename = "fulldumpers.txt"
prefixtoAS = defaultdict(set)
pathIDtoAS = defaultdict(set)
pathIDtoSession = defaultdict(set)
ASnotInSet = defaultdict(set)
with open(filename, 'r') as fp:
AS = ''
pathID = ''
oldPathID = ''
prefix = ''
session = ''
flag = 0
firstNLRI = 0
for line in fp:
line = line.rstrip()
if " Path Segment Value: " in line:
AS = line.replace(" Path Segment Value: ", '').split(' ')[0]
if " COMMUNITY: " in line:
line = line.replace(" COMMUNITY: ", '')
sessionMap = {pair.split(":")[0] : pair.split(":")[1] for pair in line.split(' ')}
session = sessionMap["47065"]
if " Path Identifier: " in line:
pathID = line.replace(" Path Identifier: ", '')
if firstNLRI == 0:
firstNLRI = 1
elif flag == 1:
assert oldPathID == pathID
oldPathID = pathID
if flag == 1:
pathIDtoAS[pathID].add(AS)
pathIDtoSession[pathID].add(session)
if AS not in ASset:
ASnotInSet[pathID].add(AS)
if line == " NLRI":
flag = 1
if line == " Withdrawn Routes":
flag = 2
if line == "---------------------------------------------------------------":
firstNLRI = 0
if " Prefix: " in line:
prefix = line.replace(" Prefix: ", '')
if flag == 1:
prefixtoAS[prefix].add(AS)
if flag == 2:
prefixtoAS[prefix] = set([AS for AS in prefixtoAS[prefix] if AS not in pathIDtoAS[pathID]])
if len(prefixtoAS[prefix]) == 0:
del prefixtoAS[prefix]
print("\n Changing session for pathID: ", {key:value for key, value in pathIDtoSession.items() if len(value) > 1})
print("\n Changing AS for session: ")
sessiontoAS = {list(pathIDtoSession[key])[0] : value for key, value in pathIDtoAS.items() if len(value) > 1}
for key, value in sessiontoAS.items():
print("session ID: ", key)
print("peer Info: ", sessiontoLine[int(key)-10000])
print("Next-Hop ASes: ", value)
print("\n Session for not-in ASes: ", {key : pathIDtoSession[key] for key in ASnotInSet.keys()})
print("\n not-in ASes: ", ASnotInSet.keys())
prefixes = set(prefixtoAS.keys())
nextHops = set.union(*list(prefixtoAS.values()))
print("\n %d nexthops, %d prefixes" % (len(nextHops), len(prefixes)))
counts = set([len(set(hopset)) for hopset in prefixtoAS.values()])
print(counts)
print("\n count of in ASes: ", len(ASset))
print("\n count of intersecting ASes: ", len(ASset.intersection(nextHops)))