-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py.server
297 lines (240 loc) · 9.82 KB
/
fabfile.py.server
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
#!/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
#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']
exps = ['run_exp']
__all__ = clears+setups+exps+['sync'] + helpers
env.key_filename = '/home/xarokk/.ssh/exp'
env.user = 'user'
env.roledefs = {
'server':['[email protected]'],
'client':['[email protected]'],
'router':['[email protected]']
}
@roles('router')
def now():
execute(clear_nat,inface='enx00e04c534458',outface='enp0s25')
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('server')
def setup_ipip_server():
with cd('roc/tunneling/'):
sudo('./ipip-server.sh')
@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='enx00e04c534458',outface='ipiptun1')
def setup_ipip():
execute(setup_ipip_router)
execute(setup_ipip_server)
@roles('router')
def clear_ipip_router():
execute(clear_nat_8080,inface='enx00e04c534458',outface='ipiptun1')
execute(setup_nat_8080,inface='enx00e04c534458',outface='enp0s25')
sudo('ip tun del ipiptun1')
#execute(setup_nat,inface='enx00e04c534458',outface='enp0s25')
@roles('server')
def clear_ipip_server():
sudo('ip tun del ipiptun1')
def clear_ipip():
execute(clear_ipip_router)
execute(clear_ipip_server)
@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('server')
def setup_tcplp_server():
with cd('roc/tunneling/tcp_lp'):
sudo('screen -S tcplp -d -m ./simpletun_tcplp -i tcplp -s')
sudo('ifconfig tcplp 192.168.10.1/24 up')
@roles('router')
def setup_tcplp_router():
#sudo('screen -wipe')
with cd('roc/tunneling/tcp_lp'):
run('sudo screen -S tcplp -d -m ./simpletun_tcplp -i tcplp -c 147.83.118.124')
with warn_only():
local('sudo screen -ls')
#sudo('sudo ifconfig -a')
run('sudo ifconfig tcplp 192.168.10.2/24 up')
execute(clear_nat_8080,inface='enx00e04c534458',outface='enp0s25')
execute(setup_nat_8080,inface='enx00e04c534458',outface='tcplp')
def setup_tcplp():
execute(setup_tcplp_server)
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='enx00e04c534458',outface='tcplp')
execute(setup_nat_8080,inface='enx00e04c534458',outface='enp0s25')
@roles('server')
def clear_tcplp_server():
sudo('ifconfig tcplp down')
sudo('sudo screen -X -S tcplp quit')
def clear_tcplp():
execute(clear_tcplp_router)
execute(clear_tcplp_server)
@roles('server')
def setup_tcpvegas_server():
with cd('roc/tunneling/tcp_vegas'):
sudo('screen -S tcpvegas -d -m ./simpletun_tcpvegas -i tcpvegas -s')
sudo('ifconfig tcpvegas 192.168.10.1/24 up')
@roles('router')
def setup_tcpvegas_router():
#sudo('screen -wipe')
with cd('roc/tunneling/tcp_vegas'):
run('sudo screen -S tcpvegas -d -m ./simpletun_tcpvegas -i tcpvegas -c 147.83.118.124')
with warn_only():
local('sudo screen -ls')
#sudo('sudo ifconfig -a')
run('sudo ifconfig tcpvegas 192.168.10.2/24 up')
execute(clear_nat_8080,inface='enx00e04c534458',outface='enp0s25')
execute(setup_nat_8080,inface='enx00e04c534458',outface='tcpvegas')
def setup_tcpvegas():
execute(setup_tcpvegas_server)
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='enx00e04c534458',outface='tcpvegas')
execute(setup_nat_8080,inface='enx00e04c534458',outface='enp0s25')
@roles('server')
def clear_tcpvegas_server():
sudo('ifconfig tcpvegas down')
sudo('sudo screen -X -S tcpvegas quit')
def clear_tcpvegas():
execute(clear_tcpvegas_router)
execute(clear_tcpvegas_server)
@roles('client')
def run_exp_client(exp,mixed,exp_no,duration,ip):
"""Client monitored traffic experiment"""
#if exp in ['tcpvegas']:
# ip = "192.168.10.1"
with cd('/home/xarokk1/manos/primary/wrk2'):
cmd_env = 'env dir='+exp+' num='+exp_no+' mixed='+mixed+' '
cmd_wrk = ' ./wrk -t1 -c5 -d'+duration+' -R5 --script scripts/report.lua '
cmd_wrk_url = ' http://'+ip+'/02Mb.html '
cmd = cmd_env+cmd_wrk+cmd_wrk_url
run('echo '+cmd+' > command')
run('at now + 2 minutes < command')
@roles('client')
def run_exp_client2(exp,mixed,exp_no,duration,ip):
"""Client background(shared) traffic"""
port = '8080'
if exp in ['ipip','tcplp','ledbat','tcpvegas','ipip_router','tcplp_router','tcpvegas_router','ledbat_router']:
ip = "192.168.10.1"
#port = '8080'
#elif exp in ['borrowing']:
# port = '8080'
with cd('/home/xarokk1/manos/secondary/wrk2'):
cmd_env = 'env dir='+exp+' num='+exp_no+' mixed='+mixed+' '
cmd_wrk = ' ./wrk -t1 -c25 -d'+duration+' -R25 --script scripts/report.lua'
cmd_wrk_url = ' http://'+ip+':'+port+'/004Mb.html '
cmd = cmd_env+cmd_wrk+cmd_wrk_url
run('echo '+cmd+' > command')
run('at now + 2 minutes < command')
@roles('router')
def run_exp_router(exp,mixed,exp_no,duration,ip):
"""Router background(shared) traffic"""
port = '8080'
if exp in ['ipip','tcplp','ledbat','tcpvegas']:
exp = "192.168.10.1"
port = '8080'
with cd('/home/xarokk/manos/wrk2'):
cmd_wrk = ' ./wrk -t1 -c25 -d'+duration+' -R25'
cmd_wrk_url = ' http://'+ip+':'+port+'/004Mb.html '
cmd = cmd_wrk+cmd_wrk_url
run('echo '+cmd+' > command')
run('at now + 2 minutes < command')
def run_exp(exp,mixed,exp_no,duration):
"""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.124"
execute(run_exp_client,exp,mixed,exp_no,duration,ip)
if mixed == 'mix':
execute(run_exp_client2,exp,mixed,exp_no,duration,ip)
def setup_nat(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+' -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+' -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):
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+' -p tcp --dport 80 -o '+outface+' -j ACCEPT')
def clear_nat_8080(inface,outface):
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+' -p tcp --dport 8080 -o '+outface+' -j ACCEPT')
@roles('router')
def restore_nat():
execute(setup_nat,inface='enx00e04c534458',outface='enp0s25')
execute(setup_nat_8080,inface='enx00e04c534458',outface='enp0s25')
@roles('router')
def delete_nat():
execute(clear_nat,inface='enx00e04c534458',outface='enp0s25')
execute(clear_nat_8080,inface='enx00e04c534458',outface='enp0s25')
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 [email protected]:~/manos/primary/wrk2/exps /home/xarokk/manos/.')
run('rsync -rz [email protected]:~/manos/secondary/wrk2/exps /home/xarokk/manos/.')
sudo("iptables-restore < iptables.rules")