1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# +----------------------------+                   +--------------------------+
5# | H1 (vrf)                   |                   |                 H2 (vrf) |
6# |                            |                   |                          |
7# |        + LAG1 (team)       |                   |     + LAG4 (team)        |
8# |        | 192.0.2.1/28      |                   |     | 192.0.2.130/28     |
9# |        | 2001:db8:1::1/64  |                   |     | 2001:db8:2::2/64   |
10# |      __^___                |                   |   __^_____               |
11# |     /      \               |                   |  /        \              |
12# |    + $h1    + $h4          |                   | + $h2      + $h3         |
13# |    |        |              |                   | |          |             |
14# +----|--------|--------------+                   +-|----------|-------------+
15#      |        |                                    |          |
16# +----|--------|------------------------------------|----------|-------------+
17# | SW |        |                                    |          |             |
18# |    + $swp1  + $swp4                              + $swp2    + $swp3       |
19# |     \__ ___/                                      \__ _____/              |
20# |        v                                             v                    |
21# | +------|-------------------------------+             |                    |
22# | |      + LAG2       BR1 (802.1q)       |             + LAG3 (team)        |
23# | |        (team)       192.0.2.2/28     |               192.0.2.129/28     |
24# | |                     2001:db8:1::2/64 |               2001:db8:2::1/64   |
25# | |                                      |                                  |
26# | +--------------------------------------+                                  |
27# +---------------------------------------------------------------------------+
28
29: ${ALL_TESTS:="
30	ping_ipv4
31	ping_ipv6
32
33	$(: exercise remastering of LAG2 slaves )
34	config_deslave_swp4
35	config_wait
36	ping_ipv4
37	ping_ipv6
38	config_enslave_swp4
39	config_deslave_swp1
40	config_wait
41	ping_ipv4
42	ping_ipv6
43	config_deslave_swp4
44	config_enslave_swp1
45	config_enslave_swp4
46	config_wait
47	ping_ipv4
48	ping_ipv6
49
50	$(: exercise remastering of LAG2 itself )
51	config_remaster_lag2
52	config_wait
53	ping_ipv4
54	ping_ipv6
55
56	$(: exercise remastering of LAG3 slaves )
57	config_deslave_swp2
58	config_wait
59	ping_ipv4
60	ping_ipv6
61	config_enslave_swp2
62	config_deslave_swp3
63	config_wait
64	ping_ipv4
65	ping_ipv6
66	config_deslave_swp2
67	config_enslave_swp3
68	config_enslave_swp2
69	config_wait
70	ping_ipv4
71	ping_ipv6
72
73	$(: move LAG3 to a bridge and then out )
74	config_remaster_lag3
75	config_wait
76	ping_ipv4
77	ping_ipv6
78    "}
79NUM_NETIFS=8
80: ${lib_dir:=.}
81source $lib_dir/lib.sh
82$EXTRA_SOURCE
83
84h1_create()
85{
86	team_create lag1 lacp
87	ip link set dev lag1 address $(mac_get $h1)
88	ip link set dev $h1 master lag1
89	ip link set dev $h4 master lag1
90	simple_if_init lag1 192.0.2.1/28 2001:db8:1::1/64
91	ip link set dev $h1 up
92	ip link set dev $h4 up
93	ip -4 route add 192.0.2.128/28 vrf vlag1 nexthop via 192.0.2.2
94	ip -6 route add 2001:db8:2::/64 vrf vlag1 nexthop via 2001:db8:1::2
95}
96
97h1_destroy()
98{
99	ip -6 route del 2001:db8:2::/64 vrf vlag1
100	ip -4 route del 192.0.2.128/28 vrf vlag1
101	ip link set dev $h4 down
102	ip link set dev $h1 down
103	simple_if_fini lag1 192.0.2.1/28 2001:db8:1::1/64
104	ip link set dev $h4 nomaster
105	ip link set dev $h1 nomaster
106	team_destroy lag1
107}
108
109h2_create()
110{
111	team_create lag4 lacp
112	ip link set dev lag4 address $(mac_get $h2)
113	ip link set dev $h2 master lag4
114	ip link set dev $h3 master lag4
115	simple_if_init lag4 192.0.2.130/28 2001:db8:2::2/64
116	ip link set dev $h2 up
117	ip link set dev $h3 up
118	ip -4 route add 192.0.2.0/28 vrf vlag4 nexthop via 192.0.2.129
119	ip -6 route add 2001:db8:1::/64 vrf vlag4 nexthop via 2001:db8:2::1
120}
121
122h2_destroy()
123{
124	ip -6 route del 2001:db8:1::/64 vrf vlag4
125	ip -4 route del 192.0.2.0/28 vrf vlag4
126	ip link set dev $h3 down
127	ip link set dev $h2 down
128	simple_if_fini lag4 192.0.2.130/28 2001:db8:2::2/64
129	ip link set dev $h3 nomaster
130	ip link set dev $h2 nomaster
131	team_destroy lag4
132}
133
134router_create()
135{
136	team_create lag2 lacp
137	ip link set dev lag2 address $(mac_get $swp1)
138	ip link set dev $swp1 master lag2
139	ip link set dev $swp4 master lag2
140
141	ip link add name br1 address $(mac_get lag2) \
142		type bridge vlan_filtering 1
143	ip link set dev lag2 master br1
144
145	ip link set dev $swp1 up
146	ip link set dev $swp4 up
147	ip link set dev br1 up
148
149	__addr_add_del br1 add 192.0.2.2/28 2001:db8:1::2/64
150
151	team_create lag3 lacp
152	ip link set dev lag3 address $(mac_get $swp2)
153	ip link set dev $swp2 master lag3
154	ip link set dev $swp3 master lag3
155	ip link set dev $swp2 up
156	ip link set dev $swp3 up
157	__addr_add_del lag3 add 192.0.2.129/28 2001:db8:2::1/64
158}
159
160router_destroy()
161{
162	__addr_add_del lag3 del 192.0.2.129/28 2001:db8:2::1/64
163	ip link set dev $swp3 down
164	ip link set dev $swp2 down
165	ip link set dev $swp3 nomaster
166	ip link set dev $swp2 nomaster
167	team_destroy lag3
168
169	__addr_add_del br1 del 192.0.2.2/28 2001:db8:1::2/64
170
171	ip link set dev $swp4 down
172	ip link set dev $swp1 down
173	ip link set dev br1 down
174
175	ip link set dev lag2 nomaster
176	ip link del dev br1
177
178	ip link set dev $swp4 nomaster
179	ip link set dev $swp1 nomaster
180	team_destroy lag2
181}
182
183config_remaster_lag2()
184{
185	log_info "Remaster bridge slave"
186
187	ip link set dev lag2 nomaster
188	sleep 2
189	ip link set dev lag2 master br1
190}
191
192config_remaster_lag3()
193{
194	log_info "Move lag3 to the bridge, then out again"
195
196	ip link set dev lag3 master br1
197	sleep 2
198	ip link set dev lag3 nomaster
199}
200
201config_deslave()
202{
203	local netdev=$1; shift
204
205	log_info "Deslave $netdev"
206	ip link set dev $netdev down
207	ip link set dev $netdev nomaster
208	ip link set dev $netdev up
209}
210
211config_deslave_swp1()
212{
213	config_deslave $swp1
214}
215
216config_deslave_swp2()
217{
218	config_deslave $swp2
219}
220
221config_deslave_swp3()
222{
223	config_deslave $swp3
224}
225
226config_deslave_swp4()
227{
228	config_deslave $swp4
229}
230
231config_enslave()
232{
233	local netdev=$1; shift
234	local master=$1; shift
235
236	log_info "Enslave $netdev to $master"
237	ip link set dev $netdev down
238	ip link set dev $netdev master $master
239	ip link set dev $netdev up
240}
241
242config_enslave_swp1()
243{
244	config_enslave $swp1 lag2
245}
246
247config_enslave_swp2()
248{
249	config_enslave $swp2 lag3
250}
251
252config_enslave_swp3()
253{
254	config_enslave $swp3 lag3
255}
256
257config_enslave_swp4()
258{
259	config_enslave $swp4 lag2
260}
261
262config_wait()
263{
264	setup_wait_dev lag2
265	setup_wait_dev lag3
266}
267
268setup_prepare()
269{
270	h1=${NETIFS[p1]}
271	swp1=${NETIFS[p2]}
272
273	swp2=${NETIFS[p3]}
274	h2=${NETIFS[p4]}
275
276	swp3=${NETIFS[p5]}
277	h3=${NETIFS[p6]}
278
279	h4=${NETIFS[p7]}
280	swp4=${NETIFS[p8]}
281
282	vrf_prepare
283
284	h1_create
285	h2_create
286
287	router_create
288
289	forwarding_enable
290}
291
292cleanup()
293{
294	pre_cleanup
295
296	forwarding_restore
297
298	router_destroy
299
300	h2_destroy
301	h1_destroy
302
303	vrf_cleanup
304}
305
306ping_ipv4()
307{
308	ping_test lag1 192.0.2.130
309}
310
311ping_ipv6()
312{
313	ping6_test lag1 2001:db8:2::2
314}
315
316trap cleanup EXIT
317
318setup_prepare
319setup_wait
320
321tests_run
322
323exit $EXIT_STATUS
324