-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
410 lines (340 loc) · 14.7 KB
/
fabfile.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
#!/usr/bin/env python
from fabric.api import env, run, local, roles, execute, sudo, warn_only
from fabric.context_managers import cd
import time
import help
import sys,getopt
import ipdb
#from datetime import datetime as dt
##HOUR = datetime.timedelta(minutes=2).now().time().strftime('%H%M')
##EXP_HOUR = (datetime.timedelta(minutes=2)+datetime.datetime.now()).time().strftime('%H%M')
clears = ['clear_codel','clear_ipip','clear_sfq','clear_tcplp','clear_tcpvegas','clear_borrowing']
setups = ['setup_codel','setup_ipip','setup_sfq','setup_tcplp','setup_tcpvegas','setup_borrowing']
helpers = ['restore_nat','delete_nat', 'setup_limit','clear_limit','setup_nat_now','clear_nat_now']
exps = ['run_exp']
__all__ = clears+setups+exps+['sync'] + helpers
env.key_filename = '/home/xarokk/.ssh/exp'
env.user = 'user'
env.roledefs = {
'server':['xarokk2@147.83.118.123'],
'client':['xarokk1@192.168.240.2'],
'router':['xarokk@147.83.118.126']
}
@roles('router')
def now():
with warn_only():
output = run('cat /proc/sys/net/ipv4/conf/tcplp; echo $?')
print output.stdout[-1].strip()
if output.stdout[-1].strip() == "1":
print 'Hi'
def server():
env.hosts = ['147.83.118.124']
def client():
env.hosts = ['192.168.240.2']
def router():
env.hosts = ['localhost']
def all():
env.hosts = ['147.83.118.124','192.168.240.2','localhost']
def test():
cmd = '"touch manos/test"'
run('echo '+cmd+' > command')
run('at now + 1 minutes < command')
@roles('client')
def setup_ipip_client():
with cd('roc/tunneling/'):
sudo('./ipip-server.sh')
sudo('./tunel_client_setup.bash ipiptun1')
#sudo('route del default gw 192.168.240.1 enp0s25')
#sudo('route add default gw 192.168.10.1')
@roles('router')
def setup_ipip_router():
#execute(clear_nat,inface='enx00e04c534458',outface='enp0s25')
with cd('roc/tunneling/'):
sudo('./ipip-client.sh')
execute(clear_nat_8080,inface='enx00e04c534458',outface='enp0s25')
execute(setup_nat_8080,inface='ipiptun1',outface='enp0s25')
def setup_ipip():
execute(setup_ipip_router)
execute(setup_ipip_client)
@roles('router')
def clear_ipip_router():
execute(clear_nat_8080,inface='ipiptun1',outface='enp0s25')
execute(setup_nat_8080,inface='enx00e04c534458',outface='enp0s25')
sudo('ip tun del ipiptun1')
#sudo('route del default gw 192.168.240.1 enp0s25')
#execute(setup_nat,inface='enx00e04c534458',outface='enp0s25')
@roles('client')
def clear_ipip_client():
with cd('roc/tunneling/'):
sudo('./tunel_client_clear.bash ipiptun1')
sudo('ip tun del ipiptun1')
def clear_ipip():
execute(clear_ipip_router)
execute(clear_ipip_client)
@roles('router')
def setup_codel():
with cd('roc/tunneling/'):
sudo('./tc_codel.bash start')
@roles('router')
def clear_codel():
with cd('roc/tunneling/'):
sudo('./tc_codel.bash stop')
@roles('router')
def setup_borrowing():
with cd('roc/tunneling/'):
sudo('./tc_borrowing.bash start')
@roles('router')
def clear_borrowing():
with cd('roc/tunneling/'):
sudo('./tc_borrowing.bash stop')
@roles('router')
def setup_sfq():
with cd('roc/tunneling/'):
sudo('./tc_sfq.bash start')
@roles('router')
def clear_sfq():
with cd('roc/tunneling/'):
sudo('./tc_sfq.bash stop')
@roles('client')
def setup_tcplp_client():
while True:
with cd('roc/tunneling/tcp_lp'):
sudo('screen -S tcplp -d -m ./simpletun_tcplp -i tcplp -s')
with warn_only():
sudo('screen -ls')
output = run('ls /proc/sys/net/ipv4/conf/tcplp; echo $?')
if output.stdout[-1].strip() != '2':
break
else:
local('sudo screen -wipe')
#with cd('roc/tunneling/tcp_lp'):
# sudo('screen -S tcplp -d -m ./simpletun_tcplp -i tcplp -s')
sudo('ifconfig tcplp 192.168.10.2/24 up')
with cd('roc/tunneling'):
sudo('./tunel_client_setup.bash tcplp')
#sudo('route add default gw 192.168.10.1 tcplp')
@roles('router')
def setup_tcplp_router():
while True:
with cd('roc/tunneling/tcp_lp'):
run('sudo screen -S tcplp -d -m ./simpletun_tcplp -i tcplp -c 192.168.240.2')
with warn_only():
local('sudo screen -ls')
output = run('ls /proc/sys/net/ipv4/conf/tcplp; echo $?')
if output.stdout[-1].strip() != '2':
break
else:
local('sudo screen -wipe')
run('sudo ifconfig tcplp 192.168.10.1/24 up')
execute(clear_nat_8080,inface='enx00e04c534458',outface='enp0s25')
execute(setup_nat_8080,inface='tcplp',outface='enp0s25')
def setup_tcplp():
execute(setup_tcplp_client)
execute(setup_tcplp_router)
@roles('router')
def clear_tcplp_router():
sudo('ifconfig tcplp down')
sudo('sudo screen -X -S tcplp quit')
execute(clear_nat_8080,inface='tcplp',outface='enp0s25')
execute(setup_nat_8080,inface='enx00e04c534458',outface='enp0s25')
@roles('client')
def clear_tcplp_client():
with cd('roc/tunneling'):
sudo('./tunel_client_clear.bash tcplp')
with warn_only():
sudo('ifconfig tcplp down')
sudo('sudo screen -X -S tcplp quit')
def clear_tcplp():
execute(clear_tcplp_router)
execute(clear_tcplp_client)
@roles('client')
def setup_tcpvegas_client():
while True:
with cd('roc/tunneling/tcp_vegas'):
sudo('screen -S tcpvegas -d -m ./simpletun_tcpvegas -i tcpvegas -s')
with warn_only():
sudo('screen -ls')
output = run('ls /proc/sys/net/ipv4/conf/tcpvegas; echo $?')
if output.stdout[-1].strip() != '2':
break
else:
local('sudo screen -wipe')
#with cd('roc/tunneling/tcp_vegas'):
# sudo('screen -S tcpvegas -d -m ./simpletun_tcpvegas -i tcpvegas -s')
sudo('ifconfig tcpvegas 192.168.10.2/24 up')
with cd('roc/tunneling'):
sudo('./tunel_client_setup.bash tcpvegas')
#sudo('route add default gw 192.168.10.1 tcpvegas')
@roles('router')
def setup_tcpvegas_router():
#sudo('screen -wipe')
while True:
with cd('roc/tunneling/tcp_vegas'):
run('sudo screen -S tcpvegas -d -m ./simpletun_tcpvegas -i tcpvegas -c 192.168.240.2')
with warn_only():
local('sudo screen -ls')
output = run('ls /proc/sys/net/ipv4/conf/tcpvegas; echo $?')
if output.stdout[-1].strip() != '2':
break
else:
local('sudo screen -wipe')
#sudo('sudo ifconfig -a')
run('sudo ifconfig tcpvegas 192.168.10.1/24 up')
execute(clear_nat_8080,inface='enx00e04c534458',outface='enp0s25')
execute(setup_nat_8080,inface='tcpvegas',outface='enp0s25')
def setup_tcpvegas():
execute(setup_tcpvegas_client)
execute(setup_tcpvegas_router)
@roles('router')
def clear_tcpvegas_router():
sudo('ifconfig tcpvegas down')
sudo('sudo screen -X -S tcpvegas quit')
execute(clear_nat_8080,inface='tcpvegas',outface='enp0s25')
execute(setup_nat_8080,inface='enx00e04c534458',outface='enp0s25')
@roles('client')
def clear_tcpvegas_client():
with cd('roc/tunneling'):
sudo('./tunel_client_clear.bash tcpvegas')
with warn_only():
sudo('ifconfig tcpvegas down')
sudo('sudo screen -X -S tcpvegas quit')
def clear_tcpvegas():
execute(clear_tcpvegas_router)
execute(clear_tcpvegas_client)
@roles('client')
def run_exp_client(exp,mixed,exp_no,duration,ip,delay,size,req1):
"""Client monitored traffic experiment"""
#if exp in ['tcpvegas']:
# ip = "192.168.10.1"
with cd('/home/xarokk1/manos/primary/wrk2'):
with warn_only():
run('mkdir exps/'+exp)
cmd_env = 'env dir='+exp+' num='+exp_no+' mixed='+mixed+' '
#cmd_wrk = ' ./wrk -t1 -c25 -d'+duration+' -R25'
cmd_wrk = ' ./wrk -t1 -c'+req1+' -d'+duration+' -R'+req1+' --script scripts/report'+delay+'.lua '
cmd_wrk_url = ' http://'+ip+'/'+size+'Mb.html '
cmd = cmd_env+cmd_wrk+cmd_wrk_url
run('echo '+cmd+' > command')
tshark = ' tshark -Y "tcp.analysis.retransmission" -Tfields -e ip.src -e ip.dst -e tcp.port -i enp0s25 '
retrans_timeout = 'sudo timeout '+duration + tshark
retrans = ' > exps/'+exp+'/retrans_'+mixed+'_'+exp_no+'.log 2>&1'
retrans_cmd = retrans_timeout + retrans
run('echo \"'+retrans_cmd+'\" > retrans_cmd')
run('at now + 2 minutes < command')
sudo('at now + 2 minutes < retrans_cmd')
if 'ipip' in exp:
tshark = ' tshark -Y "tcp.analysis.retransmission" -Tfields -e ip.src -e ip.dst -e tcp.port -i ipiptun1'
retrans_timeout = 'sudo timeout '+duration + tshark
retrans = ' > exps/'+exp+'/retrans_'+mixed+'_'+exp_no+'_ipiptun1.log 2>&1'
retrans_cmd = retrans_timeout + retrans
run('echo \"'+retrans_cmd+'\" > retrans_cmd1')
sudo('at now + 2 minutes < retrans_cmd1')
if 'tcpvegas' in exp:
tshark = ' tshark -Y "tcp.analysis.retransmission" -Tfields -e ip.src -e ip.dst -e tcp.port -i tcpvegas'
retrans_timeout = 'sudo timeout '+duration + tshark
retrans = ' > exps/'+exp+'/retrans_'+mixed+'_'+exp_no+'_tcpvegas.log 2>&1'
retrans_cmd = retrans_timeout + retrans
run('echo \"'+retrans_cmd+'\" > retrans_cmd1')
sudo('at now + 2 minutes < retrans_cmd1')
if 'tcplp' in exp:
tshark = ' tshark -Y "tcp.analysis.retransmission" -Tfields -e ip.src -e ip.dst -e tcp.port -i tcplp'
retrans_timeout = 'sudo timeout '+duration + tshark
retrans = ' > exps/'+exp+'/retrans_'+mixed+'_'+exp_no+'_tcpvp.log 2>&1'
retrans_cmd = retrans_timeout + retrans
run('echo \"'+retrans_cmd+'\" > retrans_cmd1')
sudo('at now + 2 minutes < retrans_cmd1')
@roles('client')
def run_exp_client2(exp,mixed,exp_no,duration,ip,size,req2):
"""Client background(shared) traffic"""
port = '8080'
#for i in ['ipip','tcplp','ledbat','tcpvegas']:
# if i in exp:
# ip = "192.168.10.1"
#port = '8080'
#elif exp in ['borrowing']:
# port = '8080'
with cd('/home/xarokk1/manos/secondary/wrk2'):
with warn_only():
run('mkdir exps/'+exp)
cmd_env = 'env dir='+exp+' num='+exp_no+' mixed='+mixed+' '
cmd_wrk = ' ./wrk -t1 -c'+req2+' -d'+duration+' -R'+req2+' --timeout 55s --script scripts/report.lua'
cmd_wrk_url = ' http://'+ip+':'+port+'/'+size+'Mb.html '
cmd = cmd_env+cmd_wrk+cmd_wrk_url
run('echo '+cmd+' > command')
run('at now + 2 minutes < command')
def run_exp(exp,mixed,exp_no,duration,delay="delay",size='008',req1='5',req2='25'):
"""Experiment traffic and background traffic from client, if mix chosen"""
#exp = raw_input('Exp name?')
#mixed = raw_input('mixed?(mix/no)')
#exp_no = raw_input('Exp number?')
##FILE_SIZE = raw_input('File size? (1Mb)')
#duration = raw_input('Duration? (20s)')
ip = "147.83.118.123"
execute(run_exp_client,exp,mixed,exp_no,duration,ip,delay,size,req1)
if mixed == 'mix':
execute(run_exp_client2,exp,mixed,exp_no,duration,ip,size,req2)
def setup_nat(inface,outface):
sudo('iptables -t nat -A POSTROUTING -o '+outface+' -j MASQUERADE')
sudo('iptables -A FORWARD -i '+outface+' -p tcp --sport 80 -o '+inface+' -m state --state RELATED,ESTABLISHED -j ACCEPT')
sudo('iptables -A FORWARD -i '+inface+' -p tcp --dport 80 -o '+outface+' -j ACCEPT')
def setup_nat_8080(inface,outface):
sudo('iptables -t nat -A POSTROUTING -o '+outface+' -j MASQUERADE')
sudo('iptables -A FORWARD -i '+outface+' -p tcp --sport 8080 -o '+inface+' -m state --state RELATED,ESTABLISHED -j ACCEPT')
sudo('iptables -A FORWARD -i '+inface+' -p tcp --dport 8080 -o '+outface+' -j ACCEPT')
def clear_nat(inface,outface):
with warn_only():
sudo('iptables -t nat -D POSTROUTING -o '+outface+' -j MASQUERADE')
sudo('iptables -D FORWARD -i '+outface+' -p tcp --sport 80 -o '+inface+' -m state --state RELATED,ESTABLISHED -j ACCEPT')
sudo('iptables -D FORWARD -i '+inface+' -p tcp --dport 80 -o '+outface+' -j ACCEPT')
def clear_nat_8080(inface,outface):
with warn_only():
sudo('iptables -t nat -D POSTROUTING -o '+outface+' -j MASQUERADE')
sudo('iptables -D FORWARD -i '+outface+' -p tcp --sport 8080 -o '+inface+' -m state --state RELATED,ESTABLISHED -j ACCEPT')
sudo('iptables -D FORWARD -i '+inface+' -p tcp --dport 8080 -o '+outface+' -j ACCEPT')
@roles('router')
def setup_nat_now(inface,outface):
sudo('iptables -t nat -A POSTROUTING -o '+outface+' -j MASQUERADE')
sudo('iptables -A FORWARD -i '+outface+' -o '+inface+' -m state --state RELATED,ESTABLISHED -j ACCEPT')
sudo('iptables -A FORWARD -i '+inface+' -o '+outface+' -j ACCEPT')
@roles('router')
def clear_nat_now(inface,outface):
with warn_only():
sudo('iptables -t nat -D POSTROUTING -o '+outface+' -j MASQUERADE')
sudo('iptables -D FORWARD -i '+outface+' -o '+inface+' -m state --state RELATED,ESTABLISHED -j ACCEPT')
sudo('iptables -D FORWARD -i '+inface+' -o '+outface+' -j ACCEPT')
@roles('router')
def restore_nat1():
execute(setup_nat,inface='enx00e04c534458',outface='enp0s25')
execute(setup_nat_8080,inface='enx00e04c534458',outface='enp0s25')
@roles('client')
def restore_route():
with warn_only():
sudo('ip route add default via 192.168.240.1')
def restore_nat():
execute(restore_nat1)
execute(restore_route)
@roles('router')
def delete_nat1():
execute(clear_nat,inface='enx00e04c534458',outface='enp0s25')
execute(clear_nat_8080,inface='enx00e04c534458',outface='enp0s25')
@roles('client')
def delete_route():
with warn_only():
sudo('ip route del default via 192.168.240.1')
def delete_nat():
execute(delete_nat1)
execute(delete_route)
def setup_limit():
with cd('roc/tunneling/'):
sudo('./tc_bandwidth_'+env.roles[0]+'.bash start')
def clear_limit():
with cd('roc/tunneling/'):
sudo('./tc_bandwidth_'+env.roles[0]+'.bash stop')
@roles('router')
def sync():
"""Sync exp result folders from client to router"""
sudo("iptables-save > iptables.rules")
sudo("iptables -F")
run('eval $(ssh-agent) && ssh-add ~/.ssh/exp && rsync -rz xarokk1@192.168.240.2:~/manos/primary/wrk2/exps /home/xarokk/manos/.')
run('rsync -rz xarokk1@192.168.240.2:~/manos/secondary/wrk2/exps /home/xarokk/manos/.')
sudo("iptables-restore < iptables.rules")