2 # SPDX-License-Identifier: GPL-2.0
5 # +--------------------------------+ +-----------------------------+
6 # | vrf-h1 | | vrf-h2 |
8 # | | 2001:db8:1::1/64 | | | 2001:db8:2::1/64 |
9 # | | default via 2001:db8:1::3 | | | default via 2001:db8:2::3 |
10 # +----|---------------------------+ +-|---------------------------+
12 # +----|------------------------------------------|---------------------------+
14 # | +--|------------------------------------------|-------------------------+ |
15 # | | + $swp1 br1 + $swp2 | |
16 # | | vid 10 pvid untagged vid 20 pvid untagged | |
18 # | | + vx10 + vx20 | |
19 # | | local 2001:db8:3::1 local 2001:db8:3::1 | |
20 # | | remote 2001:db8:3::2 remote 2001:db8:3::2 | |
21 # | | id 1010 id 1020 | |
22 # | | dstport 4789 dstport 4789 | |
23 # | | vid 10 pvid untagged vid 20 pvid untagged | |
26 # | | local 2001:db8:3::1 | |
27 # | | remote 2001:db8:3::2 | |
29 # | | dstport 4789 | |
30 # | | vid 4001 pvid untagged | |
32 # | +-----------------------------------+-----------------------------------+ |
34 # | +-----------------------------------|-----------------------------------+ |
36 # | | +--------------------------------+--------------------------------+ | |
38 # | | + vlan10 | vlan20 + | |
39 # | | | 2001:db8:1::2/64 | 2001:db8:2::2/64 | | |
41 # | | + vlan10-v (macvlan) + vlan20-v (macvlan) + | |
42 # | | 2001:db8:1::3/64 vlan4001 2001:db8:2::3/64 | |
43 # | | 00:00:5e:00:01:01 00:00:5e:00:01:01 | |
45 # | +-----------------------------------------------------------------------+ |
48 # | | 2001:db8:4::1/64 2001:db8:3::1 |
49 # +----|----------------------------------------------------------------------+
51 # +----|--------------------------------------------------------+
54 # | 2001:db8:4::2/64 |
56 # =============================================================================
60 # | | 2001:db8:5::2/64 |
61 # +----|--------------------------------------------------------+
63 # +----|----------------------------------------------------------------------+
64 # | + v2 (veth) +lo NS1 (netns) |
65 # | 2001:db8:5::1/64 2001:db8:3::2/128 |
67 # | +-----------------------------------------------------------------------+ |
69 # | | + vlan10-v (macvlan) vlan20-v (macvlan) + | |
70 # | | | 2001:db8:1::3/64 2001:db8:2::3/64 | | |
71 # | | | 00:00:5e:00:01:01 00:00:5e:00:01:01 | | |
72 # | | | vlan4001 | | |
73 # | | + vlan10 + vlan20 + | |
74 # | | | 2001:db8:1::3/64 | 2001:db8:2::3/64 | | |
76 # | | +--------------------------------+--------------------------------+ | |
78 # | +-----------------------------------|-----------------------------------+ |
80 # | +-----------------------------------+-----------------------------------+ |
82 # | | + vx10 + vx20 | |
83 # | | local 2001:db8:3::2 local 2001:db8:3::2 | |
84 # | | remote 2001:db8:3::1 remote 2001:db8:3::1 | |
85 # | | id 1010 id 1020 | |
86 # | | dstport 4789 dstport 4789 | |
87 # | | vid 10 pvid untagged vid 20 pvid untagged | |
90 # | | local 2001:db8:3::2 | |
91 # | | remote 2001:db8:3::1 | |
93 # | | dstport 4789 | |
94 # | | vid 4001 pvid untagged | |
96 # | | + w1 (veth) + w3 (veth) | |
97 # | | | vid 10 pvid untagged br1 | vid 20 pvid untagged | |
98 # | +--|------------------------------------------|-------------------------+ |
101 # | +--|----------------------+ +--|-------------------------+ |
102 # | | | vrf-h1 | | | vrf-h2 | |
103 # | | + w2 (veth) | | + w4 (veth) | |
104 # | | 2001:db8:1::4/64 | | 2001:db8:2::4/64 | |
105 # | | default via | | default via | |
106 # | | 2001:db8:1::3/64 | | 2001:db8:2::3/64 | |
107 # | +-------------------------+ +----------------------------+ |
108 # +---------------------------------------------------------------------------+
118 local vrf_name
=$1; shift
119 local if_name
=$1; shift
120 local ip_addr
=$1; shift
121 local gw_ip
=$1; shift
124 ip link
set dev
$if_name master
$vrf_name
125 ip link
set dev
$vrf_name up
126 ip link
set dev
$if_name up
128 ip address add
$ip_addr/64 dev
$if_name
129 ip neigh replace
$gw_ip lladdr
00:00:5e
:00:01:01 nud permanent \
131 ip route add default vrf
$vrf_name nexthop via
$gw_ip
137 local vrf_name
=$1; shift
138 local if_name
=$1; shift
139 local ip_addr
=$1; shift
140 local gw_ip
=$1; shift
142 ip route del default vrf
$vrf_name nexthop via
$gw_ip
143 ip neigh del
$gw_ip dev
$if_name
144 ip address del
$ip_addr/64 dev
$if_name
146 ip link
set dev
$if_name down
147 vrf_destroy
$vrf_name
152 hx_create
"vrf-h1" $h1 2001:db8
:1::1 2001:db8
:1::3
157 hx_destroy
"vrf-h1" $h1 2001:db8
:1::1 2001:db8
:1::3
162 hx_create
"vrf-h2" $h2 2001:db8
:2::1 2001:db8
:2::3
167 hx_destroy
"vrf-h2" $h2 2001:db8
:2::1 2001:db8
:2::3
172 ip link add name br1
type bridge vlan_filtering
1 vlan_default_pvid
0 \
174 # Make sure the bridge uses the MAC address of the local port and not
175 # that of the VxLAN's device.
176 ip link
set dev br1 address $
(mac_get
$swp1)
177 ip link
set dev br1 up
179 ip link
set dev
$rp1 up
180 ip address add dev
$rp1 2001:db8
:4::1/64
181 ip route add
2001:db8
:3::2/128 nexthop via
2001:db8
:4::2
183 ip link add name vx10
type vxlan id
1010 \
184 local 2001:db8
:3::1 remote
2001:db8
:3::2 dstport
4789 \
185 nolearning udp6zerocsumrx udp6zerocsumtx tos inherit ttl
100
186 ip link
set dev vx10 up
188 ip link
set dev vx10 master br1
189 bridge vlan add vid
10 dev vx10 pvid untagged
191 ip link add name vx20
type vxlan id
1020 \
192 local 2001:db8
:3::1 remote
2001:db8
:3::2 dstport
4789 \
193 nolearning udp6zerocsumrx udp6zerocsumtx tos inherit ttl
100
194 ip link
set dev vx20 up
196 ip link
set dev vx20 master br1
197 bridge vlan add vid
20 dev vx20 pvid untagged
199 ip link
set dev
$swp1 master br1
200 ip link
set dev
$swp1 up
202 ip link
set dev
$swp2 master br1
203 ip link
set dev
$swp2 up
205 ip link add name vx4001
type vxlan id
104001 \
206 local 2001:db8
:3::1 dstport
4789 \
207 nolearning udp6zerocsumrx udp6zerocsumtx tos inherit ttl
100
208 ip link
set dev vx4001 up
210 ip link
set dev vx4001 master br1
211 bridge vlan add vid
4001 dev vx4001 pvid untagged
213 ip address add
2001:db8
:3::1/128 dev lo
216 vrf_create
"vrf-green"
217 ip link
set dev vrf-green up
219 ip link add link br1 name vlan10 up master vrf-green
type vlan id
10
220 ip address add
2001:db8
:1::2/64 dev vlan10
221 ip link add link vlan10 name vlan10-v up master vrf-green \
222 address
00:00:5e
:00:01:01 type macvlan mode private
223 ip address add
2001:db8
:1::3/64 dev vlan10-v
225 ip link add link br1 name vlan20 up master vrf-green
type vlan id
20
226 ip address add
2001:db8
:2::2/64 dev vlan20
227 ip link add link vlan20 name vlan20-v up master vrf-green \
228 address
00:00:5e
:00:01:01 type macvlan mode private
229 ip address add
2001:db8
:2::3/64 dev vlan20-v
231 ip link add link br1 name vlan4001 up master vrf-green \
234 bridge vlan add vid
10 dev br1 self
235 bridge vlan add vid
20 dev br1 self
236 bridge vlan add vid
4001 dev br1 self
238 bridge fdb add
00:00:5e
:00:01:01 dev br1 self
local vlan
10
239 bridge fdb add
00:00:5e
:00:01:01 dev br1 self
local vlan
20
241 bridge vlan add vid
10 dev
$swp1 pvid untagged
242 bridge vlan add vid
20 dev
$swp2 pvid untagged
247 bridge vlan del vid
20 dev br1 self
248 bridge vlan del vid
10 dev br1 self
250 bridge fdb del
00:00:5e
:00:01:01 dev br1 self
local vlan
20
251 bridge fdb del
00:00:5e
:00:01:01 dev br1 self
local vlan
10
253 bridge vlan del vid
4001 dev br1 self
254 ip link del dev vlan4001
256 ip link del dev vlan20
258 ip link del dev vlan10
260 vrf_destroy
"vrf-green"
262 ip address del
2001:db8
:3::1/128 dev lo
264 bridge vlan del vid
20 dev
$swp2
265 ip link
set dev
$swp2 down
266 ip link
set dev
$swp2 nomaster
268 bridge vlan del vid
10 dev
$swp1
269 ip link
set dev
$swp1 down
270 ip link
set dev
$swp1 nomaster
272 bridge vlan del vid
4001 dev vx4001
273 ip link
set dev vx4001 nomaster
275 ip link
set dev vx4001 down
276 ip link del dev vx4001
278 bridge vlan del vid
20 dev vx20
279 ip link
set dev vx20 nomaster
281 ip link
set dev vx20 down
284 bridge vlan del vid
10 dev vx10
285 ip link
set dev vx10 nomaster
287 ip link
set dev vx10 down
290 ip route del
2001:db8
:3::2 nexthop via
2001:db8
:4::2
291 ip address del dev
$rp1 2001:db8
:4::1/64
292 ip link
set dev
$rp1 down
294 ip link
set dev br1 down
300 vrf_create
"vrf-spine"
301 ip link
set dev
$rp2 master vrf-spine
302 ip link
set dev v1 master vrf-spine
303 ip link
set dev vrf-spine up
304 ip link
set dev
$rp2 up
305 ip link
set dev v1 up
307 ip address add
2001:db8
:4::2/64 dev
$rp2
308 ip address add
2001:db8
:5::2/64 dev v1
310 ip route add
2001:db8
:3::1/128 vrf vrf-spine nexthop via \
312 ip route add
2001:db8
:3::2/128 vrf vrf-spine nexthop via \
318 ip route del
2001:db8
:3::2/128 vrf vrf-spine nexthop via \
320 ip route del
2001:db8
:3::1/128 vrf vrf-spine nexthop via \
323 ip address del
2001:db8
:5::2/64 dev v1
324 ip address del
2001:db8
:4::2/64 dev
$rp2
326 ip link
set dev v1 down
327 ip link
set dev
$rp2 down
328 vrf_destroy
"vrf-spine"
333 hx_create
"vrf-h1" w2
2001:db8
:1::4 2001:db8
:1::3
335 export -f ns_h1_create
339 hx_create
"vrf-h2" w4
2001:db8
:2::4 2001:db8
:2::3
341 export -f ns_h2_create
345 ip link add name br1
type bridge vlan_filtering
1 vlan_default_pvid
0 \
347 ip link
set dev br1 up
349 ip link
set dev v2 up
350 ip address add dev v2
2001:db8
:5::1/64
351 ip route add
2001:db8
:3::1 nexthop via
2001:db8
:5::2
353 ip link add name vx10
type vxlan id
1010 \
354 local 2001:db8
:3::2 remote
2001:db8
:3::1 dstport
4789 \
355 nolearning udp6zerocsumrx udp6zerocsumtx tos inherit ttl
100
356 ip link
set dev vx10 up
358 ip link
set dev vx10 master br1
359 bridge vlan add vid
10 dev vx10 pvid untagged
361 ip link add name vx20
type vxlan id
1020 \
362 local 2001:db8
:3::2 remote
2001:db8
:3::1 dstport
4789 \
363 nolearning udp6zerocsumrx udp6zerocsumtx tos inherit ttl
100
364 ip link
set dev vx20 up
366 ip link
set dev vx20 master br1
367 bridge vlan add vid
20 dev vx20 pvid untagged
369 ip link add name vx4001
type vxlan id
104001 \
370 local 2001:db8
:3::2 dstport
4789 \
371 nolearning udp6zerocsumrx udp6zerocsumtx tos inherit ttl
100
372 ip link
set dev vx4001 up
374 ip link
set dev vx4001 master br1
375 bridge vlan add vid
4001 dev vx4001 pvid untagged
377 ip link
set dev w1 master br1
378 ip link
set dev w1 up
379 bridge vlan add vid
10 dev w1 pvid untagged
381 ip link
set dev w3 master br1
382 ip link
set dev w3 up
383 bridge vlan add vid
20 dev w3 pvid untagged
385 ip address add
2001:db8
:3::2/128 dev lo
388 vrf_create
"vrf-green"
389 ip link
set dev vrf-green up
391 ip link add link br1 name vlan10 up master vrf-green
type vlan id
10
392 ip address add
2001:db8
:1::3/64 dev vlan10
393 ip link add link vlan10 name vlan10-v up master vrf-green \
394 address
00:00:5e
:00:01:01 type macvlan mode private
395 ip address add
2001:db8
:1::3/64 dev vlan10-v
397 ip link add link br1 name vlan20 up master vrf-green
type vlan id
20
398 ip address add
2001:db8
:2::3/64 dev vlan20
399 ip link add link vlan20 name vlan20-v up master vrf-green \
400 address
00:00:5e
:00:01:01 type macvlan mode private
401 ip address add
2001:db8
:2::3/64 dev vlan20-v
403 ip link add link br1 name vlan4001 up master vrf-green \
406 bridge vlan add vid
10 dev br1 self
407 bridge vlan add vid
20 dev br1 self
408 bridge vlan add vid
4001 dev br1 self
410 bridge fdb add
00:00:5e
:00:01:01 dev br1 self
local vlan
10
411 bridge fdb add
00:00:5e
:00:01:01 dev br1 self
local vlan
20
413 export -f ns_switch_create
417 ip link add name w1
type veth peer name w2
418 ip link add name w3
type veth peer name w4
420 ip link
set dev lo up
431 ip link
set dev v2 netns ns1
437 ip netns
exec ns1 ip link
set dev v2 netns
1
449 bridge fdb add
$mac1 dev vx10 self master extern_learn static \
451 bridge fdb add
$mac2 dev vx20 self master extern_learn static \
454 ip neigh add
$ip1 lladdr
$mac1 nud noarp dev vlan10 \
456 ip neigh add
$ip2 lladdr
$mac2 nud noarp dev vlan20 \
459 export -f __l2_vni_init
463 local h1_ns_mac
=$
(in_ns ns1 mac_get w2
)
464 local h2_ns_mac
=$
(in_ns ns1 mac_get w4
)
465 local h1_mac
=$
(mac_get
$h1)
466 local h2_mac
=$
(mac_get
$h2)
468 __l2_vni_init
$h1_ns_mac $h2_ns_mac 2001:db8
:1::4 2001:db8
:2::4 \
470 in_ns ns1 __l2_vni_init
$h1_mac $h2_mac 2001:db8
:1::1 2001:db8
:2::1 \
477 local vtep_ip
=$1; shift
478 local host1_ip
=$1; shift
479 local host2_ip
=$1; shift
481 bridge fdb add
$mac dev vx4001 self master extern_learn static \
482 dst
$vtep_ip vlan
4001
484 ip neigh add
$vtep_ip lladdr
$mac nud noarp dev vlan4001 extern_learn
486 ip route add
$host1_ip/128 vrf vrf-green nexthop via
$vtep_ip \
488 ip route add
$host2_ip/128 vrf vrf-green nexthop via
$vtep_ip \
491 export -f __l3_vni_init
495 local vlan4001_ns_mac
=$
(in_ns ns1 mac_get vlan4001
)
496 local vlan4001_mac
=$
(mac_get vlan4001
)
498 __l3_vni_init
$vlan4001_ns_mac 2001:db8
:3::2 2001:db8
:1::4 \
500 in_ns ns1 __l3_vni_init
$vlan4001_mac 2001:db8
:3::1 2001:db8
:1::1 \
522 ip link add name v1
type veth peer name v2
525 in_ns ns1 forwarding_enable
549 ping6_test
$h1 2001:db8
:2::1 ": local->local vid 10->vid 20"
550 ping6_test
$h1 2001:db8
:1::4 ": local->remote vid 10->vid 10"
551 ping6_test
$h2 2001:db8
:2::4 ": local->remote vid 20->vid 20"
552 ping6_test
$h1 2001:db8
:2::4 ": local->remote vid 10->vid 20"
553 ping6_test
$h2 2001:db8
:1::4 ": local->remote vid 20->vid 10"