xref: /linux/tools/testing/selftests/net/forwarding/mirror_gre_lag_lacp.sh (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
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# team device.
6#
7# +----------------------+                             +----------------------+
8# | H1                   |                             |                   H2 |
9# |    + $h1.333         |                             |        $h1.555 +     |
10# |    | 192.0.2.1/28    |                             |  192.0.2.18/28 |     |
11# +----|-----------------+                             +----------------|-----+
12#      |                                $h1                             |
13#      +---------------------------------+------------------------------+
14#                                        |
15# +--------------------------------------|------------------------------------+
16# | SW                                   o---> mirror                         |
17# |                                      |                                    |
18# |   +----------------------------------+------------------------------+     |
19# |   |                                $swp1                            |     |
20# |   + $swp1.333                                             $swp1.555 +     |
21# |     192.0.2.2/28                                      192.0.2.17/28       |
22# |                                                                           |
23# |                                                                           |
24# |   + gt4 (gretap)      ,-> + lag1 (team)                                   |
25# |     loc=192.0.2.129   |   | 192.0.2.129/28                                |
26# |     rem=192.0.2.130 --'   |                                               |
27# |     ttl=100               |                                               |
28# |     tos=inherit           |                                               |
29# |      _____________________|______________________                         |
30# |     /                                            \                        |
31# |    /                                              \                       |
32# |   + $swp3                                          + $swp4                |
33# +---|------------------------------------------------|----------------------+
34#     |                                                |
35# +---|------------------------------------------------|----------------------+
36# |   + $h3                                            + $h4               H3 |
37# |    \                                              /                       |
38# |     \____________________________________________/                        |
39# |                           |                                               |
40# |                           + lag2 (team)  ------>   + gt4-dst (gretap)     |
41# |                             192.0.2.130/28           loc=192.0.2.130      |
42# |                                                      rem=192.0.2.129      |
43# |                                                      ttl=100              |
44# |                                                      tos=inherit          |
45# |                                                                           |
46# |                                                                           |
47# |                                                                           |
48# |                                                                           |
49# +---------------------------------------------------------------------------+
50
51ALL_TESTS="
52	test_mirror_gretap_first
53	test_mirror_gretap_second
54"
55
56NUM_NETIFS=6
57source lib.sh
58source mirror_lib.sh
59
60vlan_host_create()
61{
62	local if_name=$1; shift
63	local vid=$1; shift
64	local vrf_name=$1; shift
65	local ips=("${@}")
66
67	vrf_create $vrf_name
68	ip link set dev $vrf_name up
69	vlan_create $if_name $vid $vrf_name "${ips[@]}"
70}
71
72vlan_host_destroy()
73{
74	local if_name=$1; shift
75	local vid=$1; shift
76	local vrf_name=$1; shift
77
78	vlan_destroy $if_name $vid
79	ip link set dev $vrf_name down
80	vrf_destroy $vrf_name
81}
82
83h1_create()
84{
85	vlan_host_create $h1 333 vrf-h1 192.0.2.1/28
86	ip -4 route add 192.0.2.16/28 vrf vrf-h1 nexthop via 192.0.2.2
87}
88
89h1_destroy()
90{
91	ip -4 route del 192.0.2.16/28 vrf vrf-h1
92	vlan_host_destroy $h1 333 vrf-h1
93}
94
95h2_create()
96{
97	vlan_host_create $h1 555 vrf-h2 192.0.2.18/28
98	ip -4 route add 192.0.2.0/28 vrf vrf-h2 nexthop via 192.0.2.17
99}
100
101h2_destroy()
102{
103	ip -4 route del 192.0.2.0/28 vrf vrf-h2
104	vlan_host_destroy $h1 555 vrf-h2
105}
106
107h3_create_team()
108{
109	team_create lag2 lacp $h3 $h4
110	__simple_if_init lag2 vrf-h3 192.0.2.130/32
111	ip -4 route add vrf vrf-h3 192.0.2.129/32 dev lag2
112}
113
114h3_destroy_team()
115{
116	ip -4 route del vrf vrf-h3 192.0.2.129/32 dev lag2
117	__simple_if_fini lag2 192.0.2.130/32
118	team_destroy lag2
119
120	ip link set dev $h3 down
121	ip link set dev $h4 down
122}
123
124h3_create()
125{
126	vrf_create vrf-h3
127	ip link set dev vrf-h3 up
128	h3_create_team
129
130	tunnel_create gt4-dst gretap 192.0.2.130 192.0.2.129 \
131		      ttl 100 tos inherit
132	ip link set dev gt4-dst master vrf-h3
133	tc qdisc add dev gt4-dst clsact
134}
135
136h3_destroy()
137{
138	tc qdisc del dev gt4-dst clsact
139	ip link set dev gt4-dst nomaster
140	tunnel_destroy gt4-dst
141
142	h3_destroy_team
143	ip link set dev vrf-h3 down
144	vrf_destroy vrf-h3
145}
146
147switch_create()
148{
149	ip link set dev $swp1 up
150	tc qdisc add dev $swp1 clsact
151	vlan_create $swp1 333 "" 192.0.2.2/28
152	vlan_create $swp1 555 "" 192.0.2.17/28
153
154	tunnel_create gt4 gretap 192.0.2.129 192.0.2.130 \
155		      ttl 100 tos inherit
156
157	ip link set dev $swp3 up
158	ip link set dev $swp4 up
159	team_create lag1 lacp $swp3 $swp4
160	__addr_add_del lag1 add 192.0.2.129/32
161	ip -4 route add 192.0.2.130/32 dev lag1
162}
163
164switch_destroy()
165{
166	ip -4 route del 192.0.2.130/32 dev lag1
167	__addr_add_del lag1 del 192.0.2.129/32
168	team_destroy lag1
169
170	ip link set dev $swp4 down
171	ip link set dev $swp3 down
172
173	tunnel_destroy gt4
174
175	vlan_destroy $swp1 555
176	vlan_destroy $swp1 333
177	tc qdisc del dev $swp1 clsact
178	ip link set dev $swp1 down
179}
180
181setup_prepare()
182{
183	h1=${NETIFS[p1]}
184	swp1=${NETIFS[p2]}
185
186	swp3=${NETIFS[p3]}
187	h3=${NETIFS[p4]}
188
189	swp4=${NETIFS[p5]}
190	h4=${NETIFS[p6]}
191
192	vrf_prepare
193
194	ip link set dev $h1 up
195	h1_create
196	h2_create
197	h3_create
198	switch_create
199}
200
201cleanup()
202{
203	pre_cleanup
204
205	switch_destroy
206	h3_destroy
207	h2_destroy
208	h1_destroy
209	ip link set dev $h1 down
210
211	vrf_cleanup
212}
213
214test_lag_slave()
215{
216	local up_dev=$1; shift
217	local down_dev=$1; shift
218	local what=$1; shift
219
220	RET=0
221
222	mirror_install $swp1 ingress gt4 \
223		       "proto 802.1q flower vlan_id 333"
224	vlan_capture_install gt4-dst "vlan_ethtype ipv4 ip_proto icmp type 8"
225
226	# Move $down_dev away from the team. That will prompt change in
227	# txability of the connected device, without changing its upness. The
228	# driver should notice the txability change and move the traffic to the
229	# other slave.
230	ip link set dev $down_dev nomaster
231	sleep 2
232	mirror_test vrf-h1 192.0.2.1 192.0.2.18 gt4-dst 100 10
233
234	# Test lack of connectivity when neither slave is txable.
235	ip link set dev $up_dev nomaster
236	sleep 2
237	mirror_test vrf-h1 192.0.2.1 192.0.2.18 gt4-dst 100 0
238
239	vlan_capture_uninstall gt4-dst
240	mirror_uninstall $swp1 ingress
241
242	# Recreate H3's team device, because mlxsw, which this test is
243	# predominantly mean to test, requires a bottom-up construction and
244	# doesn't allow enslavement to a device that already has an upper.
245	h3_destroy_team
246	h3_create_team
247	# Wait for ${h,swp}{3,4}.
248	setup_wait
249
250	log_test "$what"
251}
252
253test_mirror_gretap_first()
254{
255	test_lag_slave $h3 $h4 "mirror to gretap: LAG first slave"
256}
257
258test_mirror_gretap_second()
259{
260	test_lag_slave $h4 $h3 "mirror to gretap: LAG second slave"
261}
262
263trap cleanup EXIT
264
265setup_prepare
266setup_wait
267
268tests_run
269
270exit $EXIT_STATUS
271