-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_for_vpp.py
executable file
·468 lines (379 loc) · 14.7 KB
/
simple_for_vpp.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
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
#!/usr/bin/python2
from mininet.net import Mininet
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel
from mininet.node import OVSController
from mininet.link import TCLink
import datetime
import os
import subprocess
import shutil
import shlex
import time
import sys
import argparse
import random
import string
parser = argparse.ArgumentParser(description='Run a minq measurement experiment, creating a trace for VPP analysis')
parser.add_argument("--echo", action="store_true") # WIP
parser.add_argument("--run-name")
parser.add_argument("--dynamic-intf")
parser.add_argument("--no-baseline", action="store_true")
parser.add_argument("--heartbeat", type=int)
parser.add_argument("--file")
parser.add_argument("--time", type=float)
parser.add_argument("--wait-for-client", action="store_true")
parser.add_argument("--traffic-gen")
parser.add_argument("--one-direction", action="store_true")
parser.add_argument("--tcp", action="store_true")
args = parser.parse_args()
d = dict()
with open('config') as config_file:
for line in config_file:
line = line.strip().split()
if len(line) == 2:
d[line[0]] = line[1]
d['MINQ_LOG_LEVEL'] = "stats"
LOCAL = None
class Logger(object):
def __init__(self, path):
self.terminal = sys.stdout
self.log = open(path, "a")
def write(self, message):
self.terminal.write(message)
self.log.write(message)
def flush(self):
self.terminal.flush()
self.log.flush()
def fileno(self):
return self.terminal.fileno()
def configureNetem(interfaces, options):
for intf in interfaces:
node = intf.node
intf_name = intf.name
## see if there is already a configuration.
cmd = "tc qdisc show dev {}".format(intf)
tc_output = node.cmd(cmd)
print("[{}] tc_output:: {}".format(node, tc_output))
if tc_output.find("netem") != -1:
operator = "change"
else:
operator = "add"
## add / update the netem qdisc
cmd = "tc qdisc {operator} dev {interface} parent 5:1 handle 10: netem {options}"
cmd = cmd.format(operator = operator, interface = intf_name, options = options)
tc_output = node.cmd(cmd)
#print("tc_output:: {}".format(tc_output))
# check the configuration
cmd = "tc qdisc show dev {}".format(intf)
tc_output = node.cmd(cmd)
print("[{}] tc_output:: {}".format(node, tc_output))
####################################################
## MAKE FOLDER AND ARCHIVE CODE
####################################################
d['timestamp'] = datetime.datetime.now().isoformat()
d['epoch'] = int(time.time())
d['randID'] = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(5))
if args.run_name != None:
run_name = args.run_name
else:
run_name = raw_input("Name for run: ").strip()
if run_name:
run_name = run_name.replace(' ', '-')
outputdir = "{OUTPUT_BASE_PATH}/{epoch}-{randID}_{run_name}"
outputdir = outputdir.format(run_name=run_name, **d)
else:
outputdir = "{OUTPUT_BASE_PATH}/nameless_runs/{epoch}-{randID}"
outputdir = outputdir.format(run_name=run_name, **d)
os.makedirs(outputdir)
os.chdir(outputdir)
randID_file = open("randID", 'w')
randID_file.write(d['randID'])
randID_file.close()
epoch_file = open("epoch", 'w')
epoch_file.write(str(d['epoch']))
epoch_file.close()
timestamp_file = open("timestamp", 'w')
timestamp_file.write(d['timestamp'])
timestamp_file.close()
sys.stdout = Logger('console_output.txt')
sys.stderr = sys.stdout
shutil.make_archive("minq", "zip", d['MINQ_PATH'])
shutil.make_archive("moku", "zip", d['MOKU_PATH'])
shutil.make_archive("script", "zip", d['SCRIPT_PATH'])
argfile = open("arguments.txt", 'w')
for var in vars(args):
argfile.write("{}: {}\n".format(var, vars(args)[var]))
argfile.close()
####################################################
## BUILD NETWORK
####################################################
static_intfops = dict(bw = 100, delay = '10ms')
dynamic_intfops = dict(bw = 100)
net = Mininet(link = TCLink)
controllers = []
switches = []
servers = []
clients = []
links = []
#
#
# static shaped dynamic shaped
# link 0 link 1
# | |
# V V
# +----------+ +----------+ +----------+
# | client-0 | <---> | switch-0 | <---> | switch-1 |
# +----------+ +----------+ +----------+
# ^
# | <-- unshaped link
# | link 2
# V
# +----------+
# | observer |
# | switch-2 |
# +----------+
# ^
# | <-- unshaped link
# | link 3
# V
# +----------+ +----------+ +----------+
# | server-0 | <---> | switch-4 | <---> | switch-3 |
# +----------+ +----------+ +----------+
# ^ ^
# | |
# link 5 link 4
# static shaped dynamic shaped
#
## add switches
switches.append(net.addSwitch('switch-0'))
switches.append(net.addSwitch('switch-1'))
switches.append(net.addSwitch('switch-2'))
switches.append(net.addSwitch('switch-3'))
switches.append(net.addSwitch('switch-4'))
observer = switches[2]
## add controler and servers
controllers.append(net.addController('controller-0'))
servers.append(net.addHost('server-0', ip='10.0.0.1'))
clients.append(net.addHost('client-0', ip='10.0.0.101'))
## add links
links.append(net.addLink(clients[0], switches[0])) # link 0
links.append(net.addLink(switches[0], switches[1])) # link 1
links.append(net.addLink(switches[1], switches[2])) # link 2
links.append(net.addLink(switches[2], switches[3])) # link 3
links.append(net.addLink(switches[3], switches[4])) # link 4
links.append(net.addLink(switches[4], servers[0])) # link 5
## TEST DISABLE OFFLOADING
for link in links:
for intf in (link.intf1, link.intf2):
# node = intf.node
cmd = "ethtool -K {} tx off sg off tso off"
cmd = cmd.format(intf.name)
intf.node.cmd(cmd)
## configure interfaces
if args.one_direction:
dynamic_interfaces = (links[1].intf1, links[4].intf1)
else:
dynamic_interfaces = (links[1].intf1, links[1].intf2, links[4].intf1, links[4].intf2)
static_interfaces = (links[0].intf1, links[0].intf2, links[5].intf1, links[5].intf2)
for node in net.values():
if isinstance(node, OVSController):
print("Not configuring interfaces of controller")
continue
for intf in node.intfList():
if intf in dynamic_interfaces:
print("Configuring dynamic intf {} from {}".format(intf, node))
intf.config(**dynamic_intfops)
elif intf in static_interfaces:
print("Configuring static intf {} from {}".format(intf, node))
intf.config(**static_intfops)
else:
print("Not configuring intf {} from {}".format(intf, node))
if args.dynamic_intf and args.no_baseline:
configureNetem(dynamic_interfaces, args.dynamic_intf)
setLogLevel('info')
net.start()
net.pingAll()
####################################################
## RUN MEASUREMENT COMMANDS
####################################################
running_commands = list()
def popenWrapper(prefix, command, host = None, stdin = None, stdout = None, stderr = None):
args = shlex.split(command)
if not stdin:
stdin = subprocess.PIPE
elif type(stdin) == str:
stdin = open(stdin, 'r')
if not stdout:
stdout = open("{}_stdout.txt".format(prefix), 'w')
elif type(stdout) == str:
stdout = open(stdout, 'w')
if not stderr:
stderr = open("{}_stderr.txt".format(prefix), 'w')
elif type(stderr) == str:
stderr = open(stderr, 'w')
if host:
host_name = host.name
handle = host.popen(args, stdout=stdout, stderr=stderr, stdin=stdin)
else:
host_name = "local"
handle = subprocess.Popen(args, stdout=stdout, stderr=stderr, stdin=stdin)
print("[{}] running:: {}".format(host_name, command))
return handle
## Start tcpdump on client
cmd = """tcpdump -i {interface} -n "udp port 4433 or tcp portrange 45670-45690" -w {tcpdump_file}"""
cmd = cmd.format(interface = "client-0-eth0", tcpdump_file = "client-0_tcpdump.pcap")
handle = popenWrapper("client-0_tcmpdump", cmd, clients[0])
running_commands.append(handle)
## Start tcpdump on server
cmd = """tcpdump -i {interface} -n "udp port 4433 or tcp portrange 45670-45690" -w {tcpdump_file}"""
cmd = cmd.format(interface = "server-0-eth0", tcpdump_file = "server-0_tcpdump.pcap")
handle = popenWrapper("server-0_tcmpdump", cmd, servers[0])
running_commands.append(handle)
## Start tcpdump on observer
cmd = """tcpdump -i {interface} -n "udp port 4433 or tcp portrange 45670-45690" -w {tcpdump_file}"""
cmd = cmd.format(interface = "switch-2-eth1", tcpdump_file = "switch-2_tcpdump.pcap")
handle = popenWrapper("switch-2_tcpdump", cmd, LOCAL)
running_commands.append(handle)
## start ping on client
#cmd = """{SCRIPT_PATH}/ping.py {target_ip}"""
cmd = """ping -D -i 0.001 {target_ip}"""
cmd = cmd.format(target_ip = servers[0].IP(), **d)
handle = popenWrapper("client-0_ping", cmd, clients[0])
running_commands.append(handle)
## Start Minq | TCP Server
if not args.tcp:
cmd = """sudo -u {USER} MINQ_LOG={MINQ_LOG_LEVEL} /usr/local/go/bin/go run {MINQ_PATH}/bin/server/main.go -addr {server_ip}:4433 -server-name {server_ip}"""
else:
cmd = """sudo -u {USER} {SCRIPT_PATH}/tcp_endpoint.py server --server-ip {server_ip}"""
if args.echo:
cmd += " -echo"
cmd = cmd.format(server_ip = servers[0].IP(), **d)
server_stdout_path = "server-0_minq_stdout"
handle = popenWrapper("server-0_minq", cmd, servers[0], stdout = server_stdout_path)
running_commands.append(handle)
## Give the server some time to initialize.
time.sleep(10)
## Start Minq Client
#cmd = """sudo -u {USER} MINQ_LOG={MINQ_LOG_LEVEL} /usr/local/go/bin/go run {MINQ_PATH}/bin/client/main.go -heartbeat 1 -addr {server_ip}:4433"""
if not args.tcp:
srv_cmd = """sudo -u {USER} MINQ_LOG={MINQ_LOG_LEVEL} /usr/local/go/bin/go run {MINQ_PATH}/bin/client/main.go -addr {server_ip}:4433"""
else:
srv_cmd = """sudo -u {USER} {SCRIPT_PATH}/tcp_endpoint.py client --server-ip {server_ip}"""
if args.heartbeat:
srv_cmd += " -heartbeat {}".format(args.heartbeat)
srv_cmd = srv_cmd.format(server_ip = servers[0].IP(), **d)
if args.file:
client_stdin = "{FILES_PATH}/{filename}".format(filename = args.file, **d)
elif args.traffic_gen != None:
traffic_cmd = """sudo -u {USER} {SCRIPT_PATH}/traffic_gen.py {arguments}"""
traffic_cmd = traffic_cmd.format(arguments = args.traffic_gen, **d)
traffic_generator = popenWrapper("client_0_traffic_gen", traffic_cmd, None, stdout=subprocess.PIPE, stderr=sys.stdout)
running_commands.append(traffic_generator)
client_stdin = traffic_generator.stdout
else:
client_stdin = None
if not args.tcp:
handle = popenWrapper("client-0_minq", srv_cmd, clients[0], stdin=client_stdin)
else:
handle = popenWrapper("client-0_tcp", srv_cmd, clients[0], stdin=client_stdin)
running_commands.append(handle)
client_handle = handle
####################################################
## DELAY AND STOP MEASUREMENT
####################################################
def fancyWait(wait_time, steps = 50):
elapsed_time = 0
total_time = wait_time
print("Will run for {} seconds".format(wait_time))
print("|"+"-"*(steps-2)+"|")
step_size = float(total_time) / steps
while wait_time > step_size:
time.sleep(step_size)
wait_time -= step_size
sys.stdout.write('*')
sys.stdout.flush()
time.sleep(wait_time)
sys.stdout.write('\n')
if args.time:
fancyWait(args.time)
handle = popenWrapper("client-0_ip", "ip ad", clients[0])
running_commands.append(handle)
if args.dynamic_intf and not args.no_baseline:
configureNetem(dynamic_interfaces, args.dynamic_intf)
if not args.wait_for_client:
fancyWait(args.time)
if client_handle.poll() != None:
open(" EARLY TERMINATION", 'w').close()
print(">>> Something went wrong, client terminated early <<<")
try:
client_handle.terminate()
except:
pass
if args.wait_for_client:
print("Now waiting for client to terminate")
startTime = datetime.datetime.now()
client_handle.wait()
print("Client is done :) {}".format(datetime.datetime.now() - startTime))
if type(client_stdin) == str:
cmd = "cmp {} {}"
cmd = cmd.format(client_stdin, server_stdout_path)
cmd_args = shlex.split(cmd)
if not subprocess.call(cmd_args):
print("input and output file equal!")
while len(running_commands) > 0:
handle = running_commands.pop()
try:
handle.terminate()
except:
pass
print('Done, shutting down mininet')
net.stop()
#####################################################
### RUN MOKUMOKUREN
#####################################################
#cmd = """sudo -u {USER} /usr/local/go/bin/go run {MOKU_PATH}/tmoku/main.go --file {inputfile}"""
#cmd = cmd.format(inputfile = "switch-2_tcpdump.pcap", **d)
#handle = popenWrapper("switch-2_moku", cmd, LOCAL)
#handle.wait()
#####################################################
### RUN ANALYZER SCRIPTS
#####################################################
#cmd = """python3 {SCRIPT_PATH}/analyze_spinbit.py switch-2_moku_stdout.txt client-0_minq_stderr.txt server-0_minq_stderr.txt client-0_ping_stdout.txt client-0 '{title}'"""
#cmd = cmd.format(title=run_name, **d)
#handle = popenWrapper("client-0_spin_", cmd, LOCAL)
#handle.wait()
#cmd = """python3 {SCRIPT_PATH}/analyze_congestion.py client-0_minq_stderr.txt client-0 '{title}'"""
#cmd = cmd.format(title=run_name, **d)
#handle = popenWrapper("client-0_congestion_", cmd, LOCAL)
#handle.wait()
#cmd = """python3 {SCRIPT_PATH}/analyze_congestion.py server-0_minq_stderr.txt server-0 '{title}'"""
#cmd = cmd.format(title=run_name, **d)
#handle = popenWrapper("server-0_congestion_", cmd, LOCAL)
#handle.wait()
#####################################################
### VERIFY THAT FILE WAS SUCESSFULLY COPIED
#####################################################
#if type(client_stdin) == str:
#if args.wait_for_client:
#cmd = "cmp {} {}"
#cmd = cmd.format(client_stdin, server_stdout_path)
#cmd_args = shlex.split(cmd)
#not_equal = subprocess.call(cmd_args)
#if client_stdin and not_equal:
#print(">>>OUTPUT FILES ARE NOT EQUAL<<<")
#in_size = os.path.getsize(client_stdin)
#out_size = os.path.getsize(server_stdout_path)
#print("File size original: {}, copy: {}".format(in_size, out_size))
#open(" FAIL", 'w').close()
#elif client_stdin:
#print("> output files are equal :) ")
#os.system("rm server-0_minq_stdout")
#open(" SUCCESS", 'w').close()
#else:
#os.system("rm server-0_minq_stdout")
#####################################################
### CLEAN UP
#####################################################
os.system("chown piet:piet . -R")
os.system("chmod -w *")