brintos

brintos / linux-shallow public Read only

0
0
Text · 21.0 KiB · d5e3abb Raw
814 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03#4# This test is for checking functionality of flushing FDB entries.5# Check that flush works as expected with all the supported arguments and verify6# some combinations of arguments.7 8source lib.sh9 10FLUSH_BY_STATE_TESTS="11	vxlan_test_flush_by_permanent12	vxlan_test_flush_by_nopermanent13	vxlan_test_flush_by_static14	vxlan_test_flush_by_nostatic15	vxlan_test_flush_by_dynamic16	vxlan_test_flush_by_nodynamic17"18 19FLUSH_BY_FLAG_TESTS="20	vxlan_test_flush_by_extern_learn21	vxlan_test_flush_by_noextern_learn22	vxlan_test_flush_by_router23	vxlan_test_flush_by_norouter24"25 26TESTS="27	vxlan_test_flush_by_dev28	vxlan_test_flush_by_vni29	vxlan_test_flush_by_src_vni30	vxlan_test_flush_by_port31	vxlan_test_flush_by_dst_ip32	vxlan_test_flush_by_nhid33	$FLUSH_BY_STATE_TESTS34	$FLUSH_BY_FLAG_TESTS35	vxlan_test_flush_by_several_args36	vxlan_test_flush_by_remote_attributes37	bridge_test_flush_by_dev38	bridge_test_flush_by_vlan39	bridge_vxlan_test_flush40"41 42: ${VERBOSE:=0}43: ${PAUSE_ON_FAIL:=no}44: ${PAUSE:=no}45: ${VXPORT:=4789}46 47run_cmd()48{49	local cmd="$1"50	local out51	local rc52	local stderr="2>/dev/null"53 54	if [ "$VERBOSE" = "1" ]; then55		printf "COMMAND: $cmd\n"56		stderr=57	fi58 59	out=$(eval $cmd $stderr)60	rc=$?61	if [ "$VERBOSE" = "1" -a -n "$out" ]; then62		echo "    $out"63	fi64 65	return $rc66}67 68log_test()69{70	local rc=$171	local expected=$272	local msg="$3"73	local nsuccess74	local nfail75	local ret76 77	if [ ${rc} -eq ${expected} ]; then78		printf "TEST: %-60s  [ OK ]\n" "${msg}"79		nsuccess=$((nsuccess+1))80	else81		ret=182		nfail=$((nfail+1))83		printf "TEST: %-60s  [FAIL]\n" "${msg}"84		if [ "$VERBOSE" = "1" ]; then85			echo "    rc=$rc, expected $expected"86		fi87 88		if [ "${PAUSE_ON_FAIL}" = "yes" ]; then89		echo90			echo "hit enter to continue, 'q' to quit"91			read a92			[ "$a" = "q" ] && exit 193		fi94	fi95 96	if [ "${PAUSE}" = "yes" ]; then97		echo98		echo "hit enter to continue, 'q' to quit"99		read a100		[ "$a" = "q" ] && exit 1101	fi102 103	[ "$VERBOSE" = "1" ] && echo104}105 106MAC_POOL_1="107	de:ad:be:ef:13:10108	de:ad:be:ef:13:11109	de:ad:be:ef:13:12110	de:ad:be:ef:13:13111	de:ad:be:ef:13:14112"113mac_pool_1_len=$(echo "$MAC_POOL_1" | grep -c .)114 115MAC_POOL_2="116	ca:fe:be:ef:13:10117	ca:fe:be:ef:13:11118	ca:fe:be:ef:13:12119	ca:fe:be:ef:13:13120	ca:fe:be:ef:13:14121"122mac_pool_2_len=$(echo "$MAC_POOL_2" | grep -c .)123 124fdb_add_mac_pool_1()125{126	local dev=$1; shift127	local args="$@"128 129	for mac in $MAC_POOL_1130	do131		$BRIDGE fdb add $mac dev $dev $args132	done133}134 135fdb_add_mac_pool_2()136{137	local dev=$1; shift138	local args="$@"139 140	for mac in $MAC_POOL_2141	do142		$BRIDGE fdb add $mac dev $dev $args143	done144}145 146fdb_check_n_entries_by_dev_filter()147{148	local dev=$1; shift149	local exp_entries=$1; shift150	local filter="$@"151 152	local entries=$($BRIDGE fdb show dev $dev | grep "$filter" | wc -l)153 154	[[ $entries -eq $exp_entries ]]155	rc=$?156 157	log_test $rc 0 "$dev: Expected $exp_entries FDB entries, got $entries"158	return $rc159}160 161vxlan_test_flush_by_dev()162{163	local vni=3000164	local dst_ip=192.0.2.1165 166	fdb_add_mac_pool_1 vx10 vni $vni dst $dst_ip167	fdb_add_mac_pool_2 vx20 vni $vni dst $dst_ip168 169	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len170	fdb_check_n_entries_by_dev_filter vx20 $mac_pool_2_len171 172	run_cmd "$BRIDGE fdb flush dev vx10"173	log_test $? 0 "Flush FDB by dev vx10"174 175	fdb_check_n_entries_by_dev_filter vx10 0176	log_test $? 0 "Flush FDB by dev vx10 - test vx10 entries"177 178	fdb_check_n_entries_by_dev_filter vx20 $mac_pool_2_len179	log_test $? 0 "Flush FDB by dev vx10 - test vx20 entries"180}181 182vxlan_test_flush_by_vni()183{184	local vni_1=3000185	local vni_2=4000186	local dst_ip=192.0.2.1187 188	fdb_add_mac_pool_1 vx10 vni $vni_1 dst $dst_ip189	fdb_add_mac_pool_2 vx10 vni $vni_2 dst $dst_ip190 191	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len vni $vni_1192	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len vni $vni_2193 194	run_cmd "$BRIDGE fdb flush dev vx10 vni $vni_2"195	log_test $? 0 "Flush FDB by dev vx10 and vni $vni_2"196 197	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len vni $vni_1198	log_test $? 0 "Test entries with vni $vni_1"199 200	fdb_check_n_entries_by_dev_filter vx10 0 vni $vni_2201	log_test $? 0 "Test entries with vni $vni_2"202}203 204vxlan_test_flush_by_src_vni()205{206	# Set some entries with {vni=x,src_vni=y} and some with the opposite -207	# {vni=y,src_vni=x}, to verify that when we flush by src_vni=x, entries208	# with vni=x are not flused.209	local vni_1=3000210	local vni_2=4000211	local src_vni_1=4000212	local src_vni_2=3000213	local dst_ip=192.0.2.1214 215	# Reconfigure vx10 with 'external' to get 'src_vni' details in216	# 'bridge fdb' output217	$IP link del dev vx10218	$IP link add name vx10 type vxlan dstport "$VXPORT" external219 220	fdb_add_mac_pool_1 vx10 vni $vni_1 src_vni $src_vni_1 dst $dst_ip221	fdb_add_mac_pool_2 vx10 vni $vni_2 src_vni $src_vni_2 dst $dst_ip222 223	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len \224		src_vni $src_vni_1225	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len \226		src_vni $src_vni_2227 228	run_cmd "$BRIDGE fdb flush dev vx10 src_vni $src_vni_2"229	log_test $? 0 "Flush FDB by dev vx10 and src_vni $src_vni_2"230 231	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len \232		src_vni $src_vni_1233	log_test $? 0 "Test entries with src_vni $src_vni_1"234 235	fdb_check_n_entries_by_dev_filter vx10 0 src_vni $src_vni_2236	log_test $? 0 "Test entries with src_vni $src_vni_2"237}238 239vxlan_test_flush_by_port()240{241	local port_1=1234242	local port_2=4321243	local dst_ip=192.0.2.1244 245	fdb_add_mac_pool_1 vx10 port $port_1 dst $dst_ip246	fdb_add_mac_pool_2 vx10 port $port_2 dst $dst_ip247 248	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len port $port_1249	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len port $port_2250 251	run_cmd "$BRIDGE fdb flush dev vx10 port $port_2"252	log_test $? 0 "Flush FDB by dev vx10 and port $port_2"253 254	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len port $port_1255	log_test $? 0 "Test entries with port $port_1"256 257	fdb_check_n_entries_by_dev_filter vx10 0 port $port_2258	log_test $? 0 "Test entries with port $port_2"259}260 261vxlan_test_flush_by_dst_ip()262{263	local dst_ip_1=192.0.2.1264	local dst_ip_2=192.0.2.2265 266	fdb_add_mac_pool_1 vx10 dst $dst_ip_1267	fdb_add_mac_pool_2 vx10 dst $dst_ip_2268 269	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip_1270	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len dst $dst_ip_2271 272	run_cmd "$BRIDGE fdb flush dev vx10 dst $dst_ip_2"273	log_test $? 0 "Flush FDB by dev vx10 and dst $dst_ip_2"274 275	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip_1276	log_test $? 0 "Test entries with dst $dst_ip_1"277 278	fdb_check_n_entries_by_dev_filter vx10 0 dst $dst_ip_2279	log_test $? 0 "Test entries with dst $dst_ip_2"280}281 282nexthops_add()283{284	local nhid_1=$1; shift285	local nhid_2=$1; shift286 287	$IP nexthop add id 10 via 192.0.2.1 fdb288	$IP nexthop add id $nhid_1 group 10 fdb289 290	$IP nexthop add id 20 via 192.0.2.2 fdb291	$IP nexthop add id $nhid_2 group 20 fdb292}293 294vxlan_test_flush_by_nhid()295{296	local nhid_1=100297	local nhid_2=200298 299	nexthops_add $nhid_1 $nhid_2300 301	fdb_add_mac_pool_1 vx10 nhid $nhid_1302	fdb_add_mac_pool_2 vx10 nhid $nhid_2303 304	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len nhid $nhid_1305	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len nhid $nhid_2306 307	run_cmd "$BRIDGE fdb flush dev vx10 nhid $nhid_2"308	log_test $? 0 "Flush FDB by dev vx10 and nhid $nhid_2"309 310	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len nhid $nhid_1311	log_test $? 0 "Test entries with nhid $nhid_1"312 313	fdb_check_n_entries_by_dev_filter vx10 0 nhid $nhid_2314	log_test $? 0 "Test entries with nhid $nhid_2"315 316	# Flush also entries with $nhid_1, and then verify that flushing by317	# 'nhid' does not return an error when there are no entries with318	# nexthops.319	run_cmd "$BRIDGE fdb flush dev vx10 nhid $nhid_1"320	log_test $? 0 "Flush FDB by dev vx10 and nhid $nhid_1"321 322	fdb_check_n_entries_by_dev_filter vx10 0 nhid323	log_test $? 0 "Test entries with 'nhid' keyword"324 325	run_cmd "$BRIDGE fdb flush dev vx10 nhid $nhid_1"326	log_test $? 0 "Flush FDB by nhid when there are no entries with nexthop"327}328 329vxlan_test_flush_by_state()330{331	local flush_by_state=$1; shift332	local state_1=$1; shift333	local exp_state_1=$1; shift334	local state_2=$1; shift335	local exp_state_2=$1; shift336 337	local dst_ip_1=192.0.2.1338	local dst_ip_2=192.0.2.2339 340	fdb_add_mac_pool_1 vx10 dst $dst_ip_1 $state_1341	fdb_add_mac_pool_2 vx10 dst $dst_ip_2 $state_2342 343	# Check the entries by dst_ip as not all states appear in 'bridge fdb'344	# output.345	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip_1346	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len dst $dst_ip_2347 348	run_cmd "$BRIDGE fdb flush dev vx10 $flush_by_state"349	log_test $? 0 "Flush FDB by dev vx10 and state $flush_by_state"350 351	fdb_check_n_entries_by_dev_filter vx10 $exp_state_1 dst $dst_ip_1352	log_test $? 0 "Test entries with state $state_1"353 354	fdb_check_n_entries_by_dev_filter vx10 $exp_state_2 dst $dst_ip_2355	log_test $? 0 "Test entries with state $state_2"356}357 358vxlan_test_flush_by_permanent()359{360	# Entries that are added without state get 'permanent' state by361	# default, add some entries with flag 'extern_learn' instead of state,362	# so they will be added with 'permanent' and should be flushed also.363	local flush_by_state="permanent"364	local state_1="permanent"365	local exp_state_1=0366	local state_2="extern_learn"367	local exp_state_2=0368 369	vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \370		$state_2 $exp_state_2371}372 373vxlan_test_flush_by_nopermanent()374{375	local flush_by_state="nopermanent"376	local state_1="permanent"377	local exp_state_1=$mac_pool_1_len378	local state_2="static"379	local exp_state_2=0380 381	vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \382		$state_2 $exp_state_2383}384 385vxlan_test_flush_by_static()386{387	local flush_by_state="static"388	local state_1="static"389	local exp_state_1=0390	local state_2="dynamic"391	local exp_state_2=$mac_pool_2_len392 393	vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \394		$state_2 $exp_state_2395}396 397vxlan_test_flush_by_nostatic()398{399	local flush_by_state="nostatic"400	local state_1="permanent"401	local exp_state_1=$mac_pool_1_len402	local state_2="dynamic"403	local exp_state_2=0404 405	vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \406		$state_2 $exp_state_2407}408 409vxlan_test_flush_by_dynamic()410{411	local flush_by_state="dynamic"412	local state_1="dynamic"413	local exp_state_1=0414	local state_2="static"415	local exp_state_2=$mac_pool_2_len416 417	vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \418		$state_2 $exp_state_2419}420 421vxlan_test_flush_by_nodynamic()422{423	local flush_by_state="nodynamic"424	local state_1="permanent"425	local exp_state_1=0426	local state_2="dynamic"427	local exp_state_2=$mac_pool_2_len428 429	vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \430		$state_2 $exp_state_2431}432 433vxlan_test_flush_by_flag()434{435	local flush_by_flag=$1; shift436	local flag_1=$1; shift437	local exp_flag_1=$1; shift438	local flag_2=$1; shift439	local exp_flag_2=$1; shift440 441	local dst_ip_1=192.0.2.1442	local dst_ip_2=192.0.2.2443 444	fdb_add_mac_pool_1 vx10 dst $dst_ip_1 $flag_1445	fdb_add_mac_pool_2 vx10 dst $dst_ip_2 $flag_2446 447	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len $flag_1448	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len $flag_2449 450	run_cmd "$BRIDGE fdb flush dev vx10 $flush_by_flag"451	log_test $? 0 "Flush FDB by dev vx10 and flag $flush_by_flag"452 453	fdb_check_n_entries_by_dev_filter vx10 $exp_flag_1 dst $dst_ip_1454	log_test $? 0 "Test entries with flag $flag_1"455 456	fdb_check_n_entries_by_dev_filter vx10 $exp_flag_2 dst $dst_ip_2457	log_test $? 0 "Test entries with flag $flag_2"458}459 460vxlan_test_flush_by_extern_learn()461{462	local flush_by_flag="extern_learn"463	local flag_1="extern_learn"464	local exp_flag_1=0465	local flag_2="router"466	local exp_flag_2=$mac_pool_2_len467 468	vxlan_test_flush_by_flag $flush_by_flag $flag_1 $exp_flag_1 \469		$flag_2 $exp_flag_2470}471 472vxlan_test_flush_by_noextern_learn()473{474	local flush_by_flag="noextern_learn"475	local flag_1="extern_learn"476	local exp_flag_1=$mac_pool_1_len477	local flag_2="router"478	local exp_flag_2=0479 480	vxlan_test_flush_by_flag $flush_by_flag $flag_1 $exp_flag_1 \481		$flag_2 $exp_flag_2482}483 484vxlan_test_flush_by_router()485{486	local flush_by_flag="router"487	local flag_1="router"488	local exp_flag_1=0489	local flag_2="extern_learn"490	local exp_flag_2=$mac_pool_2_len491 492	vxlan_test_flush_by_flag $flush_by_flag $flag_1 $exp_flag_1 \493		$flag_2 $exp_flag_2494}495 496vxlan_test_flush_by_norouter()497{498 499	local flush_by_flag="norouter"500	local flag_1="router"501	local exp_flag_1=$mac_pool_1_len502	local flag_2="extern_learn"503	local exp_flag_2=0504 505	vxlan_test_flush_by_flag $flush_by_flag $flag_1 $exp_flag_1 \506		$flag_2 $exp_flag_2507}508 509vxlan_test_flush_by_several_args()510{511	local dst_ip_1=192.0.2.1512	local dst_ip_2=192.0.2.2513	local state_1=permanent514	local state_2=static515	local vni=3000516	local port=1234517	local nhid=100518	local flag=router519	local flush_args520 521	################### Flush by 2 args - nhid and flag ####################522	$IP nexthop add id 10 via 192.0.2.1 fdb523	$IP nexthop add id $nhid group 10 fdb524 525	fdb_add_mac_pool_1 vx10 nhid $nhid $flag $state_1526	fdb_add_mac_pool_2 vx10 nhid $nhid $flag $state_2527 528	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len $state_1529	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len $state_2530 531	run_cmd "$BRIDGE fdb flush dev vx10 nhid $nhid $flag"532	log_test $? 0 "Flush FDB by dev vx10 nhid $nhid $flag"533 534	# All entries should be flushed as 'state' is not an argument for flush535	# filtering.536	fdb_check_n_entries_by_dev_filter vx10 0 $state_1537	log_test $? 0 "Test entries with state $state_1"538 539	fdb_check_n_entries_by_dev_filter vx10 0 $state_2540	log_test $? 0 "Test entries with state $state_2"541 542	################ Flush by 3 args - VNI, port and dst_ip ################543	fdb_add_mac_pool_1 vx10 vni $vni port $port dst $dst_ip_1544	fdb_add_mac_pool_2 vx10 vni $vni port $port dst $dst_ip_2545 546	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip_1547	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len dst $dst_ip_2548 549	flush_args="vni $vni port $port dst $dst_ip_2"550	run_cmd "$BRIDGE fdb flush dev vx10 $flush_args"551	log_test $? 0 "Flush FDB by dev vx10 $flush_args"552 553	# Only entries with $dst_ip_2 should be flushed, even the rest arguments554	# match the filter, the flush should be AND of all the arguments.555	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip_1556	log_test $? 0 "Test entries with dst $dst_ip_1"557 558	fdb_check_n_entries_by_dev_filter vx10 0 dst $dst_ip_2559	log_test $? 0 "Test entries with dst $dst_ip_2"560}561 562multicast_fdb_entries_add()563{564	mac=00:00:00:00:00:00565	vnis=(2000 3000)566 567	for vni in "${vnis[@]}"; do568		$BRIDGE fdb append $mac dev vx10 dst 192.0.2.1 vni $vni \569			src_vni 5000570		$BRIDGE fdb append $mac dev vx10 dst 192.0.2.1 vni $vni \571			port 1111572		$BRIDGE fdb append $mac dev vx10 dst 192.0.2.2 vni $vni \573			port 2222574	done575}576 577vxlan_test_flush_by_remote_attributes()578{579	local flush_args580 581	# Reconfigure vx10 with 'external' to get 'src_vni' details in582	# 'bridge fdb' output583	$IP link del dev vx10584	$IP link add name vx10 type vxlan dstport "$VXPORT" external585 586	# For multicat FDB entries, the VXLAN driver stores a linked list of587	# remotes for a given key. Verify that only the expected remotes are588	# flushed.589	multicast_fdb_entries_add590 591	## Flush by 3 remote's attributes - destination IP, port and VNI ##592	flush_args="dst 192.0.2.1 port 1111 vni 2000"593	fdb_check_n_entries_by_dev_filter vx10 1 $flush_args594 595	t0_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)596	run_cmd "$BRIDGE fdb flush dev vx10 $flush_args"597	log_test $? 0 "Flush FDB by dev vx10 $flush_args"598 599	fdb_check_n_entries_by_dev_filter vx10 0 $flush_args600 601	exp_n_entries=$((t0_n_entries - 1))602	t1_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)603	[[ $t1_n_entries -eq $exp_n_entries ]]604	log_test $? 0 "Check how many entries were flushed"605 606	## Flush by 2 remote's attributes - destination IP and port ##607	flush_args="dst 192.0.2.2 port 2222"608 609	fdb_check_n_entries_by_dev_filter vx10 2 $flush_args610 611	t0_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)612	run_cmd "$BRIDGE fdb flush dev vx10 $flush_args"613	log_test $? 0 "Flush FDB by dev vx10 $flush_args"614 615	fdb_check_n_entries_by_dev_filter vx10 0 $flush_args616 617	exp_n_entries=$((t0_n_entries - 2))618	t1_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)619	[[ $t1_n_entries -eq $exp_n_entries ]]620	log_test $? 0 "Check how many entries were flushed"621 622	## Flush by source VNI, which is not remote's attribute and VNI ##623	flush_args="vni 3000 src_vni 5000"624 625	fdb_check_n_entries_by_dev_filter vx10 1 $flush_args626 627	t0_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)628	run_cmd "$BRIDGE fdb flush dev vx10 $flush_args"629	log_test $? 0 "Flush FDB by dev vx10 $flush_args"630 631	fdb_check_n_entries_by_dev_filter vx10 0 $flush_args632 633	exp_n_entries=$((t0_n_entries -1))634	t1_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)635	[[ $t1_n_entries -eq $exp_n_entries ]]636	log_test $? 0 "Check how many entries were flushed"637 638	# Flush by 1 remote's attribute - destination IP ##639	flush_args="dst 192.0.2.1"640 641	fdb_check_n_entries_by_dev_filter vx10 2 $flush_args642 643	t0_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)644	run_cmd "$BRIDGE fdb flush dev vx10 $flush_args"645	log_test $? 0 "Flush FDB by dev vx10 $flush_args"646 647	fdb_check_n_entries_by_dev_filter vx10 0 $flush_args648 649	exp_n_entries=$((t0_n_entries -2))650	t1_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)651	[[ $t1_n_entries -eq $exp_n_entries ]]652	log_test $? 0 "Check how many entries were flushed"653}654 655bridge_test_flush_by_dev()656{657	local dst_ip=192.0.2.1658	local br0_n_ent_t0=$($BRIDGE fdb show dev br0 | wc -l)659	local br1_n_ent_t0=$($BRIDGE fdb show dev br1 | wc -l)660 661	fdb_add_mac_pool_1 br0 dst $dst_ip662	fdb_add_mac_pool_2 br1 dst $dst_ip663 664	# Each 'fdb add' command adds one extra entry in the bridge with the665	# default vlan.666	local exp_br0_n_ent=$(($br0_n_ent_t0 + 2 * $mac_pool_1_len))667	local exp_br1_n_ent=$(($br1_n_ent_t0 + 2 * $mac_pool_2_len))668 669	fdb_check_n_entries_by_dev_filter br0 $exp_br0_n_ent670	fdb_check_n_entries_by_dev_filter br1 $exp_br1_n_ent671 672	run_cmd "$BRIDGE fdb flush dev br0"673	log_test $? 0 "Flush FDB by dev br0"674 675	# The default entry should not be flushed676	fdb_check_n_entries_by_dev_filter br0 1677	log_test $? 0 "Flush FDB by dev br0 - test br0 entries"678 679	fdb_check_n_entries_by_dev_filter br1 $exp_br1_n_ent680	log_test $? 0 "Flush FDB by dev br0 - test br1 entries"681}682 683bridge_test_flush_by_vlan()684{685	local vlan_1=10686	local vlan_2=20687	local vlan_1_ent_t0688	local vlan_2_ent_t0689 690	$BRIDGE vlan add vid $vlan_1 dev br0 self691	$BRIDGE vlan add vid $vlan_2 dev br0 self692 693	vlan_1_ent_t0=$($BRIDGE fdb show dev br0 | grep "vlan $vlan_1" | wc -l)694	vlan_2_ent_t0=$($BRIDGE fdb show dev br0 | grep "vlan $vlan_2" | wc -l)695 696	fdb_add_mac_pool_1 br0 vlan $vlan_1697	fdb_add_mac_pool_2 br0 vlan $vlan_2698 699	local exp_vlan_1_ent=$(($vlan_1_ent_t0 + $mac_pool_1_len))700	local exp_vlan_2_ent=$(($vlan_2_ent_t0 + $mac_pool_2_len))701 702	fdb_check_n_entries_by_dev_filter br0 $exp_vlan_1_ent vlan $vlan_1703	fdb_check_n_entries_by_dev_filter br0 $exp_vlan_2_ent vlan $vlan_2704 705	run_cmd "$BRIDGE fdb flush dev br0 vlan $vlan_1"706	log_test $? 0 "Flush FDB by dev br0 and vlan $vlan_1"707 708	fdb_check_n_entries_by_dev_filter br0 0 vlan $vlan_1709	log_test $? 0 "Test entries with vlan $vlan_1"710 711	fdb_check_n_entries_by_dev_filter br0 $exp_vlan_2_ent vlan $vlan_2712	log_test $? 0 "Test entries with vlan $vlan_2"713}714 715bridge_vxlan_test_flush()716{717	local vlan_1=10718	local dst_ip=192.0.2.1719 720	$IP link set dev vx10 master br0721	$BRIDGE vlan add vid $vlan_1 dev br0 self722	$BRIDGE vlan add vid $vlan_1 dev vx10723 724	fdb_add_mac_pool_1 vx10 vni 3000 dst $dst_ip self master725 726	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len vlan $vlan_1727	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len vni 3000728 729	# Such command should fail in VXLAN driver as vlan is not supported,730	# but the command should flush the entries in the bridge731	run_cmd "$BRIDGE fdb flush dev vx10 vlan $vlan_1 master self"732	log_test $? 255 \733		"Flush FDB by dev vx10, vlan $vlan_1, master and self"734 735	fdb_check_n_entries_by_dev_filter vx10 0 vlan $vlan_1736	log_test $? 0 "Test entries with vlan $vlan_1"737 738	fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip739	log_test $? 0 "Test entries with dst $dst_ip"740}741 742setup()743{744	setup_ns NS745	IP="ip -netns ${NS}"746	BRIDGE="bridge -netns ${NS}"747 748	$IP link add name vx10 type vxlan id 1000 dstport "$VXPORT"749	$IP link add name vx20 type vxlan id 2000 dstport "$VXPORT"750 751	$IP link add br0 type bridge vlan_filtering 1752	$IP link add br1 type bridge vlan_filtering 1753}754 755cleanup()756{757	$IP link del dev br1758	$IP link del dev br0759 760	$IP link del dev vx20761	$IP link del dev vx10762 763	cleanup_ns ${NS}764}765 766################################################################################767# main768 769while getopts :t:pPhvw: o770do771	case $o in772		t) TESTS=$OPTARG;;773		p) PAUSE_ON_FAIL=yes;;774		P) PAUSE=yes;;775		v) VERBOSE=$(($VERBOSE + 1));;776		w) PING_TIMEOUT=$OPTARG;;777		h) usage; exit 0;;778		*) usage; exit 1;;779	esac780done781 782# make sure we don't pause twice783[ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no784 785if [ "$(id -u)" -ne 0 ];then786	echo "SKIP: Need root privileges"787	exit $ksft_skip;788fi789 790if [ ! -x "$(command -v ip)" ]; then791	echo "SKIP: Could not run test without ip tool"792	exit $ksft_skip793fi794 795# Check a flag that is added to flush command as part of VXLAN flush support796bridge fdb help 2>&1 | grep -q "\[no\]router"797if [ $? -ne 0 ]; then798	echo "SKIP: iproute2 too old, missing flush command for VXLAN"799	exit $ksft_skip800fi801 802ip link add dev vx10 type vxlan id 1000 2> /dev/null803out=$(bridge fdb flush dev vx10 2>&1 | grep -q "Operation not supported")804if [ $? -eq 0 ]; then805	echo "SKIP: kernel lacks vxlan flush support"806	exit $ksft_skip807fi808ip link del dev vx10809 810for t in $TESTS811do812	setup; $t; cleanup;813done814