Skip to content

Commit 494f2e7

Browse files
committed
Merge branch 'selftests-mirror-to-gretap-with-team'
Petr Machata says: ==================== A test for mirror-to-gretap with team in UL packet path This patchset adds a test for "tc action mirred mirror" where the mirrored-to device is a gretap, and underlay path contains a team device. In patch #1 require_command() is added, which should henceforth be used to declare dependence on a certain tool. In patch #2, two new functions, team_create() and team_destroy(), are added to lib.sh. The newly-added test uses arping, which isn't necessarily available. Therefore patch #3 introduces $ARPING, and a preexisting test is fixed to require_command $ARPING. In patches #4 and #5, two new tests are added. In both cases, a team device is on egress path of a mirrored packet in a mirror-to-gretap scenario. In the first one, the team device is in loadbalance mode, in the second one it's in lacp mode. (The difference in modes necessitates a different testing strategy, hence two test cases instead of just parameterizing one.) ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 778c4d5 + 541c6ce commit 494f2e7

File tree

4 files changed

+607
-10
lines changed

4 files changed

+607
-10
lines changed

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
PING=${PING:=ping}
99
PING6=${PING6:=ping6}
1010
MZ=${MZ:=mausezahn}
11+
ARPING=${ARPING:=arping}
12+
TEAMD=${TEAMD:=teamd}
1113
WAIT_TIME=${WAIT_TIME:=5}
1214
PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no}
1315
PAUSE_ON_CLEANUP=${PAUSE_ON_CLEANUP:=no}
@@ -62,15 +64,18 @@ if [[ "$CHECK_TC" = "yes" ]]; then
6264
check_tc_version
6365
fi
6466

65-
if [[ ! -x "$(command -v jq)" ]]; then
66-
echo "SKIP: jq not installed"
67-
exit 1
68-
fi
67+
require_command()
68+
{
69+
local cmd=$1; shift
6970

70-
if [[ ! -x "$(command -v $MZ)" ]]; then
71-
echo "SKIP: $MZ not installed"
72-
exit 1
73-
fi
71+
if [[ ! -x "$(command -v "$cmd")" ]]; then
72+
echo "SKIP: $cmd not installed"
73+
exit 1
74+
fi
75+
}
76+
77+
require_command jq
78+
require_command $MZ
7479

7580
if [[ ! -v NUM_NETIFS ]]; then
7681
echo "SKIP: importer does not define \"NUM_NETIFS\""
@@ -422,6 +427,28 @@ vlan_destroy()
422427
ip link del dev $name
423428
}
424429

