-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcp.sh
executable file
·473 lines (407 loc) · 14.8 KB
/
gcp.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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#!/bin/bash
MTU=${MTU:-1400}
WRK=${WRK:-1} # 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
PAGES=${PAGES:-1024} # symlink build directory
RXQ=${RXQ:-1}
DRIVER=${DRIVER:-""}
RXD=${RXD:-4096}
TXD=${TXD:-4096}
GSO=${GSO:-0}
BPN=${BPN:-128} # buffers per numa in K - default 64K
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))
VM2_IP2_IT=($(ip_it $VM2_IP2 $VM2_LAST_IP2))
VM2_IP3_IT=($(ip_it $VM2_IP3 $VM2_LAST_IP3))
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=4
gcp_configure_test_pmd ()
{
sudo pkill vpp || true
sudo modprobe vfio-pci
echo 1 | sudo tee /sys/module/vfio/parameters/enable_unsafe_noiommu_mode
sudo $DPDK_DEVBIND --force -b vfio-pci $ROUTER_VM1_IF_PCI
sudo $DPDK_DEVBIND --force -b vfio-pci $ROUTER_VM2_IF_PCI
sudo sysctl -w vm.nr_hugepages=$PAGES
sudo LD_LIBRARY_PATH=$VPP_LIB_DIR $TESTPMD \
-w $ROUTER_VM1_IF_PCI \
-w $ROUTER_VM2_IF_PCI \
-l 0,1,2,3,4,5 \
-- \
-i \
--eth-peer=0,${GCP_RT_MAC//[$'\r']} \
--eth-peer=1,${GCP_RT_MAC//[$'\r']} \
-a \
--forward-mode=mac \
--burst=32 \
--rss \
--rxq=$WRK \
--txq=$WRK \
--nb-cores=$WRK
}
gcp_configure_vm1 ()
{
# OK
sudo ip link set $VM1_IF down
sudo ip link set $VM1_IF up
sudo ip addr flush dev $VM1_IF
sudo ip addr add $VM1_BASE_IP/26 dev $VM1_IF || true
sudo arp -i $VM1_IF -s $ROUTER_VM1_IP $ROUTER_VM1_MAC
sudo arp -i $VM1_IF -s $VM2_BASE_IP3 $VM2_IF3_MAC
for ((i = 0; i < $IP_CNT; i++)); do
sudo ip addr add ${VM1_IP_IT[$i]}/26 dev $VM1_IF || true
done
sleep 1
sudo ip route add $VM2_IP_PREFIX via $ROUTER_VM1_IP || true
sudo ip route add $VM2_IP2_PREFIX via $ROUTER_VM1_IP || true
sudo ip route add $VM2_IP3_PREFIX via $VM2_BASE_IP3 || true
sudo ip link set $VM1_IF mtu $MTU
}
gcp_configure_vm2 ()
{
if [[ "$1" = "" ]]; then
echo "please provide zero|one|two"
exit 1
fi
# OK
# if1
sudo ip link set $VM2_IF down
sudo ip link set $VM2_IF up
sudo ip addr flush dev $VM2_IF
# if2
sudo ip link set $VM2_IF2 down
sudo ip link set $VM2_IF2 up
sudo ip addr flush dev $VM2_IF2
# if3
sudo ip link set $VM2_IF3 down
sudo ip link set $VM2_IF3 up
sudo ip addr flush dev $VM2_IF3
sudo ip addr add $VM2_BASE_IP/26 dev $VM2_IF || true
sudo ip addr add $VM2_BASE_IP2/26 dev $VM2_IF2 || true
sudo ip addr add $VM2_BASE_IP3/26 dev $VM2_IF3 || true
sudo arp -i $VM2_IF -s $ROUTER2_VM2_IP $ROUTER2_VM2_MAC
sudo arp -i $VM2_IF2 -s $ROUTER_VM2_BASE_IP $ROUTER_VM2_MAC
sudo arp -i $VM2_IF3 -s $VM1_BASE_IP $VM1_MAC
for ((i = 0; i < $IP_CNT; i++)); do
sudo ip addr add ${VM2_IP_IT[$i]}/26 dev $VM2_IF || true
sudo ip addr add ${VM2_IP2_IT[$i]}/26 dev $VM2_IF2 || true
sudo ip addr add ${VM2_IP3_IT[$i]}/26 dev $VM2_IF3 || true
done
sleep 2
if [[ "$1" = "one" ]] ; then
# one hop route to VM1
sudo ip route add $VM1_IP_PREFIX via $ROUTER_VM2_BASE_IP || true
elif [[ "$1" = "zero" ]]; then
# zero hop route to VM1
sudo ip route add $VM1_IP_PREFIX via $VM1_BASE_IP || true
elif [[ "$1" = "two" ]]; then
sudo ip route add $VM1_IP_PREFIX via $ROUTER2_VM2_IP || true
else
echo "Wot ?"
fi
sudo ip link set $VM2_IF mtu $MTU
sudo ip link set $VM2_IF2 mtu $MTU
sudo ip link set $VM2_IF3 mtu $MTU
}
gcp_unconfigure_all ()
{
sudo pkill vpp || true
}
gcp_configure_linux_router ()
{
# OK
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
if [[ "$1" = "1" ]] ; then
sudo ip addr add $ROUTER_VM1_IP/24 dev $ROUTER_VM1_IF
sudo ip addr add $ROUTER_VM2_BASE_IP/24 dev $ROUTER_VM2_IF
sudo ip route add $VM1_IP_PREFIX dev $ROUTER_VM1_IF via $VM1_BASE_IP || true
sudo ip route add $VM2_IP_PREFIX dev $ROUTER_VM2_IF via $ROUTER2_VM1_BASE_IP || true
sudo arp -i $ROUTER_VM2_IF -s $ROUTER2_VM1_BASE_IP $GCP_RT_MAC
sudo arp -i $ROUTER_VM1_IF -s $VM1_BASE_IP $GCP_RT_MAC
elif [[ "$1" = "2" ]] ; then
sudo ip addr add $ROUTER2_VM1_BASE_IP/24 dev $ROUTER_VM1_IF
sudo ip addr add $ROUTER2_VM2_IP/24 dev $ROUTER_VM2_IF
sudo ip route add $VM1_IP_PREFIX dev $ROUTER_VM1_IF via $ROUTER_VM2_BASE_IP || true
sudo ip route add $VM2_IP_PREFIX dev $ROUTER_VM2_IF via $VM2_BASE_IP || true
sudo arp -i $ROUTER_VM2_IF -s $VM2_BASE_IP $GCP_RT_MAC
sudo arp -i $ROUTER_VM1_IF -s $ROUTER_VM2_BASE_IP $GCP_RT_MAC
else
echo "One hop"
sudo ip addr add $ROUTER_VM1_IP/24 dev $ROUTER_VM1_IF
sudo ip addr add $ROUTER_VM2_BASE_IP/24 dev $ROUTER_VM2_IF
sudo ip route add $VM1_IP_PREFIX dev $ROUTER_VM1_IF via $VM1_BASE_IP || true
sudo ip route add $VM2_IP2_PREFIX dev $ROUTER_VM2_IF via $VM2_BASE_IP2 || true
sudo arp -i $ROUTER_VM2_IF -s $VM2_BASE_IP2 $GCP_RT_MAC
sudo arp -i $ROUTER_VM1_IF -s $VM1_BASE_IP $GCP_RT_MAC
fi
sudo sysctl net.ipv4.ip_forward=1
sudo ip link set $ROUTER_VM1_IF mtu $MTU
sudo ip link set $ROUTER_VM2_IF mtu $MTU
}
gcp_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 \
libssl-dev \
netsniff-ng \
libmnl-dev librdmacm-dev librdmacm1 build-essential libnuma-dev # dpdk
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
}
gcp_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
ROUTER_VM2_IF_NAME=VM2_IF
IF_PCI2="dev $ROUTER_VM2_IF_PCI { name VM2_IF }"
else
ROUTER_VM2_IF_NAME=VM1_IF
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
}
" | 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
elif [[ "$DRIVER" = "both" ]]; then
echo "
dpdk {
enable-tcp-udp-checksum
dev default {
num-rx-queues $RXQ
num-rx-desc $RXD
num-tx-desc $RXD
}
dev $ROUTER_VM1_IF_PCI { name VM1_IF tso on }
}
" | 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
}
dev $ROUTER_VM1_IF_PCI { name VM1_IF tso on }
$IF_PCI2
}
" | sudo tee -a $VPP_RUN_DIR/vpp.conf > /dev/null
fi
}
gcp_configure_vpp ()
{
sudo pkill vpp || true
sudo modprobe vfio_pci
echo 1 | sudo tee /sys/module/vfio/parameters/enable_unsafe_noiommu_mode
bind_to $ROUTER_VM1_IF_PCI vfio-pci
bind_to $ROUTER_VM2_IF_PCI vfio-pci
sudo sysctl -w vm.nr_hugepages=$PAGES
gcp_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/5/0
ROUTER_VM2_IF_NAME=virtio-0/0/6/0
echo "
create interface virtio $ROUTER_VM1_IF_PCI gso-enabled
create interface virtio $ROUTER_VM2_IF_PCI gso-enabled
set interface feature gso $ROUTER_VM1_IF_NAME enable
set interface feature gso $ROUTER_VM1_IF_NAME enable
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
elif [[ "$DRIVER" = "both" ]]; then
ROUTER_VM2_IF_NAME=virtio-0/0/6/0
echo "
create interface virtio $ROUTER_VM2_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 state $ROUTER_VM2_IF_NAME up
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
if [[ "$1" = "1" ]] ; then
echo "
set int ip addr $ROUTER_VM1_IF_NAME $ROUTER_VM1_IP/24
set int ip addr $ROUTER_VM2_IF_NAME $ROUTER_VM2_BASE_IP/24
set ip neighbor $ROUTER_VM1_IF_NAME $VM1_BASE_IP ${VM1_MAC//[$'\r']}
set ip neighbor $ROUTER_VM2_IF_NAME $ROUTER2_VM1_BASE_IP ${ROUTER2_VM1_MAC//[$'\r']}
ip route add $VM1_IP_PREFIX via $VM1_BASE_IP $ROUTER_VM1_IF_NAME
ip route add $VM2_IP_PREFIX via $ROUTER2_VM1_BASE_IP $ROUTER_VM2_IF_NAME
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
elif [[ "$1" = "2" ]] ; then
echo "
set int ip addr $ROUTER_VM1_IF_NAME $ROUTER2_VM1_BASE_IP/24
set int ip addr $ROUTER_VM2_IF_NAME $ROUTER2_VM2_IP/24
set ip neighbor $ROUTER_VM1_IF_NAME $ROUTER_VM2_BASE_IP ${ROUTER_VM2_MAC//[$'\r']}
set ip neighbor $ROUTER_VM2_IF_NAME $VM2_BASE_IP ${VM2_IF_MAC//[$'\r']}
ip route add $VM1_IP_PREFIX via $ROUTER_VM2_BASE_IP $ROUTER_VM1_IF_NAME
ip route add $VM2_IP_PREFIX via $VM2_BASE_IP $ROUTER_VM2_IF_NAME
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
else
echo "
set int ip addr $ROUTER_VM1_IF_NAME $ROUTER_VM1_IP/24
set int ip addr $ROUTER_VM2_IF_NAME $ROUTER_VM2_BASE_IP/24
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
for ((i = 0; i < $IP_CNT; i++)); do
echo "
set ip neighbor $ROUTER_VM1_IF_NAME ${VM1_IP_IT[$i]} ${VM1_MAC//[$'\r']}
set ip neighbor $ROUTER_VM2_IF_NAME ${VM2_IP2_IT[$i]} ${VM2_IF2_MAC//[$'\r']}
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
done
fi
run_vpp
}
gcp_configure_ipsec ()
{
sudo pkill vpp || true
sudo modprobe vfio_pci
echo 1 | sudo tee /sys/module/vfio/parameters/enable_unsafe_noiommu_mode
bind_to $ROUTER_VM1_IF_PCI vfio-pci
bind_to $ROUTER_VM2_IF_PCI vfio-pci
sudo sysctl -w vm.nr_hugepages=$PAGES
gcp_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/5/0
ROUTER_VM2_IF_NAME=virtio-0/0/6/0
echo "
create interface virtio $ROUTER_VM1_IF_PCI gso-enabled
create interface virtio $ROUTER_VM2_IF_PCI gso-enabled
set interface feature gso $ROUTER_VM1_IF_NAME enable
set interface feature gso $ROUTER_VM2_IF_NAME enable
set int st $ROUTER_VM1_IF_NAME up
set int st $ROUTER_VM2_IF_NAME up
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
fi
echo "
set int st $ROUTER_VM1_IF_NAME up
set int st $ROUTER_VM2_IF_NAME up
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
if [[ "$1" = "1" ]] ; then
echo "
set int ip addr $ROUTER_VM1_IF_NAME $ROUTER_VM1_IP/24
set int ip addr $ROUTER_VM2_IF_NAME $ROUTER_VM2_BASE_IP/24
ip route add $VM1_IP_PREFIX via $VM1_BASE_IP $ROUTER_VM1_IF_NAME
set ip neighbor $ROUTER_VM1_IF_NAME $VM1_BASE_IP ${GCP_RT_MAC//[$'\r']}
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
for ((i = 0; i < $IP_CNT; i++)); do
echo "
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 udp-encap tunnel-src ${ROUTER2_VM1_IP_IT[$i]} tunnel-dst ${ROUTER_VM2_IP_IT[$i]}
ipsec sa add 3$i spi 30$i crypto-key $CRYPTO_KEY crypto-alg $CRYPTO_ALG udp-encap tunnel-src ${ROUTER_VM2_IP_IT[$i]} tunnel-dst ${ROUTER2_VM1_IP_IT[$i]}
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
ip route add ${VM2_IP_IT[$i]}/32 via ipip$i
set int ip addr $ROUTER_VM2_IF_NAME ${ROUTER_VM2_IP_IT[$i]}/24
set ip neighbor $ROUTER_VM1_IF_NAME ${VM1_IP_IT[$i]} ${GCP_RT_MAC//[$'\r']}
set ip neighbor $ROUTER_VM2_IF_NAME ${ROUTER2_VM1_IP_IT[$i]} ${GCP_RT_MAC//[$'\r']}
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
done
elif [[ "$1" = "2" ]] ; then
echo "
set int ip addr $ROUTER_VM1_IF_NAME $ROUTER2_VM1_BASE_IP/24
set int ip addr $ROUTER_VM2_IF_NAME $ROUTER2_VM2_IP/24
ip route add $VM2_IP_PREFIX via $VM2_BASE_IP $ROUTER_VM2_IF_NAME
set ip neighbor $ROUTER_VM2_IF_NAME $VM2_BASE_IP ${GCP_RT_MAC//[$'\r']}
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
for ((i = 0; i < $IP_CNT; i++)); do
echo "
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 udp-encap tunnel-src ${ROUTER2_VM1_IP_IT[$i]} tunnel-dst ${ROUTER_VM2_IP_IT[$i]}
ipsec sa add 3$i spi 30$i crypto-key $CRYPTO_KEY crypto-alg $CRYPTO_ALG udp-encap tunnel-src ${ROUTER_VM2_IP_IT[$i]} tunnel-dst ${ROUTER2_VM1_IP_IT[$i]}
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
ip route add ${VM1_IP_IT[$i]}/32 via ipip$i
set int ip addr $ROUTER_VM1_IF_NAME ${ROUTER2_VM1_IP_IT[$i]}/24
set ip neighbor $ROUTER_VM2_IF_NAME ${VM2_IP_IT[$i]} ${GCP_RT_MAC//[$'\r']}
set ip neighbor $ROUTER_VM1_IF_NAME ${ROUTER_VM2_IP_IT[$i]} ${GCP_RT_MAC//[$'\r']}
" | sudo tee -a $VPP_RUN_DIR/startup.conf > /dev/null
done
else
echo "Missing machine #ID"
exit 1
fi
run_vpp
}
aws_test_cli ()
{
if [[ "$1" = "install" ]]; then
gcp_install_deps ${@:2}
elif [[ "$1" = "pmd" ]]; then
gcp_configure_test_pmd ${@:2}
elif [[ "$1" = "linux" ]]; then
gcp_configure_linux_router ${@:2}
elif [[ "$1" = "vpp" ]]; then
gcp_configure_vpp ${@:2}
elif [[ "$1" = "ipsec" ]]; then
gcp_configure_ipsec ${@:2}
# VM configuration
elif [[ "$1" = "vm1" ]]; then
gcp_configure_vm1
elif [[ "$1" = "vm2" ]]; then
gcp_configure_vm2 $2
else
echo "Usage:"
echo "aws.sh sync - sync this script"
echo "aws.sh install - install deps"
echo "aws.sh ptest [zero|one|two] [NAME] [Nparallel] [OPTIONS] - run tests"
fi
}
aws_test_cli $@