386 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03#4# Test bonding options with mode 1,5,65 6ALL_TESTS="7 prio8 arp_validate9 num_grat_arp10"11 12lib_dir=$(dirname "$0")13source ${lib_dir}/bond_topo_3d1c.sh14c_maddr="33:33:00:00:00:10"15g_maddr="33:33:00:00:02:54"16 17skip_prio()18{19 local skip=120 21 # check if iproute support prio option22 ip -n ${s_ns} link set eth0 type bond_slave prio 1023 [[ $? -ne 0 ]] && skip=024 25 # check if kernel support prio option26 ip -n ${s_ns} -d link show eth0 | grep -q "prio 10"27 [[ $? -ne 0 ]] && skip=028 29 return $skip30}31 32skip_ns()33{34 local skip=135 36 # check if iproute support ns_ip6_target option37 ip -n ${s_ns} link add bond1 type bond ns_ip6_target ${g_ip6}38 [[ $? -ne 0 ]] && skip=039 40 # check if kernel support ns_ip6_target option41 ip -n ${s_ns} -d link show bond1 | grep -q "ns_ip6_target ${g_ip6}"42 [[ $? -ne 0 ]] && skip=043 44 ip -n ${s_ns} link del bond145 46 return $skip47}48 49active_slave=""50active_slave_changed()51{52 local old_active_slave=$153 local new_active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" \54 ".[].linkinfo.info_data.active_slave")55 [ "$new_active_slave" != "$old_active_slave" -a "$new_active_slave" != "null" ]56}57 58check_active_slave()59{60 local target_active_slave=$161 slowwait 5 active_slave_changed $active_slave62 active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave")63 test "$active_slave" = "$target_active_slave"64 check_err $? "Current active slave is $active_slave but not $target_active_slave"65}66 67# Test bonding prio option68prio_test()69{70 local param="$1"71 RET=072 73 # create bond74 bond_reset "${param}"75 # set active_slave to primary eth1 specifically76 ip -n ${s_ns} link set bond0 type bond active_slave eth177 78 # check bonding member prio value79 ip -n ${s_ns} link set eth0 type bond_slave prio 080 ip -n ${s_ns} link set eth1 type bond_slave prio 1081 ip -n ${s_ns} link set eth2 type bond_slave prio 1182 cmd_jq "ip -n ${s_ns} -d -j link show eth0" \83 ".[].linkinfo.info_slave_data | select (.prio == 0)" "-e" &> /dev/null84 check_err $? "eth0 prio is not 0"85 cmd_jq "ip -n ${s_ns} -d -j link show eth1" \86 ".[].linkinfo.info_slave_data | select (.prio == 10)" "-e" &> /dev/null87 check_err $? "eth1 prio is not 10"88 cmd_jq "ip -n ${s_ns} -d -j link show eth2" \89 ".[].linkinfo.info_slave_data | select (.prio == 11)" "-e" &> /dev/null90 check_err $? "eth2 prio is not 11"91 92 bond_check_connection "setup"93 94 # active slave should be the primary slave95 check_active_slave eth196 97 # active slave should be the higher prio slave98 ip -n ${s_ns} link set $active_slave down99 check_active_slave eth2100 bond_check_connection "fail over"101 102 # when only 1 slave is up103 ip -n ${s_ns} link set $active_slave down104 check_active_slave eth0105 bond_check_connection "only 1 slave up"106 107 # when a higher prio slave change to up108 ip -n ${s_ns} link set eth2 up109 bond_check_connection "higher prio slave up"110 case $primary_reselect in111 "0")112 check_active_slave "eth2"113 ;;114 "1")115 check_active_slave "eth0"116 ;;117 "2")118 check_active_slave "eth0"119 ;;120 esac121 local pre_active_slave=$active_slave122 123 # when the primary slave change to up124 ip -n ${s_ns} link set eth1 up125 bond_check_connection "primary slave up"126 case $primary_reselect in127 "0")128 check_active_slave "eth1"129 ;;130 "1")131 check_active_slave "$pre_active_slave"132 ;;133 "2")134 check_active_slave "$pre_active_slave"135 ip -n ${s_ns} link set $active_slave down136 bond_check_connection "pre_active slave down"137 check_active_slave "eth1"138 ;;139 esac140 141 # Test changing bond slave prio142 if [[ "$primary_reselect" == "0" ]];then143 ip -n ${s_ns} link set eth0 type bond_slave prio 1000000144 ip -n ${s_ns} link set eth1 type bond_slave prio 0145 ip -n ${s_ns} link set eth2 type bond_slave prio -50146 ip -n ${s_ns} -d link show eth0 | grep -q 'prio 1000000'147 check_err $? "eth0 prio is not 1000000"148 ip -n ${s_ns} -d link show eth1 | grep -q 'prio 0'149 check_err $? "eth1 prio is not 0"150 ip -n ${s_ns} -d link show eth2 | grep -q 'prio -50'151 check_err $? "eth3 prio is not -50"152 check_active_slave "eth1"153 154 ip -n ${s_ns} link set $active_slave down155 check_active_slave "eth0"156 bond_check_connection "change slave prio"157 fi158}159 160prio_miimon()161{162 local primary_reselect163 local mode=$1164 165 for primary_reselect in 0 1 2; do166 prio_test "mode $mode miimon 100 primary eth1 primary_reselect $primary_reselect"167 log_test "prio" "$mode miimon primary_reselect $primary_reselect"168 done169}170 171prio_arp()172{173 local primary_reselect174 local mode=$1175 176 for primary_reselect in 0 1 2; do177 prio_test "mode $mode arp_interval 100 arp_ip_target ${g_ip4} primary eth1 primary_reselect $primary_reselect"178 log_test "prio" "$mode arp_ip_target primary_reselect $primary_reselect"179 done180}181 182prio_ns()183{184 local primary_reselect185 local mode=$1186 187 if skip_ns; then188 log_test_skip "prio ns" "Current iproute or kernel doesn't support bond option 'ns_ip6_target'."189 return 0190 fi191 192 for primary_reselect in 0 1 2; do193 prio_test "mode $mode arp_interval 100 ns_ip6_target ${g_ip6} primary eth1 primary_reselect $primary_reselect"194 log_test "prio" "$mode ns_ip6_target primary_reselect $primary_reselect"195 done196}197 198prio()199{200 local mode modes="active-backup balance-tlb balance-alb"201 202 if skip_prio; then203 log_test_skip "prio" "Current iproute or kernel doesn't support bond option 'prio'."204 return 0205 fi206 207 for mode in $modes; do208 prio_miimon $mode209 done210 prio_arp "active-backup"211 prio_ns "active-backup"212}213 214wait_mii_up()215{216 for i in $(seq 0 2); do217 mii_status=$(cmd_jq "ip -n ${s_ns} -j -d link show eth$i" ".[].linkinfo.info_slave_data.mii_status")218 [ ${mii_status} != "UP" ] && return 1219 done220 return 0221}222 223arp_validate_test()224{225 local param="$1"226 RET=0227 228 # create bond229 bond_reset "${param}"230 231 bond_check_connection232 [ $RET -ne 0 ] && log_test "arp_validate" "$retmsg"233 234 # wait for a while to make sure the mii status stable235 slowwait 5 wait_mii_up236 for i in $(seq 0 2); do237 mii_status=$(cmd_jq "ip -n ${s_ns} -j -d link show eth$i" ".[].linkinfo.info_slave_data.mii_status")238 if [ ${mii_status} != "UP" ]; then239 RET=1240 log_test "arp_validate" "interface eth$i mii_status $mii_status"241 fi242 done243}244 245# Testing correct multicast groups are added to slaves for ns targets246arp_validate_mcast()247{248 RET=0249 local arp_valid=$(cmd_jq "ip -n ${s_ns} -j -d link show bond0" ".[].linkinfo.info_data.arp_validate")250 local active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave")251 252 for i in $(seq 0 2); do253 maddr_list=$(ip -n ${s_ns} maddr show dev eth${i})254 255 # arp_valid == 0 or active_slave should not join any maddrs256 if { [ "$arp_valid" == "null" ] || [ "eth${i}" == ${active_slave} ]; } && \257 echo "$maddr_list" | grep -qE "${c_maddr}|${g_maddr}"; then258 RET=1259 check_err 1 "arp_valid $arp_valid active_slave $active_slave, eth$i has mcast group"260 # arp_valid != 0 and backup_slave should join both maddrs261 elif [ "$arp_valid" != "null" ] && [ "eth${i}" != ${active_slave} ] && \262 ( ! echo "$maddr_list" | grep -q "${c_maddr}" || \263 ! echo "$maddr_list" | grep -q "${m_maddr}"); then264 RET=1265 check_err 1 "arp_valid $arp_valid active_slave $active_slave, eth$i has mcast group"266 fi267 done268 269 # Do failover270 ip -n ${s_ns} link set ${active_slave} down271 # wait for active link change272 slowwait 2 active_slave_changed $active_slave273 active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave")274 275 for i in $(seq 0 2); do276 maddr_list=$(ip -n ${s_ns} maddr show dev eth${i})277 278 # arp_valid == 0 or active_slave should not join any maddrs279 if { [ "$arp_valid" == "null" ] || [ "eth${i}" == ${active_slave} ]; } && \280 echo "$maddr_list" | grep -qE "${c_maddr}|${g_maddr}"; then281 RET=1282 check_err 1 "arp_valid $arp_valid active_slave $active_slave, eth$i has mcast group"283 # arp_valid != 0 and backup_slave should join both maddrs284 elif [ "$arp_valid" != "null" ] && [ "eth${i}" != ${active_slave} ] && \285 ( ! echo "$maddr_list" | grep -q "${c_maddr}" || \286 ! echo "$maddr_list" | grep -q "${m_maddr}"); then287 RET=1288 check_err 1 "arp_valid $arp_valid active_slave $active_slave, eth$i has mcast group"289 fi290 done291}292 293arp_validate_arp()294{295 local mode=$1296 local val297 for val in $(seq 0 6); do298 arp_validate_test "mode $mode arp_interval 100 arp_ip_target ${g_ip4} arp_validate $val"299 log_test "arp_validate" "$mode arp_ip_target arp_validate $val"300 done301}302 303arp_validate_ns()304{305 local mode=$1306 local val307 308 if skip_ns; then309 log_test_skip "arp_validate ns" "Current iproute or kernel doesn't support bond option 'ns_ip6_target'."310 return 0311 fi312 313 for val in $(seq 0 6); do314 arp_validate_test "mode $mode arp_interval 100 ns_ip6_target ${g_ip6},${c_ip6} arp_validate $val"315 log_test "arp_validate" "$mode ns_ip6_target arp_validate $val"316 arp_validate_mcast317 log_test "arp_validate" "join mcast group"318 done319}320 321arp_validate()322{323 arp_validate_arp "active-backup"324 arp_validate_ns "active-backup"325}326 327garp_test()328{329 local param="$1"330 local active_slave exp_num real_num i331 RET=0332 333 # create bond334 bond_reset "${param}"335 336 bond_check_connection337 [ $RET -ne 0 ] && log_test "num_grat_arp" "$retmsg"338 339 340 # Add tc rules to count GARP number341 for i in $(seq 0 2); do342 tc -n ${g_ns} filter add dev s$i ingress protocol arp pref 1 handle 101 \343 flower skip_hw arp_op request arp_sip ${s_ip4} arp_tip ${s_ip4} action pass344 done345 346 # Do failover347 active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave")348 ip -n ${s_ns} link set ${active_slave} down349 350 # wait for active link change351 slowwait 2 active_slave_changed $active_slave352 353 exp_num=$(echo "${param}" | cut -f6 -d ' ')354 active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave")355 slowwait_for_counter $((exp_num + 5)) $exp_num \356 tc_rule_handle_stats_get "dev s${active_slave#eth} ingress" 101 ".packets" "-n ${g_ns}"357 358 # check result359 real_num=$(tc_rule_handle_stats_get "dev s${active_slave#eth} ingress" 101 ".packets" "-n ${g_ns}")360 if [ "${real_num}" -ne "${exp_num}" ]; then361 echo "$real_num garp packets sent on active slave ${active_slave}"362 RET=1363 fi364 365 for i in $(seq 0 2); do366 tc -n ${g_ns} filter del dev s$i ingress367 done368}369 370num_grat_arp()371{372 local val373 for val in 10 20 30; do374 garp_test "mode active-backup miimon 10 num_grat_arp $val peer_notify_delay 100"375 log_test "num_grat_arp" "active-backup miimon num_grat_arp $val"376 done377}378 379trap cleanup EXIT380 381setup_prepare382setup_wait383tests_run384 385exit $EXIT_STATUS386