fdb_flush.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  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.
  7. source lib.sh
  8. FLUSH_BY_STATE_TESTS="
  9. vxlan_test_flush_by_permanent
  10. vxlan_test_flush_by_nopermanent
  11. vxlan_test_flush_by_static
  12. vxlan_test_flush_by_nostatic
  13. vxlan_test_flush_by_dynamic
  14. vxlan_test_flush_by_nodynamic
  15. "
  16. FLUSH_BY_FLAG_TESTS="
  17. vxlan_test_flush_by_extern_learn
  18. vxlan_test_flush_by_noextern_learn
  19. vxlan_test_flush_by_router
  20. vxlan_test_flush_by_norouter
  21. "
  22. TESTS="
  23. vxlan_test_flush_by_dev
  24. vxlan_test_flush_by_vni
  25. vxlan_test_flush_by_src_vni
  26. vxlan_test_flush_by_port
  27. vxlan_test_flush_by_dst_ip
  28. vxlan_test_flush_by_nhid
  29. $FLUSH_BY_STATE_TESTS
  30. $FLUSH_BY_FLAG_TESTS
  31. vxlan_test_flush_by_several_args
  32. vxlan_test_flush_by_remote_attributes
  33. bridge_test_flush_by_dev
  34. bridge_test_flush_by_vlan
  35. bridge_vxlan_test_flush
  36. "
  37. : ${VERBOSE:=0}
  38. : ${PAUSE_ON_FAIL:=no}
  39. : ${PAUSE:=no}
  40. : ${VXPORT:=4789}
  41. run_cmd()
  42. {
  43. local cmd="$1"
  44. local out
  45. local rc
  46. local stderr="2>/dev/null"
  47. if [ "$VERBOSE" = "1" ]; then
  48. printf "COMMAND: $cmd\n"
  49. stderr=
  50. fi
  51. out=$(eval $cmd $stderr)
  52. rc=$?
  53. if [ "$VERBOSE" = "1" -a -n "$out" ]; then
  54. echo " $out"
  55. fi
  56. return $rc
  57. }
  58. log_test()
  59. {
  60. local rc=$1
  61. local expected=$2
  62. local msg="$3"
  63. local nsuccess
  64. local nfail
  65. local ret
  66. if [ ${rc} -eq ${expected} ]; then
  67. printf "TEST: %-60s [ OK ]\n" "${msg}"
  68. nsuccess=$((nsuccess+1))
  69. else
  70. ret=1
  71. nfail=$((nfail+1))
  72. printf "TEST: %-60s [FAIL]\n" "${msg}"
  73. if [ "$VERBOSE" = "1" ]; then
  74. echo " rc=$rc, expected $expected"
  75. fi
  76. if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
  77. echo
  78. echo "hit enter to continue, 'q' to quit"
  79. read a
  80. [ "$a" = "q" ] && exit 1
  81. fi
  82. fi
  83. if [ "${PAUSE}" = "yes" ]; then
  84. echo
  85. echo "hit enter to continue, 'q' to quit"
  86. read a
  87. [ "$a" = "q" ] && exit 1
  88. fi
  89. [ "$VERBOSE" = "1" ] && echo
  90. }
  91. MAC_POOL_1="
  92. de:ad:be:ef:13:10
  93. de:ad:be:ef:13:11
  94. de:ad:be:ef:13:12
  95. de:ad:be:ef:13:13
  96. de:ad:be:ef:13:14
  97. "
  98. mac_pool_1_len=$(echo "$MAC_POOL_1" | grep -c .)
  99. MAC_POOL_2="
  100. ca:fe:be:ef:13:10
  101. ca:fe:be:ef:13:11
  102. ca:fe:be:ef:13:12
  103. ca:fe:be:ef:13:13
  104. ca:fe:be:ef:13:14
  105. "
  106. mac_pool_2_len=$(echo "$MAC_POOL_2" | grep -c .)
  107. fdb_add_mac_pool_1()
  108. {
  109. local dev=$1; shift
  110. local args="$@"
  111. for mac in $MAC_POOL_1
  112. do
  113. $BRIDGE fdb add $mac dev $dev $args
  114. done
  115. }
  116. fdb_add_mac_pool_2()
  117. {
  118. local dev=$1; shift
  119. local args="$@"
  120. for mac in $MAC_POOL_2
  121. do
  122. $BRIDGE fdb add $mac dev $dev $args
  123. done
  124. }
  125. fdb_check_n_entries_by_dev_filter()
  126. {
  127. local dev=$1; shift
  128. local exp_entries=$1; shift
  129. local filter="$@"
  130. local entries=$($BRIDGE fdb show dev $dev | grep "$filter" | wc -l)
  131. [[ $entries -eq $exp_entries ]]
  132. rc=$?
  133. log_test $rc 0 "$dev: Expected $exp_entries FDB entries, got $entries"
  134. return $rc
  135. }
  136. vxlan_test_flush_by_dev()
  137. {
  138. local vni=3000
  139. local dst_ip=192.0.2.1
  140. fdb_add_mac_pool_1 vx10 vni $vni dst $dst_ip
  141. fdb_add_mac_pool_2 vx20 vni $vni dst $dst_ip
  142. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len
  143. fdb_check_n_entries_by_dev_filter vx20 $mac_pool_2_len
  144. run_cmd "$BRIDGE fdb flush dev vx10"
  145. log_test $? 0 "Flush FDB by dev vx10"
  146. fdb_check_n_entries_by_dev_filter vx10 0
  147. log_test $? 0 "Flush FDB by dev vx10 - test vx10 entries"
  148. fdb_check_n_entries_by_dev_filter vx20 $mac_pool_2_len
  149. log_test $? 0 "Flush FDB by dev vx10 - test vx20 entries"
  150. }
  151. vxlan_test_flush_by_vni()
  152. {
  153. local vni_1=3000
  154. local vni_2=4000
  155. local dst_ip=192.0.2.1
  156. fdb_add_mac_pool_1 vx10 vni $vni_1 dst $dst_ip
  157. fdb_add_mac_pool_2 vx10 vni $vni_2 dst $dst_ip
  158. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len vni $vni_1
  159. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len vni $vni_2
  160. run_cmd "$BRIDGE fdb flush dev vx10 vni $vni_2"
  161. log_test $? 0 "Flush FDB by dev vx10 and vni $vni_2"
  162. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len vni $vni_1
  163. log_test $? 0 "Test entries with vni $vni_1"
  164. fdb_check_n_entries_by_dev_filter vx10 0 vni $vni_2
  165. log_test $? 0 "Test entries with vni $vni_2"
  166. }
  167. vxlan_test_flush_by_src_vni()
  168. {
  169. # Set some entries with {vni=x,src_vni=y} and some with the opposite -
  170. # {vni=y,src_vni=x}, to verify that when we flush by src_vni=x, entries
  171. # with vni=x are not flused.
  172. local vni_1=3000
  173. local vni_2=4000
  174. local src_vni_1=4000
  175. local src_vni_2=3000
  176. local dst_ip=192.0.2.1
  177. # Reconfigure vx10 with 'external' to get 'src_vni' details in
  178. # 'bridge fdb' output
  179. $IP link del dev vx10
  180. $IP link add name vx10 type vxlan dstport "$VXPORT" external
  181. fdb_add_mac_pool_1 vx10 vni $vni_1 src_vni $src_vni_1 dst $dst_ip
  182. fdb_add_mac_pool_2 vx10 vni $vni_2 src_vni $src_vni_2 dst $dst_ip
  183. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len \
  184. src_vni $src_vni_1
  185. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len \
  186. src_vni $src_vni_2
  187. run_cmd "$BRIDGE fdb flush dev vx10 src_vni $src_vni_2"
  188. log_test $? 0 "Flush FDB by dev vx10 and src_vni $src_vni_2"
  189. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len \
  190. src_vni $src_vni_1
  191. log_test $? 0 "Test entries with src_vni $src_vni_1"
  192. fdb_check_n_entries_by_dev_filter vx10 0 src_vni $src_vni_2
  193. log_test $? 0 "Test entries with src_vni $src_vni_2"
  194. }
  195. vxlan_test_flush_by_port()
  196. {
  197. local port_1=1234
  198. local port_2=4321
  199. local dst_ip=192.0.2.1
  200. fdb_add_mac_pool_1 vx10 port $port_1 dst $dst_ip
  201. fdb_add_mac_pool_2 vx10 port $port_2 dst $dst_ip
  202. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len port $port_1
  203. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len port $port_2
  204. run_cmd "$BRIDGE fdb flush dev vx10 port $port_2"
  205. log_test $? 0 "Flush FDB by dev vx10 and port $port_2"
  206. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len port $port_1
  207. log_test $? 0 "Test entries with port $port_1"
  208. fdb_check_n_entries_by_dev_filter vx10 0 port $port_2
  209. log_test $? 0 "Test entries with port $port_2"
  210. }
  211. vxlan_test_flush_by_dst_ip()
  212. {
  213. local dst_ip_1=192.0.2.1
  214. local dst_ip_2=192.0.2.2
  215. fdb_add_mac_pool_1 vx10 dst $dst_ip_1
  216. fdb_add_mac_pool_2 vx10 dst $dst_ip_2
  217. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip_1
  218. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len dst $dst_ip_2
  219. run_cmd "$BRIDGE fdb flush dev vx10 dst $dst_ip_2"
  220. log_test $? 0 "Flush FDB by dev vx10 and dst $dst_ip_2"
  221. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip_1
  222. log_test $? 0 "Test entries with dst $dst_ip_1"
  223. fdb_check_n_entries_by_dev_filter vx10 0 dst $dst_ip_2
  224. log_test $? 0 "Test entries with dst $dst_ip_2"
  225. }
  226. nexthops_add()
  227. {
  228. local nhid_1=$1; shift
  229. local nhid_2=$1; shift
  230. $IP nexthop add id 10 via 192.0.2.1 fdb
  231. $IP nexthop add id $nhid_1 group 10 fdb
  232. $IP nexthop add id 20 via 192.0.2.2 fdb
  233. $IP nexthop add id $nhid_2 group 20 fdb
  234. }
  235. vxlan_test_flush_by_nhid()
  236. {
  237. local nhid_1=100
  238. local nhid_2=200
  239. nexthops_add $nhid_1 $nhid_2
  240. fdb_add_mac_pool_1 vx10 nhid $nhid_1
  241. fdb_add_mac_pool_2 vx10 nhid $nhid_2
  242. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len nhid $nhid_1
  243. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len nhid $nhid_2
  244. run_cmd "$BRIDGE fdb flush dev vx10 nhid $nhid_2"
  245. log_test $? 0 "Flush FDB by dev vx10 and nhid $nhid_2"
  246. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len nhid $nhid_1
  247. log_test $? 0 "Test entries with nhid $nhid_1"
  248. fdb_check_n_entries_by_dev_filter vx10 0 nhid $nhid_2
  249. log_test $? 0 "Test entries with nhid $nhid_2"
  250. # Flush also entries with $nhid_1, and then verify that flushing by
  251. # 'nhid' does not return an error when there are no entries with
  252. # nexthops.
  253. run_cmd "$BRIDGE fdb flush dev vx10 nhid $nhid_1"
  254. log_test $? 0 "Flush FDB by dev vx10 and nhid $nhid_1"
  255. fdb_check_n_entries_by_dev_filter vx10 0 nhid
  256. log_test $? 0 "Test entries with 'nhid' keyword"
  257. run_cmd "$BRIDGE fdb flush dev vx10 nhid $nhid_1"
  258. log_test $? 0 "Flush FDB by nhid when there are no entries with nexthop"
  259. }
  260. vxlan_test_flush_by_state()
  261. {
  262. local flush_by_state=$1; shift
  263. local state_1=$1; shift
  264. local exp_state_1=$1; shift
  265. local state_2=$1; shift
  266. local exp_state_2=$1; shift
  267. local dst_ip_1=192.0.2.1
  268. local dst_ip_2=192.0.2.2
  269. fdb_add_mac_pool_1 vx10 dst $dst_ip_1 $state_1
  270. fdb_add_mac_pool_2 vx10 dst $dst_ip_2 $state_2
  271. # Check the entries by dst_ip as not all states appear in 'bridge fdb'
  272. # output.
  273. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip_1
  274. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len dst $dst_ip_2
  275. run_cmd "$BRIDGE fdb flush dev vx10 $flush_by_state"
  276. log_test $? 0 "Flush FDB by dev vx10 and state $flush_by_state"
  277. fdb_check_n_entries_by_dev_filter vx10 $exp_state_1 dst $dst_ip_1
  278. log_test $? 0 "Test entries with state $state_1"
  279. fdb_check_n_entries_by_dev_filter vx10 $exp_state_2 dst $dst_ip_2
  280. log_test $? 0 "Test entries with state $state_2"
  281. }
  282. vxlan_test_flush_by_permanent()
  283. {
  284. # Entries that are added without state get 'permanent' state by
  285. # default, add some entries with flag 'extern_learn' instead of state,
  286. # so they will be added with 'permanent' and should be flushed also.
  287. local flush_by_state="permanent"
  288. local state_1="permanent"
  289. local exp_state_1=0
  290. local state_2="extern_learn"
  291. local exp_state_2=0
  292. vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \
  293. $state_2 $exp_state_2
  294. }
  295. vxlan_test_flush_by_nopermanent()
  296. {
  297. local flush_by_state="nopermanent"
  298. local state_1="permanent"
  299. local exp_state_1=$mac_pool_1_len
  300. local state_2="static"
  301. local exp_state_2=0
  302. vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \
  303. $state_2 $exp_state_2
  304. }
  305. vxlan_test_flush_by_static()
  306. {
  307. local flush_by_state="static"
  308. local state_1="static"
  309. local exp_state_1=0
  310. local state_2="dynamic"
  311. local exp_state_2=$mac_pool_2_len
  312. vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \
  313. $state_2 $exp_state_2
  314. }
  315. vxlan_test_flush_by_nostatic()
  316. {
  317. local flush_by_state="nostatic"
  318. local state_1="permanent"
  319. local exp_state_1=$mac_pool_1_len
  320. local state_2="dynamic"
  321. local exp_state_2=0
  322. vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \
  323. $state_2 $exp_state_2
  324. }
  325. vxlan_test_flush_by_dynamic()
  326. {
  327. local flush_by_state="dynamic"
  328. local state_1="dynamic"
  329. local exp_state_1=0
  330. local state_2="static"
  331. local exp_state_2=$mac_pool_2_len
  332. vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \
  333. $state_2 $exp_state_2
  334. }
  335. vxlan_test_flush_by_nodynamic()
  336. {
  337. local flush_by_state="nodynamic"
  338. local state_1="permanent"
  339. local exp_state_1=0
  340. local state_2="dynamic"
  341. local exp_state_2=$mac_pool_2_len
  342. vxlan_test_flush_by_state $flush_by_state $state_1 $exp_state_1 \
  343. $state_2 $exp_state_2
  344. }
  345. vxlan_test_flush_by_flag()
  346. {
  347. local flush_by_flag=$1; shift
  348. local flag_1=$1; shift
  349. local exp_flag_1=$1; shift
  350. local flag_2=$1; shift
  351. local exp_flag_2=$1; shift
  352. local dst_ip_1=192.0.2.1
  353. local dst_ip_2=192.0.2.2
  354. fdb_add_mac_pool_1 vx10 dst $dst_ip_1 $flag_1
  355. fdb_add_mac_pool_2 vx10 dst $dst_ip_2 $flag_2
  356. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len $flag_1
  357. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len $flag_2
  358. run_cmd "$BRIDGE fdb flush dev vx10 $flush_by_flag"
  359. log_test $? 0 "Flush FDB by dev vx10 and flag $flush_by_flag"
  360. fdb_check_n_entries_by_dev_filter vx10 $exp_flag_1 dst $dst_ip_1
  361. log_test $? 0 "Test entries with flag $flag_1"
  362. fdb_check_n_entries_by_dev_filter vx10 $exp_flag_2 dst $dst_ip_2
  363. log_test $? 0 "Test entries with flag $flag_2"
  364. }
  365. vxlan_test_flush_by_extern_learn()
  366. {
  367. local flush_by_flag="extern_learn"
  368. local flag_1="extern_learn"
  369. local exp_flag_1=0
  370. local flag_2="router"
  371. local exp_flag_2=$mac_pool_2_len
  372. vxlan_test_flush_by_flag $flush_by_flag $flag_1 $exp_flag_1 \
  373. $flag_2 $exp_flag_2
  374. }
  375. vxlan_test_flush_by_noextern_learn()
  376. {
  377. local flush_by_flag="noextern_learn"
  378. local flag_1="extern_learn"
  379. local exp_flag_1=$mac_pool_1_len
  380. local flag_2="router"
  381. local exp_flag_2=0
  382. vxlan_test_flush_by_flag $flush_by_flag $flag_1 $exp_flag_1 \
  383. $flag_2 $exp_flag_2
  384. }
  385. vxlan_test_flush_by_router()
  386. {
  387. local flush_by_flag="router"
  388. local flag_1="router"
  389. local exp_flag_1=0
  390. local flag_2="extern_learn"
  391. local exp_flag_2=$mac_pool_2_len
  392. vxlan_test_flush_by_flag $flush_by_flag $flag_1 $exp_flag_1 \
  393. $flag_2 $exp_flag_2
  394. }
  395. vxlan_test_flush_by_norouter()
  396. {
  397. local flush_by_flag="norouter"
  398. local flag_1="router"
  399. local exp_flag_1=$mac_pool_1_len
  400. local flag_2="extern_learn"
  401. local exp_flag_2=0
  402. vxlan_test_flush_by_flag $flush_by_flag $flag_1 $exp_flag_1 \
  403. $flag_2 $exp_flag_2
  404. }
  405. vxlan_test_flush_by_several_args()
  406. {
  407. local dst_ip_1=192.0.2.1
  408. local dst_ip_2=192.0.2.2
  409. local state_1=permanent
  410. local state_2=static
  411. local vni=3000
  412. local port=1234
  413. local nhid=100
  414. local flag=router
  415. local flush_args
  416. ################### Flush by 2 args - nhid and flag ####################
  417. $IP nexthop add id 10 via 192.0.2.1 fdb
  418. $IP nexthop add id $nhid group 10 fdb
  419. fdb_add_mac_pool_1 vx10 nhid $nhid $flag $state_1
  420. fdb_add_mac_pool_2 vx10 nhid $nhid $flag $state_2
  421. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len $state_1
  422. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len $state_2
  423. run_cmd "$BRIDGE fdb flush dev vx10 nhid $nhid $flag"
  424. log_test $? 0 "Flush FDB by dev vx10 nhid $nhid $flag"
  425. # All entries should be flushed as 'state' is not an argument for flush
  426. # filtering.
  427. fdb_check_n_entries_by_dev_filter vx10 0 $state_1
  428. log_test $? 0 "Test entries with state $state_1"
  429. fdb_check_n_entries_by_dev_filter vx10 0 $state_2
  430. log_test $? 0 "Test entries with state $state_2"
  431. ################ Flush by 3 args - VNI, port and dst_ip ################
  432. fdb_add_mac_pool_1 vx10 vni $vni port $port dst $dst_ip_1
  433. fdb_add_mac_pool_2 vx10 vni $vni port $port dst $dst_ip_2
  434. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip_1
  435. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_2_len dst $dst_ip_2
  436. flush_args="vni $vni port $port dst $dst_ip_2"
  437. run_cmd "$BRIDGE fdb flush dev vx10 $flush_args"
  438. log_test $? 0 "Flush FDB by dev vx10 $flush_args"
  439. # Only entries with $dst_ip_2 should be flushed, even the rest arguments
  440. # match the filter, the flush should be AND of all the arguments.
  441. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip_1
  442. log_test $? 0 "Test entries with dst $dst_ip_1"
  443. fdb_check_n_entries_by_dev_filter vx10 0 dst $dst_ip_2
  444. log_test $? 0 "Test entries with dst $dst_ip_2"
  445. }
  446. multicast_fdb_entries_add()
  447. {
  448. mac=00:00:00:00:00:00
  449. vnis=(2000 3000)
  450. for vni in "${vnis[@]}"; do
  451. $BRIDGE fdb append $mac dev vx10 dst 192.0.2.1 vni $vni \
  452. src_vni 5000
  453. $BRIDGE fdb append $mac dev vx10 dst 192.0.2.1 vni $vni \
  454. port 1111
  455. $BRIDGE fdb append $mac dev vx10 dst 192.0.2.2 vni $vni \
  456. port 2222
  457. done
  458. }
  459. vxlan_test_flush_by_remote_attributes()
  460. {
  461. local flush_args
  462. # Reconfigure vx10 with 'external' to get 'src_vni' details in
  463. # 'bridge fdb' output
  464. $IP link del dev vx10
  465. $IP link add name vx10 type vxlan dstport "$VXPORT" external
  466. # For multicast FDB entries, the VXLAN driver stores a linked list of
  467. # remotes for a given key. Verify that only the expected remotes are
  468. # flushed.
  469. multicast_fdb_entries_add
  470. ## Flush by 3 remote's attributes - destination IP, port and VNI ##
  471. flush_args="dst 192.0.2.1 port 1111 vni 2000"
  472. fdb_check_n_entries_by_dev_filter vx10 1 $flush_args
  473. t0_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)
  474. run_cmd "$BRIDGE fdb flush dev vx10 $flush_args"
  475. log_test $? 0 "Flush FDB by dev vx10 $flush_args"
  476. fdb_check_n_entries_by_dev_filter vx10 0 $flush_args
  477. exp_n_entries=$((t0_n_entries - 1))
  478. t1_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)
  479. [[ $t1_n_entries -eq $exp_n_entries ]]
  480. log_test $? 0 "Check how many entries were flushed"
  481. ## Flush by 2 remote's attributes - destination IP and port ##
  482. flush_args="dst 192.0.2.2 port 2222"
  483. fdb_check_n_entries_by_dev_filter vx10 2 $flush_args
  484. t0_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)
  485. run_cmd "$BRIDGE fdb flush dev vx10 $flush_args"
  486. log_test $? 0 "Flush FDB by dev vx10 $flush_args"
  487. fdb_check_n_entries_by_dev_filter vx10 0 $flush_args
  488. exp_n_entries=$((t0_n_entries - 2))
  489. t1_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)
  490. [[ $t1_n_entries -eq $exp_n_entries ]]
  491. log_test $? 0 "Check how many entries were flushed"
  492. ## Flush by source VNI, which is not remote's attribute and VNI ##
  493. flush_args="vni 3000 src_vni 5000"
  494. fdb_check_n_entries_by_dev_filter vx10 1 $flush_args
  495. t0_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)
  496. run_cmd "$BRIDGE fdb flush dev vx10 $flush_args"
  497. log_test $? 0 "Flush FDB by dev vx10 $flush_args"
  498. fdb_check_n_entries_by_dev_filter vx10 0 $flush_args
  499. exp_n_entries=$((t0_n_entries -1))
  500. t1_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)
  501. [[ $t1_n_entries -eq $exp_n_entries ]]
  502. log_test $? 0 "Check how many entries were flushed"
  503. # Flush by 1 remote's attribute - destination IP ##
  504. flush_args="dst 192.0.2.1"
  505. fdb_check_n_entries_by_dev_filter vx10 2 $flush_args
  506. t0_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)
  507. run_cmd "$BRIDGE fdb flush dev vx10 $flush_args"
  508. log_test $? 0 "Flush FDB by dev vx10 $flush_args"
  509. fdb_check_n_entries_by_dev_filter vx10 0 $flush_args
  510. exp_n_entries=$((t0_n_entries -2))
  511. t1_n_entries=$($BRIDGE fdb show dev vx10 | wc -l)
  512. [[ $t1_n_entries -eq $exp_n_entries ]]
  513. log_test $? 0 "Check how many entries were flushed"
  514. }
  515. bridge_test_flush_by_dev()
  516. {
  517. local dst_ip=192.0.2.1
  518. local br0_n_ent_t0=$($BRIDGE fdb show dev br0 | wc -l)
  519. local br1_n_ent_t0=$($BRIDGE fdb show dev br1 | wc -l)
  520. fdb_add_mac_pool_1 br0 dst $dst_ip
  521. fdb_add_mac_pool_2 br1 dst $dst_ip
  522. # Each 'fdb add' command adds one extra entry in the bridge with the
  523. # default vlan.
  524. local exp_br0_n_ent=$(($br0_n_ent_t0 + 2 * $mac_pool_1_len))
  525. local exp_br1_n_ent=$(($br1_n_ent_t0 + 2 * $mac_pool_2_len))
  526. fdb_check_n_entries_by_dev_filter br0 $exp_br0_n_ent
  527. fdb_check_n_entries_by_dev_filter br1 $exp_br1_n_ent
  528. run_cmd "$BRIDGE fdb flush dev br0"
  529. log_test $? 0 "Flush FDB by dev br0"
  530. # The default entry should not be flushed
  531. fdb_check_n_entries_by_dev_filter br0 1
  532. log_test $? 0 "Flush FDB by dev br0 - test br0 entries"
  533. fdb_check_n_entries_by_dev_filter br1 $exp_br1_n_ent
  534. log_test $? 0 "Flush FDB by dev br0 - test br1 entries"
  535. }
  536. bridge_test_flush_by_vlan()
  537. {
  538. local vlan_1=10
  539. local vlan_2=20
  540. local vlan_1_ent_t0
  541. local vlan_2_ent_t0
  542. $BRIDGE vlan add vid $vlan_1 dev br0 self
  543. $BRIDGE vlan add vid $vlan_2 dev br0 self
  544. vlan_1_ent_t0=$($BRIDGE fdb show dev br0 | grep "vlan $vlan_1" | wc -l)
  545. vlan_2_ent_t0=$($BRIDGE fdb show dev br0 | grep "vlan $vlan_2" | wc -l)
  546. fdb_add_mac_pool_1 br0 vlan $vlan_1
  547. fdb_add_mac_pool_2 br0 vlan $vlan_2
  548. local exp_vlan_1_ent=$(($vlan_1_ent_t0 + $mac_pool_1_len))
  549. local exp_vlan_2_ent=$(($vlan_2_ent_t0 + $mac_pool_2_len))
  550. fdb_check_n_entries_by_dev_filter br0 $exp_vlan_1_ent vlan $vlan_1
  551. fdb_check_n_entries_by_dev_filter br0 $exp_vlan_2_ent vlan $vlan_2
  552. run_cmd "$BRIDGE fdb flush dev br0 vlan $vlan_1"
  553. log_test $? 0 "Flush FDB by dev br0 and vlan $vlan_1"
  554. fdb_check_n_entries_by_dev_filter br0 0 vlan $vlan_1
  555. log_test $? 0 "Test entries with vlan $vlan_1"
  556. fdb_check_n_entries_by_dev_filter br0 $exp_vlan_2_ent vlan $vlan_2
  557. log_test $? 0 "Test entries with vlan $vlan_2"
  558. }
  559. bridge_vxlan_test_flush()
  560. {
  561. local vlan_1=10
  562. local dst_ip=192.0.2.1
  563. $IP link set dev vx10 master br0
  564. $BRIDGE vlan add vid $vlan_1 dev br0 self
  565. $BRIDGE vlan add vid $vlan_1 dev vx10
  566. fdb_add_mac_pool_1 vx10 vni 3000 dst $dst_ip self master
  567. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len vlan $vlan_1
  568. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len vni 3000
  569. # Such command should fail in VXLAN driver as vlan is not supported,
  570. # but the command should flush the entries in the bridge
  571. run_cmd "$BRIDGE fdb flush dev vx10 vlan $vlan_1 master self"
  572. log_test $? 255 \
  573. "Flush FDB by dev vx10, vlan $vlan_1, master and self"
  574. fdb_check_n_entries_by_dev_filter vx10 0 vlan $vlan_1
  575. log_test $? 0 "Test entries with vlan $vlan_1"
  576. fdb_check_n_entries_by_dev_filter vx10 $mac_pool_1_len dst $dst_ip
  577. log_test $? 0 "Test entries with dst $dst_ip"
  578. }
  579. setup()
  580. {
  581. setup_ns NS
  582. IP="ip -netns ${NS}"
  583. BRIDGE="bridge -netns ${NS}"
  584. $IP link add name vx10 type vxlan id 1000 dstport "$VXPORT"
  585. $IP link add name vx20 type vxlan id 2000 dstport "$VXPORT"
  586. $IP link add br0 type bridge vlan_filtering 1
  587. $IP link add br1 type bridge vlan_filtering 1
  588. }
  589. cleanup()
  590. {
  591. $IP link del dev br1
  592. $IP link del dev br0
  593. $IP link del dev vx20
  594. $IP link del dev vx10
  595. cleanup_ns ${NS}
  596. }
  597. ################################################################################
  598. # main
  599. while getopts :t:pPhvw: o
  600. do
  601. case $o in
  602. t) TESTS=$OPTARG;;
  603. p) PAUSE_ON_FAIL=yes;;
  604. P) PAUSE=yes;;
  605. v) VERBOSE=$(($VERBOSE + 1));;
  606. w) PING_TIMEOUT=$OPTARG;;
  607. h) usage; exit 0;;
  608. *) usage; exit 1;;
  609. esac
  610. done
  611. # make sure we don't pause twice
  612. [ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no
  613. if [ "$(id -u)" -ne 0 ];then
  614. echo "SKIP: Need root privileges"
  615. exit $ksft_skip;
  616. fi
  617. if [ ! -x "$(command -v ip)" ]; then
  618. echo "SKIP: Could not run test without ip tool"
  619. exit $ksft_skip
  620. fi
  621. # Check a flag that is added to flush command as part of VXLAN flush support
  622. bridge fdb help 2>&1 | grep -q "\[no\]router"
  623. if [ $? -ne 0 ]; then
  624. echo "SKIP: iproute2 too old, missing flush command for VXLAN"
  625. exit $ksft_skip
  626. fi
  627. ip link add dev vx10 type vxlan id 1000 2> /dev/null
  628. out=$(bridge fdb flush dev vx10 2>&1 | grep -q "Operation not supported")
  629. if [ $? -eq 0 ]; then
  630. echo "SKIP: kernel lacks vxlan flush support"
  631. exit $ksft_skip
  632. fi
  633. ip link del dev vx10
  634. for t in $TESTS
  635. do
  636. setup; $t; cleanup;
  637. done