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