|
| 1 | +#!/bin/bash |
| 2 | +# SPDX-License-Identifier: GPL-2.0 |
| 3 | +# |
| 4 | +# Test bonding options with mode 1,5,6 |
| 5 | + |
| 6 | +ALL_TESTS=" |
| 7 | + prio |
| 8 | +" |
| 9 | + |
| 10 | +REQUIRE_MZ=no |
| 11 | +NUM_NETIFS=0 |
| 12 | +lib_dir=$(dirname "$0") |
| 13 | +source ${lib_dir}/net_forwarding_lib.sh |
| 14 | +source ${lib_dir}/bond_topo_3d1c.sh |
| 15 | + |
| 16 | +skip_prio() |
| 17 | +{ |
| 18 | + local skip=1 |
| 19 | + |
| 20 | + # check if iproute support prio option |
| 21 | + ip -n ${s_ns} link set eth0 type bond_slave prio 10 |
| 22 | + [[ $? -ne 0 ]] && skip=0 |
| 23 | + |
| 24 | + # check if kernel support prio option |
| 25 | + ip -n ${s_ns} -d link show eth0 | grep -q "prio 10" |
| 26 | + [[ $? -ne 0 ]] && skip=0 |
| 27 | + |
| 28 | + return $skip |
| 29 | +} |
| 30 | + |
| 31 | +skip_ns() |
| 32 | +{ |
| 33 | + local skip=1 |
| 34 | + |
| 35 | + # check if iproute support ns_ip6_target option |
| 36 | + ip -n ${s_ns} link add bond1 type bond ns_ip6_target ${g_ip6} |
| 37 | + [[ $? -ne 0 ]] && skip=0 |
| 38 | + |
| 39 | + # check if kernel support ns_ip6_target option |
| 40 | + ip -n ${s_ns} -d link show bond1 | grep -q "ns_ip6_target ${g_ip6}" |
| 41 | + [[ $? -ne 0 ]] && skip=0 |
| 42 | + |
| 43 | + ip -n ${s_ns} link del bond1 |
| 44 | + |
| 45 | + return $skip |
| 46 | +} |
| 47 | + |
| 48 | +active_slave="" |
| 49 | +check_active_slave() |
| 50 | +{ |
| 51 | + local target_active_slave=$1 |
| 52 | + active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave") |
| 53 | + test "$active_slave" = "$target_active_slave" |
| 54 | + check_err $? "Current active slave is $active_slave but not $target_active_slave" |
| 55 | +} |
| 56 | + |
| 57 | + |
| 58 | +# Test bonding prio option |
| 59 | +prio_test() |
| 60 | +{ |
| 61 | + local param="$1" |
| 62 | + RET=0 |
| 63 | + |
| 64 | + # create bond |
| 65 | + bond_reset "${param}" |
| 66 | + |
| 67 | + # check bonding member prio value |
| 68 | + ip -n ${s_ns} link set eth0 type bond_slave prio 0 |
| 69 | + ip -n ${s_ns} link set eth1 type bond_slave prio 10 |
| 70 | + ip -n ${s_ns} link set eth2 type bond_slave prio 11 |
| 71 | + cmd_jq "ip -n ${s_ns} -d -j link show eth0" \ |
| 72 | + ".[].linkinfo.info_slave_data | select (.prio == 0)" "-e" &> /dev/null |
| 73 | + check_err $? "eth0 prio is not 0" |
| 74 | + cmd_jq "ip -n ${s_ns} -d -j link show eth1" \ |
| 75 | + ".[].linkinfo.info_slave_data | select (.prio == 10)" "-e" &> /dev/null |
| 76 | + check_err $? "eth1 prio is not 10" |
| 77 | + cmd_jq "ip -n ${s_ns} -d -j link show eth2" \ |
| 78 | + ".[].linkinfo.info_slave_data | select (.prio == 11)" "-e" &> /dev/null |
| 79 | + check_err $? "eth2 prio is not 11" |
| 80 | + |
| 81 | + bond_check_connection "setup" |
| 82 | + |
| 83 | + # active slave should be the primary slave |
| 84 | + check_active_slave eth1 |
| 85 | + |
| 86 | + # active slave should be the higher prio slave |
| 87 | + ip -n ${s_ns} link set $active_slave down |
| 88 | + bond_check_connection "fail over" |
| 89 | + check_active_slave eth2 |
| 90 | + |
| 91 | + # when only 1 slave is up |
| 92 | + ip -n ${s_ns} link set $active_slave down |
| 93 | + bond_check_connection "only 1 slave up" |
| 94 | + check_active_slave eth0 |
| 95 | + |
| 96 | + # when a higher prio slave change to up |
| 97 | + ip -n ${s_ns} link set eth2 up |
| 98 | + bond_check_connection "higher prio slave up" |
| 99 | + case $primary_reselect in |
| 100 | + "0") |
| 101 | + check_active_slave "eth2" |
| 102 | + ;; |
| 103 | + "1") |
| 104 | + check_active_slave "eth0" |
| 105 | + ;; |
| 106 | + "2") |
| 107 | + check_active_slave "eth0" |
| 108 | + ;; |
| 109 | + esac |
| 110 | + local pre_active_slave=$active_slave |
| 111 | + |
| 112 | + # when the primary slave change to up |
| 113 | + ip -n ${s_ns} link set eth1 up |
| 114 | + bond_check_connection "primary slave up" |
| 115 | + case $primary_reselect in |
| 116 | + "0") |
| 117 | + check_active_slave "eth1" |
| 118 | + ;; |
| 119 | + "1") |
| 120 | + check_active_slave "$pre_active_slave" |
| 121 | + ;; |
| 122 | + "2") |
| 123 | + check_active_slave "$pre_active_slave" |
| 124 | + ip -n ${s_ns} link set $active_slave down |
| 125 | + bond_check_connection "pre_active slave down" |
| 126 | + check_active_slave "eth1" |
| 127 | + ;; |
| 128 | + esac |
| 129 | + |
| 130 | + # Test changing bond slave prio |
| 131 | + if [[ "$primary_reselect" == "0" ]];then |
| 132 | + ip -n ${s_ns} link set eth0 type bond_slave prio 1000000 |
| 133 | + ip -n ${s_ns} link set eth1 type bond_slave prio 0 |
| 134 | + ip -n ${s_ns} link set eth2 type bond_slave prio -50 |
| 135 | + ip -n ${s_ns} -d link show eth0 | grep -q 'prio 1000000' |
| 136 | + check_err $? "eth0 prio is not 1000000" |
| 137 | + ip -n ${s_ns} -d link show eth1 | grep -q 'prio 0' |
| 138 | + check_err $? "eth1 prio is not 0" |
| 139 | + ip -n ${s_ns} -d link show eth2 | grep -q 'prio -50' |
| 140 | + check_err $? "eth3 prio is not -50" |
| 141 | + check_active_slave "eth1" |
| 142 | + |
| 143 | + ip -n ${s_ns} link set $active_slave down |
| 144 | + bond_check_connection "change slave prio" |
| 145 | + check_active_slave "eth0" |
| 146 | + fi |
| 147 | +} |
| 148 | + |
| 149 | +prio_miimon() |
| 150 | +{ |
| 151 | + local primary_reselect |
| 152 | + local mode=$1 |
| 153 | + |
| 154 | + for primary_reselect in 0 1 2; do |
| 155 | + prio_test "mode $mode miimon 100 primary eth1 primary_reselect $primary_reselect" |
| 156 | + log_test "prio" "$mode miimon primary_reselect $primary_reselect" |
| 157 | + done |
| 158 | +} |
| 159 | + |
| 160 | +prio_arp() |
| 161 | +{ |
| 162 | + local primary_reselect |
| 163 | + local mode=$1 |
| 164 | + |
| 165 | + for primary_reselect in 0 1 2; do |
| 166 | + prio_test "mode active-backup arp_interval 100 arp_ip_target ${g_ip4} primary eth1 primary_reselect $primary_reselect" |
| 167 | + log_test "prio" "$mode arp_ip_target primary_reselect $primary_reselect" |
| 168 | + done |
| 169 | +} |
| 170 | + |
| 171 | +prio_ns() |
| 172 | +{ |
| 173 | + local primary_reselect |
| 174 | + local mode=$1 |
| 175 | + |
| 176 | + if skip_ns; then |
| 177 | + log_test_skip "prio ns" "Current iproute or kernel doesn't support bond option 'ns_ip6_target'." |
| 178 | + return 0 |
| 179 | + fi |
| 180 | + |
| 181 | + for primary_reselect in 0 1 2; do |
| 182 | + prio_test "mode active-backup arp_interval 100 ns_ip6_target ${g_ip6} primary eth1 primary_reselect $primary_reselect" |
| 183 | + log_test "prio" "$mode ns_ip6_target primary_reselect $primary_reselect" |
| 184 | + done |
| 185 | +} |
| 186 | + |
| 187 | +prio() |
| 188 | +{ |
| 189 | + local mode modes="active-backup balance-tlb balance-alb" |
| 190 | + |
| 191 | + if skip_prio; then |
| 192 | + log_test_skip "prio" "Current iproute or kernel doesn't support bond option 'prio'." |
| 193 | + return 0 |
| 194 | + fi |
| 195 | + |
| 196 | + for mode in $modes; do |
| 197 | + prio_miimon $mode |
| 198 | + prio_arp $mode |
| 199 | + prio_ns $mode |
| 200 | + done |
| 201 | +} |
| 202 | + |
| 203 | +trap cleanup EXIT |
| 204 | + |
| 205 | +setup_prepare |
| 206 | +setup_wait |
| 207 | +tests_run |
| 208 | + |
| 209 | +exit $EXIT_STATUS |
0 commit comments