forked from segment-routing/nanonet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·47 lines (33 loc) · 889 Bytes
/
build
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
#!/usr/bin/env python
import sys, os
from node import *
from net import *
# ./build topos/file.py toponame [outdir]
# custom exec inspired by mininet
def usage():
print('Usage: %s topofile.py toponame [outdir]' % (sys.argv[0]))
sys.exit(-1)
if len(sys.argv) < 3 or len(sys.argv) > 4:
usage()
outdir='.'
if len(sys.argv) == 4:
outdir = sys.argv[3]
topos = {}
sys.path.append('.')
customs = {}
exec(compile(open(sys.argv[1], "rb").read(), sys.argv[1], 'exec'), customs, customs)
for name, val in customs.items():
if name == 'topos':
globals()['topos'].update(val)
else:
globals()[name] = val
topo = topos[sys.argv[2]]()
os.chdir(outdir)
net = Nanonet(topo)
net.start()
f = open(sys.argv[2]+'.topo.sh', 'w')
for n in net.topo.nodes:
f.write('# %s loop: %s\n' % (n.name, n.addr))
f.write('\n')
net.dump_commands(lambda x: f.write('%s\n' % x), noroute=False)
f.close()