1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# +------------------------+                           +----------------------+
5# | H1 (vrf)               |                           |             H2 (vrf) |
6# |    + $h1.555           |                           |  + $h2.777           |
7# |    | 192.0.2.1/28      |                           |  | 192.0.2.18/28     |
8# |    | 2001:db8:1::1/64  |                           |  | 2001:db8:2::2/64  |
9# |    |                   |                           |  |                   |
10# |    + $h1               |                           |  + $h2               |
11# +----|-------------------+                           +--|-------------------+
12#      |                                                  |
13# +----|--------------------------------------------------|-------------------+
14# | SW |                                                  |                   |
15# | +--|--------------------------------------------------|-----------------+ |
16# | |  + $swp1                   BR1 (802.1q)             + $swp2           | |
17# | |                                                                       | |
18# | +------+------------------------------------------+---------------------+ |
19# |        |                                          |                       |
20# |        + br1.555                                  + br1.777               |
21# |          192.0.2.2/28                               192.0.2.17/28         |
22# |          2001:db8:1::2/64                           2001:db8:2::1/64      |
23# +---------------------------------------------------------------------------+
24
25ALL_TESTS="
26	ping_ipv4
27	ping_ipv6
28	respin_config
29	ping_ipv4
30	ping_ipv6
31"
32NUM_NETIFS=4
33source lib.sh
34
35h1_create()
36{
37	simple_if_init $h1
38	vlan_create $h1 555 v$h1 192.0.2.1/28 2001:db8:1::1/64
39	ip -4 route add 192.0.2.16/28 vrf v$h1 nexthop via 192.0.2.2
40	ip -6 route add 2001:db8:2::/64 vrf v$h1 nexthop via 2001:db8:1::2
41}
42
43h1_destroy()
44{
45	ip -6 route del 2001:db8:2::/64 vrf v$h1
46	ip -4 route del 192.0.2.16/28 vrf v$h1
47	vlan_destroy $h1 555
48	simple_if_fini $h1
49}
50
51h2_create()
52{
53	simple_if_init $h2
54	vlan_create $h2 777 v$h2 192.0.2.18/28 2001:db8:2::2/64
55	ip -4 route add 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.17
56	ip -6 route add 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:2::1
57}
58
59h2_destroy()
60{
61	ip -6 route del 2001:db8:1::/64 vrf v$h2
62	ip -4 route del 192.0.2.0/28 vrf v$h2
63	vlan_destroy $h2 777
64	simple_if_fini $h2
65}
66
67router_create()
68{
69	ip link add name br1 address $(mac_get $swp1) \
70		type bridge vlan_filtering 1
71	ip link set dev br1 up
72
73	ip link set dev $swp1 master br1
74	ip link set dev $swp2 master br1
75	ip link set dev $swp1 up
76	ip link set dev $swp2 up
77
78	bridge vlan add dev br1 vid 555 self
79	bridge vlan add dev br1 vid 777 self
80	bridge vlan add dev $swp1 vid 555
81	bridge vlan add dev $swp2 vid 777
82
83	vlan_create br1 555 "" 192.0.2.2/28 2001:db8:1::2/64
84	vlan_create br1 777 "" 192.0.2.17/28 2001:db8:2::1/64
85}
86
87router_destroy()
88{
89	vlan_destroy br1 777
90	vlan_destroy br1 555
91
92	bridge vlan del dev $swp2 vid 777
93	bridge vlan del dev $swp1 vid 555
94	bridge vlan del dev br1 vid 777 self
95	bridge vlan del dev br1 vid 555 self
96
97	ip link set dev $swp2 down nomaster
98	ip link set dev $swp1 down nomaster
99
100	ip link set dev br1 down
101	ip link del dev br1
102}
103
104setup_prepare()
105{
106	h1=${NETIFS[p1]}
107	swp1=${NETIFS[p2]}
108
109	swp2=${NETIFS[p3]}
110	h2=${NETIFS[p4]}
111
112	vrf_prepare
113
114	h1_create
115	h2_create
116
117	router_create
118
119	forwarding_enable
120}
121
122cleanup()
123{
124	pre_cleanup
125
126	forwarding_restore
127
128	router_destroy
129
130	h2_destroy
131	h1_destroy
132
133	vrf_cleanup
134}
135
136ping_ipv4()
137{
138	ping_test $h1 192.0.2.18
139}
140
141ping_ipv6()
142{
143	ping6_test $h1 2001:db8:2::2
144}
145
146respin_config()
147{
148	log_info "Remaster bridge slave"
149
150	ip link set dev $swp2 nomaster
151	ip link set dev $swp1 nomaster
152
153	sleep 2
154
155	ip link set dev $swp1 master br1
156	ip link set dev $swp2 master br1
157
158	bridge vlan add dev $swp1 vid 555
159	bridge vlan add dev $swp2 vid 777
160}
161
162trap cleanup EXIT
163
164setup_prepare
165setup_wait
166
167tests_run
168
169exit $EXIT_STATUS
170