devlink_trap.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Test generic devlink-trap functionality over mlxsw. These tests are not
  5. # specific to a single trap, but do not check the devlink-trap common
  6. # infrastructure either.
  7. lib_dir=$(dirname $0)/../../../net/forwarding
  8. ALL_TESTS="
  9. dev_del_test
  10. "
  11. NUM_NETIFS=4
  12. source $lib_dir/tc_common.sh
  13. source $lib_dir/lib.sh
  14. source $lib_dir/devlink_lib.sh
  15. h1_create()
  16. {
  17. simple_if_init $h1
  18. }
  19. h1_destroy()
  20. {
  21. simple_if_fini $h1
  22. }
  23. h2_create()
  24. {
  25. simple_if_init $h2
  26. }
  27. h2_destroy()
  28. {
  29. simple_if_fini $h2
  30. }
  31. switch_create()
  32. {
  33. ip link add dev br0 type bridge vlan_filtering 1 mcast_snooping 0
  34. ip link set dev $swp1 master br0
  35. ip link set dev $swp2 master br0
  36. ip link set dev br0 up
  37. ip link set dev $swp1 up
  38. ip link set dev $swp2 up
  39. }
  40. switch_destroy()
  41. {
  42. ip link set dev $swp2 down
  43. ip link set dev $swp1 down
  44. ip link del dev br0
  45. }
  46. setup_prepare()
  47. {
  48. h1=${NETIFS[p1]}
  49. swp1=${NETIFS[p2]}
  50. swp2=${NETIFS[p3]}
  51. h2=${NETIFS[p4]}
  52. vrf_prepare
  53. h1_create
  54. h2_create
  55. switch_create
  56. }
  57. cleanup()
  58. {
  59. pre_cleanup
  60. switch_destroy
  61. h2_destroy
  62. h1_destroy
  63. vrf_cleanup
  64. }
  65. dev_del_test()
  66. {
  67. local trap_name="source_mac_is_multicast"
  68. local smac=01:02:03:04:05:06
  69. local num_iter=5
  70. local mz_pid
  71. local i
  72. $MZ $h1 -c 0 -p 100 -a $smac -b bcast -t ip -q &
  73. mz_pid=$!
  74. # The purpose of this test is to make sure we correctly dismantle a
  75. # port while packets are trapped from it. This is done by reloading the
  76. # the driver while the 'ingress_smac_mc_drop' trap is triggered.
  77. RET=0
  78. for i in $(seq 1 $num_iter); do
  79. log_info "Iteration $i / $num_iter"
  80. devlink_trap_action_set $trap_name "trap"
  81. sleep 1
  82. devlink_reload
  83. # Allow netdevices to be re-created following the reload
  84. sleep 20
  85. cleanup
  86. setup_prepare
  87. setup_wait
  88. done
  89. log_test "Device delete"
  90. kill $mz_pid && wait $mz_pid &> /dev/null
  91. }
  92. trap cleanup EXIT
  93. setup_prepare
  94. setup_wait
  95. tests_run
  96. exit $EXIT_STATUS