xref: /linux/tools/testing/selftests/net/test_vxlan_mdb.sh (revision ef9226cd56b718c79184a3466d32984a51cb449c)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# This test is for checking VXLAN MDB functionality. The topology consists of
5# two sets of namespaces: One for the testing of IPv4 underlay and another for
6# IPv6. In both cases, both IPv4 and IPv6 overlay traffic are tested.
7#
8# Data path functionality is tested by sending traffic from one of the upper
9# namespaces and checking using ingress tc filters that the expected traffic
10# was received by one of the lower namespaces.
11#
12# +------------------------------------+ +------------------------------------+
13# | ns1_v4                             | | ns1_v6                             |
14# |                                    | |                                    |
15# |    br0.10    br0.4000  br0.20      | |    br0.10    br0.4000  br0.20      |
16# |       +         +         +        | |       +         +         +        |
17# |       |         |         |        | |       |         |         |        |
18# |       |         |         |        | |       |         |         |        |
19# |       +---------+---------+        | |       +---------+---------+        |
20# |                 |                  | |                 |                  |
21# |                 |                  | |                 |                  |
22# |                 +                  | |                 +                  |
23# |                br0                 | |                br0                 |
24# |                 +                  | |                 +                  |
25# |                 |                  | |                 |                  |
26# |                 |                  | |                 |                  |
27# |                 +                  | |                 +                  |
28# |                vx0                 | |                vx0                 |
29# |                                    | |                                    |
30# |                                    | |                                    |
31# |               veth0                | |               veth0                |
32# |                 +                  | |                 +                  |
33# +-----------------|------------------+ +-----------------|------------------+
34#                   |                                      |
35# +-----------------|------------------+ +-----------------|------------------+
36# |                 +                  | |                 +                  |
37# |               veth0                | |               veth0                |
38# |                                    | |                                    |
39# |                                    | |                                    |
40# |                vx0                 | |                vx0                 |
41# |                 +                  | |                 +                  |
42# |                 |                  | |                 |                  |
43# |                 |                  | |                 |                  |
44# |                 +                  | |                 +                  |
45# |                br0                 | |                br0                 |
46# |                 +                  | |                 +                  |
47# |                 |                  | |                 |                  |
48# |                 |                  | |                 |                  |
49# |       +---------+---------+        | |       +---------+---------+        |
50# |       |         |         |        | |       |         |         |        |
51# |       |         |         |        | |       |         |         |        |
52# |       +         +         +        | |       +         +         +        |
53# |    br0.10    br0.4000  br0.10      | |    br0.10    br0.4000  br0.20      |
54# |                                    | |                                    |
55# | ns2_v4                             | | ns2_v6                             |
56# +------------------------------------+ +------------------------------------+
57
58source lib.sh
59ret=0
60
61CONTROL_PATH_TESTS="
62	basic_star_g_ipv4_ipv4
63	basic_star_g_ipv6_ipv4
64	basic_star_g_ipv4_ipv6
65	basic_star_g_ipv6_ipv6
66	basic_sg_ipv4_ipv4
67	basic_sg_ipv6_ipv4
68	basic_sg_ipv4_ipv6
69	basic_sg_ipv6_ipv6
70	star_g_ipv4_ipv4
71	star_g_ipv6_ipv4
72	star_g_ipv4_ipv6
73	star_g_ipv6_ipv6
74	sg_ipv4_ipv4
75	sg_ipv6_ipv4
76	sg_ipv4_ipv6
77	sg_ipv6_ipv6
78	dump_ipv4_ipv4
79	dump_ipv6_ipv4
80	dump_ipv4_ipv6
81	dump_ipv6_ipv6
82	flush
83"
84
85DATA_PATH_TESTS="
86	encap_params_ipv4_ipv4
87	encap_params_ipv6_ipv4
88	encap_params_ipv4_ipv6
89	encap_params_ipv6_ipv6
90	starg_exclude_ir_ipv4_ipv4
91	starg_exclude_ir_ipv6_ipv4
92	starg_exclude_ir_ipv4_ipv6
93	starg_exclude_ir_ipv6_ipv6
94	starg_include_ir_ipv4_ipv4
95	starg_include_ir_ipv6_ipv4
96	starg_include_ir_ipv4_ipv6
97	starg_include_ir_ipv6_ipv6
98	starg_exclude_p2mp_ipv4_ipv4
99	starg_exclude_p2mp_ipv6_ipv4
100	starg_exclude_p2mp_ipv4_ipv6
101	starg_exclude_p2mp_ipv6_ipv6
102	starg_include_p2mp_ipv4_ipv4
103	starg_include_p2mp_ipv6_ipv4
104	starg_include_p2mp_ipv4_ipv6
105	starg_include_p2mp_ipv6_ipv6
106	egress_vni_translation_ipv4_ipv4
107	egress_vni_translation_ipv6_ipv4
108	egress_vni_translation_ipv4_ipv6
109	egress_vni_translation_ipv6_ipv6
110	all_zeros_mdb_ipv4
111	all_zeros_mdb_ipv6
112	mdb_fdb_ipv4_ipv4
113	mdb_fdb_ipv6_ipv4
114	mdb_fdb_ipv4_ipv6
115	mdb_fdb_ipv6_ipv6
116	mdb_torture_ipv4_ipv4
117	mdb_torture_ipv6_ipv4
118	mdb_torture_ipv4_ipv6
119	mdb_torture_ipv6_ipv6
120"
121
122# All tests in this script. Can be overridden with -t option.
123TESTS="
124	$CONTROL_PATH_TESTS
125	$DATA_PATH_TESTS
126"
127VERBOSE=0
128PAUSE_ON_FAIL=no
129PAUSE=no
130
131################################################################################
132# Utilities
133
134log_test()
135{
136	local rc=$1
137	local expected=$2
138	local msg="$3"
139
140	if [ ${rc} -eq ${expected} ]; then
141		printf "TEST: %-60s  [ OK ]\n" "${msg}"
142		nsuccess=$((nsuccess+1))
143	else
144		ret=1
145		nfail=$((nfail+1))
146		printf "TEST: %-60s  [FAIL]\n" "${msg}"
147		if [ "$VERBOSE" = "1" ]; then
148			echo "    rc=$rc, expected $expected"
149		fi
150
151		if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
152		echo
153			echo "hit enter to continue, 'q' to quit"
154			read a
155			[ "$a" = "q" ] && exit 1
156		fi
157	fi
158
159	if [ "${PAUSE}" = "yes" ]; then
160		echo
161		echo "hit enter to continue, 'q' to quit"
162		read a
163		[ "$a" = "q" ] && exit 1
164	fi
165
166	[ "$VERBOSE" = "1" ] && echo
167}
168
169run_cmd()
170{
171	local cmd="$1"
172	local out
173	local stderr="2>/dev/null"
174
175	if [ "$VERBOSE" = "1" ]; then
176		printf "COMMAND: $cmd\n"
177		stderr=
178	fi
179
180	out=$(eval $cmd $stderr)
181	rc=$?
182	if [ "$VERBOSE" = "1" -a -n "$out" ]; then
183		echo "    $out"
184	fi
185
186	return $rc
187}
188
189tc_check_packets()
190{
191	local ns=$1; shift
192	local id=$1; shift
193	local handle=$1; shift
194	local count=$1; shift
195	local pkts
196
197	sleep 0.1
198	pkts=$(tc -n $ns -j -s filter show $id \
199		| jq ".[] | select(.options.handle == $handle) | \
200		.options.actions[0].stats.packets")
201	[[ $pkts == $count ]]
202}
203
204################################################################################
205# Setup
206
207setup_common_ns()
208{
209	local ns=$1; shift
210	local local_addr=$1; shift
211
212	ip netns exec $ns sysctl -qw net.ipv4.ip_forward=1
213	ip netns exec $ns sysctl -qw net.ipv4.fib_multipath_use_neigh=1
214	ip netns exec $ns sysctl -qw net.ipv4.conf.default.ignore_routes_with_linkdown=1
215	ip netns exec $ns sysctl -qw net.ipv6.conf.all.keep_addr_on_down=1
216	ip netns exec $ns sysctl -qw net.ipv6.conf.all.forwarding=1
217	ip netns exec $ns sysctl -qw net.ipv6.conf.default.forwarding=1
218	ip netns exec $ns sysctl -qw net.ipv6.conf.default.ignore_routes_with_linkdown=1
219	ip netns exec $ns sysctl -qw net.ipv6.conf.all.accept_dad=0
220	ip netns exec $ns sysctl -qw net.ipv6.conf.default.accept_dad=0
221
222	ip -n $ns link set dev lo up
223	ip -n $ns address add $local_addr dev lo
224
225	ip -n $ns link set dev veth0 up
226
227	ip -n $ns link add name br0 up type bridge vlan_filtering 1 \
228		vlan_default_pvid 0 mcast_snooping 0
229
230	ip -n $ns link add link br0 name br0.10 up type vlan id 10
231	bridge -n $ns vlan add vid 10 dev br0 self
232
233	ip -n $ns link add link br0 name br0.20 up type vlan id 20
234	bridge -n $ns vlan add vid 20 dev br0 self
235
236	ip -n $ns link add link br0 name br0.4000 up type vlan id 4000
237	bridge -n $ns vlan add vid 4000 dev br0 self
238
239	ip -n $ns link add name vx0 up master br0 type vxlan \
240		local $local_addr dstport 4789 external vnifilter
241	bridge -n $ns link set dev vx0 vlan_tunnel on
242
243	bridge -n $ns vlan add vid 10 dev vx0
244	bridge -n $ns vlan add vid 10 dev vx0 tunnel_info id 10010
245	bridge -n $ns vni add vni 10010 dev vx0
246
247	bridge -n $ns vlan add vid 20 dev vx0
248	bridge -n $ns vlan add vid 20 dev vx0 tunnel_info id 10020
249	bridge -n $ns vni add vni 10020 dev vx0
250
251	bridge -n $ns vlan add vid 4000 dev vx0 pvid
252	bridge -n $ns vlan add vid 4000 dev vx0 tunnel_info id 14000
253	bridge -n $ns vni add vni 14000 dev vx0
254}
255
256setup_common()
257{
258	local ns1=$1; shift
259	local ns2=$1; shift
260	local local_addr1=$1; shift
261	local local_addr2=$1; shift
262
263	ip link add name veth0 type veth peer name veth1
264	ip link set dev veth0 netns $ns1 name veth0
265	ip link set dev veth1 netns $ns2 name veth0
266
267	setup_common_ns $ns1 $local_addr1
268	setup_common_ns $ns2 $local_addr2
269}
270
271setup_v4()
272{
273	setup_ns ns1_v4 ns2_v4
274	setup_common $ns1_v4 $ns2_v4 192.0.2.1 192.0.2.2
275
276	ip -n $ns1_v4 address add 192.0.2.17/28 dev veth0
277	ip -n $ns2_v4 address add 192.0.2.18/28 dev veth0
278
279	ip -n $ns1_v4 route add default via 192.0.2.18
280	ip -n $ns2_v4 route add default via 192.0.2.17
281}
282
283cleanup_v4()
284{
285	cleanup_ns $ns2_v4 $ns1_v4
286}
287
288setup_v6()
289{
290	setup_ns ns1_v6 ns2_v6
291	setup_common $ns1_v6 $ns2_v6 2001:db8:1::1 2001:db8:1::2
292
293	ip -n $ns1_v6 address add 2001:db8:2::1/64 dev veth0 nodad
294	ip -n $ns2_v6 address add 2001:db8:2::2/64 dev veth0 nodad
295
296	ip -n $ns1_v6 route add default via 2001:db8:2::2
297	ip -n $ns2_v6 route add default via 2001:db8:2::1
298}
299
300cleanup_v6()
301{
302	cleanup_ns $ns2_v6 $ns1_v6
303}
304
305setup()
306{
307	set -e
308
309	setup_v4
310	setup_v6
311
312	sleep 5
313
314	set +e
315}
316
317cleanup()
318{
319	cleanup_v6 &> /dev/null
320	cleanup_v4 &> /dev/null
321}
322
323################################################################################
324# Tests - Control path
325
326basic_common()
327{
328	local ns1=$1; shift
329	local grp_key=$1; shift
330	local vtep_ip=$1; shift
331
332	# Test basic control path operations common to all MDB entry types.
333
334	# Basic add, replace and delete behavior.
335	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 $grp_key permanent dst $vtep_ip src_vni 10010"
336	log_test $? 0 "MDB entry addition"
337	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 $grp_key src_vni 10010"
338	log_test $? 0 "MDB entry presence after addition"
339
340	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 $grp_key permanent dst $vtep_ip src_vni 10010"
341	log_test $? 0 "MDB entry replacement"
342	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 $grp_key src_vni 10010"
343	log_test $? 0 "MDB entry presence after replacement"
344
345	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 $grp_key dst $vtep_ip src_vni 10010"
346	log_test $? 0 "MDB entry deletion"
347	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 $grp_key src_vni 10010"
348	log_test $? 254 "MDB entry presence after deletion"
349
350	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 $grp_key dst $vtep_ip src_vni 10010"
351	log_test $? 255 "Non-existent MDB entry deletion"
352
353	# Default protocol and replacement.
354	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 $grp_key permanent dst $vtep_ip src_vni 10010"
355	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 $grp_key src_vni 10010 | grep \"proto static\""
356	log_test $? 0 "MDB entry default protocol"
357
358	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 $grp_key permanent proto 123 dst $vtep_ip src_vni 10010"
359	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 $grp_key src_vni 10010 | grep \"proto 123\""
360	log_test $? 0 "MDB entry protocol replacement"
361
362	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 $grp_key dst $vtep_ip src_vni 10010"
363
364	# Default destination port and replacement.
365	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 $grp_key permanent dst $vtep_ip src_vni 10010"
366	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 $grp_key src_vni 10010 | grep \" dst_port \""
367	log_test $? 1 "MDB entry default destination port"
368
369	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 $grp_key permanent dst $vtep_ip dst_port 1234 src_vni 10010"
370	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 $grp_key src_vni 10010 | grep \"dst_port 1234\""
371	log_test $? 0 "MDB entry destination port replacement"
372
373	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 $grp_key dst $vtep_ip src_vni 10010"
374
375	# Default destination VNI and replacement.
376	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 $grp_key permanent dst $vtep_ip src_vni 10010"
377	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 $grp_key src_vni 10010 | grep \" vni \""
378	log_test $? 1 "MDB entry default destination VNI"
379
380	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 $grp_key permanent dst $vtep_ip vni 1234 src_vni 10010"
381	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 $grp_key src_vni 10010 | grep \"vni 1234\""
382	log_test $? 0 "MDB entry destination VNI replacement"
383
384	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 $grp_key dst $vtep_ip src_vni 10010"
385
386	# Default outgoing interface and replacement.
387	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 $grp_key permanent dst $vtep_ip src_vni 10010"
388	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 $grp_key src_vni 10010 | grep \" via \""
389	log_test $? 1 "MDB entry default outgoing interface"
390
391	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 $grp_key permanent dst $vtep_ip src_vni 10010 via veth0"
392	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 $grp_key src_vni 10010 | grep \"via veth0\""
393	log_test $? 0 "MDB entry outgoing interface replacement"
394
395	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 $grp_key dst $vtep_ip src_vni 10010"
396
397	# Common error cases.
398	run_cmd "bridge -n $ns1 mdb add dev vx0 port veth0 $grp_key permanent dst $vtep_ip src_vni 10010"
399	log_test $? 255 "MDB entry with mismatch between device and port"
400
401	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 $grp_key temp dst $vtep_ip src_vni 10010"
402	log_test $? 255 "MDB entry with temp state"
403
404	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 $grp_key permanent vid 10 dst $vtep_ip src_vni 10010"
405	log_test $? 255 "MDB entry with VLAN"
406
407	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp 01:02:03:04:05:06 permanent dst $vtep_ip src_vni 10010"
408	log_test $? 255 "MDB entry MAC address"
409
410	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 $grp_key permanent"
411	log_test $? 255 "MDB entry without extended parameters"
412
413	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 $grp_key permanent proto 3 dst $vtep_ip src_vni 10010"
414	log_test $? 255 "MDB entry with an invalid protocol"
415
416	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 $grp_key permanent dst $vtep_ip vni $((2 ** 24)) src_vni 10010"
417	log_test $? 255 "MDB entry with an invalid destination VNI"
418
419	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 $grp_key permanent dst $vtep_ip src_vni $((2 ** 24))"
420	log_test $? 255 "MDB entry with an invalid source VNI"
421
422	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 $grp_key permanent src_vni 10010"
423	log_test $? 255 "MDB entry without a remote destination IP"
424
425	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 $grp_key permanent dst $vtep_ip src_vni 10010"
426	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 $grp_key permanent dst $vtep_ip src_vni 10010"
427	log_test $? 255 "Duplicate MDB entries"
428	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 $grp_key dst $vtep_ip src_vni 10010"
429}
430
431basic_star_g_ipv4_ipv4()
432{
433	local ns1=$ns1_v4
434	local grp_key="grp 239.1.1.1"
435	local vtep_ip=198.51.100.100
436
437	echo
438	echo "Control path: Basic (*, G) operations - IPv4 overlay / IPv4 underlay"
439	echo "--------------------------------------------------------------------"
440
441	basic_common $ns1 "$grp_key" $vtep_ip
442}
443
444basic_star_g_ipv6_ipv4()
445{
446	local ns1=$ns1_v4
447	local grp_key="grp ff0e::1"
448	local vtep_ip=198.51.100.100
449
450	echo
451	echo "Control path: Basic (*, G) operations - IPv6 overlay / IPv4 underlay"
452	echo "--------------------------------------------------------------------"
453
454	basic_common $ns1 "$grp_key" $vtep_ip
455}
456
457basic_star_g_ipv4_ipv6()
458{
459	local ns1=$ns1_v6
460	local grp_key="grp 239.1.1.1"
461	local vtep_ip=2001:db8:1000::1
462
463	echo
464	echo "Control path: Basic (*, G) operations - IPv4 overlay / IPv6 underlay"
465	echo "--------------------------------------------------------------------"
466
467	basic_common $ns1 "$grp_key" $vtep_ip
468}
469
470basic_star_g_ipv6_ipv6()
471{
472	local ns1=$ns1_v6
473	local grp_key="grp ff0e::1"
474	local vtep_ip=2001:db8:1000::1
475
476	echo
477	echo "Control path: Basic (*, G) operations - IPv6 overlay / IPv6 underlay"
478	echo "--------------------------------------------------------------------"
479
480	basic_common $ns1 "$grp_key" $vtep_ip
481}
482
483basic_sg_ipv4_ipv4()
484{
485	local ns1=$ns1_v4
486	local grp_key="grp 239.1.1.1 src 192.0.2.129"
487	local vtep_ip=198.51.100.100
488
489	echo
490	echo "Control path: Basic (S, G) operations - IPv4 overlay / IPv4 underlay"
491	echo "--------------------------------------------------------------------"
492
493	basic_common $ns1 "$grp_key" $vtep_ip
494}
495
496basic_sg_ipv6_ipv4()
497{
498	local ns1=$ns1_v4
499	local grp_key="grp ff0e::1 src 2001:db8:100::1"
500	local vtep_ip=198.51.100.100
501
502	echo
503	echo "Control path: Basic (S, G) operations - IPv6 overlay / IPv4 underlay"
504	echo "---------------------------------------------------------------------"
505
506	basic_common $ns1 "$grp_key" $vtep_ip
507}
508
509basic_sg_ipv4_ipv6()
510{
511	local ns1=$ns1_v6
512	local grp_key="grp 239.1.1.1 src 192.0.2.129"
513	local vtep_ip=2001:db8:1000::1
514
515	echo
516	echo "Control path: Basic (S, G) operations - IPv4 overlay / IPv6 underlay"
517	echo "--------------------------------------------------------------------"
518
519	basic_common $ns1 "$grp_key" $vtep_ip
520}
521
522basic_sg_ipv6_ipv6()
523{
524	local ns1=$ns1_v6
525	local grp_key="grp ff0e::1 src 2001:db8:100::1"
526	local vtep_ip=2001:db8:1000::1
527
528	echo
529	echo "Control path: Basic (S, G) operations - IPv6 overlay / IPv6 underlay"
530	echo "--------------------------------------------------------------------"
531
532	basic_common $ns1 "$grp_key" $vtep_ip
533}
534
535star_g_common()
536{
537	local ns1=$1; shift
538	local grp=$1; shift
539	local src1=$1; shift
540	local src2=$1; shift
541	local src3=$1; shift
542	local vtep_ip=$1; shift
543	local all_zeros_grp=$1; shift
544
545	# Test control path operations specific to (*, G) entries.
546
547	# Basic add, replace and delete behavior.
548	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $src1 dst $vtep_ip src_vni 10010"
549	log_test $? 0 "(*, G) MDB entry addition with source list"
550	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src_vni 10010"
551	log_test $? 0 "(*, G) MDB entry presence after addition"
552	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010"
553	log_test $? 0 "(S, G) MDB entry presence after addition"
554
555	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $src1 dst $vtep_ip src_vni 10010"
556	log_test $? 0 "(*, G) MDB entry replacement with source list"
557	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src_vni 10010"
558	log_test $? 0 "(*, G) MDB entry presence after replacement"
559	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010"
560	log_test $? 0 "(S, G) MDB entry presence after replacement"
561
562	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep_ip src_vni 10010"
563	log_test $? 0 "(*, G) MDB entry deletion"
564	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src_vni 10010"
565	log_test $? 254 "(*, G) MDB entry presence after deletion"
566	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010"
567	log_test $? 254 "(S, G) MDB entry presence after deletion"
568
569	# Default filter mode and replacement.
570	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp permanent dst $vtep_ip src_vni 10010"
571	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src_vni 10010 | grep exclude"
572	log_test $? 0 "(*, G) MDB entry default filter mode"
573
574	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent filter_mode include source_list $src1 dst $vtep_ip src_vni 10010"
575	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src_vni 10010 | grep include"
576	log_test $? 0 "(*, G) MDB entry after replacing filter mode to \"include\""
577	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010"
578	log_test $? 0 "(S, G) MDB entry after replacing filter mode to \"include\""
579	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010 | grep blocked"
580	log_test $? 1 "\"blocked\" flag after replacing filter mode to \"include\""
581
582	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $src1 dst $vtep_ip src_vni 10010"
583	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src_vni 10010 | grep exclude"
584	log_test $? 0 "(*, G) MDB entry after replacing filter mode to \"exclude\""
585	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grep grp $grp src $src1 src_vni 10010"
586	log_test $? 0 "(S, G) MDB entry after replacing filter mode to \"exclude\""
587	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010 | grep blocked"
588	log_test $? 0 "\"blocked\" flag after replacing filter mode to \"exclude\""
589
590	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep_ip src_vni 10010"
591
592	# Default source list and replacement.
593	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp permanent dst $vtep_ip src_vni 10010"
594	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src_vni 10010 | grep source_list"
595	log_test $? 1 "(*, G) MDB entry default source list"
596
597	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $src1,$src2,$src3 dst $vtep_ip src_vni 10010"
598	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010"
599	log_test $? 0 "(S, G) MDB entry of 1st source after replacing source list"
600	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src2 src_vni 10010"
601	log_test $? 0 "(S, G) MDB entry of 2nd source after replacing source list"
602	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src3 src_vni 10010"
603	log_test $? 0 "(S, G) MDB entry of 3rd source after replacing source list"
604
605	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $src1,$src3 dst $vtep_ip src_vni 10010"
606	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010"
607	log_test $? 0 "(S, G) MDB entry of 1st source after removing source"
608	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src2 src_vni 10010"
609	log_test $? 254 "(S, G) MDB entry of 2nd source after removing source"
610	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src3 src_vni 10010"
611	log_test $? 0 "(S, G) MDB entry of 3rd source after removing source"
612
613	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep_ip src_vni 10010"
614
615	# Default protocol and replacement.
616	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $src1 dst $vtep_ip src_vni 10010"
617	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src_vni 10010 | grep \"proto static\""
618	log_test $? 0 "(*, G) MDB entry default protocol"
619	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010 | grep \"proto static\""
620	log_test $? 0 "(S, G) MDB entry default protocol"
621
622	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $src1 proto bgp dst $vtep_ip src_vni 10010"
623	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src_vni 10010 | grep \"proto bgp\""
624	log_test $? 0 "(*, G) MDB entry protocol after replacement"
625	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010 | grep \"proto bgp\""
626	log_test $? 0 "(S, G) MDB entry protocol after replacement"
627
628	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep_ip src_vni 10010"
629
630	# Default destination port and replacement.
631	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $src1 dst $vtep_ip src_vni 10010"
632	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src_vni 10010 | grep \" dst_port \""
633	log_test $? 1 "(*, G) MDB entry default destination port"
634	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010 | grep \" dst_port \""
635	log_test $? 1 "(S, G) MDB entry default destination port"
636
637	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $src1 dst $vtep_ip dst_port 1234 src_vni 10010"
638	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src_vni 10010 | grep \" dst_port 1234 \""
639	log_test $? 0 "(*, G) MDB entry destination port after replacement"
640	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010 | grep \" dst_port 1234 \""
641	log_test $? 0 "(S, G) MDB entry destination port after replacement"
642
643	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep_ip src_vni 10010"
644
645	# Default destination VNI and replacement.
646	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $src1 dst $vtep_ip src_vni 10010"
647	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src_vni 10010 | grep \" vni \""
648	log_test $? 1 "(*, G) MDB entry default destination VNI"
649	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010 | grep \" vni \""
650	log_test $? 1 "(S, G) MDB entry default destination VNI"
651
652	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $src1 dst $vtep_ip vni 1234 src_vni 10010"
653	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src_vni 10010 | grep \" vni 1234 \""
654	log_test $? 0 "(*, G) MDB entry destination VNI after replacement"
655	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010 | grep \" vni 1234 \""
656	log_test $? 0 "(S, G) MDB entry destination VNI after replacement"
657
658	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep_ip src_vni 10010"
659
660	# Default outgoing interface and replacement.
661	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $src1 dst $vtep_ip src_vni 10010"
662	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src_vni 10010 | grep \" via \""
663	log_test $? 1 "(*, G) MDB entry default outgoing interface"
664	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010 | grep \" via \""
665	log_test $? 1 "(S, G) MDB entry default outgoing interface"
666
667	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $src1 dst $vtep_ip src_vni 10010 via veth0"
668	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src_vni 10010 | grep \" via veth0 \""
669	log_test $? 0 "(*, G) MDB entry outgoing interface after replacement"
670	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src1 src_vni 10010 | grep \" via veth0 \""
671	log_test $? 0 "(S, G) MDB entry outgoing interface after replacement"
672
673	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep_ip src_vni 10010"
674
675	# Error cases.
676	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $all_zeros_grp permanent filter_mode exclude dst $vtep_ip src_vni 10010"
677	log_test $? 255 "All-zeros group with filter mode"
678
679	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $all_zeros_grp permanent source_list $src1 dst $vtep_ip src_vni 10010"
680	log_test $? 255 "All-zeros group with source list"
681
682	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp permanent filter_mode include dst $vtep_ip src_vni 10010"
683	log_test $? 255 "(*, G) INCLUDE with an empty source list"
684
685	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $grp dst $vtep_ip src_vni 10010"
686	log_test $? 255 "Invalid source in source list"
687
688	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp permanent source_list $src1 dst $vtep_ip src_vni 10010"
689	log_test $? 255 "Source list without filter mode"
690}
691
692star_g_ipv4_ipv4()
693{
694	local ns1=$ns1_v4
695	local grp=239.1.1.1
696	local src1=192.0.2.129
697	local src2=192.0.2.130
698	local src3=192.0.2.131
699	local vtep_ip=198.51.100.100
700	local all_zeros_grp=0.0.0.0
701
702	echo
703	echo "Control path: (*, G) operations - IPv4 overlay / IPv4 underlay"
704	echo "--------------------------------------------------------------"
705
706	star_g_common $ns1 $grp $src1 $src2 $src3 $vtep_ip $all_zeros_grp
707}
708
709star_g_ipv6_ipv4()
710{
711	local ns1=$ns1_v4
712	local grp=ff0e::1
713	local src1=2001:db8:100::1
714	local src2=2001:db8:100::2
715	local src3=2001:db8:100::3
716	local vtep_ip=198.51.100.100
717	local all_zeros_grp=::
718
719	echo
720	echo "Control path: (*, G) operations - IPv6 overlay / IPv4 underlay"
721	echo "--------------------------------------------------------------"
722
723	star_g_common $ns1 $grp $src1 $src2 $src3 $vtep_ip $all_zeros_grp
724}
725
726star_g_ipv4_ipv6()
727{
728	local ns1=$ns1_v6
729	local grp=239.1.1.1
730	local src1=192.0.2.129
731	local src2=192.0.2.130
732	local src3=192.0.2.131
733	local vtep_ip=2001:db8:1000::1
734	local all_zeros_grp=0.0.0.0
735
736	echo
737	echo "Control path: (*, G) operations - IPv4 overlay / IPv6 underlay"
738	echo "--------------------------------------------------------------"
739
740	star_g_common $ns1 $grp $src1 $src2 $src3 $vtep_ip $all_zeros_grp
741}
742
743star_g_ipv6_ipv6()
744{
745	local ns1=$ns1_v6
746	local grp=ff0e::1
747	local src1=2001:db8:100::1
748	local src2=2001:db8:100::2
749	local src3=2001:db8:100::3
750	local vtep_ip=2001:db8:1000::1
751	local all_zeros_grp=::
752
753	echo
754	echo "Control path: (*, G) operations - IPv6 overlay / IPv6 underlay"
755	echo "--------------------------------------------------------------"
756
757	star_g_common $ns1 $grp $src1 $src2 $src3 $vtep_ip $all_zeros_grp
758}
759
760sg_common()
761{
762	local ns1=$1; shift
763	local grp=$1; shift
764	local src=$1; shift
765	local vtep_ip=$1; shift
766	local all_zeros_grp=$1; shift
767
768	# Test control path operations specific to (S, G) entries.
769
770	# Default filter mode.
771	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp src $src permanent dst $vtep_ip src_vni 10010"
772	run_cmd "bridge -n $ns1 -d -s mdb get dev vx0 grp $grp src $src src_vni 10010 | grep include"
773	log_test $? 0 "(S, G) MDB entry default filter mode"
774
775	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp src $src permanent dst $vtep_ip src_vni 10010"
776
777	# Error cases.
778	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp src $src permanent filter_mode include dst $vtep_ip src_vni 10010"
779	log_test $? 255 "(S, G) with filter mode"
780
781	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp src $src permanent source_list $src dst $vtep_ip src_vni 10010"
782	log_test $? 255 "(S, G) with source list"
783
784	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp src $grp permanent dst $vtep_ip src_vni 10010"
785	log_test $? 255 "(S, G) with an invalid source list"
786
787	run_cmd "bridge -n $ns1 mdb add dev vx0 port vx0 grp $all_zeros_grp src $src permanent dst $vtep_ip src_vni 10010"
788	log_test $? 255 "All-zeros group with source"
789}
790
791sg_ipv4_ipv4()
792{
793	local ns1=$ns1_v4
794	local grp=239.1.1.1
795	local src=192.0.2.129
796	local vtep_ip=198.51.100.100
797	local all_zeros_grp=0.0.0.0
798
799	echo
800	echo "Control path: (S, G) operations - IPv4 overlay / IPv4 underlay"
801	echo "--------------------------------------------------------------"
802
803	sg_common $ns1 $grp $src $vtep_ip $all_zeros_grp
804}
805
806sg_ipv6_ipv4()
807{
808	local ns1=$ns1_v4
809	local grp=ff0e::1
810	local src=2001:db8:100::1
811	local vtep_ip=198.51.100.100
812	local all_zeros_grp=::
813
814	echo
815	echo "Control path: (S, G) operations - IPv6 overlay / IPv4 underlay"
816	echo "--------------------------------------------------------------"
817
818	sg_common $ns1 $grp $src $vtep_ip $all_zeros_grp
819}
820
821sg_ipv4_ipv6()
822{
823	local ns1=$ns1_v6
824	local grp=239.1.1.1
825	local src=192.0.2.129
826	local vtep_ip=2001:db8:1000::1
827	local all_zeros_grp=0.0.0.0
828
829	echo
830	echo "Control path: (S, G) operations - IPv4 overlay / IPv6 underlay"
831	echo "--------------------------------------------------------------"
832
833	sg_common $ns1 $grp $src $vtep_ip $all_zeros_grp
834}
835
836sg_ipv6_ipv6()
837{
838	local ns1=$ns1_v6
839	local grp=ff0e::1
840	local src=2001:db8:100::1
841	local vtep_ip=2001:db8:1000::1
842	local all_zeros_grp=::
843
844	echo
845	echo "Control path: (S, G) operations - IPv6 overlay / IPv6 underlay"
846	echo "--------------------------------------------------------------"
847
848	sg_common $ns1 $grp $src $vtep_ip $all_zeros_grp
849}
850
851ipv4_grps_get()
852{
853	local max_grps=$1; shift
854	local i
855
856	for i in $(seq 0 $((max_grps - 1))); do
857		echo "239.1.1.$i"
858	done
859}
860
861ipv6_grps_get()
862{
863	local max_grps=$1; shift
864	local i
865
866	for i in $(seq 0 $((max_grps - 1))); do
867		echo "ff0e::$(printf %x $i)"
868	done
869}
870
871dump_common()
872{
873	local ns1=$1; shift
874	local local_addr=$1; shift
875	local remote_prefix=$1; shift
876	local fn=$1; shift
877	local max_vxlan_devs=2
878	local max_remotes=64
879	local max_grps=256
880	local num_entries
881	local batch_file
882	local grp
883	local i j
884
885	# The kernel maintains various markers for the MDB dump. Add a test for
886	# large scale MDB dump to make sure that all the configured entries are
887	# dumped and that the markers are used correctly.
888
889	# Create net devices.
890	for i in $(seq 1 $max_vxlan_devs); do
891		ip -n $ns1 link add name vx-test${i} up type vxlan \
892			local $local_addr dstport 4789 external vnifilter
893	done
894
895	# Create batch file with MDB entries.
896	batch_file=$(mktemp)
897	for i in $(seq 1 $max_vxlan_devs); do
898		for j in $(seq 1 $max_remotes); do
899			for grp in $($fn $max_grps); do
900				echo "mdb add dev vx-test${i} port vx-test${i} grp $grp permanent dst ${remote_prefix}${j}" >> $batch_file
901			done
902		done
903	done
904
905	# Program the batch file and check for expected number of entries.
906	bridge -n $ns1 -b $batch_file
907	for i in $(seq 1 $max_vxlan_devs); do
908		num_entries=$(bridge -n $ns1 mdb show dev vx-test${i} | grep "permanent" | wc -l)
909		[[ $num_entries -eq $((max_grps * max_remotes)) ]]
910		log_test $? 0 "Large scale dump - VXLAN device #$i"
911	done
912
913	rm -rf $batch_file
914}
915
916dump_ipv4_ipv4()
917{
918	local ns1=$ns1_v4
919	local local_addr=192.0.2.1
920	local remote_prefix=198.51.100.
921	local fn=ipv4_grps_get
922
923	echo
924	echo "Control path: Large scale MDB dump - IPv4 overlay / IPv4 underlay"
925	echo "-----------------------------------------------------------------"
926
927	dump_common $ns1 $local_addr $remote_prefix $fn
928}
929
930dump_ipv6_ipv4()
931{
932	local ns1=$ns1_v4
933	local local_addr=192.0.2.1
934	local remote_prefix=198.51.100.
935	local fn=ipv6_grps_get
936
937	echo
938	echo "Control path: Large scale MDB dump - IPv6 overlay / IPv4 underlay"
939	echo "-----------------------------------------------------------------"
940
941	dump_common $ns1 $local_addr $remote_prefix $fn
942}
943
944dump_ipv4_ipv6()
945{
946	local ns1=$ns1_v6
947	local local_addr=2001:db8:1::1
948	local remote_prefix=2001:db8:1000::
949	local fn=ipv4_grps_get
950
951	echo
952	echo "Control path: Large scale MDB dump - IPv4 overlay / IPv6 underlay"
953	echo "-----------------------------------------------------------------"
954
955	dump_common $ns1 $local_addr $remote_prefix $fn
956}
957
958dump_ipv6_ipv6()
959{
960	local ns1=$ns1_v6
961	local local_addr=2001:db8:1::1
962	local remote_prefix=2001:db8:1000::
963	local fn=ipv6_grps_get
964
965	echo
966	echo "Control path: Large scale MDB dump - IPv6 overlay / IPv6 underlay"
967	echo "-----------------------------------------------------------------"
968
969	dump_common $ns1 $local_addr $remote_prefix $fn
970}
971
972flush()
973{
974	local num_entries
975
976	echo
977	echo "Control path: Flush"
978	echo "-------------------"
979
980	# Add entries with different attributes and check that they are all
981	# flushed when the flush command is given with no parameters.
982
983	# Different source VNI.
984	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10010"
985	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.2 permanent dst 198.51.100.1 src_vni 10011"
986
987	# Different routing protocol.
988	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.3 permanent proto bgp dst 198.51.100.1 src_vni 10010"
989	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.4 permanent proto zebra dst 198.51.100.1 src_vni 10010"
990
991	# Different destination IP.
992	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.5 permanent dst 198.51.100.1 src_vni 10010"
993	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.6 permanent dst 198.51.100.2 src_vni 10010"
994
995	# Different destination port.
996	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.7 permanent dst 198.51.100.1 dst_port 11111 src_vni 10010"
997	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.8 permanent dst 198.51.100.1 dst_port 22222 src_vni 10010"
998
999	# Different VNI.
1000	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.9 permanent dst 198.51.100.1 vni 10010 src_vni 10010"
1001	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.10 permanent dst 198.51.100.1 vni 10020 src_vni 10010"
1002
1003	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0"
1004	num_entries=$(bridge -n $ns1_v4 mdb show dev vx0 | wc -l)
1005	[[ $num_entries -eq 0 ]]
1006	log_test $? 0 "Flush all"
1007
1008	# Check that entries are flushed when port is specified as the VXLAN
1009	# device and that an error is returned when port is specified as a
1010	# different net device.
1011
1012	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10010"
1013	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.2 src_vni 10010"
1014
1015	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0 port vx0"
1016	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010"
1017	log_test $? 254 "Flush by port - matching"
1018
1019	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0 port veth0"
1020	log_test $? 255 "Flush by port - non-matching"
1021
1022	# Check that when flushing by source VNI only entries programmed with
1023	# the specified source VNI are flushed and the rest are not.
1024
1025	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10010"
1026	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.2 src_vni 10010"
1027	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10011"
1028	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.2 src_vni 10011"
1029
1030	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0 src_vni 10010"
1031
1032	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010"
1033	log_test $? 254 "Flush by source VNI - matching"
1034	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10011"
1035	log_test $? 0 "Flush by source VNI - non-matching"
1036
1037	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0"
1038
1039	# Check that all entries are flushed when "permanent" is specified and
1040	# that an error is returned when "nopermanent" is specified.
1041
1042	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10010"
1043	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.2 src_vni 10010"
1044
1045	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0 permanent"
1046	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010"
1047	log_test $? 254 "Flush by \"permanent\" state"
1048
1049	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0 nopermanent"
1050	log_test $? 255 "Flush by \"nopermanent\" state"
1051
1052	# Check that when flushing by routing protocol only entries programmed
1053	# with the specified routing protocol are flushed and the rest are not.
1054
1055	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent proto bgp dst 198.51.100.1 src_vni 10010"
1056	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent proto zebra dst 198.51.100.2 src_vni 10010"
1057
1058	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0 proto bgp"
1059
1060	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep \"proto bgp\""
1061	log_test $? 1 "Flush by routing protocol - matching"
1062	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep \"proto zebra\""
1063	log_test $? 0 "Flush by routing protocol - non-matching"
1064
1065	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0"
1066
1067	# Check that when flushing by destination IP only entries programmed
1068	# with the specified destination IP are flushed and the rest are not.
1069
1070	# IPv4.
1071
1072	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10010"
1073	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.2 src_vni 10010"
1074
1075	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0 dst 198.51.100.2"
1076
1077	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 198.51.100.2"
1078	log_test $? 1 "Flush by IPv4 destination IP - matching"
1079	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 198.51.100.1"
1080	log_test $? 0 "Flush by IPv4 destination IP - non-matching"
1081
1082	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0"
1083
1084	# IPv6.
1085
1086	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 2001:db8:1000::1 src_vni 10010"
1087	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 2001:db8:1000::2 src_vni 10010"
1088
1089	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0 dst 2001:db8:1000::2"
1090
1091	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 2001:db8:1000::2"
1092	log_test $? 1 "Flush by IPv6 destination IP - matching"
1093	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 2001:db8:1000::1"
1094	log_test $? 0 "Flush by IPv6 destination IP - non-matching"
1095
1096	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0"
1097
1098	# Check that when flushing by UDP destination port only entries
1099	# programmed with the specified port are flushed and the rest are not.
1100
1101	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst_port 11111 dst 198.51.100.1 src_vni 10010"
1102	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst_port 22222 dst 198.51.100.2 src_vni 10010"
1103
1104	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0 dst_port 11111"
1105
1106	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep \"dst_port 11111\""
1107	log_test $? 1 "Flush by UDP destination port - matching"
1108	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep \"dst_port 22222\""
1109	log_test $? 0 "Flush by UDP destination port - non-matching"
1110
1111	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0"
1112
1113	# When not specifying a UDP destination port for an entry, traffic is
1114	# encapsulated with the device's UDP destination port. Check that when
1115	# flushing by the device's UDP destination port only entries programmed
1116	# with this port are flushed and the rest are not.
1117
1118	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10010"
1119	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst_port 22222 dst 198.51.100.2 src_vni 10010"
1120
1121	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0 dst_port 4789"
1122
1123	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 198.51.100.1"
1124	log_test $? 1 "Flush by device's UDP destination port - matching"
1125	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 198.51.100.2"
1126	log_test $? 0 "Flush by device's UDP destination port - non-matching"
1127
1128	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0"
1129
1130	# Check that when flushing by destination VNI only entries programmed
1131	# with the specified destination VNI are flushed and the rest are not.
1132
1133	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent vni 20010 dst 198.51.100.1 src_vni 10010"
1134	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent vni 20011 dst 198.51.100.2 src_vni 10010"
1135
1136	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0 vni 20010"
1137
1138	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep \" vni 20010\""
1139	log_test $? 1 "Flush by destination VNI - matching"
1140	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep \" vni 20011\""
1141	log_test $? 0 "Flush by destination VNI - non-matching"
1142
1143	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0"
1144
1145	# When not specifying a destination VNI for an entry, traffic is
1146	# encapsulated with the source VNI. Check that when flushing by a
1147	# destination VNI that is equal to the source VNI only such entries are
1148	# flushed and the rest are not.
1149
1150	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10010"
1151	run_cmd "bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent vni 20010 dst 198.51.100.2 src_vni 10010"
1152
1153	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0 vni 10010"
1154
1155	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 198.51.100.1"
1156	log_test $? 1 "Flush by destination VNI equal to source VNI - matching"
1157	run_cmd "bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 198.51.100.2"
1158	log_test $? 0 "Flush by destination VNI equal to source VNI - non-matching"
1159
1160	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0"
1161
1162	# Test that an error is returned when trying to flush using VLAN ID.
1163
1164	run_cmd "bridge -n $ns1_v4 mdb flush dev vx0 vid 10"
1165	log_test $? 255 "Flush by VLAN ID"
1166}
1167
1168################################################################################
1169# Tests - Data path
1170
1171encap_params_common()
1172{
1173	local ns1=$1; shift
1174	local ns2=$1; shift
1175	local vtep1_ip=$1; shift
1176	local vtep2_ip=$1; shift
1177	local plen=$1; shift
1178	local enc_ethtype=$1; shift
1179	local grp=$1; shift
1180	local grp_dmac=$1; shift
1181	local src=$1; shift
1182	local mz=$1; shift
1183
1184	# Test that packets forwarded by the VXLAN MDB are encapsulated with
1185	# the correct parameters. Transmit packets from the first namespace and
1186	# check that they hit the corresponding filters on the ingress of the
1187	# second namespace.
1188
1189	run_cmd "tc -n $ns2 qdisc replace dev veth0 clsact"
1190	run_cmd "tc -n $ns2 qdisc replace dev vx0 clsact"
1191	run_cmd "ip -n $ns2 address replace $vtep1_ip/$plen dev lo"
1192	run_cmd "ip -n $ns2 address replace $vtep2_ip/$plen dev lo"
1193
1194	# Check destination IP.
1195	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent dst $vtep1_ip src_vni 10010"
1196	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent dst $vtep2_ip src_vni 10020"
1197
1198	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 101 proto all flower enc_dst_ip $vtep1_ip action pass"
1199	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1200	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
1201	log_test $? 0 "Destination IP - match"
1202
1203	run_cmd "ip netns exec $ns1 $mz br0.20 -a own -b $grp_dmac -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1204	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
1205	log_test $? 0 "Destination IP - no match"
1206
1207	run_cmd "tc -n $ns2 filter del dev vx0 ingress pref 1 handle 101 flower"
1208	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep2_ip src_vni 10020"
1209	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep1_ip src_vni 10010"
1210
1211	# Check destination port.
1212	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent dst $vtep1_ip src_vni 10010"
1213	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent dst $vtep1_ip dst_port 1111 src_vni 10020"
1214
1215	run_cmd "tc -n $ns2 filter replace dev veth0 ingress pref 1 handle 101 proto $enc_ethtype flower ip_proto udp dst_port 4789 action pass"
1216	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1217	tc_check_packets "$ns2" "dev veth0 ingress" 101 1
1218	log_test $? 0 "Default destination port - match"
1219
1220	run_cmd "ip netns exec $ns1 $mz br0.20 -a own -b $grp_dmac -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1221	tc_check_packets "$ns2" "dev veth0 ingress" 101 1
1222	log_test $? 0 "Default destination port - no match"
1223
1224	run_cmd "tc -n $ns2 filter replace dev veth0 ingress pref 1 handle 101 proto $enc_ethtype flower ip_proto udp dst_port 1111 action pass"
1225	run_cmd "ip netns exec $ns1 $mz br0.20 -a own -b $grp_dmac -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1226	tc_check_packets "$ns2" "dev veth0 ingress" 101 1
1227	log_test $? 0 "Non-default destination port - match"
1228
1229	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1230	tc_check_packets "$ns2" "dev veth0 ingress" 101 1
1231	log_test $? 0 "Non-default destination port - no match"
1232
1233	run_cmd "tc -n $ns2 filter del dev veth0 ingress pref 1 handle 101 flower"
1234	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep1_ip src_vni 10020"
1235	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep1_ip src_vni 10010"
1236
1237	# Check default VNI.
1238	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent dst $vtep1_ip src_vni 10010"
1239	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent dst $vtep1_ip src_vni 10020"
1240
1241	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 101 proto all flower enc_key_id 10010 action pass"
1242	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1243	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
1244	log_test $? 0 "Default destination VNI - match"
1245
1246	run_cmd "ip netns exec $ns1 $mz br0.20 -a own -b $grp_dmac -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1247	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
1248	log_test $? 0 "Default destination VNI - no match"
1249
1250	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent dst $vtep1_ip vni 10020 src_vni 10010"
1251	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent dst $vtep1_ip vni 10010 src_vni 10020"
1252
1253	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 101 proto all flower enc_key_id 10020 action pass"
1254	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1255	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
1256	log_test $? 0 "Non-default destination VNI - match"
1257
1258	run_cmd "ip netns exec $ns1 $mz br0.20 -a own -b $grp_dmac -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1259	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
1260	log_test $? 0 "Non-default destination VNI - no match"
1261
1262	run_cmd "tc -n $ns2 filter del dev vx0 ingress pref 1 handle 101 flower"
1263	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep1_ip src_vni 10020"
1264	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep1_ip src_vni 10010"
1265}
1266
1267encap_params_ipv4_ipv4()
1268{
1269	local ns1=$ns1_v4
1270	local ns2=$ns2_v4
1271	local vtep1_ip=198.51.100.100
1272	local vtep2_ip=198.51.100.200
1273	local plen=32
1274	local enc_ethtype="ip"
1275	local grp=239.1.1.1
1276	local grp_dmac=01:00:5e:01:01:01
1277	local src=192.0.2.129
1278
1279	echo
1280	echo "Data path: Encapsulation parameters - IPv4 overlay / IPv4 underlay"
1281	echo "------------------------------------------------------------------"
1282
1283	encap_params_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $enc_ethtype \
1284		$grp $grp_dmac $src "mausezahn"
1285}
1286
1287encap_params_ipv6_ipv4()
1288{
1289	local ns1=$ns1_v4
1290	local ns2=$ns2_v4
1291	local vtep1_ip=198.51.100.100
1292	local vtep2_ip=198.51.100.200
1293	local plen=32
1294	local enc_ethtype="ip"
1295	local grp=ff0e::1
1296	local grp_dmac=33:33:00:00:00:01
1297	local src=2001:db8:100::1
1298
1299	echo
1300	echo "Data path: Encapsulation parameters - IPv6 overlay / IPv4 underlay"
1301	echo "------------------------------------------------------------------"
1302
1303	encap_params_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $enc_ethtype \
1304		$grp $grp_dmac $src "mausezahn -6"
1305}
1306
1307encap_params_ipv4_ipv6()
1308{
1309	local ns1=$ns1_v6
1310	local ns2=$ns2_v6
1311	local vtep1_ip=2001:db8:1000::1
1312	local vtep2_ip=2001:db8:2000::1
1313	local plen=128
1314	local enc_ethtype="ipv6"
1315	local grp=239.1.1.1
1316	local grp_dmac=01:00:5e:01:01:01
1317	local src=192.0.2.129
1318
1319	echo
1320	echo "Data path: Encapsulation parameters - IPv4 overlay / IPv6 underlay"
1321	echo "------------------------------------------------------------------"
1322
1323	encap_params_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $enc_ethtype \
1324		$grp $grp_dmac $src "mausezahn"
1325}
1326
1327encap_params_ipv6_ipv6()
1328{
1329	local ns1=$ns1_v6
1330	local ns2=$ns2_v6
1331	local vtep1_ip=2001:db8:1000::1
1332	local vtep2_ip=2001:db8:2000::1
1333	local plen=128
1334	local enc_ethtype="ipv6"
1335	local grp=ff0e::1
1336	local grp_dmac=33:33:00:00:00:01
1337	local src=2001:db8:100::1
1338
1339	echo
1340	echo "Data path: Encapsulation parameters - IPv6 overlay / IPv6 underlay"
1341	echo "------------------------------------------------------------------"
1342
1343	encap_params_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $enc_ethtype \
1344		$grp $grp_dmac $src "mausezahn -6"
1345}
1346
1347starg_exclude_ir_common()
1348{
1349	local ns1=$1; shift
1350	local ns2=$1; shift
1351	local vtep1_ip=$1; shift
1352	local vtep2_ip=$1; shift
1353	local plen=$1; shift
1354	local grp=$1; shift
1355	local grp_dmac=$1; shift
1356	local valid_src=$1; shift
1357	local invalid_src=$1; shift
1358	local mz=$1; shift
1359
1360	# Install a (*, G) EXCLUDE MDB entry with one source and two remote
1361	# VTEPs. Make sure that the source in the source list is not forwarded
1362	# and that a source not in the list is forwarded. Remove one of the
1363	# VTEPs from the entry and make sure that packets are only forwarded to
1364	# the remaining VTEP.
1365
1366	run_cmd "tc -n $ns2 qdisc replace dev vx0 clsact"
1367	run_cmd "ip -n $ns2 address replace $vtep1_ip/$plen dev lo"
1368	run_cmd "ip -n $ns2 address replace $vtep2_ip/$plen dev lo"
1369
1370	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 101 proto all flower enc_dst_ip $vtep1_ip action pass"
1371	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 102 proto all flower enc_dst_ip $vtep2_ip action pass"
1372
1373	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $invalid_src dst $vtep1_ip src_vni 10010"
1374	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $invalid_src dst $vtep2_ip src_vni 10010"
1375
1376	# Check that invalid source is not forwarded to any VTEP.
1377	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $invalid_src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1378	tc_check_packets "$ns2" "dev vx0 ingress" 101 0
1379	log_test $? 0 "Block excluded source - first VTEP"
1380	tc_check_packets "$ns2" "dev vx0 ingress" 102 0
1381	log_test $? 0 "Block excluded source - second VTEP"
1382
1383	# Check that valid source is forwarded to both VTEPs.
1384	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $valid_src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1385	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
1386	log_test $? 0 "Forward valid source - first VTEP"
1387	tc_check_packets "$ns2" "dev vx0 ingress" 102 1
1388	log_test $? 0 "Forward valid source - second VTEP"
1389
1390	# Remove second VTEP.
1391	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep2_ip src_vni 10010"
1392
1393	# Check that invalid source is not forwarded to any VTEP.
1394	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $invalid_src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1395	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
1396	log_test $? 0 "Block excluded source after removal - first VTEP"
1397	tc_check_packets "$ns2" "dev vx0 ingress" 102 1
1398	log_test $? 0 "Block excluded source after removal - second VTEP"
1399
1400	# Check that valid source is forwarded to the remaining VTEP.
1401	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $valid_src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1402	tc_check_packets "$ns2" "dev vx0 ingress" 101 2
1403	log_test $? 0 "Forward valid source after removal - first VTEP"
1404	tc_check_packets "$ns2" "dev vx0 ingress" 102 1
1405	log_test $? 0 "Forward valid source after removal - second VTEP"
1406}
1407
1408starg_exclude_ir_ipv4_ipv4()
1409{
1410	local ns1=$ns1_v4
1411	local ns2=$ns2_v4
1412	local vtep1_ip=198.51.100.100
1413	local vtep2_ip=198.51.100.200
1414	local plen=32
1415	local grp=239.1.1.1
1416	local grp_dmac=01:00:5e:01:01:01
1417	local valid_src=192.0.2.129
1418	local invalid_src=192.0.2.145
1419
1420	echo
1421	echo "Data path: (*, G) EXCLUDE - IR - IPv4 overlay / IPv4 underlay"
1422	echo "-------------------------------------------------------------"
1423
1424	starg_exclude_ir_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $grp \
1425		$grp_dmac $valid_src $invalid_src "mausezahn"
1426}
1427
1428starg_exclude_ir_ipv6_ipv4()
1429{
1430	local ns1=$ns1_v4
1431	local ns2=$ns2_v4
1432	local vtep1_ip=198.51.100.100
1433	local vtep2_ip=198.51.100.200
1434	local plen=32
1435	local grp=ff0e::1
1436	local grp_dmac=33:33:00:00:00:01
1437	local valid_src=2001:db8:100::1
1438	local invalid_src=2001:db8:200::1
1439
1440	echo
1441	echo "Data path: (*, G) EXCLUDE - IR - IPv6 overlay / IPv4 underlay"
1442	echo "-------------------------------------------------------------"
1443
1444	starg_exclude_ir_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $grp \
1445		$grp_dmac $valid_src $invalid_src "mausezahn -6"
1446}
1447
1448starg_exclude_ir_ipv4_ipv6()
1449{
1450	local ns1=$ns1_v6
1451	local ns2=$ns2_v6
1452	local vtep1_ip=2001:db8:1000::1
1453	local vtep2_ip=2001:db8:2000::1
1454	local plen=128
1455	local grp=239.1.1.1
1456	local grp_dmac=01:00:5e:01:01:01
1457	local valid_src=192.0.2.129
1458	local invalid_src=192.0.2.145
1459
1460	echo
1461	echo "Data path: (*, G) EXCLUDE - IR - IPv4 overlay / IPv6 underlay"
1462	echo "-------------------------------------------------------------"
1463
1464	starg_exclude_ir_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $grp \
1465		$grp_dmac $valid_src $invalid_src "mausezahn"
1466}
1467
1468starg_exclude_ir_ipv6_ipv6()
1469{
1470	local ns1=$ns1_v6
1471	local ns2=$ns2_v6
1472	local vtep1_ip=2001:db8:1000::1
1473	local vtep2_ip=2001:db8:2000::1
1474	local plen=128
1475	local grp=ff0e::1
1476	local grp_dmac=33:33:00:00:00:01
1477	local valid_src=2001:db8:100::1
1478	local invalid_src=2001:db8:200::1
1479
1480	echo
1481	echo "Data path: (*, G) EXCLUDE - IR - IPv6 overlay / IPv6 underlay"
1482	echo "-------------------------------------------------------------"
1483
1484	starg_exclude_ir_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $grp \
1485		$grp_dmac $valid_src $invalid_src "mausezahn -6"
1486}
1487
1488starg_include_ir_common()
1489{
1490	local ns1=$1; shift
1491	local ns2=$1; shift
1492	local vtep1_ip=$1; shift
1493	local vtep2_ip=$1; shift
1494	local plen=$1; shift
1495	local grp=$1; shift
1496	local grp_dmac=$1; shift
1497	local valid_src=$1; shift
1498	local invalid_src=$1; shift
1499	local mz=$1; shift
1500
1501	# Install a (*, G) INCLUDE MDB entry with one source and two remote
1502	# VTEPs. Make sure that the source in the source list is forwarded and
1503	# that a source not in the list is not forwarded. Remove one of the
1504	# VTEPs from the entry and make sure that packets are only forwarded to
1505	# the remaining VTEP.
1506
1507	run_cmd "tc -n $ns2 qdisc replace dev vx0 clsact"
1508	run_cmd "ip -n $ns2 address replace $vtep1_ip/$plen dev lo"
1509	run_cmd "ip -n $ns2 address replace $vtep2_ip/$plen dev lo"
1510
1511	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 101 proto all flower enc_dst_ip $vtep1_ip action pass"
1512	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 102 proto all flower enc_dst_ip $vtep2_ip action pass"
1513
1514	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent filter_mode include source_list $valid_src dst $vtep1_ip src_vni 10010"
1515	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent filter_mode include source_list $valid_src dst $vtep2_ip src_vni 10010"
1516
1517	# Check that invalid source is not forwarded to any VTEP.
1518	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $invalid_src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1519	tc_check_packets "$ns2" "dev vx0 ingress" 101 0
1520	log_test $? 0 "Block excluded source - first VTEP"
1521	tc_check_packets "$ns2" "dev vx0 ingress" 102 0
1522	log_test $? 0 "Block excluded source - second VTEP"
1523
1524	# Check that valid source is forwarded to both VTEPs.
1525	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $valid_src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1526	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
1527	log_test $? 0 "Forward valid source - first VTEP"
1528	tc_check_packets "$ns2" "dev vx0 ingress" 102 1
1529	log_test $? 0 "Forward valid source - second VTEP"
1530
1531	# Remove second VTEP.
1532	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep2_ip src_vni 10010"
1533
1534	# Check that invalid source is not forwarded to any VTEP.
1535	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $invalid_src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1536	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
1537	log_test $? 0 "Block excluded source after removal - first VTEP"
1538	tc_check_packets "$ns2" "dev vx0 ingress" 102 1
1539	log_test $? 0 "Block excluded source after removal - second VTEP"
1540
1541	# Check that valid source is forwarded to the remaining VTEP.
1542	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $valid_src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1543	tc_check_packets "$ns2" "dev vx0 ingress" 101 2
1544	log_test $? 0 "Forward valid source after removal - first VTEP"
1545	tc_check_packets "$ns2" "dev vx0 ingress" 102 1
1546	log_test $? 0 "Forward valid source after removal - second VTEP"
1547}
1548
1549starg_include_ir_ipv4_ipv4()
1550{
1551	local ns1=$ns1_v4
1552	local ns2=$ns2_v4
1553	local vtep1_ip=198.51.100.100
1554	local vtep2_ip=198.51.100.200
1555	local plen=32
1556	local grp=239.1.1.1
1557	local grp_dmac=01:00:5e:01:01:01
1558	local valid_src=192.0.2.129
1559	local invalid_src=192.0.2.145
1560
1561	echo
1562	echo "Data path: (*, G) INCLUDE - IR - IPv4 overlay / IPv4 underlay"
1563	echo "-------------------------------------------------------------"
1564
1565	starg_include_ir_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $grp \
1566		$grp_dmac $valid_src $invalid_src "mausezahn"
1567}
1568
1569starg_include_ir_ipv6_ipv4()
1570{
1571	local ns1=$ns1_v4
1572	local ns2=$ns2_v4
1573	local vtep1_ip=198.51.100.100
1574	local vtep2_ip=198.51.100.200
1575	local plen=32
1576	local grp=ff0e::1
1577	local grp_dmac=33:33:00:00:00:01
1578	local valid_src=2001:db8:100::1
1579	local invalid_src=2001:db8:200::1
1580
1581	echo
1582	echo "Data path: (*, G) INCLUDE - IR - IPv6 overlay / IPv4 underlay"
1583	echo "-------------------------------------------------------------"
1584
1585	starg_include_ir_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $grp \
1586		$grp_dmac $valid_src $invalid_src "mausezahn -6"
1587}
1588
1589starg_include_ir_ipv4_ipv6()
1590{
1591	local ns1=$ns1_v6
1592	local ns2=$ns2_v6
1593	local vtep1_ip=2001:db8:1000::1
1594	local vtep2_ip=2001:db8:2000::1
1595	local plen=128
1596	local grp=239.1.1.1
1597	local grp_dmac=01:00:5e:01:01:01
1598	local valid_src=192.0.2.129
1599	local invalid_src=192.0.2.145
1600
1601	echo
1602	echo "Data path: (*, G) INCLUDE - IR - IPv4 overlay / IPv6 underlay"
1603	echo "-------------------------------------------------------------"
1604
1605	starg_include_ir_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $grp \
1606		$grp_dmac $valid_src $invalid_src "mausezahn"
1607}
1608
1609starg_include_ir_ipv6_ipv6()
1610{
1611	local ns1=$ns1_v6
1612	local ns2=$ns2_v6
1613	local vtep1_ip=2001:db8:1000::1
1614	local vtep2_ip=2001:db8:2000::1
1615	local plen=128
1616	local grp=ff0e::1
1617	local grp_dmac=33:33:00:00:00:01
1618	local valid_src=2001:db8:100::1
1619	local invalid_src=2001:db8:200::1
1620
1621	echo
1622	echo "Data path: (*, G) INCLUDE - IR - IPv6 overlay / IPv6 underlay"
1623	echo "-------------------------------------------------------------"
1624
1625	starg_include_ir_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $grp \
1626		$grp_dmac $valid_src $invalid_src "mausezahn -6"
1627}
1628
1629starg_exclude_p2mp_common()
1630{
1631	local ns1=$1; shift
1632	local ns2=$1; shift
1633	local mcast_grp=$1; shift
1634	local plen=$1; shift
1635	local grp=$1; shift
1636	local grp_dmac=$1; shift
1637	local valid_src=$1; shift
1638	local invalid_src=$1; shift
1639	local mz=$1; shift
1640
1641	# Install a (*, G) EXCLUDE MDB entry with one source and one multicast
1642	# group to which packets are sent. Make sure that the source in the
1643	# source list is not forwarded and that a source not in the list is
1644	# forwarded.
1645
1646	run_cmd "tc -n $ns2 qdisc replace dev vx0 clsact"
1647	run_cmd "ip -n $ns2 address replace $mcast_grp/$plen dev veth0 autojoin"
1648
1649	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 101 proto all flower enc_dst_ip $mcast_grp action pass"
1650
1651	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent filter_mode exclude source_list $invalid_src dst $mcast_grp src_vni 10010 via veth0"
1652
1653	# Check that invalid source is not forwarded.
1654	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $invalid_src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1655	tc_check_packets "$ns2" "dev vx0 ingress" 101 0
1656	log_test $? 0 "Block excluded source"
1657
1658	# Check that valid source is forwarded.
1659	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $valid_src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1660	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
1661	log_test $? 0 "Forward valid source"
1662
1663	# Remove the VTEP from the multicast group.
1664	run_cmd "ip -n $ns2 address del $mcast_grp/$plen dev veth0"
1665
1666	# Check that valid source is not received anymore.
1667	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $valid_src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1668	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
1669	log_test $? 0 "Receive of valid source after removal from group"
1670}
1671
1672starg_exclude_p2mp_ipv4_ipv4()
1673{
1674	local ns1=$ns1_v4
1675	local ns2=$ns2_v4
1676	local mcast_grp=238.1.1.1
1677	local plen=32
1678	local grp=239.1.1.1
1679	local grp_dmac=01:00:5e:01:01:01
1680	local valid_src=192.0.2.129
1681	local invalid_src=192.0.2.145
1682
1683	echo
1684	echo "Data path: (*, G) EXCLUDE - P2MP - IPv4 overlay / IPv4 underlay"
1685	echo "---------------------------------------------------------------"
1686
1687	starg_exclude_p2mp_common $ns1 $ns2 $mcast_grp $plen $grp $grp_dmac \
1688		$valid_src $invalid_src "mausezahn"
1689}
1690
1691starg_exclude_p2mp_ipv6_ipv4()
1692{
1693	local ns1=$ns1_v4
1694	local ns2=$ns2_v4
1695	local mcast_grp=238.1.1.1
1696	local plen=32
1697	local grp=ff0e::1
1698	local grp_dmac=33:33:00:00:00:01
1699	local valid_src=2001:db8:100::1
1700	local invalid_src=2001:db8:200::1
1701
1702	echo
1703	echo "Data path: (*, G) EXCLUDE - P2MP - IPv6 overlay / IPv4 underlay"
1704	echo "---------------------------------------------------------------"
1705
1706	starg_exclude_p2mp_common $ns1 $ns2 $mcast_grp $plen $grp $grp_dmac \
1707		$valid_src $invalid_src "mausezahn -6"
1708}
1709
1710starg_exclude_p2mp_ipv4_ipv6()
1711{
1712	local ns1=$ns1_v6
1713	local ns2=$ns2_v6
1714	local mcast_grp=ff0e::2
1715	local plen=128
1716	local grp=239.1.1.1
1717	local grp_dmac=01:00:5e:01:01:01
1718	local valid_src=192.0.2.129
1719	local invalid_src=192.0.2.145
1720
1721	echo
1722	echo "Data path: (*, G) EXCLUDE - P2MP - IPv4 overlay / IPv6 underlay"
1723	echo "---------------------------------------------------------------"
1724
1725	starg_exclude_p2mp_common $ns1 $ns2 $mcast_grp $plen $grp $grp_dmac \
1726		$valid_src $invalid_src "mausezahn"
1727}
1728
1729starg_exclude_p2mp_ipv6_ipv6()
1730{
1731	local ns1=$ns1_v6
1732	local ns2=$ns2_v6
1733	local mcast_grp=ff0e::2
1734	local plen=128
1735	local grp=ff0e::1
1736	local grp_dmac=33:33:00:00:00:01
1737	local valid_src=2001:db8:100::1
1738	local invalid_src=2001:db8:200::1
1739
1740	echo
1741	echo "Data path: (*, G) EXCLUDE - P2MP - IPv6 overlay / IPv6 underlay"
1742	echo "---------------------------------------------------------------"
1743
1744	starg_exclude_p2mp_common $ns1 $ns2 $mcast_grp $plen $grp $grp_dmac \
1745		$valid_src $invalid_src "mausezahn -6"
1746}
1747
1748starg_include_p2mp_common()
1749{
1750	local ns1=$1; shift
1751	local ns2=$1; shift
1752	local mcast_grp=$1; shift
1753	local plen=$1; shift
1754	local grp=$1; shift
1755	local grp_dmac=$1; shift
1756	local valid_src=$1; shift
1757	local invalid_src=$1; shift
1758	local mz=$1; shift
1759
1760	# Install a (*, G) INCLUDE MDB entry with one source and one multicast
1761	# group to which packets are sent. Make sure that the source in the
1762	# source list is forwarded and that a source not in the list is not
1763	# forwarded.
1764
1765	run_cmd "tc -n $ns2 qdisc replace dev vx0 clsact"
1766	run_cmd "ip -n $ns2 address replace $mcast_grp/$plen dev veth0 autojoin"
1767
1768	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 101 proto all flower enc_dst_ip $mcast_grp action pass"
1769
1770	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent filter_mode include source_list $valid_src dst $mcast_grp src_vni 10010 via veth0"
1771
1772	# Check that invalid source is not forwarded.
1773	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $invalid_src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1774	tc_check_packets "$ns2" "dev vx0 ingress" 101 0
1775	log_test $? 0 "Block excluded source"
1776
1777	# Check that valid source is forwarded.
1778	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $valid_src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1779	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
1780	log_test $? 0 "Forward valid source"
1781
1782	# Remove the VTEP from the multicast group.
1783	run_cmd "ip -n $ns2 address del $mcast_grp/$plen dev veth0"
1784
1785	# Check that valid source is not received anymore.
1786	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $valid_src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1787	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
1788	log_test $? 0 "Receive of valid source after removal from group"
1789}
1790
1791starg_include_p2mp_ipv4_ipv4()
1792{
1793	local ns1=$ns1_v4
1794	local ns2=$ns2_v4
1795	local mcast_grp=238.1.1.1
1796	local plen=32
1797	local grp=239.1.1.1
1798	local grp_dmac=01:00:5e:01:01:01
1799	local valid_src=192.0.2.129
1800	local invalid_src=192.0.2.145
1801
1802	echo
1803	echo "Data path: (*, G) INCLUDE - P2MP - IPv4 overlay / IPv4 underlay"
1804	echo "---------------------------------------------------------------"
1805
1806	starg_include_p2mp_common $ns1 $ns2 $mcast_grp $plen $grp $grp_dmac \
1807		$valid_src $invalid_src "mausezahn"
1808}
1809
1810starg_include_p2mp_ipv6_ipv4()
1811{
1812	local ns1=$ns1_v4
1813	local ns2=$ns2_v4
1814	local mcast_grp=238.1.1.1
1815	local plen=32
1816	local grp=ff0e::1
1817	local grp_dmac=33:33:00:00:00:01
1818	local valid_src=2001:db8:100::1
1819	local invalid_src=2001:db8:200::1
1820
1821	echo
1822	echo "Data path: (*, G) INCLUDE - P2MP - IPv6 overlay / IPv4 underlay"
1823	echo "---------------------------------------------------------------"
1824
1825	starg_include_p2mp_common $ns1 $ns2 $mcast_grp $plen $grp $grp_dmac \
1826		$valid_src $invalid_src "mausezahn -6"
1827}
1828
1829starg_include_p2mp_ipv4_ipv6()
1830{
1831	local ns1=$ns1_v6
1832	local ns2=$ns2_v6
1833	local mcast_grp=ff0e::2
1834	local plen=128
1835	local grp=239.1.1.1
1836	local grp_dmac=01:00:5e:01:01:01
1837	local valid_src=192.0.2.129
1838	local invalid_src=192.0.2.145
1839
1840	echo
1841	echo "Data path: (*, G) INCLUDE - P2MP - IPv4 overlay / IPv6 underlay"
1842	echo "---------------------------------------------------------------"
1843
1844	starg_include_p2mp_common $ns1 $ns2 $mcast_grp $plen $grp $grp_dmac \
1845		$valid_src $invalid_src "mausezahn"
1846}
1847
1848starg_include_p2mp_ipv6_ipv6()
1849{
1850	local ns1=$ns1_v6
1851	local ns2=$ns2_v6
1852	local mcast_grp=ff0e::2
1853	local plen=128
1854	local grp=ff0e::1
1855	local grp_dmac=33:33:00:00:00:01
1856	local valid_src=2001:db8:100::1
1857	local invalid_src=2001:db8:200::1
1858
1859	echo
1860	echo "Data path: (*, G) INCLUDE - P2MP - IPv6 overlay / IPv6 underlay"
1861	echo "---------------------------------------------------------------"
1862
1863	starg_include_p2mp_common $ns1 $ns2 $mcast_grp $plen $grp $grp_dmac \
1864		$valid_src $invalid_src "mausezahn -6"
1865}
1866
1867egress_vni_translation_common()
1868{
1869	local ns1=$1; shift
1870	local ns2=$1; shift
1871	local mcast_grp=$1; shift
1872	local plen=$1; shift
1873	local proto=$1; shift
1874	local grp=$1; shift
1875	local grp_dmac=$1; shift
1876	local src=$1; shift
1877	local mz=$1; shift
1878
1879	# When P2MP tunnels are used with optimized inter-subnet multicast
1880	# (OISM) [1], the ingress VTEP does not perform VNI translation and
1881	# uses the VNI of the source broadcast domain (BD). If the egress VTEP
1882	# is a member in the source BD, then no VNI translation is needed.
1883	# Otherwise, the egress VTEP needs to translate the VNI to the
1884	# supplementary broadcast domain (SBD) VNI, which is usually the L3VNI.
1885	#
1886	# In this test, remove the VTEP in the second namespace from VLAN 10
1887	# (VNI 10010) and make sure that a packet sent from this VLAN on the
1888	# first VTEP is received by the SVI corresponding to the L3VNI (14000 /
1889	# VLAN 4000) on the second VTEP.
1890	#
1891	# The second VTEP will be able to decapsulate the packet with VNI 10010
1892	# because this VNI is configured on its shared VXLAN device. Later,
1893	# when ingressing the bridge, the VNI to VLAN lookup will fail because
1894	# the VTEP is not a member in VLAN 10, which will cause the packet to
1895	# be tagged with VLAN 4000 since it is configured as PVID.
1896	#
1897	# [1] https://datatracker.ietf.org/doc/html/draft-ietf-bess-evpn-irb-mcast
1898
1899	run_cmd "tc -n $ns2 qdisc replace dev br0.4000 clsact"
1900	run_cmd "ip -n $ns2 address replace $mcast_grp/$plen dev veth0 autojoin"
1901	run_cmd "tc -n $ns2 filter replace dev br0.4000 ingress pref 1 handle 101 proto $proto flower src_ip $src dst_ip $grp action pass"
1902
1903	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp src $src permanent dst $mcast_grp src_vni 10010 via veth0"
1904
1905	# Remove the second VTEP from VLAN 10.
1906	run_cmd "bridge -n $ns2 vlan del vid 10 dev vx0"
1907
1908	# Make sure that packets sent from the first VTEP over VLAN 10 are
1909	# received by the SVI corresponding to the L3VNI (14000 / VLAN 4000) on
1910	# the second VTEP, since it is configured as PVID.
1911	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1912	tc_check_packets "$ns2" "dev br0.4000 ingress" 101 1
1913	log_test $? 0 "Egress VNI translation - PVID configured"
1914
1915	# Remove PVID flag from VLAN 4000 on the second VTEP and make sure
1916	# packets are no longer received by the SVI interface.
1917	run_cmd "bridge -n $ns2 vlan add vid 4000 dev vx0"
1918	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1919	tc_check_packets "$ns2" "dev br0.4000 ingress" 101 1
1920	log_test $? 0 "Egress VNI translation - no PVID configured"
1921
1922	# Reconfigure the PVID and make sure packets are received again.
1923	run_cmd "bridge -n $ns2 vlan add vid 4000 dev vx0 pvid"
1924	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
1925	tc_check_packets "$ns2" "dev br0.4000 ingress" 101 2
1926	log_test $? 0 "Egress VNI translation - PVID reconfigured"
1927}
1928
1929egress_vni_translation_ipv4_ipv4()
1930{
1931	local ns1=$ns1_v4
1932	local ns2=$ns2_v4
1933	local mcast_grp=238.1.1.1
1934	local plen=32
1935	local proto="ipv4"
1936	local grp=239.1.1.1
1937	local grp_dmac=01:00:5e:01:01:01
1938	local src=192.0.2.129
1939
1940	echo
1941	echo "Data path: Egress VNI translation - IPv4 overlay / IPv4 underlay"
1942	echo "----------------------------------------------------------------"
1943
1944	egress_vni_translation_common $ns1 $ns2 $mcast_grp $plen $proto $grp \
1945		$grp_dmac $src "mausezahn"
1946}
1947
1948egress_vni_translation_ipv6_ipv4()
1949{
1950	local ns1=$ns1_v4
1951	local ns2=$ns2_v4
1952	local mcast_grp=238.1.1.1
1953	local plen=32
1954	local proto="ipv6"
1955	local grp=ff0e::1
1956	local grp_dmac=33:33:00:00:00:01
1957	local src=2001:db8:100::1
1958
1959	echo
1960	echo "Data path: Egress VNI translation - IPv6 overlay / IPv4 underlay"
1961	echo "----------------------------------------------------------------"
1962
1963	egress_vni_translation_common $ns1 $ns2 $mcast_grp $plen $proto $grp \
1964		$grp_dmac $src "mausezahn -6"
1965}
1966
1967egress_vni_translation_ipv4_ipv6()
1968{
1969	local ns1=$ns1_v6
1970	local ns2=$ns2_v6
1971	local mcast_grp=ff0e::2
1972	local plen=128
1973	local proto="ipv4"
1974	local grp=239.1.1.1
1975	local grp_dmac=01:00:5e:01:01:01
1976	local src=192.0.2.129
1977
1978	echo
1979	echo "Data path: Egress VNI translation - IPv4 overlay / IPv6 underlay"
1980	echo "----------------------------------------------------------------"
1981
1982	egress_vni_translation_common $ns1 $ns2 $mcast_grp $plen $proto $grp \
1983		$grp_dmac $src "mausezahn"
1984}
1985
1986egress_vni_translation_ipv6_ipv6()
1987{
1988	local ns1=$ns1_v6
1989	local ns2=$ns2_v6
1990	local mcast_grp=ff0e::2
1991	local plen=128
1992	local proto="ipv6"
1993	local grp=ff0e::1
1994	local grp_dmac=33:33:00:00:00:01
1995	local src=2001:db8:100::1
1996
1997	echo
1998	echo "Data path: Egress VNI translation - IPv6 overlay / IPv6 underlay"
1999	echo "----------------------------------------------------------------"
2000
2001	egress_vni_translation_common $ns1 $ns2 $mcast_grp $plen $proto $grp \
2002		$grp_dmac $src "mausezahn -6"
2003}
2004
2005all_zeros_mdb_common()
2006{
2007	local ns1=$1; shift
2008	local ns2=$1; shift
2009	local vtep1_ip=$1; shift
2010	local vtep2_ip=$1; shift
2011	local vtep3_ip=$1; shift
2012	local vtep4_ip=$1; shift
2013	local plen=$1; shift
2014	local ipv4_grp=239.1.1.1
2015	local ipv4_grp_dmac=01:00:5e:01:01:01
2016	local ipv4_unreg_grp=239.2.2.2
2017	local ipv4_unreg_grp_dmac=01:00:5e:02:02:02
2018	local ipv4_ll_grp=224.0.0.100
2019	local ipv4_ll_grp_dmac=01:00:5e:00:00:64
2020	local ipv4_src=192.0.2.129
2021	local ipv6_grp=ff0e::1
2022	local ipv6_grp_dmac=33:33:00:00:00:01
2023	local ipv6_unreg_grp=ff0e::2
2024	local ipv6_unreg_grp_dmac=33:33:00:00:00:02
2025	local ipv6_ll_grp=ff02::1
2026	local ipv6_ll_grp_dmac=33:33:00:00:00:01
2027	local ipv6_src=2001:db8:100::1
2028
2029	# Install all-zeros (catchall) MDB entries for IPv4 and IPv6 traffic
2030	# and make sure they only forward unregistered IP multicast traffic
2031	# which is not link-local. Also make sure that each entry only forwards
2032	# traffic from the matching address family.
2033
2034	# Associate two different VTEPs with one all-zeros MDB entry: Two with
2035	# the IPv4 entry (0.0.0.0) and another two with the IPv6 one (::).
2036	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp 0.0.0.0 permanent dst $vtep1_ip src_vni 10010"
2037	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp 0.0.0.0 permanent dst $vtep2_ip src_vni 10010"
2038	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp :: permanent dst $vtep3_ip src_vni 10010"
2039	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp :: permanent dst $vtep4_ip src_vni 10010"
2040
2041	# Associate one VTEP from each set with a regular MDB entry: One with
2042	# an IPv4 entry and another with an IPv6 one.
2043	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $ipv4_grp permanent dst $vtep1_ip src_vni 10010"
2044	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $ipv6_grp permanent dst $vtep3_ip src_vni 10010"
2045
2046	# Add filters to match on decapsulated traffic in the second namespace.
2047	run_cmd "tc -n $ns2 qdisc replace dev vx0 clsact"
2048	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 101 proto all flower enc_dst_ip $vtep1_ip action pass"
2049	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 102 proto all flower enc_dst_ip $vtep2_ip action pass"
2050	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 103 proto all flower enc_dst_ip $vtep3_ip action pass"
2051	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 104 proto all flower enc_dst_ip $vtep4_ip action pass"
2052
2053	# Configure the VTEP addresses in the second namespace to enable
2054	# decapsulation.
2055	run_cmd "ip -n $ns2 address replace $vtep1_ip/$plen dev lo"
2056	run_cmd "ip -n $ns2 address replace $vtep2_ip/$plen dev lo"
2057	run_cmd "ip -n $ns2 address replace $vtep3_ip/$plen dev lo"
2058	run_cmd "ip -n $ns2 address replace $vtep4_ip/$plen dev lo"
2059
2060	# Send registered IPv4 multicast and make sure it only arrives to the
2061	# first VTEP.
2062	run_cmd "ip netns exec $ns1 mausezahn br0.10 -a own -b $ipv4_grp_dmac -A $ipv4_src -B $ipv4_grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
2063	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
2064	log_test $? 0 "Registered IPv4 multicast - first VTEP"
2065	tc_check_packets "$ns2" "dev vx0 ingress" 102 0
2066	log_test $? 0 "Registered IPv4 multicast - second VTEP"
2067
2068	# Send unregistered IPv4 multicast that is not link-local and make sure
2069	# it arrives to the first and second VTEPs.
2070	run_cmd "ip netns exec $ns1 mausezahn br0.10 -a own -b $ipv4_unreg_grp_dmac -A $ipv4_src -B $ipv4_unreg_grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
2071	tc_check_packets "$ns2" "dev vx0 ingress" 101 2
2072	log_test $? 0 "Unregistered IPv4 multicast - first VTEP"
2073	tc_check_packets "$ns2" "dev vx0 ingress" 102 1
2074	log_test $? 0 "Unregistered IPv4 multicast - second VTEP"
2075
2076	# Send IPv4 link-local multicast traffic and make sure it does not
2077	# arrive to any VTEP.
2078	run_cmd "ip netns exec $ns1 mausezahn br0.10 -a own -b $ipv4_ll_grp_dmac -A $ipv4_src -B $ipv4_ll_grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
2079	tc_check_packets "$ns2" "dev vx0 ingress" 101 2
2080	log_test $? 0 "Link-local IPv4 multicast - first VTEP"
2081	tc_check_packets "$ns2" "dev vx0 ingress" 102 1
2082	log_test $? 0 "Link-local IPv4 multicast - second VTEP"
2083
2084	# Send registered IPv4 multicast using a unicast MAC address and make
2085	# sure it does not arrive to any VTEP.
2086	run_cmd "ip netns exec $ns1 mausezahn br0.10 -a own -b 00:11:22:33:44:55 -A $ipv4_src -B $ipv4_grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
2087	tc_check_packets "$ns2" "dev vx0 ingress" 101 2
2088	log_test $? 0 "Registered IPv4 multicast with a unicast MAC - first VTEP"
2089	tc_check_packets "$ns2" "dev vx0 ingress" 102 1
2090	log_test $? 0 "Registered IPv4 multicast with a unicast MAC - second VTEP"
2091
2092	# Send registered IPv4 multicast using a broadcast MAC address and make
2093	# sure it does not arrive to any VTEP.
2094	run_cmd "ip netns exec $ns1 mausezahn br0.10 -a own -b bcast -A $ipv4_src -B $ipv4_grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
2095	tc_check_packets "$ns2" "dev vx0 ingress" 101 2
2096	log_test $? 0 "Registered IPv4 multicast with a broadcast MAC - first VTEP"
2097	tc_check_packets "$ns2" "dev vx0 ingress" 102 1
2098	log_test $? 0 "Registered IPv4 multicast with a broadcast MAC - second VTEP"
2099
2100	# Make sure IPv4 traffic did not reach the VTEPs associated with
2101	# IPv6 entries.
2102	tc_check_packets "$ns2" "dev vx0 ingress" 103 0
2103	log_test $? 0 "IPv4 traffic - third VTEP"
2104	tc_check_packets "$ns2" "dev vx0 ingress" 104 0
2105	log_test $? 0 "IPv4 traffic - fourth VTEP"
2106
2107	# Reset IPv4 filters before testing IPv6 traffic.
2108	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 101 proto all flower enc_dst_ip $vtep1_ip action pass"
2109	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 102 proto all flower enc_dst_ip $vtep2_ip action pass"
2110
2111	# Send registered IPv6 multicast and make sure it only arrives to the
2112	# third VTEP.
2113	run_cmd "ip netns exec $ns1 mausezahn -6 br0.10 -a own -b $ipv6_grp_dmac -A $ipv6_src -B $ipv6_grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
2114	tc_check_packets "$ns2" "dev vx0 ingress" 103 1
2115	log_test $? 0 "Registered IPv6 multicast - third VTEP"
2116	tc_check_packets "$ns2" "dev vx0 ingress" 104 0
2117	log_test $? 0 "Registered IPv6 multicast - fourth VTEP"
2118
2119	# Send unregistered IPv6 multicast that is not link-local and make sure
2120	# it arrives to the third and fourth VTEPs.
2121	run_cmd "ip netns exec $ns1 mausezahn -6 br0.10 -a own -b $ipv6_unreg_grp_dmac -A $ipv6_src -B $ipv6_unreg_grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
2122	tc_check_packets "$ns2" "dev vx0 ingress" 103 2
2123	log_test $? 0 "Unregistered IPv6 multicast - third VTEP"
2124	tc_check_packets "$ns2" "dev vx0 ingress" 104 1
2125	log_test $? 0 "Unregistered IPv6 multicast - fourth VTEP"
2126
2127	# Send IPv6 link-local multicast traffic and make sure it does not
2128	# arrive to any VTEP.
2129	run_cmd "ip netns exec $ns1 mausezahn -6 br0.10 -a own -b $ipv6_ll_grp_dmac -A $ipv6_src -B $ipv6_ll_grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
2130	tc_check_packets "$ns2" "dev vx0 ingress" 103 2
2131	log_test $? 0 "Link-local IPv6 multicast - third VTEP"
2132	tc_check_packets "$ns2" "dev vx0 ingress" 104 1
2133	log_test $? 0 "Link-local IPv6 multicast - fourth VTEP"
2134
2135	# Send registered IPv6 multicast using a unicast MAC address and make
2136	# sure it does not arrive to any VTEP.
2137	run_cmd "ip netns exec $ns1 mausezahn -6 br0.10 -a own -b 00:11:22:33:44:55 -A $ipv6_src -B $ipv6_grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
2138	tc_check_packets "$ns2" "dev vx0 ingress" 103 2
2139	log_test $? 0 "Registered IPv6 multicast with a unicast MAC - third VTEP"
2140	tc_check_packets "$ns2" "dev vx0 ingress" 104 1
2141	log_test $? 0 "Registered IPv6 multicast with a unicast MAC - fourth VTEP"
2142
2143	# Send registered IPv6 multicast using a broadcast MAC address and make
2144	# sure it does not arrive to any VTEP.
2145	run_cmd "ip netns exec $ns1 mausezahn -6 br0.10 -a own -b bcast -A $ipv6_src -B $ipv6_grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
2146	tc_check_packets "$ns2" "dev vx0 ingress" 103 2
2147	log_test $? 0 "Registered IPv6 multicast with a broadcast MAC - third VTEP"
2148	tc_check_packets "$ns2" "dev vx0 ingress" 104 1
2149	log_test $? 0 "Registered IPv6 multicast with a broadcast MAC - fourth VTEP"
2150
2151	# Make sure IPv6 traffic did not reach the VTEPs associated with
2152	# IPv4 entries.
2153	tc_check_packets "$ns2" "dev vx0 ingress" 101 0
2154	log_test $? 0 "IPv6 traffic - first VTEP"
2155	tc_check_packets "$ns2" "dev vx0 ingress" 102 0
2156	log_test $? 0 "IPv6 traffic - second VTEP"
2157}
2158
2159all_zeros_mdb_ipv4()
2160{
2161	local ns1=$ns1_v4
2162	local ns2=$ns2_v4
2163	local vtep1_ip=198.51.100.101
2164	local vtep2_ip=198.51.100.102
2165	local vtep3_ip=198.51.100.103
2166	local vtep4_ip=198.51.100.104
2167	local plen=32
2168
2169	echo
2170	echo "Data path: All-zeros MDB entry - IPv4 underlay"
2171	echo "----------------------------------------------"
2172
2173	all_zeros_mdb_common $ns1 $ns2 $vtep1_ip $vtep2_ip $vtep3_ip \
2174		$vtep4_ip $plen
2175}
2176
2177all_zeros_mdb_ipv6()
2178{
2179	local ns1=$ns1_v6
2180	local ns2=$ns2_v6
2181	local vtep1_ip=2001:db8:1000::1
2182	local vtep2_ip=2001:db8:2000::1
2183	local vtep3_ip=2001:db8:3000::1
2184	local vtep4_ip=2001:db8:4000::1
2185	local plen=128
2186
2187	echo
2188	echo "Data path: All-zeros MDB entry - IPv6 underlay"
2189	echo "----------------------------------------------"
2190
2191	all_zeros_mdb_common $ns1 $ns2 $vtep1_ip $vtep2_ip $vtep3_ip \
2192		$vtep4_ip $plen
2193}
2194
2195mdb_fdb_common()
2196{
2197	local ns1=$1; shift
2198	local ns2=$1; shift
2199	local vtep1_ip=$1; shift
2200	local vtep2_ip=$1; shift
2201	local plen=$1; shift
2202	local proto=$1; shift
2203	local grp=$1; shift
2204	local grp_dmac=$1; shift
2205	local src=$1; shift
2206	local mz=$1; shift
2207
2208	# Install an MDB entry and an FDB entry and make sure that the FDB
2209	# entry only forwards traffic that was not forwarded by the MDB.
2210
2211	# Associate the MDB entry with one VTEP and the FDB entry with another
2212	# VTEP.
2213	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp permanent dst $vtep1_ip src_vni 10010"
2214	run_cmd "bridge -n $ns1 fdb add 00:00:00:00:00:00 dev vx0 self static dst $vtep2_ip src_vni 10010"
2215
2216	# Add filters to match on decapsulated traffic in the second namespace.
2217	run_cmd "tc -n $ns2 qdisc replace dev vx0 clsact"
2218	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 101 proto $proto flower ip_proto udp dst_port 54321 enc_dst_ip $vtep1_ip action pass"
2219	run_cmd "tc -n $ns2 filter replace dev vx0 ingress pref 1 handle 102 proto $proto flower ip_proto udp dst_port 54321 enc_dst_ip $vtep2_ip action pass"
2220
2221	# Configure the VTEP addresses in the second namespace to enable
2222	# decapsulation.
2223	run_cmd "ip -n $ns2 address replace $vtep1_ip/$plen dev lo"
2224	run_cmd "ip -n $ns2 address replace $vtep2_ip/$plen dev lo"
2225
2226	# Send IP multicast traffic and make sure it is forwarded by the MDB
2227	# and only arrives to the first VTEP.
2228	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
2229	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
2230	log_test $? 0 "IP multicast - first VTEP"
2231	tc_check_packets "$ns2" "dev vx0 ingress" 102 0
2232	log_test $? 0 "IP multicast - second VTEP"
2233
2234	# Send broadcast traffic and make sure it is forwarded by the FDB and
2235	# only arrives to the second VTEP.
2236	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b bcast -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
2237	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
2238	log_test $? 0 "Broadcast - first VTEP"
2239	tc_check_packets "$ns2" "dev vx0 ingress" 102 1
2240	log_test $? 0 "Broadcast - second VTEP"
2241
2242	# Remove the MDB entry and make sure that IP multicast is now forwarded
2243	# by the FDB to the second VTEP.
2244	run_cmd "bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp dst $vtep1_ip src_vni 10010"
2245	run_cmd "ip netns exec $ns1 $mz br0.10 -a own -b $grp_dmac -A $src -B $grp -t udp sp=12345,dp=54321 -p 100 -c 1 -q"
2246	tc_check_packets "$ns2" "dev vx0 ingress" 101 1
2247	log_test $? 0 "IP multicast after removal - first VTEP"
2248	tc_check_packets "$ns2" "dev vx0 ingress" 102 2
2249	log_test $? 0 "IP multicast after removal - second VTEP"
2250}
2251
2252mdb_fdb_ipv4_ipv4()
2253{
2254	local ns1=$ns1_v4
2255	local ns2=$ns2_v4
2256	local vtep1_ip=198.51.100.100
2257	local vtep2_ip=198.51.100.200
2258	local plen=32
2259	local proto="ipv4"
2260	local grp=239.1.1.1
2261	local grp_dmac=01:00:5e:01:01:01
2262	local src=192.0.2.129
2263
2264	echo
2265	echo "Data path: MDB with FDB - IPv4 overlay / IPv4 underlay"
2266	echo "------------------------------------------------------"
2267
2268	mdb_fdb_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $proto $grp \
2269		$grp_dmac $src "mausezahn"
2270}
2271
2272mdb_fdb_ipv6_ipv4()
2273{
2274	local ns1=$ns1_v4
2275	local ns2=$ns2_v4
2276	local vtep1_ip=198.51.100.100
2277	local vtep2_ip=198.51.100.200
2278	local plen=32
2279	local proto="ipv6"
2280	local grp=ff0e::1
2281	local grp_dmac=33:33:00:00:00:01
2282	local src=2001:db8:100::1
2283
2284	echo
2285	echo "Data path: MDB with FDB - IPv6 overlay / IPv4 underlay"
2286	echo "------------------------------------------------------"
2287
2288	mdb_fdb_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $proto $grp \
2289		$grp_dmac $src "mausezahn -6"
2290}
2291
2292mdb_fdb_ipv4_ipv6()
2293{
2294	local ns1=$ns1_v6
2295	local ns2=$ns2_v6
2296	local vtep1_ip=2001:db8:1000::1
2297	local vtep2_ip=2001:db8:2000::1
2298	local plen=128
2299	local proto="ipv4"
2300	local grp=239.1.1.1
2301	local grp_dmac=01:00:5e:01:01:01
2302	local src=192.0.2.129
2303
2304	echo
2305	echo "Data path: MDB with FDB - IPv4 overlay / IPv6 underlay"
2306	echo "------------------------------------------------------"
2307
2308	mdb_fdb_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $proto $grp \
2309		$grp_dmac $src "mausezahn"
2310}
2311
2312mdb_fdb_ipv6_ipv6()
2313{
2314	local ns1=$ns1_v6
2315	local ns2=$ns2_v6
2316	local vtep1_ip=2001:db8:1000::1
2317	local vtep2_ip=2001:db8:2000::1
2318	local plen=128
2319	local proto="ipv6"
2320	local grp=ff0e::1
2321	local grp_dmac=33:33:00:00:00:01
2322	local src=2001:db8:100::1
2323
2324	echo
2325	echo "Data path: MDB with FDB - IPv6 overlay / IPv6 underlay"
2326	echo "------------------------------------------------------"
2327
2328	mdb_fdb_common $ns1 $ns2 $vtep1_ip $vtep2_ip $plen $proto $grp \
2329		$grp_dmac $src "mausezahn -6"
2330}
2331
2332mdb_grp1_loop()
2333{
2334	local ns1=$1; shift
2335	local vtep1_ip=$1; shift
2336	local grp1=$1; shift
2337
2338	while true; do
2339		bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp1 dst $vtep1_ip src_vni 10010
2340		bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp1 permanent dst $vtep1_ip src_vni 10010
2341	done >/dev/null 2>&1
2342}
2343
2344mdb_grp2_loop()
2345{
2346	local ns1=$1; shift
2347	local vtep1_ip=$1; shift
2348	local vtep2_ip=$1; shift
2349	local grp2=$1; shift
2350
2351	while true; do
2352		bridge -n $ns1 mdb del dev vx0 port vx0 grp $grp2 dst $vtep1_ip src_vni 10010
2353		bridge -n $ns1 mdb add dev vx0 port vx0 grp $grp2 permanent dst $vtep1_ip src_vni 10010
2354		bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp2 permanent dst $vtep2_ip src_vni 10010
2355	done >/dev/null 2>&1
2356}
2357
2358mdb_torture_common()
2359{
2360	local ns1=$1; shift
2361	local vtep1_ip=$1; shift
2362	local vtep2_ip=$1; shift
2363	local grp1=$1; shift
2364	local grp1_dmac=$1; shift
2365	local grp2=$1; shift
2366	local grp2_dmac=$1; shift
2367	local src=$1; shift
2368	local mz=$1; shift
2369	local pid1
2370	local pid2
2371	local pid3
2372	local pid4
2373
2374	# Continuously send two streams that are forwarded by two different MDB
2375	# entries. The first entry will be added and deleted in a loop. This
2376	# allows us to test that the data path does not use freed MDB entry
2377	# memory. The second entry will have two remotes, one that is added and
2378	# deleted in a loop and another that is replaced in a loop. This allows
2379	# us to test that the data path does not use freed remote entry memory.
2380	# The test is considered successful if nothing crashed.
2381
2382	# Create the MDB entries that will be continuously deleted / replaced.
2383	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp1 permanent dst $vtep1_ip src_vni 10010"
2384	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp2 permanent dst $vtep1_ip src_vni 10010"
2385	run_cmd "bridge -n $ns1 mdb replace dev vx0 port vx0 grp $grp2 permanent dst $vtep2_ip src_vni 10010"
2386
2387	mdb_grp1_loop $ns1 $vtep1_ip $grp1 &
2388	pid1=$!
2389	mdb_grp2_loop $ns1 $vtep1_ip $vtep2_ip $grp2 &
2390	pid2=$!
2391	ip netns exec $ns1 $mz br0.10 -a own -b $grp1_dmac -A $src -B $grp1 -t udp sp=12345,dp=54321 -p 100 -c 0 -q &
2392	pid3=$!
2393	ip netns exec $ns1 $mz br0.10 -a own -b $grp2_dmac -A $src -B $grp2 -t udp sp=12345,dp=54321 -p 100 -c 0 -q &
2394	pid4=$!
2395
2396	sleep 30
2397	kill -9 $pid1 $pid2 $pid3 $pid4
2398	wait $pid1 $pid2 $pid3 $pid4 2>/dev/null
2399
2400	log_test 0 0 "Torture test"
2401}
2402
2403mdb_torture_ipv4_ipv4()
2404{
2405	local ns1=$ns1_v4
2406	local vtep1_ip=198.51.100.100
2407	local vtep2_ip=198.51.100.200
2408	local grp1=239.1.1.1
2409	local grp1_dmac=01:00:5e:01:01:01
2410	local grp2=239.2.2.2
2411	local grp2_dmac=01:00:5e:02:02:02
2412	local src=192.0.2.129
2413
2414	echo
2415	echo "Data path: MDB torture test - IPv4 overlay / IPv4 underlay"
2416	echo "----------------------------------------------------------"
2417
2418	mdb_torture_common $ns1 $vtep1_ip $vtep2_ip $grp1 $grp1_dmac $grp2 \
2419		$grp2_dmac $src "mausezahn"
2420}
2421
2422mdb_torture_ipv6_ipv4()
2423{
2424	local ns1=$ns1_v4
2425	local vtep1_ip=198.51.100.100
2426	local vtep2_ip=198.51.100.200
2427	local grp1=ff0e::1
2428	local grp1_dmac=33:33:00:00:00:01
2429	local grp2=ff0e::2
2430	local grp2_dmac=33:33:00:00:00:02
2431	local src=2001:db8:100::1
2432
2433	echo
2434	echo "Data path: MDB torture test - IPv6 overlay / IPv4 underlay"
2435	echo "----------------------------------------------------------"
2436
2437	mdb_torture_common $ns1 $vtep1_ip $vtep2_ip $grp1 $grp1_dmac $grp2 \
2438		$grp2_dmac $src "mausezahn -6"
2439}
2440
2441mdb_torture_ipv4_ipv6()
2442{
2443	local ns1=$ns1_v6
2444	local vtep1_ip=2001:db8:1000::1
2445	local vtep2_ip=2001:db8:2000::1
2446	local grp1=239.1.1.1
2447	local grp1_dmac=01:00:5e:01:01:01
2448	local grp2=239.2.2.2
2449	local grp2_dmac=01:00:5e:02:02:02
2450	local src=192.0.2.129
2451
2452	echo
2453	echo "Data path: MDB torture test - IPv4 overlay / IPv6 underlay"
2454	echo "----------------------------------------------------------"
2455
2456	mdb_torture_common $ns1 $vtep1_ip $vtep2_ip $grp1 $grp1_dmac $grp2 \
2457		$grp2_dmac $src "mausezahn"
2458}
2459
2460mdb_torture_ipv6_ipv6()
2461{
2462	local ns1=$ns1_v6
2463	local vtep1_ip=2001:db8:1000::1
2464	local vtep2_ip=2001:db8:2000::1
2465	local grp1=ff0e::1
2466	local grp1_dmac=33:33:00:00:00:01
2467	local grp2=ff0e::2
2468	local grp2_dmac=33:33:00:00:00:02
2469	local src=2001:db8:100::1
2470
2471	echo
2472	echo "Data path: MDB torture test - IPv6 overlay / IPv6 underlay"
2473	echo "----------------------------------------------------------"
2474
2475	mdb_torture_common $ns1 $vtep1_ip $vtep2_ip $grp1 $grp1_dmac $grp2 \
2476		$grp2_dmac $src "mausezahn -6"
2477}
2478
2479################################################################################
2480# Usage
2481
2482usage()
2483{
2484	cat <<EOF
2485usage: ${0##*/} OPTS
2486
2487        -t <test>   Test(s) to run (default: all)
2488                    (options: $TESTS)
2489        -c          Control path tests only
2490        -d          Data path tests only
2491        -p          Pause on fail
2492        -P          Pause after each test before cleanup
2493        -v          Verbose mode (show commands and output)
2494EOF
2495}
2496
2497################################################################################
2498# Main
2499
2500trap cleanup EXIT
2501
2502while getopts ":t:cdpPvh" opt; do
2503	case $opt in
2504		t) TESTS=$OPTARG;;
2505		c) TESTS=${CONTROL_PATH_TESTS};;
2506		d) TESTS=${DATA_PATH_TESTS};;
2507		p) PAUSE_ON_FAIL=yes;;
2508		P) PAUSE=yes;;
2509		v) VERBOSE=$(($VERBOSE + 1));;
2510		h) usage; exit 0;;
2511		*) usage; exit 1;;
2512	esac
2513done
2514
2515# Make sure we don't pause twice.
2516[ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no
2517
2518if [ "$(id -u)" -ne 0 ];then
2519	echo "SKIP: Need root privileges"
2520	exit $ksft_skip;
2521fi
2522
2523if [ ! -x "$(command -v ip)" ]; then
2524	echo "SKIP: Could not run test without ip tool"
2525	exit $ksft_skip
2526fi
2527
2528if [ ! -x "$(command -v bridge)" ]; then
2529	echo "SKIP: Could not run test without bridge tool"
2530	exit $ksft_skip
2531fi
2532
2533if [ ! -x "$(command -v mausezahn)" ]; then
2534	echo "SKIP: Could not run test without mausezahn tool"
2535	exit $ksft_skip
2536fi
2537
2538if [ ! -x "$(command -v jq)" ]; then
2539	echo "SKIP: Could not run test without jq tool"
2540	exit $ksft_skip
2541fi
2542
2543bridge mdb help 2>&1 | grep -q "flush"
2544if [ $? -ne 0 ]; then
2545   echo "SKIP: iproute2 bridge too old, missing VXLAN MDB flush support"
2546   exit $ksft_skip
2547fi
2548
2549# Start clean.
2550cleanup
2551
2552for t in $TESTS
2553do
2554	setup; $t; cleanup;
2555done
2556
2557if [ "$TESTS" != "none" ]; then
2558	printf "\nTests passed: %3d\n" ${nsuccess}
2559	printf "Tests failed: %3d\n"   ${nfail}
2560fi
2561
2562exit $ret
2563