drm/bridge: adv7511: Switch to atomic operations
[drm/drm-misc.git] / tools / testing / selftests / net / fdb_flush.sh
blobd5e3abb8658c31aab8c30c6fbef59ece17924124
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # This test is for checking functionality of flushing FDB entries.
5 # Check that flush works as expected with all the supported arguments and verify
6 # some combinations of arguments.
8 source lib.sh
10 FLUSH_BY_STATE_TESTS="
11 vxlan_test_flush_by_permanent
12 vxlan_test_flush_by_nopermanent
13 vxlan_test_flush_by_static
14 vxlan_test_flush_by_nostatic
15 vxlan_test_flush_by_dynamic
16 vxlan_test_flush_by_nodynamic
19 FLUSH_BY_FLAG_TESTS="
20 vxlan_test_flush_by_extern_learn
21 vxlan_test_flush_by_noextern_learn
22 vxlan_test_flush_by_router
23 vxlan_test_flush_by_norouter
26 TESTS="
27 vxlan_test_flush_by_dev
28 vxlan_test_flush_by_vni
29 vxlan_test_flush_by_src_vni
30 vxlan_test_flush_by_port
31 vxlan_test_flush_by_dst_ip
32 vxlan_test_flush_by_nhid
33 $FLUSH_BY_STATE_TESTS
34 $FLUSH_BY_FLAG_TESTS
35 vxlan_test_flush_by_several_args
36 vxlan_test_flush_by_remote_attributes
37 bridge_test_flush_by_dev
38 bridge_test_flush_by_vlan
39 bridge_vxlan_test_flush
42 : ${VERBOSE:=0}
43 : ${PAUSE_ON_FAIL:=no}
44 : ${PAUSE:=no}
45 : ${VXPORT:=4789}
47 run_cmd()
49 local cmd="$1"
50 local out
51 local rc
52 local stderr="2>/dev/null"
54 if [ "$VERBOSE" = "1" ]; then
55 printf "COMMAND: $cmd\n"
56 stderr=
59 out=$(eval $cmd $stderr)
60 rc=$?
61 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
62 echo " $out"
65 return $rc
68 log_test()
70 local rc=$1
71 local expected=$2
72 local msg="$3"
73 local nsuccess
74 local nfail
75 local ret
77 if [ ${rc} -eq ${expected} ]; then
78 printf "TEST: %-60s [ OK ]\n" "${msg}"
79 nsuccess=$((nsuccess+1))
80 else
81 ret=1
82 nfail=$((nfail+1))
83 printf "TEST: %-60s [FAIL]\n" "${msg}"
84 if [ "$VERBOSE" = "1" ]; then
85 echo " rc=$rc, expected $expected"
88 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
89 echo
90 echo "hit enter to continue, 'q' to quit"
91 read a
92 [ "$a" = "q" ] && exit 1
96 if [ "${PAUSE}" = "yes" ]; then
97 echo
98 echo "hit enter to continue, 'q' to quit"
99 read a
100 [ "$a" = "q" ] && exit 1
103 [ "$VERBOSE" = "1" ] && echo
106 MAC_POOL_1="
107 de:ad:be:ef:13:10
108 de:ad:be:ef:13:11
109 de:ad:be:ef:13:12
110 de:ad:be:ef:13:13
111 de:ad:be:ef:13:14
113 mac_pool_1_len=$(echo "$MAC_POOL_1" | grep -c .)
115 MAC_POOL_2="
116 ca:fe:be:ef:13:10
117 ca:fe:be:ef:13:11
118 ca:fe:be:ef:13:12
119 ca:fe:be:ef:13:13
120 ca:fe:be:ef:13:14
122 mac_pool_2_len=$(echo "$MAC_POOL_2" | grep -c .)
124 fdb_add_mac_pool_1()
126 local dev=$1; shift
127 local args="$@"
129 for mac in $MAC_POOL_1
131 $BRIDGE fdb add $mac dev $dev $args
132 done
135 fdb_add_mac_pool_2()
137 local dev=$1; shift
138 local args="$@"
140 for mac in $MAC_POOL_2
142 $BRIDGE fdb add $mac dev $dev $args
143 done
146 fdb_check_n_entries_by_dev_filter()
148 local dev=$1; shift
149 local exp_entries=$1; shift
150 local filter="$@"
152 local entries=$($BRIDGE fdb show dev $dev | grep "$filter" | wc -l)
154 [[ $entries -eq $exp_entries ]]
155 rc=$?
157 log_test $rc 0 "$dev: Expected $exp_entries FDB entries, got $entries"
158 return $rc
161 vxlan_test_flush_by_dev()
163 local vni=3000
164 local dst_ip=192.0.2.1
166 fdb_add_mac_pool_1 vx10 vni $vni dst $dst_ip
167 fdb_add_mac_pool_2 vx20 vni $vni dst $dst_ip
169 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len
170 fdb_check_n_entries_by_dev_filter vx20 $mac_pool_2_len
172 run_cmd "$BRIDGE fdb flush dev vx10"
173 log_test $? 0 "Flush FDB by dev vx10"
175 fdb_check_n_entries_by_dev_filter vx10 0
176 log_test $? 0 "Flush FDB by dev vx10 - test vx10 entries"
178 fdb_check_n_entries_by_dev_filter vx20 $mac_pool_2_len
179 log_test $? 0 "Flush FDB by dev vx10 - test vx20 entries"
182 vxlan_test_flush_by_vni()
184 local vni_1=3000
185 local vni_2=4000
186 local dst_ip=192.0.2.1
188 fdb_add_mac_pool_1 vx10 vni $vni_1 dst $dst_ip
189 fdb_add_mac_pool_2 vx10 vni $vni_2 dst $dst_ip
191 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len vni $vni_1
192 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len vni $vni_2
194 run_cmd "$BRIDGE fdb flush dev vx10 vni $vni_2"
195 log_test $? 0 "Flush FDB by dev vx10 and vni $vni_2"
197 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len vni $vni_1
198 log_test $? 0 "Test entries with vni $vni_1"
200 fdb_check_n_entries_by_dev_filter vx10 0 vni $vni_2
201 log_test $? 0 "Test entries with vni $vni_2"
204 vxlan_test_flush_by_src_vni()
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, entries
208 # with vni=x are not flused.
209 local vni_1=3000
210 local vni_2=4000
211 local src_vni_1=4000
212 local src_vni_2=3000
213 local dst_ip=192.0.2.1
215 # Reconfigure vx10 with 'external' to get 'src_vni' details in
216 # 'bridge fdb' output
217 $IP link del dev vx10
218 $IP link add name vx10 type vxlan dstport "$VXPORT" external
220 fdb_add_mac_pool_1 vx10 vni $vni_1 src_vni $src_vni_1 dst $dst_ip
221 fdb_add_mac_pool_2 vx10 vni $vni_2 src_vni $src_vni_2 dst $dst_ip
223 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len \
224 src_vni $src_vni_1
225 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len \
226 src_vni $src_vni_2
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"
231 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len \
232 src_vni $src_vni_1
233 log_test $? 0 "Test entries with src_vni $src_vni_1"
235 fdb_check_n_entries_by_dev_filter vx10 0 src_vni $src_vni_2
236 log_test $? 0 "Test entries with src_vni $src_vni_2"
239 vxlan_test_flush_by_port()
241 local port_1=1234
242 local port_2=4321
243 local dst_ip=192.0.2.1
245 fdb_add_mac_pool_1 vx10 port $port_1 dst $dst_ip
246 fdb_add_mac_pool_2 vx10 port $port_2 dst $dst_ip
248 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len port $port_1
249 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len port $port_2
251 run_cmd "$BRIDGE fdb flush dev vx10 port $port_2"
252 log_test $? 0 "Flush FDB by dev vx10 and port $port_2"
254 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len port $port_1
255 log_test $? 0 "Test entries with port $port_1"
257 fdb_check_n_entries_by_dev_filter vx10 0 port $port_2
258 log_test $? 0 "Test entries with port $port_2"
261 vxlan_test_flush_by_dst_ip()
263 local dst_ip_1=192.0.2.1
264 local dst_ip_2=192.0.2.2
266 fdb_add_mac_pool_1 vx10 dst $dst_ip_1
267 fdb_add_mac_pool_2 vx10 dst $dst_ip_2
269 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip_1
270 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len dst $dst_ip_2
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"
275 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip_1
276 log_test $? 0 "Test entries with dst $dst_ip_1"
278 fdb_check_n_entries_by_dev_filter vx10 0 dst $dst_ip_2
279 log_test $? 0 "Test entries with dst $dst_ip_2"
282 nexthops_add()
284 local nhid_1=$1; shift
285 local nhid_2=$1; shift
287 $IP nexthop add id 10 via 192.0.2.1 fdb
288 $IP nexthop add id $nhid_1 group 10 fdb
290 $IP nexthop add id 20 via 192.0.2.2 fdb
291 $IP nexthop add id $nhid_2 group 20 fdb
294 vxlan_test_flush_by_nhid()
296 local nhid_1=100
297 local nhid_2=200
299 nexthops_add $nhid_1 $nhid_2
301 fdb_add_mac_pool_1 vx10 nhid $nhid_1
302 fdb_add_mac_pool_2 vx10 nhid $nhid_2
304 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len nhid $nhid_1
305 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len nhid $nhid_2
307 run_cmd "$BRIDGE fdb flush dev vx10 nhid $nhid_2"
308 log_test $? 0 "Flush FDB by dev vx10 and nhid $nhid_2"
310 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len nhid $nhid_1
311 log_test $? 0 "Test entries with nhid $nhid_1"
313 fdb_check_n_entries_by_dev_filter vx10 0 nhid $nhid_2
314 log_test $? 0 "Test entries with nhid $nhid_2"
316 # Flush also entries with $nhid_1, and then verify that flushing by
317 # 'nhid' does not return an error when there are no entries with
318 # 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"
322 fdb_check_n_entries_by_dev_filter vx10 0 nhid
323 log_test $? 0 "Test entries with 'nhid' keyword"
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"
329 vxlan_test_flush_by_state()
331 local flush_by_state=$1; shift
332 local state_1=$1; shift
333 local exp_state_1=$1; shift
334 local state_2=$1; shift
335 local exp_state_2=$1; shift
337 local dst_ip_1=192.0.2.1
338 local dst_ip_2=192.0.2.2
340 fdb_add_mac_pool_1 vx10 dst $dst_ip_1 $state_1
341 fdb_add_mac_pool_2 vx10 dst $dst_ip_2 $state_2
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_1
346 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len dst $dst_ip_2
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"
351 fdb_check_n_entries_by_dev_filter vx10 $exp_state_1 dst $dst_ip_1
352 log_test $? 0 "Test entries with state $state_1"
354 fdb_check_n_entries_by_dev_filter vx10 $exp_state_2 dst $dst_ip_2
355 log_test $? 0 "Test entries with state $state_2"
358 vxlan_test_flush_by_permanent()
360 # Entries that are added without state get 'permanent' state by
361 # 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=0
366 local state_2="extern_learn"
367 local exp_state_2=0
369 vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \
370 $state_2 $exp_state_2
373 vxlan_test_flush_by_nopermanent()
375 local flush_by_state="nopermanent"
376 local state_1="permanent"
377 local exp_state_1=$mac_pool_1_len
378 local state_2="static"
379 local exp_state_2=0
381 vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \
382 $state_2 $exp_state_2
385 vxlan_test_flush_by_static()
387 local flush_by_state="static"
388 local state_1="static"
389 local exp_state_1=0
390 local state_2="dynamic"
391 local exp_state_2=$mac_pool_2_len
393 vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \
394 $state_2 $exp_state_2
397 vxlan_test_flush_by_nostatic()
399 local flush_by_state="nostatic"
400 local state_1="permanent"
401 local exp_state_1=$mac_pool_1_len
402 local state_2="dynamic"
403 local exp_state_2=0
405 vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \
406 $state_2 $exp_state_2
409 vxlan_test_flush_by_dynamic()
411 local flush_by_state="dynamic"
412 local state_1="dynamic"
413 local exp_state_1=0
414 local state_2="static"
415 local exp_state_2=$mac_pool_2_len
417 vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \
418 $state_2 $exp_state_2
421 vxlan_test_flush_by_nodynamic()
423 local flush_by_state="nodynamic"
424 local state_1="permanent"
425 local exp_state_1=0
426 local state_2="dynamic"
427 local exp_state_2=$mac_pool_2_len
429 vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \
430 $state_2 $exp_state_2
433 vxlan_test_flush_by_flag()
435 local flush_by_flag=$1; shift
436 local flag_1=$1; shift
437 local exp_flag_1=$1; shift
438 local flag_2=$1; shift
439 local exp_flag_2=$1; shift
441 local dst_ip_1=192.0.2.1
442 local dst_ip_2=192.0.2.2
444 fdb_add_mac_pool_1 vx10 dst $dst_ip_1 $flag_1
445 fdb_add_mac_pool_2 vx10 dst $dst_ip_2 $flag_2
447 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len $flag_1
448 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len $flag_2
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"
453 fdb_check_n_entries_by_dev_filter vx10 $exp_flag_1 dst $dst_ip_1
454 log_test $? 0 "Test entries with flag $flag_1"
456 fdb_check_n_entries_by_dev_filter vx10 $exp_flag_2 dst $dst_ip_2
457 log_test $? 0 "Test entries with flag $flag_2"
460 vxlan_test_flush_by_extern_learn()
462 local flush_by_flag="extern_learn"
463 local flag_1="extern_learn"
464 local exp_flag_1=0
465 local flag_2="router"
466 local exp_flag_2=$mac_pool_2_len
468 vxlan_test_flush_by_flag $flush_by_flag $flag_1 $exp_flag_1 \
469 $flag_2 $exp_flag_2
472 vxlan_test_flush_by_noextern_learn()
474 local flush_by_flag="noextern_learn"
475 local flag_1="extern_learn"
476 local exp_flag_1=$mac_pool_1_len
477 local flag_2="router"
478 local exp_flag_2=0
480 vxlan_test_flush_by_flag $flush_by_flag $flag_1 $exp_flag_1 \
481 $flag_2 $exp_flag_2
484 vxlan_test_flush_by_router()
486 local flush_by_flag="router"
487 local flag_1="router"
488 local exp_flag_1=0
489 local flag_2="extern_learn"
490 local exp_flag_2=$mac_pool_2_len
492 vxlan_test_flush_by_flag $flush_by_flag $flag_1 $exp_flag_1 \
493 $flag_2 $exp_flag_2
496 vxlan_test_flush_by_norouter()
499 local flush_by_flag="norouter"
500 local flag_1="router"
501 local exp_flag_1=$mac_pool_1_len
502 local flag_2="extern_learn"
503 local exp_flag_2=0
505 vxlan_test_flush_by_flag $flush_by_flag $flag_1 $exp_flag_1 \
506 $flag_2 $exp_flag_2
509 vxlan_test_flush_by_several_args()
511 local dst_ip_1=192.0.2.1
512 local dst_ip_2=192.0.2.2
513 local state_1=permanent
514 local state_2=static
515 local vni=3000
516 local port=1234
517 local nhid=100
518 local flag=router
519 local flush_args
521 ################### Flush by 2 args - nhid and flag ####################
522 $IP nexthop add id 10 via 192.0.2.1 fdb
523 $IP nexthop add id $nhid group 10 fdb
525 fdb_add_mac_pool_1 vx10 nhid $nhid $flag $state_1
526 fdb_add_mac_pool_2 vx10 nhid $nhid $flag $state_2
528 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len $state_1
529 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len $state_2
531 run_cmd "$BRIDGE fdb flush dev vx10 nhid $nhid $flag"
532 log_test $? 0 "Flush FDB by dev vx10 nhid $nhid $flag"
534 # All entries should be flushed as 'state' is not an argument for flush
535 # filtering.
536 fdb_check_n_entries_by_dev_filter vx10 0 $state_1
537 log_test $? 0 "Test entries with state $state_1"
539 fdb_check_n_entries_by_dev_filter vx10 0 $state_2
540 log_test $? 0 "Test entries with state $state_2"
542 ################ Flush by 3 args - VNI, port and dst_ip ################
543 fdb_add_mac_pool_1 vx10 vni $vni port $port dst $dst_ip_1
544 fdb_add_mac_pool_2 vx10 vni $vni port $port dst $dst_ip_2
546 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip_1
547 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len dst $dst_ip_2
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"
553 # Only entries with $dst_ip_2 should be flushed, even the rest arguments
554 # 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_1
556 log_test $? 0 "Test entries with dst $dst_ip_1"
558 fdb_check_n_entries_by_dev_filter vx10 0 dst $dst_ip_2
559 log_test $? 0 "Test entries with dst $dst_ip_2"
562 multicast_fdb_entries_add()
564 mac=00:00:00:00:00:00
565 vnis=(2000 3000)
567 for vni in "${vnis[@]}"; do
568 $BRIDGE fdb append $mac dev vx10 dst 192.0.2.1 vni $vni \
569 src_vni 5000
570 $BRIDGE fdb append $mac dev vx10 dst 192.0.2.1 vni $vni \
571 port 1111
572 $BRIDGE fdb append $mac dev vx10 dst 192.0.2.2 vni $vni \
573 port 2222
574 done
577 vxlan_test_flush_by_remote_attributes()
579 local flush_args
581 # Reconfigure vx10 with 'external' to get 'src_vni' details in
582 # 'bridge fdb' output
583 $IP link del dev vx10
584 $IP link add name vx10 type vxlan dstport "$VXPORT" external
586 # For multicat FDB entries, the VXLAN driver stores a linked list of
587 # remotes for a given key. Verify that only the expected remotes are
588 # flushed.
589 multicast_fdb_entries_add
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_args
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"
599 fdb_check_n_entries_by_dev_filter vx10 0 $flush_args
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"
606 ## Flush by 2 remote's attributes - destination IP and port ##
607 flush_args="dst 192.0.2.2 port 2222"
609 fdb_check_n_entries_by_dev_filter vx10 2 $flush_args
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"
615 fdb_check_n_entries_by_dev_filter vx10 0 $flush_args
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"
622 ## Flush by source VNI, which is not remote's attribute and VNI ##
623 flush_args="vni 3000 src_vni 5000"
625 fdb_check_n_entries_by_dev_filter vx10 1 $flush_args
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"
631 fdb_check_n_entries_by_dev_filter vx10 0 $flush_args
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"
638 # Flush by 1 remote's attribute - destination IP ##
639 flush_args="dst 192.0.2.1"
641 fdb_check_n_entries_by_dev_filter vx10 2 $flush_args
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"
647 fdb_check_n_entries_by_dev_filter vx10 0 $flush_args
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"
655 bridge_test_flush_by_dev()
657 local dst_ip=192.0.2.1
658 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)
661 fdb_add_mac_pool_1 br0 dst $dst_ip
662 fdb_add_mac_pool_2 br1 dst $dst_ip
664 # Each 'fdb add' command adds one extra entry in the bridge with the
665 # 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))
669 fdb_check_n_entries_by_dev_filter br0 $exp_br0_n_ent
670 fdb_check_n_entries_by_dev_filter br1 $exp_br1_n_ent
672 run_cmd "$BRIDGE fdb flush dev br0"
673 log_test $? 0 "Flush FDB by dev br0"
675 # The default entry should not be flushed
676 fdb_check_n_entries_by_dev_filter br0 1
677 log_test $? 0 "Flush FDB by dev br0 - test br0 entries"
679 fdb_check_n_entries_by_dev_filter br1 $exp_br1_n_ent
680 log_test $? 0 "Flush FDB by dev br0 - test br1 entries"
683 bridge_test_flush_by_vlan()
685 local vlan_1=10
686 local vlan_2=20
687 local vlan_1_ent_t0
688 local vlan_2_ent_t0
690 $BRIDGE vlan add vid $vlan_1 dev br0 self
691 $BRIDGE vlan add vid $vlan_2 dev br0 self
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)
696 fdb_add_mac_pool_1 br0 vlan $vlan_1
697 fdb_add_mac_pool_2 br0 vlan $vlan_2
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))
702 fdb_check_n_entries_by_dev_filter br0 $exp_vlan_1_ent vlan $vlan_1
703 fdb_check_n_entries_by_dev_filter br0 $exp_vlan_2_ent vlan $vlan_2
705 run_cmd "$BRIDGE fdb flush dev br0 vlan $vlan_1"
706 log_test $? 0 "Flush FDB by dev br0 and vlan $vlan_1"
708 fdb_check_n_entries_by_dev_filter br0 0 vlan $vlan_1
709 log_test $? 0 "Test entries with vlan $vlan_1"
711 fdb_check_n_entries_by_dev_filter br0 $exp_vlan_2_ent vlan $vlan_2
712 log_test $? 0 "Test entries with vlan $vlan_2"
715 bridge_vxlan_test_flush()
717 local vlan_1=10
718 local dst_ip=192.0.2.1
720 $IP link set dev vx10 master br0
721 $BRIDGE vlan add vid $vlan_1 dev br0 self
722 $BRIDGE vlan add vid $vlan_1 dev vx10
724 fdb_add_mac_pool_1 vx10 vni 3000 dst $dst_ip self master
726 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len vlan $vlan_1
727 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len vni 3000
729 # Such command should fail in VXLAN driver as vlan is not supported,
730 # but the command should flush the entries in the bridge
731 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"
735 fdb_check_n_entries_by_dev_filter vx10 0 vlan $vlan_1
736 log_test $? 0 "Test entries with vlan $vlan_1"
738 fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip
739 log_test $? 0 "Test entries with dst $dst_ip"
742 setup()
744 setup_ns NS
745 IP="ip -netns ${NS}"
746 BRIDGE="bridge -netns ${NS}"
748 $IP link add name vx10 type vxlan id 1000 dstport "$VXPORT"
749 $IP link add name vx20 type vxlan id 2000 dstport "$VXPORT"
751 $IP link add br0 type bridge vlan_filtering 1
752 $IP link add br1 type bridge vlan_filtering 1
755 cleanup()
757 $IP link del dev br1
758 $IP link del dev br0
760 $IP link del dev vx20
761 $IP link del dev vx10
763 cleanup_ns ${NS}
766 ################################################################################
767 # main
769 while getopts :t:pPhvw: o
771 case $o in
772 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 esac
780 done
782 # make sure we don't pause twice
783 [ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no
785 if [ "$(id -u)" -ne 0 ];then
786 echo "SKIP: Need root privileges"
787 exit $ksft_skip;
790 if [ ! -x "$(command -v ip)" ]; then
791 echo "SKIP: Could not run test without ip tool"
792 exit $ksft_skip
795 # Check a flag that is added to flush command as part of VXLAN flush support
796 bridge fdb help 2>&1 | grep -q "\[no\]router"
797 if [ $? -ne 0 ]; then
798 echo "SKIP: iproute2 too old, missing flush command for VXLAN"
799 exit $ksft_skip
802 ip link add dev vx10 type vxlan id 1000 2> /dev/null
803 out=$(bridge fdb flush dev vx10 2>&1 | grep -q "Operation not supported")
804 if [ $? -eq 0 ]; then
805 echo "SKIP: kernel lacks vxlan flush support"
806 exit $ksft_skip
808 ip link del dev vx10
810 for t in $TESTS
812 setup; $t; cleanup;
813 done