-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnode_setup.py
More file actions
243 lines (199 loc) · 8.12 KB
/
node_setup.py
File metadata and controls
243 lines (199 loc) · 8.12 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
import os
import subprocess
import time
import riddler_interface as interface
bat_path = "/sys/class/net/bat0/mesh/"
bat_dbg = "/sys/kernel/debug/batman_adv/bat0/nc/"
nc_file = "network_coding"
core_file = "random_linear_network_coding"
hold_file = "max_fwd_delay"
purge_file = "max_buffer_time"
loss_file = "packet_loss"
prio_file = "relay_priority"
ipv4_path = "/proc/sys/net/ipv4/"
current_algo = "tcp_congestion_control"
available_algos = "tcp_available_congestion_control"
window_read = "tcp_rmem"
window_write = "tcp_wmem"
class setup:
def __init__(self, args):
self.error = None
self.args = args
def __del__(self):
if hasattr(self, 'fox_process') and self.fox_process:
print(" Killing current instance of fox")
self.fox_process.terminate()
del self.fox_process
# Call the different setup functions
def apply_setup(self, run_info):
if not self.setup_batman(run_info):
return False
if not self.setup_tcp(run_info):
return False
if not self.setup_iface(run_info):
return False
#if not self.setup_fox(run_info):
# return False
return True
def check_fox(self):
print(" Check fox")
if not hasattr(self, "fox_process"):
print(" no fox process")
return False
if not self.fox_process:
print(" empty fox process")
return False
if self.fox_process.poll():
print(" bad return value from fox process")
del self.fox_process
return False
print(" fox is running")
self.fox_process.terminate()
del self.fox_process
return True
def setup_fox(self, run_info):
if run_info['profile'] not in 'rlnc':
return True
if not os.path.exists(self.args.fox_path):
self.error = "'{}' does not exist".format(self.args.fox_path)
return False
if hasattr(self, 'fox_process'):
print(" Killing previous instance of fox")
self.fox_process.terminate()
del self.fox_process
time.sleep(1)
if run_info['coding'] == 'noloss':
if os.path.exists(bat_path + loss_file):
self.write(bat_path + loss_file, 0)
e1 = 0
e2 = 0
e3 = 0
elif run_info['coding'] == 'nohelper':
e1 = 99
e2 = 99
e3 = run_info["errors"][2]
else:
if os.path.exists(bat_path + loss_file):
self.write(bat_path + loss_file, 1)
e1 = run_info["errors"][0]
e2 = run_info["errors"][1]
e3 = run_info["errors"][2]
if run_info['coding'] == 'helper' and run_info['role'] == 'helper':
run_info['fixed_overshoot'] = run_info['helper_overshoot']
cmd = [self.args.fox_path]
cmd += ["-symbols", str(run_info["gen_size"])]
cmd += ["-symbol_size", str(run_info["packet_size"])]
cmd += ["-e1", str(e1)]
cmd += ["-e2", str(e2)]
cmd += ["-e3", str(e3)]
cmd += ["-encoders", str(run_info['encoders'])]
cmd += ["-encoder_timeout", str(run_info['encoder_timeout'])]
cmd += ["-decoder_timeout", str(run_info['decoder_timeout'])]
#cmd += ["-recoder_timeout", str(run_info['recoder_timeout'])]
#cmd += ["-helper_timeout", str(run_info['helper_timeout'])]
cmd += ["-fixed_overshoot", str(run_info['fixed_overshoot'])]
#cmd += ["-helper_threshold", str(run_info['helper_threshold'])]
cmd += ["-ack_timeout", str(run_info['ack_timeout'])]
cmd += ["-req_timeout", str(run_info['req_timeout'])]
cmd += ["-v", str(run_info['fox_verbose'])]
cmd += ["-alsologtostderr=false"];
if run_info['coding'] == 'helper' and run_info['role'] == 'source':
cmd += ["-systematic", str(run_info['systematic'])]
print(" starting fox")
self.fox_process = subprocess.Popen(cmd)
time.sleep(1)
if run_info['coding'] in ('loss', 'noloss'):
print(" killing fox due to (no)loss")
self.fox_process.terminate()
time.sleep(1)
del self.fox_process
if run_info['coding'] == 'nohelper' and run_info['role'] == 'helper':
print(" killing fox due to nohelper")
self.fox_process.terminate()
time.sleep(1)
del self.fox_process
return True
# Apply the received configuration for batman-adv
def setup_batman(self, run_info):
if run_info['profile'] not in ('udp_rates', 'udp_ratios', 'tcp_algos', 'tcp_windows', 'hold_times', 'power_meas', 'core', 'prio'):
return True
#nc = 1 if run_info['coding'] else 0
nc = 1 if run_info['coding'] in ('nc', 'core', 'nc_prio', True) else 0
core = 1 if run_info['coding'] in ('core', True) else 0
if run_info['coding'] in ('nc_prio', 'plain_prio'):
prio = run_info['catwoman_prio']
else:
prio = 0;
# Make sure batman-adv is enabled
if not os.path.exists(bat_path):
self.error = "'{0}' does not exist".format(bat_path)
return False
# Write the configuration
if os.path.exists(bat_path + nc_file):
self.write(bat_path + nc_file, nc)
if os.path.exists(bat_path + core_file):
self.write(bat_path + core_file, core)
if os.path.exists(bat_dbg + hold_file):
self.write(bat_dbg + hold_file, run_info['hold'])
if os.path.exists(bat_dbg + purge_file):
self.write(bat_dbg + purge_file, run_info['purge'])
if os.path.exists(bat_dbg + prio_file):
self.write(bat_dbg + prio_file, prio)
return True
# Load and enable a TCP congestion avoidance algorithm
def setup_tcp(self, run_info):
if run_info['profile'] not in ('tcp_algos', 'tcp_windows'):
return True
# Make sure we actually need to do this
if not run_info['protocol'] == 'tcp':
return True
# Write TCP window sizes
window = run_info['tcp_window']
self.write(ipv4_path + window_write, window)
# Write and enable the selected algorithm
algo = run_info['tcp_algo']
self.write(ipv4_path + current_algo, algo)
# Check if we succeeded
if algo not in self.read(ipv4_path + current_algo):
self.error = "Failed to set tcp algorithm: {0}".format(algo)
return False
return True
def setup_iface(self, run_info):
if run_info['profile'] not in ('udp_rates', 'udp_ratios', 'tcp_algos', 'tcp_windows', 'hold_times', 'power_meas'):
return True
iface = self.args.wifi_iface
state = "on" if run_info['promisc'] else "off"
cmd = ['ip', 'link', 'set', 'dev', iface, 'promisc', state]
r = subprocess.call(cmd)
if r:
return False
cmd = ['iw', 'phy0', 'set', 'rts', str(run_info['rts'])]
r = subprocess.call(cmd)
if r:
return False
if state == "on" and os.path.exists("/sys/class/net/mesh0"):
if not os.path.exists("/sys/class/net/mon0"):
cmd = ["iw", "phy0", "interface", "add", "mon0", "type", "monitor", "flags", "none"]
if interface.exec_cmd(cmd) == False:
self.error = "Failed to create mon0: {}".format(cmd)
return False
cmd = ["ip", "link", "set", "dev", "mon0", "up"]
if interface.exec_cmd(cmd) == False:
self.error = "Failed to up mon0: {}".format(cmd)
return False
cmd = ["iw", "mon0", "del"]
if interface.exec_cmd(cmd) == False:
self.error = "Failed to del mon0: {}".format(cmd)
return False
return True
# Read data from file
def read(self, path):
f = open(path, "r")
ret = f.read()
f.close()
return ret
# Write data to file
def write(self, path, value):
f = open(path, "w")
f.write(str(value))
f.close()