/
bufferbloat.py
executable file
·151 lines (126 loc) · 4.58 KB
/
bufferbloat.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/python
"CS144 In-class exercise: Buffer Bloat"
from mininet.topo import Topo
from mininet.node import CPULimitedHost, OVSController
from mininet.link import TCLink
from mininet.net import Mininet
from mininet.log import lg, info
from mininet.util import dumpNodeConnections
from mininet.cli import CLI
from monitor import monitor_qlen
from subprocess import Popen, PIPE
from time import sleep, time
from multiprocessing import Process
from argparse import ArgumentParser
import sys
import os
# Parse arguments
parser = ArgumentParser(description="BufferBloat tests")
parser.add_argument('--bw-host', '-B',
dest="bw_host",
type=float,
action="store",
help="Bandwidth of host links",
required=True)
parser.add_argument('--bw-net', '-b',
dest="bw_net",
type=float,
action="store",
help="Bandwidth of network link",
required=True)
parser.add_argument('--delay',
dest="delay",
type=float,
help="Delay in milliseconds of host links",
default=10)
parser.add_argument('--dir', '-d',
dest="dir",
action="store",
help="Directory to store outputs",
default="results",
required=True)
parser.add_argument('-n',
dest="n",
type=int,
action="store",
help="Number of nodes in star.",
required=True)
parser.add_argument('--nflows',
dest="nflows",
action="store",
type=int,
help="Number of flows per host (for TCP)",
required=True)
parser.add_argument('--maxq',
dest="maxq",
action="store",
help="Max buffer size of network interface in packets",
default=500)
parser.add_argument('--cong',
dest="cong",
help="Congestion control algorithm to use",
default="reno")
parser.add_argument('--diff',
help="Enabled differential service",
action='store_true',
dest="diff",
default=False)
# Expt parameters
args = parser.parse_args()
class StarTopo(Topo):
"Star topology for Buffer Bloat experiment"
def __init__(self, n=2, cpu=None, bw_host=1000, bw_net=1.5,
delay=10, maxq=None, diff=False):
# Add default members to class.
super(StarTopo, self ).__init__()
# Create switch and host nodes
for i in xrange(n):
self.addHost( 'h%d' % (i+1), cpu=cpu )
self.addSwitch('s0', fail_mode='open')
self.addLink('h1', 's0', bw=bw_host,
max_queue_size=int(maxq) )
for i in xrange(1, n):
self.addLink('h%d' % (i+1), 's0', bw=bw_host)
def ping_latency(net):
"(Incomplete) verify link latency"
h1 = net.getNodeByName('h1')
h1.sendCmd('ping -c 2 10.0.0.2')
result = h1.waitOutput()
print "Ping result:"
print result.strip()
def bbnet():
"Create network and run Buffer Bloat experiment"
print "starting mininet ...."
# Seconds to run iperf; keep this very high
seconds = 3600
start = time()
# Reset to known state
topo = StarTopo(n=args.n, bw_host=args.bw_host,
delay='%sms' % args.delay,
bw_net=args.bw_net, maxq=args.maxq, diff=args.diff)
net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink,
autoPinCpus=True, controller=OVSController)
net.start()
dumpNodeConnections(net.hosts)
net.pingAll()
print args.diff
if args.diff:
print "Differentiate Traffic Between iperf and wget"
os.system("bash tc_cmd_diff.sh")
else:
print "exec tc_cmd.sh"
os.system("bash tc_cmd.sh %s" % args.maxq)
sleep(2)
ping_latency(net)
print "Initially, the delay between two hosts is around %dms" % (int(args.delay)*2)
h2 = net.getNodeByName('h2')
h1 = net.getNodeByName('h1')
h1.cmd('cd ./http/; nohup python2.7 ./webserver.py &')
h1.cmd('cd ../')
h2.cmd('iperf -s -w 16m -p 5001 -i 1 > iperf-recv.txt &')
CLI( net )
h1.cmd("sudo pkill -9 -f webserver.py")
h2.cmd("rm -f index.html*")
Popen("killall -9 cat", shell=True).wait()
if __name__ == '__main__':
bbnet()