-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoneclick_config.py
executable file
·255 lines (221 loc) · 6.99 KB
/
oneclick_config.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
#!/usr/bin/env python
import os
import subprocess
import sys
import time
import argparse
import socket
### Helper Functions ###
def detect_nic_driver_type(pci_id):
lsmod = subprocess.check_output(['lspci', '-s', pci_id]).decode('utf-8')
if '82599ES' in lsmod:
return 'ixgbe'
if 'XL710' in lsmod:
return 'i40e'
def kernel_ip_map(ifname):
host = socket.gethostname()
ip = "10.7.%d.%d" % (int(ifname[-1])-1, (ord(host[0])-ord('a')) * 10 + int(host[-1]))
return ip
def check_driver_exist(drv):
lsmod = subprocess.check_output('lsmod').decode('utf-8')
lsmod = lsmod.split('\n')
for i in range(1,len(lsmod)):
line = lsmod[i].split(' ')
if line[0] == drv:
return True
return False
def current_nr_hugepages(node_id):
output = subprocess.check_output(("cat /sys/devices/system/node/node%d/hugepages/hugepages-2048kB/nr_hugepages" % node_id).split())
return int(output)
def setup_hugepages_for_numa(node_id, nr_hugepage):
print("Numa node %d..." % node_id)
if current_nr_hugepages(node_id) == nr_hugepage:
print(" nr_hugepages is already set for NUMA %d" % node_id)
return
echo = subprocess.Popen(('echo %d' % nr_hugepage).split(), stdout=subprocess.PIPE)
tee = subprocess.Popen(('sudo tee /sys/devices/system/node/node%d/hugepages/hugepages-2048kB/nr_hugepages' % node_id).split(), stdin=echo.stdout, stdout=subprocess.PIPE)
echo.stdout.close()
ret = tee.communicate()[0]
echo.wait()
if int(ret) != nr_hugepage:
print("Fail to configure hugepages for NUMA %d" % node_id)
exit(1)
def create_dir(path):
print("Creating %s..." % path)
if os.path.exists(path):
print(" %s exists." % path)
else:
cmd = "mkdir %s" % path
print(" " + cmd)
os.system(cmd)
print(" %s created." % path)
def is_hugetlbfs_mounted(hugepage_path):
mount = subprocess.check_output("mount").decode('utf-8')
mount = mount.split('\n')
for i in range(len(mount)):
line = mount[i].split(' ')
if (len(line) < 6):
continue
if line[2] == hugepage_path:
if line[4] == 'hugetlbfs':
return True
else:
os.system("sudo umount %s" % hugepage_path)
return False
def mount_hugetlbfs(hugepage_path):
print("Mounting Hugetlbfs...")
if is_hugetlbfs_mounted(hugepage_path):
print(" Hugetlbfs is already mounted.")
return
cmd = "sudo mount -t hugetlbfs nodev %s" % hugepage_path
def check_nic_exists(nic_name):
print("Checking for %s" % nic_name)
ifconfig = subprocess.check_output(["ifconfig", "-a"]).decode('utf-8')
ifconfig = ifconfig.split('\n\n')
for i in range(len(ifconfig)):
nic = ifconfig[i]
nic = nic.split(' ')
if nic[0] == nic_name or nic[0] == nic_name+':':
return;
print(" %s interface is not detected." % nic_name)
print("Failed.")
exit(1)
def iface_up(port_name, ip=''):
cmd = "sudo ifconfig %s %s up" % (port_name, ip)
print(" " + cmd)
os.system(cmd)
cmd = "sudo ip link set dev %s mtu 9000" % port_name
print(" " + cmd)
os.system(cmd)
def iface_down(port_name):
cmd = "sudo ifconfig %s down" % port_name
print(" " + cmd)
os.system(cmd)
def iface_show(port_name):
cmd = "ip link show dev %s" % (port_name)
os.system(cmd)
def install_uio():
print("Checking uio...")
if check_driver_exist('uio'):
print(" uio is already installed.")
else:
cmd = "sudo modprobe uio"
print(" " + cmd)
os.system(cmd)
print(" uio is successfully installed!")
print("Checking igb_uio...")
if check_driver_exist('igb_uio'):
print(" igb_uio is already installed.")
elif os.path.exists('deps/dpdk-19.11.4/build/kmod/igb_uio.ko'):
cmd = "sudo insmod deps/dpdk-19.11.4/build/kmod/igb_uio.ko"
print(" " + cmd)
os.system(cmd)
print(" igb_uio is successfully installed.")
else:
print("igb_uio.ko does not exsit.")
exit(1)
def dev_bind(pci_id, driver):
if not check_driver_exist(driver):
print("[%s] Driver does not exists" % driver)
exit(1)
cmd = "sudo bin/dpdk-devbind.py -b %s %s" % (driver, pci_id)
print(" " + cmd)
os.system(cmd)
def clear_dpdk_compatible():
print("Checking dpdk-compatible ports...")
devbind = subprocess.check_output(['bin/dpdk-devbind.py','--status']).decode('utf-8')
devbind = devbind.split('\n\n')
dpdk_compatible = devbind[0].split('\n')
if dpdk_compatible[-1] != "<none>":
for i in range(3, len(dpdk_compatible)):
line = dpdk_compatible[i].split(' ')
pci_id = line[0]
driver = detect_nic_driver_type(pci_id)
print(" %s ==> %s" % (pci_id, driver))
dev_bind(pci_id, driver)
def bind_ports(port_name):
print("Binding %s..." % port_name)
devbind = subprocess.check_output(['bin/dpdk-devbind.py','--status']).decode('utf-8')
devbind = devbind.split('\n\n')
kernel_compatible = devbind[1].split('\n')
if kernel_compatible[-1] != "<none>":
for i in range(2, len(kernel_compatible)):
line = kernel_compatible[i].split(' ')
if ("if=" + port_name) in line:
pci_id = line[0]
print(" %s(%s) ==> igb_uio" % (port_name, pci_id))
dev_bind(pci_id, "igb_uio")
return
print(" Cannot find %s" % port_name)
print("Failed.")
exit(1)
### ###
### Configuration start! ###
### ###
os.chdir(os.path.dirname(__file__))
parser = argparse.ArgumentParser()
parser.add_argument('--kernel', action='store_true')
args = parser.parse_args()
os.system("./kill_bess.sh > /dev/null 2> /dev/null")
os.system("sudo sysctl -w net.ipv4.tcp_congestion_control=dctcp")
# Recovery Phase #
# If bess module is already installed, remove it.
if check_driver_exist("bess"):
cmd = "sudo rmmod bess"
print(cmd)
os.system(cmd)
# clear DPDK drivers
clear_dpdk_compatible()
if args.kernel:
iface_up("xe1", kernel_ip_map("xe1"))
iface_up("xe2", kernel_ip_map("xe2"))
iface_show("xe1")
iface_show("xe2")
sys.exit(0)
# Install Phase #
# check whether bess is compiled.
if not os.path.exists('core/kmod/bess.ko'):
cmd = "./build.py"
print(cmd)
os.system(cmd)
# hugepage setup
setup_hugepages_for_numa(0, 8192)
print("Success!!\n")
#setup_hugepages_for_numa(1, 1024)
#print("Success!!\n")
# mount hugetlb file system
create_dir("/mnt/huge")
print("Success!!\n")
mount_hugetlbfs("/mnt/huge")
print("Success!!")
# Kernel module compile & install bess module
if not check_driver_exist("bess"):
print('\n' + 'No bess kernel module is detected.')
os.chdir("core/kmod")
cmd = "./install"
print(cmd)
os.system(cmd)
os.chdir("../..")
else:
print("BESS kernel module already exsits.")
#install uio
install_uio()
print("Success!!!\n")
#check whether xe1 and xe2 are alive.
time.sleep(1)
check_nic_exists("xe1")
print("Success!!!\n")
check_nic_exists("xe2")
print("Success!!!\n")
iface_down("xe1")
print("Success!!!\n")
iface_down("xe2")
print("Success!!!\n")
bind_ports("xe1")
print("Success!!!\n")
bind_ports("xe2")
print("Success!!!\n")
# execute bessctl
os.system('printf "daemon start\nrun tso\n" | bessctl/bessctl')
# os.system('sudo ip link set bess_xe1 mtu 8984')
# os.system('sudo ip link set bess_xe2 mtu 8984')