430+
team_create()
431+
{
432+
local if_name=$1; shift
433+
local mode=$1; shift
434+
435+
require_command $TEAMD
436+
$TEAMD -t $if_name -d -c '{"runner": {"name": "'$mode'"}}'
437+
for slave in "$@"; do
438+
ip link set dev $slave down
439+
ip link set dev $slave master $if_name
440+
ip link set dev $slave up
441+
done
442+
ip link set dev $if_name up
443+
}
444+
445+
team_destroy()
446+
{
447+
local if_name=$1; shift
448+
449+
$TEAMD -t $if_name -k
450+
}
451+
425452
master_name_get()
426453
{
427454
local if_name=$1
Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
# Test for "tc action mirred egress mirror" when the underlay route points at a
5+
# bridge device with vlan filtering (802.1q), and the egress device is a team
6+
# device.
7+
#
8+
# +----------------------+ +----------------------+
9+
# | H1 | | H2 |
10+
# | + $h1.333 | | $h1.555 + |
11+
# | | 192.0.2.1/28 | | 192.0.2.18/28 | |
12+
# +-----|----------------+ +----------------|-----+
13+
# | $h1 |
14+
# +--------------------------------+------------------------------+
15+
# |
16+
# +--------------------------------------|------------------------------------+
17+
# | SW o---> mirror |
18+
# | | |
19+
# | +--------------------------------+------------------------------+ |
20+
# | | $swp1 | |
21+
# | + $swp1.333 $swp1.555 + |
22+
# | 192.0.2.2/28 192.0.2.17/28 |
23+
# | |
24+
# | +-----------------------------------------------------------------------+ |
25+
# | | BR1 (802.1q) | |
26+
# | | + lag (team) 192.0.2.129/28 | |
27+
# | | / \ 2001:db8:2::1/64 | |
28+
# | +---/---\---------------------------------------------------------------+ |
29+
# | / \ ^ |
30+
# | | \ + gt4 (gretap) | |
31+
# | | \ loc=192.0.2.129 | |
32+
# | | \ rem=192.0.2.130 -+ |
33+
# | | \ ttl=100 |
34+
# | | \ tos=inherit |
35+
# | | \ |
36+
# | | \_________________________________ |
37+
# | | \ |
38+
# | + $swp3 + $swp4 |
39+
# +---|------------------------------------------------|----------------------+
40+
# | |
41+
# +---|----------------------+ +---|----------------------+
42+
# | + $h3 H3 | | + $h4 H4 |
43+
# | 192.0.2.130/28 | | 192.0.2.130/28 |
44+
# | 2001:db8:2::2/64 | | 2001:db8:2::2/64 |
45+
# +--------------------------+ +--------------------------+
46+
47+
ALL_TESTS="
48+
test_mirror_gretap_first
49+
test_mirror_gretap_second
50+
"
51+
52+
NUM_NETIFS=6
53+
source lib.sh
54+
source mirror_lib.sh
55+
source mirror_gre_lib.sh
56+
57+
require_command $ARPING
58+
59+
vlan_host_create()
60+
{
61+
local if_name=$1; shift
62+
local vid=$1; shift
63+
local vrf_name=$1; shift
64+
local ips=("${@}")
65+
66+
vrf_create $vrf_name
67+
ip link set dev $vrf_name up
68+
vlan_create $if_name $vid $vrf_name "${ips[@]}"
69+
}
70+
71+
vlan_host_destroy()
72+
{
73+
local if_name=$1; shift
74+
local vid=$1; shift
75+
local vrf_name=$1; shift
76+
77+
vlan_destroy $if_name $vid
78+
ip link set dev $vrf_name down
79+
vrf_destroy $vrf_name
80+
}
81+
82+
h1_create()
83+
{
84+
vlan_host_create $h1 333 vrf-h1 192.0.2.1/28
85+
ip -4 route add 192.0.2.16/28 vrf vrf-h1 nexthop via 192.0.2.2
86+
}
87+
88+
h1_destroy()
89+
{
90+
ip -4 route del 192.0.2.16/28 vrf vrf-h1
91+
vlan_host_destroy $h1 333 vrf-h1
92+
}
93+
94+
h2_create()
95+
{
96+
vlan_host_create $h1 555 vrf-h2 192.0.2.18/28
97+
ip -4 route add 192.0.2.0/28 vrf vrf-h2 nexthop via 192.0.2.17
98+
}
99+
100+
h2_destroy()
101+
{
102+
ip -4 route del 192.0.2.0/28 vrf vrf-h2
103+
vlan_host_destroy $h1 555 vrf-h2
104+
}
105+
106+
h3_create()
107+
{
108+
simple_if_init $h3 192.0.2.130/28
109+
tc qdisc add dev $h3 clsact
110+
}
111+
112+
h3_destroy()
113+
{
114+
tc qdisc del dev $h3 clsact
115+
simple_if_fini $h3 192.0.2.130/28
116+
}
117+
118+
h4_create()
119+
{
120+
simple_if_init $h4 192.0.2.130/28
121+
tc qdisc add dev $h4 clsact
122+
}
123+
124+
h4_destroy()
125+
{
126+
tc qdisc del dev $h4 clsact
127+
simple_if_fini $h4 192.0.2.130/28
128+
}
129+
130+
switch_create()
131+
{
132+
ip link set dev $swp1 up
133+
tc qdisc add dev $swp1 clsact
134+
vlan_create $swp1 333 "" 192.0.2.2/28
135+
vlan_create $swp1 555 "" 192.0.2.17/28
136+
137+
tunnel_create gt4 gretap 192.0.2.129 192.0.2.130 \
138+
ttl 100 tos inherit
139+
140+
ip link set dev $swp3 up
141+
ip link set dev $swp4 up
142+
143+
ip link add name br1 type bridge vlan_filtering 1
144+
ip link set dev br1 up
145+
__addr_add_del br1 add 192.0.2.129/32
146+
ip -4 route add 192.0.2.130/32 dev br1
147+
148+
team_create lag loadbalance $swp3 $swp4
149+
ip link set dev lag master br1
150+
}
151+
152+
switch_destroy()
153+
{
154+
ip link set dev lag nomaster
155+
team_destroy lag
156+
157+
ip -4 route del 192.0.2.130/32 dev br1
158+
__addr_add_del br1 del 192.0.2.129/32
159+
ip link set dev br1 down
160+
ip link del dev br1
161+
162+
ip link set dev $swp4 down
163+
ip link set dev $swp3 down
164+
165+
tunnel_destroy gt4
166+
167+
vlan_destroy $swp1 555
168+
vlan_destroy $swp1 333
169+
tc qdisc del dev $swp1 clsact
170+
ip link set dev $swp1 down
171+
}
172+
173+
setup_prepare()
174+
{
175+
h1=${NETIFS[p1]}
176+
swp1=${NETIFS[p2]}
177+
178+
swp3=${NETIFS[p3]}
179+
h3=${NETIFS[p4]}
180+
181+
swp4=${NETIFS[p5]}
182+
h4=${NETIFS[p6]}
183+
184+
vrf_prepare
185+
186+
ip link set dev $h1 up
187+
h1_create
188+
h2_create
189+
h3_create
190+
h4_create
191+
switch_create
192+
193+
trap_install $h3 ingress
194+
trap_install $h4 ingress
195+
}
196+
197+
cleanup()
198+
{
199+
pre_cleanup
200+
201+
trap_uninstall $h4 ingress
202+
trap_uninstall $h3 ingress
203+
204+
switch_destroy
205+
h4_destroy
206+
h3_destroy
207+
h2_destroy
208+
h1_destroy
209+
ip link set dev $h1 down
210+
211+
vrf_cleanup
212+
}
213+
214+
test_lag_slave()
215+
{
216+
local host_dev=$1; shift
217+
local up_dev=$1; shift
218+
local down_dev=$1; shift
219+
local what=$1; shift
220+
221+
RET=0
222+
223+
mirror_install $swp1 ingress gt4 \
224+
"proto 802.1q flower vlan_id 333 $tcflags"
225+
226+
# Test connectivity through $up_dev when $down_dev is set down.
227+
ip link set dev $down_dev down
228+
setup_wait_dev $up_dev
229+
setup_wait_dev $host_dev
230+
$ARPING -I br1 192.0.2.130 -qfc 1
231+
sleep 2
232+
mirror_test vrf-h1 192.0.2.1 192.0.2.18 $host_dev 1 10
233+
234+
# Test lack of connectivity when both slaves are down.
235+
ip link set dev $up_dev down
236+
sleep 2
237+
mirror_test vrf-h1 192.0.2.1 192.0.2.18 $h3 1 0
238+
mirror_test vrf-h1 192.0.2.1 192.0.2.18 $h4 1 0
239+
240+
ip link set dev $up_dev up
241+
ip link set dev $down_dev up
242+
mirror_uninstall $swp1 ingress
243+
244+
log_test "$what ($tcflags)"
245+
}
246+
247+
test_mirror_gretap_first()
248+
{
249+
test_lag_slave $h3 $swp3 $swp4 "mirror to gretap: LAG first slave"
250+
}
251+
252+
test_mirror_gretap_second()
253+
{
254+
test_lag_slave $h4 $swp4 $swp3 "mirror to gretap: LAG second slave"
255+
}
256+
257+
test_all()
258+
{
259+
slow_path_trap_install $swp1 ingress
260+
slow_path_trap_install $swp1 egress
261+
262+
tests_run
263+
264+
slow_path_trap_uninstall $swp1 egress
265+
slow_path_trap_uninstall $swp1 ingress
266+
}
267+
268+
trap cleanup EXIT
269+
270+
setup_prepare
271+
setup_wait
272+
273+
tcflags="skip_hw"
274+
test_all
275+
276+
if ! tc_offload_check; then
277+
echo "WARN: Could not test offloaded functionality"
278+
else
279+
tcflags="skip_sw"
280+
test_all
281+
fi
282+
283+
exit $EXIT_STATUS

0 commit comments

Comments
 (0)