forked from hundeboll/riddler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_setup.py
More file actions
92 lines (73 loc) · 2.59 KB
/
node_setup.py
File metadata and controls
92 lines (73 loc) · 2.59 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
import os
import subprocess
import riddler_interface as interface
bat_path = "/sys/class/net/bat0/mesh/"
nc_file = "network_coding"
hold_file = "nc_hold"
purge_file = "nc_purge"
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
# 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
return True
# Apply the received configuration for batman-adv
def setup_batman(self, run_info):
nc = 1 if run_info['coding'] else 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 + hold_file):
self.write(bat_path + hold_file, run_info['hold'])
if os.path.exists(bat_path + purge_file):
self.write(bat_path + purge_file, run_info['purge'])
return True
# Load and enable a TCP congestion avoidance algorithm
def setup_tcp(self, run_info):
# 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)
# 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):
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)
return False if r else 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()