-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfdb.py
executable file
·71 lines (61 loc) · 1.89 KB
/
fdb.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
#!/bin/env python
import sys
import socket
import cPickle as p
import time
s=time.time()
try:
with open("/tmp/lids.p") as fd:
lids = p.load(fd)
with open("/tmp/switch.p") as fd:
switch = p.load(fd)
print "loading existing lids and switch file"
print time.time()-s
except:
with open("lids.txt") as fd:
lids = {}
for line in fd:
data = line.split()
try:
lids[data[0]] = (data[2], ' '.join(data[4:]))
except: pass
with open("/tmp/lids.p", "w") as fd:
p.dump(lids, fd, p.HIGHEST_PROTOCOL)
with open("linear_fdb.txt") as fd:
switch = {}
for line in fd:
data = line.split()
if "SW" in data:
swname = ' '.join(data[2:])
switch[swname] = {}
continue
if switch and swname in switch:
try:
switch[swname][lids[data[0]]] = (data[1], data[2], ' '.join(data[3:]))
except: pass
with open("/tmp/switch.p", "w") as fd:
p.dump(switch, fd, p.HIGHEST_PROTOCOL)
def trace(srcname, dstname):
for swname, fdb in switch.iteritems():
if srcname == fdb[srcname][1:]: break
print fdb[srcname][2], '[' + fdb[srcname][1] + ']', '->', '[' + fdb[srcname][0] + ']', swname,
while True:
row = switch[swname][dstname]
print '[' + row[0] + ']', '->', '[' + row[1] + ']', row[2],
swname = switch[swname][dstname][2]
if dstname[1] == swname:
print
break
try:
srcname = sys.argv[1]
dstname = sys.argv[2]
except:
srcname = socket.gethostname().split('.')[0]
dstname = sys.argv[1]
print 'tracing route from', srcname,'to', dstname
srcname = ('1', srcname + ' hfi1_0')
dstname = ('1', dstname + ' hfi1_0')
s=time.time()
trace(srcname, dstname)
trace(dstname, srcname)
print time.time()-s