-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tests
executable file
·218 lines (196 loc) · 6.72 KB
/
run_tests
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
#!/bin/bash
# Copyright (c) 2022 Lars-Christian Schulz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
function print_help() {
echo "USAGE: $(basename ""$0"") [OPTIONS]"
echo "Options:"
echo " -h"
echo " Display this help message."
echo " -6"
echo " Use IPv6 underlay."
echo " --single"
echo " Run single device tests. Cannot be used together with --multi."
echo " --multi"
echo " Run multi-device tests. This is the default if --single is not specified."
echo " --tests"
echo " PTF tests or test groups to run."
echo " --veth"
echo " Create test topology (namespaces and veths) without running the tests."
echo " --attach"
echo " Run XDP border router(s) without running the tests."
echo " --no-clean"
echo " Run the tests and keep the border routers running."
echo " --detach"
echo " Stop XDP border router(s), but keep the veths."
echo " --clean"
echo " Remove the test topology."
}
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
PROJECT_DIR=$(readlink -f "$SCRIPT_DIR/../..")
NETNS="$PROJECT_DIR/utils/netns.bash"
PTF="$PROJECT_DIR/ptf/ptf"
BR_LOADER="$PROJECT_DIR/build/br/br-loader"
XDP_OBJECT="$PROJECT_DIR/build/br/xdp_br.o"
TEST_DIR="$SCRIPT_DIR/ptf_tests"
PTF_PYPATH="--pypath $PROJECT_DIR/scapy-scion-int --pypath $PROJECT_DIR/libbpfpy"
SINGLE_DEV_INTERFACES="-i 0-1@veth0 -i 0-2@veth2 -i 0-7@veth4 -i 0-8@veth6"
MULTI_DEV_INTERFACES="-i 0-1@veth0 -i 0-2@veth2 -i 1-3@veth8 -i 1-4@veth10 -i 2-5@veth12 -i 2-6@veth14"
HELP=false
MODE=multi
TESTS=
TEST_PARAMS=
BR_CONF_SUFFIX=
RUN=3
CLEAN=0
cd $SCRIPT_DIR
###############
## Functions ##
###############
function create_veths() {
if [[ $MODE = single ]]; then
if [[ ! "$(ip netns)" =~ sw0 ]]; then
echo "=== Topology Setup ==="
./single/setup.bash
fi
else
if [[ "$(ip netns | grep -c sw[0-2])" -ne 3 ]]; then
echo "=== Topology Setup ==="
./multi/setup.bash
fi
fi
}
function attach_routers() {
if [[ $(sudo ip netns exec sw0 ip link | grep veth. | grep -c xdp) -lt 4 ]]; then
echo "=== Start Router 1 ==="
sudo "$NETNS" exec sw0 "$BR_LOADER" attach "$XDP_OBJECT" \
"br_config/br1${BR_CONF_SUFFIX}.toml" veth1 veth3 veth5 veth7
fi
if [[ $MODE = multi ]]; then
if [[ $(sudo ip netns exec sw1 ip link | grep veth. | grep -c xdp) -lt 3 ]]; then
echo "=== Start Router 2 ==="
sudo "$NETNS" exec sw1 "$BR_LOADER" attach "$XDP_OBJECT" \
"br_config/br2${BR_CONF_SUFFIX}.toml" veth4 veth9 veth11
fi
if [[ $(sudo ip netns exec sw2 ip link | grep veth. | grep -c xdp) -lt 3 ]]; then
echo "=== Start Router 3 ==="
sudo "$NETNS" exec sw2 "$BR_LOADER" attach "$XDP_OBJECT" \
"br_config/br3${BR_CONF_SUFFIX}.toml" veth6 veth13 veth15
fi
fi
}
function run_tests() {
echo "=== Run Tests ==="
# Install MAC validation key
local KEY="MTExMTExMTExMTExMTExMQ=="
sudo "$BR_LOADER" key add br1-ff00_0_1-1 0 $KEY
if [[ $MODE = multi ]]; then
sudo "$BR_LOADER" key add br1-ff00_0_1-2 0 $KEY
sudo "$BR_LOADER" key add br1-ff00_0_1-3 0 $KEY
fi
# Invoke PTF
if [[ $MODE = single ]]; then
sudo "$PTF" $PTF_PYPATH $SINGLE_DEV_INTERFACES --test-dir "$TEST_DIR" \
--test-params="${TEST_PARAMS:='_'}" $TESTS
else
sudo "$PTF" $PTF_PYPATH $MULTI_DEV_INTERFACES --test-dir "$TEST_DIR" \
--test-params="${TEST_PARAMS:='_'}" $TESTS
fi
# Remove MAC validation key
sudo "$BR_LOADER" key remove br1-ff00_0_1-1 0
if [[ $MODE = multi ]]; then
sudo "$BR_LOADER" key remove br1-ff00_0_1-2 0
sudo "$BR_LOADER" key remove br1-ff00_0_1-3 0
fi
}
function detach_routers() {
local namespaces=$(sudo ip netns)
if [[ "$namespaces" =~ sw0 ]]; then
if [[ $(sudo ip netns exec sw0 ip link | grep veth. | grep -c xdp) -gt 0 ]]; then
echo "=== Stop Router 1 ==="
sudo "$NETNS" exec sw0 "$BR_LOADER" detach veth1 veth3 veth5 veth7
fi
fi
if [[ $MODE = multi ]]; then
if [[ "$namespaces" =~ sw1 ]]; then
if [[ $(sudo ip netns exec sw1 ip link | grep veth. | grep -c xdp) -gt 0 ]]; then
echo "=== Stop Router 2 ==="
sudo "$NETNS" exec sw1 "$BR_LOADER" detach veth4 veth9 veth11
fi
fi
if [[ "$namespaces" =~ sw2 ]]; then
if [[ $(sudo ip netns exec sw2 ip link | grep veth. | grep -c xdp) -gt 0 ]]; then
echo "=== Stop Router 3 ==="
sudo "$NETNS" exec sw2 "$BR_LOADER" detach veth6 veth13 veth15
fi
fi
fi
}
function destroy_veths() {
if [[ $MODE = single ]]; then
if [[ "$(ip netns)" =~ sw0 ]]; then
echo "=== Topology Teardown ==="
./single/teardown.bash
fi
else
if [[ "$(ip netns | grep -c sw[0-2])" -gt 0 ]]; then
echo "=== Topology Teardown ==="
./multi/teardown.bash
fi
fi
}
###################
## Parse options ##
###################
opts=$(getopt -o h6 -l single,multi,tests:,veth,attach,no-clean,detach,clean -- "$@")
if [ "$?" != 0 ]; then
exit 1
fi
eval set -- "$opts"
while true; do
case "$1" in
-h) HELP=true; shift 1;;
-6) TEST_PARAMS+="ipv6=1;"; BR_CONF_SUFFIX="_ipv6"; shift 1;;
--single) MODE=single; shift 1;;
--multi) MODE=multi; shift 1;;
--tests) TESTS="$2"; shift 2;;
--veth) RUN=1; CLEAN=3; shift 1;;
--attach) RUN=2; CLEAN=3; shift 1;;
--no-clean) RUN=3; CLEAN=3; shift 1;;
--detach) RUN=0; CLEAN=2; shift 1;;
--clean) RUN=0; CLEAN=1; shift 1;;
--) shift; break;;
esac
done
if [[ "$HELP" = true ]]; then
print_help
exit 0
fi
if [[ "$TESTS" = "" ]]; then
if [[ "$MODE" = "single" ]]; then
TESTS=single_device
else
TESTS=multi_device
fi
fi
if [ $RUN -ge 1 ]; then create_veths; fi
if [ $RUN -ge 2 ]; then attach_routers; fi
if [ $RUN -ge 3 ]; then run_tests; fi
if [ $CLEAN -le 2 ]; then detach_routers; fi
if [ $CLEAN -le 1 ]; then destroy_veths; fi