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