-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmn_ft.py
More file actions
270 lines (201 loc) · 7.84 KB
/
Copy pathmn_ft.py
File metadata and controls
270 lines (201 loc) · 7.84 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
'''
based on riplpox
'''
import sys
sys.path.append(".")
from mininet.topo import Topo
from mininet.node import Controller, RemoteController, OVSKernelSwitch, CPULimitedHost
from mininet.net import Mininet
from mininet.link import TCLink
from mininet.cli import CLI
from mininet.util import custom
from mininet.log import setLogLevel, info, warn, error, debug
from DCTopo import FatTreeTopo
from subprocess import Popen, PIPE
from argparse import ArgumentParser
import multiprocessing
from time import sleep
from monitor.monitor import monitor_devs_ng
import os
# Number of pods in Fat-Tree
K = 4
# Queue Size
QUEUE_SIZE = 100
# Link capacity (Mbps)
BW = 10
parser = ArgumentParser(description="mininet_fattree")
parser.add_argument('-d', '--dir', dest='output_dir', default='log',
help='Output directory')
parser.add_argument('-i', '--input', dest='input_file',
default='inputs/all_to_all_data',
help='Traffic generator input file')
parser.add_argument('-t', '--time', dest='time', type=int, default=30,
help='Duration (sec) to run the experiment')
parser.add_argument('-p', '--cpu', dest='cpu', type=float, default=-1,
help='cpu fraction to allocate to each host')
parser.add_argument('--iperf', dest='iperf', default=False, action='store_true',
help='Use iperf to generate traffics')
parser.add_argument('--ecmp',dest='ECMP',default=False,
action='store_true',help='Run the experiment with ECMP routing')
parser.add_argument('--tlr',dest='tlr', default=False,
action='store_true', help='Run the experiment with Fat-Tree two-level routing')
parser.add_argument('--dijkstra',dest='dij',default=False,
action='store_true',help='Run the experiment with dijkstra routing')
args = parser.parse_args()
def FatTreeNet(args, k=4, bw=10, cpu=-1, queue=100, controller='DCController'):
''' Create a Fat-Tree network '''
if args.ECMP:
pox_c = Popen("/home/mininet/pox/pox.py %s --topo=ft,4 --routing=ECMP > log/pox.log" %controller, shell=True)
elif args.dij:
pox_c = Popen("/home/mininet/pox/pox.py %s --topo=ft,4 --routing=dij" %controller, shell=True)
else:
info('**error** the routing scheme should be ecmp or dijkstra\n')
sleep(3)
info('*** Creating the topology\n')
topo = FatTreeTopo(k)
host = custom(CPULimitedHost, cpu=cpu)
link = custom(TCLink, bw=bw, max_queue_size=queue)
net = Mininet(topo, host=host, link=link, switch=OVSKernelSwitch,
controller=RemoteController)
return net
def start_tcpprobe():
''' Install tcp_probe module and dump to file '''
os.system("rmmod tcp_probe; modprobe tcp_probe full=1;")
Popen("cat /proc/net/tcpprobe > %s/tcp.txt" %args.output_dir ,shell=True)
def stop_tcpprobe():
os.system("killall -9 cat")
def _gen_routing_mode_str(args):
if args.ECMP:
return "ECMP"
elif args.dij:
return "dij"
else:
return 'two_level'
def wait_listening(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):
print('waiting for', server,
'to listen on port', port, '\n')
sleep(.5)
def iperfTrafficGen(args, hosts, net):
''' Generate traffic pattern using iperf and monitor all of thr interfaces
input format:
src_ip dst_ip dst_port type seed start_time stop_time flow_size r/e
repetitions time_between_flows r/e (rpc_delay r/e)
'''
host_list = {}
for h in hosts:
host_list[h.IP()] = h
port = 5001
data = open(args.input_file)
datas = []
for line in data:
flow = line.split(' ')
if flow[0] not in host_list or flow[1] not in host_list:
print '%s, %s not in host list' %(flow[0], flow[1])
continue
datas.append([flow[0], flow[1]])
start_tcpprobe()
info('*** Starting iperf ...\n')
dst_ips = set()
for data in datas:
dst_ips.add(data[1])
for dst_ip in dst_ips:
dst = host_list[dst_ip]
aa = 'mnexec -a %s iperf -s -p %s > /dev/null &' % (dst.pid, port)
Popen(aa, shell=True)
monitor = multiprocessing.Process(target=monitor_devs_ng, args=('%s/rate.txt' % args.output_dir, 0.01))
monitor.start()
# Start the senders
for data in datas:
src = host_list[data[0]]
dst = host_list[data[1]]
aa='mnexec -a %s iperf -c %s -p %s -t %d -i 1 -yc > /dev/null &' % (src.pid, dst.IP(), port, args.time)
Popen(aa, shell=True)
# for line in data:
# flow = line.split(' ')
# src_ip = flow[0]
# dst_ip = flow[1]
# print src_ip, dst_ip
# if src_ip not in host_list:
# continue
# sleep(0.2)
# server = host_list[dst_ip]
# iperf_s = 'iperf -s -p %s > %s/server.txt' % (port, args.output_dir)
# iperf_s = 'iperf -s -p %d' % (port)
# print iperf_s
# cmd_s = 'mnexec -a %s %s' %(server.pid, iperf_s)
# server.popen(iperf_s, shell=True)
# print cmd_s
# Popen(cmd_s, shell=True)
# server.popen('iperf -s -p %s > log/server.txt' % port, shell=True)
# server.popen('ifconfig > log/server.txt')
# server.popen('iperf -s -p %s > ~/hedera/server.txt' % port, shell=True)
# server.cmd('iperf -s -p %d' % port)
# client = host_list[src_ip]
# iperf_c = 'iperf -c %s -p %s -t %d > %s/client.txt' % (server.IP(), port, args.time, args.output_dir)
# iperf_c = 'iperf -c %s -p %d -t %d' % (server.IP(), port, args.time)
# print iperf_c
# client.popen(iperf_c, shell=True)
# cmd_c = 'mnexec -a %s %s' % (client.pid, iperf_c)
# print cmd_c
# Popen(cmd_c, shell=True)
# client.popen('iperf -c %s -p %s -t %d > log/client.txt'
# % (server.IP(), port, args.time), shell=True)
# client.popen('iperf -c %s -p %s -t %d > ~/hedera/client.txt'
# % (server.IP(), port, args.time), shell=True)
# client.cmd('iperf -c %s -p %s -t %d' % (server.IP(), port, args.time))
sleep(args.time)
monitor.terminate()
info('*** stoping iperf ...\n')
stop_tcpprobe()
Popen("killall -9 iperf", shell=True).wait()
def FatTreeTest(args,controller):
net = FatTreeNet(args, k=K, cpu=args.cpu, bw=BW, queue=QUEUE_SIZE,
controller=controller)
net.start()
'''
uncomment and implement the following fucntion if flow tables are installed proactively,
in this mode, the mininet can work without a controller
'''
# install_proactive(topo)
# wait for the switches to connect to the controller
info('** Waiting for switches to connect to the controller\n')
sleep(5)
info('** Start iperf test\n**')
hosts = net.hosts
iperfTrafficGen(args, hosts, net)
net.stop()
def clean():
''' Clean any the running instances of POX '''
p = Popen("ps aux | grep 'pox' | awk '{print $2}'",
stdout=PIPE, shell=True)
p.wait()
procs = (p.communicate()[0]).split('\n')
for pid in procs:
try:
pid = int(pid)
Popen('kill %d' % pid, shell=True).wait()
except:
pass
if __name__ == '__main__':
setLogLevel( 'info' )
if not os.path.exists(args.output_dir):
print args.output_dir
os.makedirs(args.output_dir)
clean()
if args.ECMP:
FatTreeTest(args,controller='DCController')
elif args.dij:
FatTreeTest(args,controller='DCController')
elif args.tlr:
FatTreeTest(args,controller= None)
else:
info('******error**** please specify either ecmp, dijkstra or tlr\n')
clean()
Popen("killall -9 top bwm-ng", shell=True).wait()
os.system('sudo mn -c')