-
Notifications
You must be signed in to change notification settings - Fork 0
/
bgp_parser_nextHop.py
39 lines (28 loc) · 1005 Bytes
/
bgp_parser_nextHop.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
#!/usr/bin/python
#Takes the output of a MRT BGP RIB human-printed (using bgpdump) and calculates the number of prefixes advertised by each next hop IP Address
BGP_FILE = 'londonIXP2016Readable.txt'
nextHop_to_prefixCount = {}
file = open(BGP_FILE, "r")
#Iterate through the BGP File
while True:
line = file.readline()
bgp_index = line.split(":")
if not line: break
prefix = ''
next_hop = ''
if bgp_index[0]=='PREFIX':
prefix = bgp_index[1]
elif bgp_index[0]=='NEXT_HOP':
next_hop = bgp_index[1].replace('\n', '')
else:
continue
if next_hop in nextHop_to_prefixCount:
nextHop_to_prefixCount[next_hop] = nextHop_to_prefixCount[next_hop] + 1
else:
nextHop_to_prefixCount[next_hop] = 1
#print entries
for entry in nextHop_to_prefixCount:
if entry == '':
print "Total entries: " + str(nextHop_to_prefixCount[entry])
else:
print entry + ": " + str(nextHop_to_prefixCount[entry])