-
Notifications
You must be signed in to change notification settings - Fork 0
/
ovh.sh
executable file
·432 lines (385 loc) · 12.8 KB
/
ovh.sh
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
#!/bin/bash
MTU=${MTU:-1500}
WRK=${WRK:-4} # N workers
CP=${CP:-""} # compact workers on one thread
AES=${AES:-256} # aes-gcm-128 or aes-gcm-256
LLQ=${LLQ:-""} # 1 ti enable LLQ
DRIVER=${DRIVER:-"virtio"} # 'uio' or vfio-pci as default
BUILD=${BUILD:-""} # symlink build directory
PAGES=${PAGES:-1024} # symlink build directory
RXQ=${RXQ:-1}
RXD=${RXD:-4096}
TXD=${TXD:-4096}
source $( dirname "${BASH_SOURCE[0]}" )/shared.sh
# ------------------------------
VM1_IP_IT=($(ip_it $VM1_IP $VM1_LAST_IP))
VM2_IP_IT=($(ip_it $VM2_IP $VM2_LAST_IP))
ROUTER_VM2_IP_IT=($(ip_it $ROUTER_VM2_IP $ROUTER_VM2_LAST_IP))
ROUTER2_VM1_IP_IT=($(ip_it $ROUTER2_VM1_IP $ROUTER2_VM1_LAST_IP))
# IP_CNT=${#VM1_IP_IT[@]}
IP_CNT=2
ovh_configure_test_pmd ()
{
sudo modprobe vfio-pci
echo 1 | sudo tee /sys/module/vfio/parameters/enable_unsafe_noiommu_mode
sudo sysctl -w vm.nr_hugepages=$PAGES
sudo $TESTPMD \
-w $ROUTER_VM1_IF_PCI \
-l 0,1,2,3,4,5 \
-- -a \
--forward-mode=mac \
--burst=32 \
--eth-peer=0,${VM1_MAC//[$'\r']} \
--eth-peer=1,${VM2_MAC//[$'\r']} \
--rss \
--nb-cores=4
}
ovh_add_vm1_addresses ()
{
for ((i = 0; i < ${IP_CNT}; i++)); do
sudo ip addr add ${VM1_IP_IT[$i]}/24 dev $VM1_IF || true
done
for ((i = 0; i < ${IP_CNT}; i++)); do
sudo arp -i $VM1_IF -s ${VM2_IP_IT[$i]} ${NXT_HOP//[$'\r']}
done
}
ovh_configure_vm1 ()
{
if [[ "$1" = "zero" ]]; then
NXT_HOP=$VM2_MAC
elif [[ "$1" = "one" ]]; then
NXT_HOP=$ROUTER_VM1_MAC
elif [[ "$1" = "two" ]]; then
NXT_HOP=$ROUTER_VM1_MAC
else
echo "Use zero|one|two"
exit 1
fi
sudo ip link set $VM1_IF down
sudo ip link set $VM1_IF up
sudo ip addr flush dev $VM1_IF
ovh_add_vm1_addresses
sudo ip link set $VM1_IF mtu $MTU
sudo ip route add 10.0.7.0/24 dev $VM1_IF
}
ovh_configure_vm2 ()
{
if [[ "$1" = "zero" ]]; then
NXT_HOP=$VM1_MAC
elif [[ "$1" = "one" ]]; then
NXT_HOP=$ROUTER_VM2_MAC
elif [[ "$1" = "two" ]]; then
NXT_HOP=$ROUTER2_VM2_MAC
elif [[ "$1" = "loop" ]]; then
NXT_HOP=$VM1_MAC
else
echo "Use zero|one|two|loop"
exit 1
fi
sudo ip link set $VM2_IF down
sudo ip link set $VM2_IF up
sudo ip addr flush dev $VM2_IF
for ((i = 0; i < ${#VM1_IP_IT[@]}; i++)); do
sudo ip addr add ${VM2_IP_IT[$i]}/24 dev $VM2_IF || true
done
for ((i = 0; i < ${#VM1_IP_IT[@]}; i++)); do
sudo arp -i $VM2_IF -s ${VM1_IP_IT[$i]} ${NXT_HOP//[$'\r']}
done
if [[ "$1" = "loop" ]]; then
NXT_HOP=$VM2_MAC
ovh_add_vm1_addresses
fi
sudo ip link set $VM2_IF mtu $MTU
sudo ip route add 10.0.2.0/24 dev $VM2_IF
}
ovh_configure_linux_router ()
{
# Cleanup
sudo pkill vpp || true
sudo ip link set $ROUTER_VM1_IF down
sudo ip link set $ROUTER_VM1_IF up
sudo ip link set $ROUTER_VM2_IF down
sudo ip link set $ROUTER_VM2_IF up
sudo ip addr flush dev $ROUTER_VM1_IF
sudo ip addr flush dev $ROUTER_VM2_IF
sudo ip link set $ROUTER_VM1_IF mtu 9000 # all tests should be below 9k mtu
sudo ip link set $ROUTER_VM2_IF mtu 9000 # all tests should be below 9k mtu
sudo sysctl net.ipv4.ip_forward=1
if [[ "$1" = "1" ]] ; then
sudo ip addr add $ROUTER_VM1_IP/24 dev $ROUTER_VM1_IF
sudo ip addr add $ROUTER_VM2_IP/24 dev $ROUTER_VM2_IF
sudo ip route add $VM1_IP_PREFIX via $ROUTER_VM1_IP || true
sudo ip route add $VM2_IP_PREFIX via $ROUTER_VM2_IP || true
for ((i = 0; i < ${IP_CNT}; i++)); do
sudo arp -i $ROUTER_VM1_IF -s ${VM1_IP_IT[$i]} ${VM1_MAC//[$'\r']}
sudo arp -i $ROUTER_VM2_IF -s ${VM2_IP_IT[$i]} ${ROUTER2_VM1_MAC//[$'\r']}
done
elif [[ "$1" = "2" ]] ; then
sudo ip addr add $ROUTER2_VM1_IP/24 dev $ROUTER_VM1_IF || true
sudo ip addr add $ROUTER2_VM2_IP/24 dev $ROUTER_VM2_IF || true
sudo ip route add $VM1_IP_PREFIX via $ROUTER2_VM1_IP || true
sudo ip route add $VM2_IP_PREFIX via $ROUTER2_VM2_IP || true
for ((i = 0; i < ${IP_CNT}; i++)); do
sudo arp -i $ROUTER_VM1_IF -s ${VM1_IP_IT[$i]} ${ROUTER_VM2_MAC//[$'\r']}
sudo arp -i $ROUTER_VM2_IF -s ${VM2_IP_IT[$i]} ${VM2_MAC//[$'\r']}
done
else
echo "One hop"
sudo ip addr add $ROUTER_VM1_IP/24 dev $ROUTER_VM1_IF || true
sudo ip addr add $ROUTER_VM2_IP/24 dev $ROUTER_VM2_IF || true
sudo ip route add $VM1_IP_PREFIX via $ROUTER_VM1_IP || true
sudo ip route add $VM2_IP_PREFIX via $ROUTER_VM2_IP || true
for ((i = 0; i < ${IP_CNT}; i++)); do
sudo arp -i $ROUTER_VM1_IF -s ${VM1_IP_IT[$i]} ${VM1_MAC//[$'\r']}
sudo arp -i $ROUTER_VM2_IF -s ${VM2_IP_IT[$i]} ${VM2_MAC//[$'\r']}
done
fi
}
ovh_install_deps ()
{
if [[ "$1" = "vm1" ]] || [[ "$1" = "vm2" ]]; then
sudo apt update && sudo apt install -y iperf iperf3 traceroute netsniff-ng
else
sudo apt update && sudo apt install -y iperf iperf3 traceroute make python linux-tools-$(uname -r) linux-tools-generic
git clone https://gerrit.fd.io/r/vpp || true
cd vpp
git apply ~/test/patch/vpp-dpdk.patch
make install-dep
make build-release
fi
}
ovh_symlink_build_dir ()
{
if [[ "$BUILD" != "" ]]; then
echo "Using build-$BUILD"
cd $VPP_DIR/build-root
rm -f install-vpp-native
ln -s build-$BUILD install-vpp-native
cd ~
fi
}
ovh_create_vpp_startup_conf ()
{
if [[ "$WRK" = "1" ]]; then
CORELIST_WORKERS="corelist-workers 1"
elif [[ "$WRK" = "0" ]]; then
CORELIST_WORKERS="workers 0"
else
CORELIST_WORKERS="corelist-workers 1-$WRK"
fi
ROUTER_VM1_IF_NAME=VM1_IF
if [[ "$ROUTER_VM2_IF_PCI" != "" ]]; then
IF_PCI2="dev $ROUTER_VM2_IF_PCI { name VM2_IF }"
else
IF_PCI2=""
fi
sudo mkdir -p $VPP_RUN_DIR
if [[ "$DBG" != "" ]]; then
MODE="interactive"
else
MODE=""
fi
echo "
unix {
$MODE
log $VPP_RUN_DIR/vpp.log
cli-listen $VPP_RUN_DIR/cli.sock
exec $VPP_RUN_DIR/startup.conf
}
cpu {
main-core 0
$CORELIST_WORKERS
}
buffers {
buffers-per-numa $((BPN << 10))
default data-size 4096
}
session { evt_qs_memfd_seg enable }
socksvr { socket-name $VPP_RUN_DIR/vpp-api.sock }
tcp { tso }
" | sudo tee $VPP_RUN_DIR/vpp.conf > /dev/null
if [[ "$DRIVER" = "native" ]]; then
echo "
plugins {
plugin dpdk_plugin.so { disable }
}
" | sudo tee -a $VPP_RUN_DIR/vpp.conf > /dev/null
else
echo "
dpdk {
enable-tcp-udp-checksum
dev default {
num-rx-queues $RXQ
num-rx-desc $RXD
num-tx-desc $RXD
tso on
}
dev $ROUTER_VM1_IF_PCI { name VM1_IF tso on }
$IF_PCI2
}
" | sudo tee -a $VPP_RUN_DIR/vpp.conf > /dev/null
fi
echo "vcl {
segment-size 4000000000
rx-fifo-size 40000000
tx-fifo-size 40000000
app-scope-local
app-scope-global
api-socket-name $VPP_RUN_DIR/vpp-api.sock
}
" | sudo tee $VPP_RUN_DIR/vcl.conf > /dev/null
}
ovh_configure_vpp_nic_drivers ()
{
sudo modprobe vfio-pci
DPDK_DRIVER="vfio-pci"
echo 1 | sudo tee /sys/module/vfio/parameters/enable_unsafe_noiommu_mode
}
ovh_configure_vpp ()
{
sudo modprobe vfio_pci
echo 1 | sudo tee /sys/module/vfio/parameters/enable_unsafe_noiommu_mode
bind_to $ROUTER_VM1_IF_PCI vfio-pci
ovh_configure_vpp_nic_drivers
ovh_create_vpp_startup_conf
echo "" | sudo tee $VPP_RUN_DIR/startup.conf > /dev/null
if [[ "$DRIVER" = "native" ]]; then
ROUTER_VM1_IF_NAME=virtio-0/0/4/0
echo "
set loggin class virtio level debug
create interface virtio $ROUTER_VM1_IF_PCI gso-enabled
set interface feature gso $ROUTER_VM1_IF_NAME enable
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
fi
echo "
set int state $ROUTER_VM1_IF_NAME up
set int ip address $ROUTER_VM1_IF_NAME 10.0.1.1$1/24
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
echo "
ip route add $VM1_IP/24 via $ROUTER_VM1_IF_NAME
ip route add $VM2_IP/24 via $ROUTER_VM1_IF_NAME
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
for ((i = 0; i < ${IP_CNT}; i++)); do
if [[ "$1" = "1" ]] ; then
echo "
set ip neighbor $ROUTER_VM1_IF_NAME ${VM1_IP_IT[$i]} ${VM1_MAC//[$'\r']}
set ip neighbor $ROUTER_VM1_IF_NAME ${VM2_IP_IT[$i]} ${ROUTER2_VM1_MAC//[$'\r']}
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
elif [[ "$1" = "2" ]] ; then
echo "
set ip neighbor $ROUTER_VM1_IF_NAME ${VM1_IP_IT[$i]} ${ROUTER_VM2_MAC//[$'\r']}
set ip neighbor $ROUTER_VM1_IF_NAME ${VM2_IP_IT[$i]} ${VM2_MAC//[$'\r']}
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
else
echo "
set ip neighbor $ROUTER_VM1_IF_NAME ${VM1_IP_IT[$i]} ${VM1_MAC//[$'\r']}
set ip neighbor $ROUTER_VM1_IF_NAME ${VM2_IP_IT[$i]} ${VM2_MAC//[$'\r']}
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
fi
done
run_vpp
}
ovh_unconfigure_all ()
{
sudo pkill vpp || true
# sudo ip link set $ROUTER_VM1_IF down
# sudo ip link set $ROUTER_VM2_IF down
}
ovh_configure_vpp_ipsec ()
{
sudo pkill vpp || true
ovh_configure_vpp_nic_drivers
ovh_create_vpp_startup_conf
echo "" | sudo tee $VPP_RUN_DIR/startup.conf > /dev/null
if [[ "$DRIVER" = "native" ]]; then
ROUTER_VM1_IF_NAME=virtio-0/0/4/0
echo "
set loggin class virtio level debug
create interface virtio $ROUTER_VM1_IF_PCI gso-enabled
set interface feature gso $ROUTER_VM1_IF_NAME enable
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
fi
echo "
set int state $ROUTER_VM1_IF_NAME up
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
# ----------------- Startup CLIs -----------------
if [[ "$1" = "1" ]] ; then
echo "
set int ip address $ROUTER_VM1_IF_NAME $ROUTER_VM1_IP/32
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
elif [[ "$1" = "2" ]] ; then
echo "
set int ip address $ROUTER_VM1_IF_NAME $ROUTER2_VM2_IP/32
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
fi
for ((i = 0; i < ${IP_CNT}; i++)); do
if [[ "$1" = "1" ]] ; then
echo "
set int ip address $ROUTER_VM1_IF_NAME ${ROUTER_VM2_IP_IT[$i]}/32
create ipip tunnel src ${ROUTER_VM2_IP_IT[$i]} dst ${ROUTER2_VM1_IP_IT[$i]}
ipsec sa add 2$i spi 20$i crypto-key $CRYPTO_KEY crypto-alg $CRYPTO_ALG
ipsec sa add 3$i spi 30$i crypto-key $CRYPTO_KEY crypto-alg $CRYPTO_ALG
ipsec tunnel protect ipip$i sa-in 2$i sa-out 3$i
set int state ipip$i up
set int ip addr ipip$i 127.0.0.$((i+1))/32
set ip neighbor $ROUTER_VM1_IF_NAME ${ROUTER2_VM1_IP_IT[$i]} ${ROUTER2_VM1_MAC//[$'\r']}
set ip neighbor $ROUTER_VM1_IF_NAME ${VM1_IP_IT[$i]} ${VM1_MAC//[$'\r']}
ip route add ${VM1_IP_IT[$i]}/32 via $ROUTER_VM1_IF_NAME
ip route add ${VM2_IP_IT[$i]}/32 via ipip$i
ip route add ${ROUTER2_VM1_IP_IT[$i]}/32 via $ROUTER_VM1_IF_NAME
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
elif [[ "$1" = "2" ]] ; then
echo "
set int ip address $ROUTER_VM1_IF_NAME ${ROUTER2_VM1_IP_IT[$i]}/32
create ipip tunnel src ${ROUTER2_VM1_IP_IT[$i]} dst ${ROUTER_VM2_IP_IT[$i]}
ipsec sa add 2$i spi 20$i crypto-key $CRYPTO_KEY crypto-alg $CRYPTO_ALG
ipsec sa add 3$i spi 30$i crypto-key $CRYPTO_KEY crypto-alg $CRYPTO_ALG
ipsec tunnel protect ipip$i sa-in 3$i sa-out 2$i
set int state ipip$i up
set int ip addr ipip$i 127.0.0.$((i+1))/32
set ip neighbor $ROUTER_VM1_IF_NAME ${ROUTER_VM2_IP_IT[$i]} ${ROUTER_VM2_MAC//[$'\r']}
set ip neighbor $ROUTER_VM1_IF_NAME ${VM2_IP_IT[$i]} ${VM2_MAC//[$'\r']}
ip route add ${VM2_IP_IT[$i]}/32 via $ROUTER_VM1_IF_NAME
ip route add ${VM1_IP_IT[$i]}/32 via ipip$i
ip route add ${ROUTER_VM2_IP_IT[$i]}/32 via $ROUTER_VM1_IF_NAME
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
fi
done
run_vpp
}
ovh_test_cli ()
{
if [[ "$1" = "install" ]]; then
ovh_install_deps ${@:2}
elif [[ "$1" = "pmd" ]]; then
ovh_symlink_build_dir
ovh_unconfigure_all
ovh_configure_test_pmd
elif [[ "$1" = "linux" ]]; then
ovh_symlink_build_dir
ovh_configure_linux_router ${@:2}
elif [[ "$1" = "vpp" ]]; then
ovh_symlink_build_dir
ovh_unconfigure_all
ovh_configure_vpp ${@:2}
elif [[ "$1" = "ipsec" ]]; then
ovh_symlink_build_dir
ovh_configure_vpp_ipsec ${@:2}
# VM configuration
elif [[ "$1" = "vm1" ]]; then
ovh_configure_vm1 ${@:2}
elif [[ "$1" = "vm2" ]]; then
ovh_configure_vm2 ${@:2}
elif [[ "$1" = "ldp" ]]; then
sudo VCL_CONFIG=$VPP_RUN_DIR/vcl.conf LD_PRELOAD=$LDPRELOAD_PATH iperf3 ${@:2}
else
echo "Usage:"
echo "aws.sh install - install deps"
echo "aws.sh vm[1|2] [zero|one|two] - configure VMs with zero/one/two hops"
echo "aws.sh pmd - configure testpmd forwarding (one hop)"
echo "aws.sh linux - configure linux router (one hop)"
echo "aws.sh vpp [uio] - configure vpp (one hop)"
echo "aws.sh ipsec [1|2] - configure ipsec (two hops)"
fi
}
ovh_test_cli $@