2 # SPDX-License-Identifier: GPL-2.0
4 # Test bonding options with mode 1,5,6
12 lib_dir=$(dirname "$0")
13 source ${lib_dir}/bond_topo_3d1c.sh
19 # check if iproute support prio option
20 ip -n ${s_ns} link set eth0 type bond_slave prio 10
21 [[ $? -ne 0 ]] && skip=0
23 # check if kernel support prio option
24 ip -n ${s_ns} -d link show eth0 | grep -q "prio 10"
25 [[ $? -ne 0 ]] && skip=0
34 # check if iproute support ns_ip6_target option
35 ip -n ${s_ns} link add bond1 type bond ns_ip6_target ${g_ip6}
36 [[ $? -ne 0 ]] && skip=0
38 # check if kernel support ns_ip6_target option
39 ip -n ${s_ns} -d link show bond1 | grep -q "ns_ip6_target ${g_ip6}"
40 [[ $? -ne 0 ]] && skip=0
42 ip -n ${s_ns} link del bond1
50 local target_active_slave=$1
51 active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave")
52 test "$active_slave" = "$target_active_slave"
53 check_err $? "Current active slave is $active_slave but not $target_active_slave"
57 # Test bonding prio option
66 # check bonding member prio value
67 ip -n ${s_ns} link set eth0 type bond_slave prio 0
68 ip -n ${s_ns} link set eth1 type bond_slave prio 10
69 ip -n ${s_ns} link set eth2 type bond_slave prio 11
70 cmd_jq "ip -n ${s_ns} -d -j link show eth0" \
71 ".[].linkinfo.info_slave_data | select (.prio == 0)" "-e" &> /dev/null
72 check_err $? "eth0 prio is not 0"
73 cmd_jq "ip -n ${s_ns} -d -j link show eth1" \
74 ".[].linkinfo.info_slave_data | select (.prio == 10)" "-e" &> /dev/null
75 check_err $? "eth1 prio is not 10"
76 cmd_jq "ip -n ${s_ns} -d -j link show eth2" \
77 ".[].linkinfo.info_slave_data | select (.prio == 11)" "-e" &> /dev/null
78 check_err $? "eth2 prio is not 11"
80 bond_check_connection "setup"
82 # active slave should be the primary slave
83 check_active_slave eth1
85 # active slave should be the higher prio slave
86 ip -n ${s_ns} link set $active_slave down
87 bond_check_connection "fail over"
88 check_active_slave eth2
90 # when only 1 slave is up
91 ip -n ${s_ns} link set $active_slave down
92 bond_check_connection "only 1 slave up"
93 check_active_slave eth0
95 # when a higher prio slave change to up
96 ip -n ${s_ns} link set eth2 up
97 bond_check_connection "higher prio slave up"
98 case $primary_reselect in
100 check_active_slave "eth2"
103 check_active_slave "eth0"
106 check_active_slave "eth0"
109 local pre_active_slave=$active_slave
111 # when the primary slave change to up
112 ip -n ${s_ns} link set eth1 up
113 bond_check_connection "primary slave up"
114 case $primary_reselect in
116 check_active_slave "eth1"
119 check_active_slave "$pre_active_slave"
122 check_active_slave "$pre_active_slave"
123 ip -n ${s_ns} link set $active_slave down
124 bond_check_connection "pre_active slave down"
125 check_active_slave "eth1"
129 # Test changing bond slave prio
130 if [[ "$primary_reselect" == "0" ]];then
131 ip -n ${s_ns} link set eth0 type bond_slave prio 1000000
132 ip -n ${s_ns} link set eth1 type bond_slave prio 0
133 ip -n ${s_ns} link set eth2 type bond_slave prio -50
134 ip -n ${s_ns} -d link show eth0 | grep -q 'prio 1000000'
135 check_err $? "eth0 prio is not 1000000"
136 ip -n ${s_ns} -d link show eth1 | grep -q 'prio 0'
137 check_err $? "eth1 prio is not 0"
138 ip -n ${s_ns} -d link show eth2 | grep -q 'prio -50'
139 check_err $? "eth3 prio is not -50"
140 check_active_slave "eth1"
142 ip -n ${s_ns} link set $active_slave down
143 bond_check_connection "change slave prio"
144 check_active_slave "eth0"
150 local primary_reselect
153 for primary_reselect in 0 1 2; do
154 prio_test "mode $mode miimon 100 primary eth1 primary_reselect $primary_reselect"
155 log_test "prio" "$mode miimon primary_reselect $primary_reselect"
161 local primary_reselect
164 for primary_reselect in 0 1 2; do
165 prio_test "mode active-backup arp_interval 100 arp_ip_target ${g_ip4} primary eth1 primary_reselect $primary_reselect"
166 log_test "prio" "$mode arp_ip_target primary_reselect $primary_reselect"
172 local primary_reselect
176 log_test_skip "prio ns" "Current iproute or kernel doesn't support bond option 'ns_ip6_target'."
180 for primary_reselect in 0 1 2; do
181 prio_test "mode active-backup arp_interval 100 ns_ip6_target ${g_ip6} primary eth1 primary_reselect $primary_reselect"
182 log_test "prio" "$mode ns_ip6_target primary_reselect $primary_reselect"
188 local mode modes="active-backup balance-tlb balance-alb"
191 log_test_skip "prio" "Current iproute or kernel doesn't support bond option 'prio'."
195 for mode in $modes; do
208 bond_reset "${param}"
210 bond_check_connection
211 [ $RET -ne 0 ] && log_test "arp_validate" "$retmsg"
213 # wait for a while to make sure the mii status stable
215 for i in $(seq 0 2); do
216 mii_status=$(cmd_jq "ip -n ${s_ns} -j -d link show eth$i" ".[].linkinfo.info_slave_data.mii_status")
217 if [ ${mii_status} != "UP" ]; then
219 log_test "arp_validate" "interface eth$i mii_status $mii_status"
228 for val in $(seq 0 6); do
229 arp_validate_test "mode $mode arp_interval 100 arp_ip_target ${g_ip4} arp_validate $val"
230 log_test "arp_validate" "$mode arp_ip_target arp_validate $val"
240 log_test_skip "arp_validate ns" "Current iproute or kernel doesn't support bond option 'ns_ip6_target'."
244 for val in $(seq 0 6); do
245 arp_validate_test "mode $mode arp_interval 100 ns_ip6_target ${g_ip6} arp_validate $val"
246 log_test "arp_validate" "$mode ns_ip6_target arp_validate $val"
252 arp_validate_arp "active-backup"
253 arp_validate_ns "active-backup"
259 local active_slave exp_num real_num i
263 bond_reset "${param}"
265 bond_check_connection
266 [ $RET -ne 0 ] && log_test "num_grat_arp" "$retmsg"
269 # Add tc rules to count GARP number
270 for i in $(seq 0 2); do
271 tc -n ${g_ns} filter add dev s$i ingress protocol arp pref 1 handle 101 \
272 flower skip_hw arp_op request arp_sip ${s_ip4} arp_tip ${s_ip4} action pass
276 active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave")
277 ip -n ${s_ns} link set ${active_slave} down
279 exp_num=$(echo "${param}" | cut -f6 -d ' ')
280 sleep $((exp_num + 2))
282 active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave")
285 real_num=$(tc_rule_handle_stats_get "dev s${active_slave#eth} ingress" 101 ".packets" "-n ${g_ns}")
286 if [ "${real_num}" -ne "${exp_num}" ]; then
287 echo "$real_num garp packets sent on active slave ${active_slave}"
291 for i in $(seq 0 2); do
292 tc -n ${g_ns} filter del dev s$i ingress
299 for val in 10 20 30 50; do
300 garp_test "mode active-backup miimon 100 num_grat_arp $val peer_notify_delay 1000"
301 log_test "num_grat_arp" "active-backup miimon num_grat_arp $val"