-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_topo.py
114 lines (84 loc) · 2.85 KB
/
run_topo.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/python
"Networking Assignment 2"
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.log import lg, output
from mininet.node import CPULimitedHost
from mininet.link import TCLink
from mininet.util import irange, custom, quietRun, dumpNetConnections
from mininet.cli import CLI
from time import sleep, time
from multiprocessing import Process
from subprocess import Popen
import argparse
import sys
import os
from linuxrouter_switch import NetworkTopo
parser = argparse.ArgumentParser(description="Topology bandwith and TCP tests")
parser.add_argument('--dir', '-d',
help="Directory to store outputs",
default="results")
parser.add_argument('--cli', '-c',
action='store_true',
help='Run CLI for topology debugging purposes')
parser.add_argument('--time', '-t',
dest="time",
type=int,
help="Duration of the experiment with iperf -R.",
default=0)
# Expt parameters
args = parser.parse_args()
if not os.path.exists(args.dir):
os.makedirs(args.dir)
lg.setLogLevel('info')
def waitListening(client, server, port):
"Wait until server is listening on port"
if not 'telnet' in client.cmd('which telnet'):
raise Exception('Could not find telnet')
cmd = ('sh -c "echo A | telnet -e A %s %s"' %
(server.IP(), port))
while 'Connected' not in client.cmd(cmd):
output('waiting for', server,
'to listen on port', port, '\n')
sleep(.5)
def progress(t):
# Begin: Template code
while t > 0:
print ' %3d seconds left \r' % (t)
t -= 1
sys.stdout.flush()
sleep(1)
def run_topology_experiment(net):
"Run experiment"
seconds = args.time
# Get receiver and clients
recvr = net.getNodeByName(args.server)
sender = net.getNodeByName('h1')
print "Starting iperf on the sender"
if (seconds>0):
sender.sendCmd('iperf3 -c %s -p 5001 -w 512K -t %d -R> %s/iperf_client.txt' % (recvr.IP(), seconds, args.dir))
# Turn off and turn on links
print "waiting for the sender to finish"
sender.waitOutput()
def main():
"Create and run experiment"
start = time()
topo = NetworkTopo()
host = custom(CPULimitedHost)
net = Mininet(topo=topo, host=host )
net.start()
print "*** Dumping network connections:"
dumpNetConnections(net)
if args.cli:
# Run CLI instead of experiment
CLI(net)
else:
print "*** Running experiment"
#run_topology_experiment(net)
net.stop()
end = time()
# os.system("killall -9 tshark")
# os.system("chown mininet:mininet /tmp/*.cap ; mv /tmp/*.cap %s" % (args.dir))
print "Experiment took %.3f seconds" % (end - start)
if __name__ == '__main__':
main()