Skip to content

Commit 0a06e0c

Browse files
pmachatadavem330
authored andcommitted
selftests: router_bridge_1d: Add a new selftest
Add a selftest to verify that routing through a 1d bridge works when VLAN upper of a physical port is used instead of a physical port. Also verify that when a port is attached to an already-configured bridge, the configuration is applied. Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Danielle Ratson <danieller@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent eb13885 commit 0a06e0c

File tree

2 files changed

+186
-0
lines changed

2 files changed

+186
-0
lines changed

tools/testing/selftests/net/forwarding/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ TEST_PROGS = bridge_igmp.sh \
6464
q_in_vni_ipv6.sh \
6565
q_in_vni.sh \
6666
router_bridge.sh \
67+
router_bridge_1d.sh \
6768
router_bridge_vlan.sh \
6869
router_bridge_pvid_vlan_upper.sh \
6970
router_bridge_vlan_upper_pvid.sh \
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
# +---------------------------------------------+ +----------------------+
5+
# | H1 (vrf) | | H2 (vrf) |
6+
# | + $h1.100 + $h1.200 | | + $h2 |
7+
# | | 192.0.2.1/28 | 192.0.2.17/28 | | | 192.0.2.130/28 |
8+
# | | 2001:db8:1::1/64 | 2001:db8:3::1/64 | | | 192.0.2.146/28 |
9+
# | \_________ __________/ | | | 2001:db8:2::2/64 |
10+
# | V | | | 2001:db8:4::2/64 |
11+
# | + $h1 | | | |
12+
# +--------------|------------------------------+ +--|-------------------+
13+
# | |
14+
# +--------------|----------------------------------------|-------------------+
15+
# | SW + $swp1 + $swp2 |
16+
# | | 192.0.2.129/28 |
17+
# | | 192.0.2.145/28 |
18+
# | | 2001:db8:2::1/64 |
19+
# | ________^___________________________ 2001:db8:4::1/64 |
20+
# | / \ |
21+
# | +---|------------------------------+ +---|------------------------------+ |
22+
# | | + $swp1.100 BR1 (802.1d) | | + $swp1.200 BR2 (802.1d) | |
23+
# | | 192.0.2.2/28 | | 192.0.2.18/28 | |
24+
# | | 2001:db8:1::2/64 | | 2001:db8:3::2/64 | |
25+
# | | | | | |
26+
# | +----------------------------------+ +----------------------------------+ |
27+
# +---------------------------------------------------------------------------+
28+
29+
ALL_TESTS="
30+
ping_ipv4
31+
ping_ipv6
32+
config_remaster
33+
ping_ipv4
34+
ping_ipv6
35+
"
36+
NUM_NETIFS=4
37+
source lib.sh
38+
39+
h1_create()
40+
{
41+
simple_if_init $h1
42+
vlan_create $h1 100 v$h1 192.0.2.1/28 2001:db8:1::1/64
43+
vlan_create $h1 200 v$h1 192.0.2.17/28 2001:db8:3::1/64
44+
ip -4 route add 192.0.2.128/28 vrf v$h1 nexthop via 192.0.2.2
45+
ip -4 route add 192.0.2.144/28 vrf v$h1 nexthop via 192.0.2.18
46+
ip -6 route add 2001:db8:2::/64 vrf v$h1 nexthop via 2001:db8:1::2
47+
ip -6 route add 2001:db8:4::/64 vrf v$h1 nexthop via 2001:db8:3::2
48+
}
49+
50+
h1_destroy()
51+
{
52+
ip -6 route del 2001:db8:4::/64 vrf v$h1
53+
ip -6 route del 2001:db8:2::/64 vrf v$h1
54+
ip -4 route del 192.0.2.144/28 vrf v$h1
55+
ip -4 route del 192.0.2.128/28 vrf v$h1
56+
vlan_destroy $h1 200
57+
vlan_destroy $h1 100
58+
simple_if_fini $h1
59+
}
60+
61+
h2_create()
62+
{
63+
simple_if_init $h2 192.0.2.130/28 2001:db8:2::2/64 \
64+
192.0.2.146/28 2001:db8:4::2/64
65+
ip -4 route add 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.129
66+
ip -4 route add 192.0.2.16/28 vrf v$h2 nexthop via 192.0.2.145
67+
ip -6 route add 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:2::1
68+
ip -6 route add 2001:db8:3::/64 vrf v$h2 nexthop via 2001:db8:4::1
69+
}
70+
71+
h2_destroy()
72+
{
73+
ip -6 route del 2001:db8:3::/64 vrf v$h2
74+
ip -6 route del 2001:db8:1::/64 vrf v$h2
75+
ip -4 route del 192.0.2.16/28 vrf v$h2
76+
ip -4 route del 192.0.2.0/28 vrf v$h2
77+
simple_if_fini $h2 192.0.2.130/28 2001:db8:2::2/64 \
78+
192.0.2.146/28 2001:db8:4::2/64
79+
}
80+
81+
router_create()
82+
{
83+
ip link set dev $swp1 up
84+
85+
vlan_create $swp1 100
86+
ip link add name br1 type bridge vlan_filtering 0
87+
ip link set dev br1 address $(mac_get $swp1.100)
88+
ip link set dev $swp1.100 master br1
89+
__addr_add_del br1 add 192.0.2.2/28 2001:db8:1::2/64
90+
ip link set dev br1 up
91+
92+
vlan_create $swp1 200
93+
ip link add name br2 type bridge vlan_filtering 0
94+
ip link set dev br2 address $(mac_get $swp1.200)
95+
ip link set dev $swp1.200 master br2
96+
__addr_add_del br2 add 192.0.2.18/28 2001:db8:3::2/64
97+
ip link set dev br2 up
98+
99+
ip link set dev $swp2 up
100+
__addr_add_del $swp2 add 192.0.2.129/28 2001:db8:2::1/64 \
101+
192.0.2.145/28 2001:db8:4::1/64
102+
}
103+
104+
router_destroy()
105+
{
106+
__addr_add_del $swp2 del 192.0.2.129/28 2001:db8:2::1/64 \
107+
192.0.2.145/28 2001:db8:4::1/64
108+
ip link set dev $swp2 down
109+
110+
__addr_add_del br2 del 192.0.2.18/28 2001:db8:3::2/64
111+
ip link set dev $swp1.200 nomaster
112+
ip link del dev br2
113+
vlan_destroy $swp1 200
114+
115+
__addr_add_del br1 del 192.0.2.2/28 2001:db8:1::2/64
116+
ip link set dev $swp1.100 nomaster
117+
ip link del dev br1
118+
vlan_destroy $swp1 100
119+
120+
ip link set dev $swp1 down
121+
}
122+
123+
config_remaster()
124+
{
125+
log_info "Remaster bridge slaves"
126+
127+
ip link set dev $swp1.100 nomaster
128+
ip link set dev $swp1.200 nomaster
129+
sleep 2
130+
ip link set dev $swp1.200 master br2
131+
ip link set dev $swp1.100 master br1
132+
}
133+
134+
setup_prepare()
135+
{
136+
h1=${NETIFS[p1]}
137+
swp1=${NETIFS[p2]}
138+
139+
swp2=${NETIFS[p3]}
140+
h2=${NETIFS[p4]}
141+
142+
vrf_prepare
143+
144+
h1_create
145+
h2_create
146+
147+
router_create
148+
149+
forwarding_enable
150+
}
151+
152+
cleanup()
153+
{
154+
pre_cleanup
155+
156+
forwarding_restore
157+
158+
router_destroy
159+
160+
h2_destroy
161+
h1_destroy
162+
163+
vrf_cleanup
164+
}
165+
166+
ping_ipv4()
167+
{
168+
ping_test $h1 192.0.2.130 ": via 100"
169+
ping_test $h1 192.0.2.146 ": via 200"
170+
}
171+
172+
ping_ipv6()
173+
{
174+
ping6_test $h1 2001:db8:2::2 ": via 100"
175+
ping6_test $h1 2001:db8:4::2 ": via 200"
176+
}
177+
178+
trap cleanup EXIT
179+
180+
setup_prepare
181+
setup_wait
182+
183+
tests_run
184+
185+
exit $EXIT_STATUS

0 commit comments

Comments
 (0)