0001
0002
0003
0004 ALL_TESTS="
0005 same_speeds_autoneg_off
0006 different_speeds_autoneg_off
0007 combination_of_neg_on_and_off
0008 advertise_subset_of_speeds
0009 check_highest_speed_is_chosen
0010 different_speeds_autoneg_on
0011 "
0012 NUM_NETIFS=2
0013 source lib.sh
0014 source ethtool_lib.sh
0015
0016 h1_create()
0017 {
0018 simple_if_init $h1 192.0.2.1/24
0019 }
0020
0021 h1_destroy()
0022 {
0023 simple_if_fini $h1 192.0.2.1/24
0024 }
0025
0026 h2_create()
0027 {
0028 simple_if_init $h2 192.0.2.2/24
0029 }
0030
0031 h2_destroy()
0032 {
0033 simple_if_fini $h2 192.0.2.2/24
0034 }
0035
0036 setup_prepare()
0037 {
0038 h1=${NETIFS[p1]}
0039 h2=${NETIFS[p2]}
0040
0041 h1_create
0042 h2_create
0043 }
0044
0045 cleanup()
0046 {
0047 pre_cleanup
0048
0049 h2_destroy
0050 h1_destroy
0051 }
0052
0053 same_speeds_autoneg_off()
0054 {
0055
0056
0057 local -a speeds_arr=($(common_speeds_get $h1 $h2 0 0))
0058
0059 for speed in "${speeds_arr[@]}"; do
0060 RET=0
0061 ethtool_set $h1 speed $speed autoneg off
0062 ethtool_set $h2 speed $speed autoneg off
0063
0064 setup_wait_dev_with_timeout $h1
0065 setup_wait_dev_with_timeout $h2
0066 ping_do $h1 192.0.2.2
0067 check_err $? "speed $speed autoneg off"
0068 log_test "force of same speed autoneg off"
0069 log_info "speed = $speed"
0070 done
0071
0072 ethtool -s $h2 autoneg on
0073 ethtool -s $h1 autoneg on
0074 }
0075
0076 different_speeds_autoneg_off()
0077 {
0078
0079
0080 RET=0
0081
0082 local -a speeds_arr=($(different_speeds_get $h1 $h2 0 0))
0083 local speed1=${speeds_arr[0]}
0084 local speed2=${speeds_arr[1]}
0085
0086 ethtool_set $h1 speed $speed1 autoneg off
0087 ethtool_set $h2 speed $speed2 autoneg off
0088
0089 setup_wait_dev_with_timeout $h1
0090 setup_wait_dev_with_timeout $h2
0091 ping_do $h1 192.0.2.2
0092 check_fail $? "ping with different speeds"
0093
0094 log_test "force of different speeds autoneg off"
0095
0096 ethtool -s $h2 autoneg on
0097 ethtool -s $h1 autoneg on
0098 }
0099
0100 combination_of_neg_on_and_off()
0101 {
0102
0103
0104
0105 local -a speeds_arr=($(common_speeds_get $h1 $h2 0 1))
0106
0107 for speed in "${speeds_arr[@]}"; do
0108 RET=0
0109 ethtool_set $h1 speed $speed autoneg off
0110
0111 setup_wait_dev_with_timeout $h1
0112 setup_wait_dev_with_timeout $h2
0113 ping_do $h1 192.0.2.2
0114 check_err $? "h1-speed=$speed autoneg off, h2 autoneg on"
0115 log_test "one side with autoneg off and another with autoneg on"
0116 log_info "force speed = $speed"
0117 done
0118
0119 ethtool -s $h1 autoneg on
0120 }
0121
0122 hex_speed_value_get()
0123 {
0124 local speed=$1; shift
0125
0126 local shift_size=${speed_values[$speed]}
0127 speed=$((0x1 << $"shift_size"))
0128 printf "%#x" "$speed"
0129 }
0130
0131 subset_of_common_speeds_get()
0132 {
0133 local dev1=$1; shift
0134 local dev2=$1; shift
0135 local adver=$1; shift
0136
0137 local -a speeds_arr=($(common_speeds_get $dev1 $dev2 0 $adver))
0138 local speed_to_advertise=0
0139 local speed_to_remove=${speeds_arr[0]}
0140 speed_to_remove+='base'
0141
0142 local -a speeds_mode_arr=($(common_speeds_get $dev1 $dev2 1 $adver))
0143
0144 for speed in ${speeds_mode_arr[@]}; do
0145 if [[ $speed != $speed_to_remove* ]]; then
0146 speed=$(hex_speed_value_get $speed)
0147 speed_to_advertise=$(($speed_to_advertise | \
0148 $speed))
0149 fi
0150
0151 done
0152
0153
0154 printf "%#x" "$speed_to_advertise"
0155 }
0156
0157 speed_to_advertise_get()
0158 {
0159
0160
0161 local speed_without_mode=$1; shift
0162 local supported_speeds=("$@"); shift
0163 local speed_to_advertise=0
0164
0165 speed_without_mode+='base'
0166
0167 for speed in ${supported_speeds[@]}; do
0168 if [[ $speed == $speed_without_mode* ]]; then
0169 speed=$(hex_speed_value_get $speed)
0170 speed_to_advertise=$(($speed_to_advertise | \
0171 $speed))
0172 fi
0173
0174 done
0175
0176
0177 printf "%#x" "$speed_to_advertise"
0178 }
0179
0180 advertise_subset_of_speeds()
0181 {
0182
0183
0184
0185 RET=0
0186
0187 local speed_1_to_advertise=$(subset_of_common_speeds_get $h1 $h2 1)
0188 ethtool_set $h1 advertise $speed_1_to_advertise
0189
0190 if [ $RET != 0 ]; then
0191 log_test "advertise subset of speeds"
0192 return
0193 fi
0194
0195 local -a speeds_arr_without_mode=($(common_speeds_get $h1 $h2 0 1))
0196
0197 unset speeds_arr_without_mode[0]
0198 local -a speeds_arr_with_mode=($(common_speeds_get $h1 $h2 1 1))
0199
0200 for speed_value in ${speeds_arr_without_mode[@]}; do
0201 RET=0
0202 local speed_2_to_advertise=$(speed_to_advertise_get $speed_value \
0203 "${speeds_arr_with_mode[@]}")
0204 ethtool_set $h2 advertise $speed_2_to_advertise
0205
0206 setup_wait_dev_with_timeout $h1
0207 setup_wait_dev_with_timeout $h2
0208 ping_do $h1 192.0.2.2
0209 check_err $? "h1=$speed_1_to_advertise, h2=$speed_2_to_advertise ($speed_value)"
0210
0211 log_test "advertise subset of speeds"
0212 log_info "h1=$speed_1_to_advertise, h2=$speed_2_to_advertise"
0213 done
0214
0215 ethtool -s $h2 autoneg on
0216 ethtool -s $h1 autoneg on
0217 }
0218
0219 check_highest_speed_is_chosen()
0220 {
0221
0222
0223
0224 RET=0
0225
0226 local max_speed
0227 local chosen_speed
0228 local speed_to_advertise=$(subset_of_common_speeds_get $h1 $h2 1)
0229
0230 ethtool_set $h1 advertise $speed_to_advertise
0231
0232 if [ $RET != 0 ]; then
0233 log_test "check highest speed"
0234 return
0235 fi
0236
0237 local -a speeds_arr=($(common_speeds_get $h1 $h2 0 1))
0238
0239 max_speed=${speeds_arr[0]}
0240 for current in ${speeds_arr[@]}; do
0241 if [[ $current -gt $max_speed ]]; then
0242 max_speed=$current
0243 fi
0244 done
0245
0246 setup_wait_dev_with_timeout $h1
0247 setup_wait_dev_with_timeout $h2
0248 chosen_speed=$(ethtool $h1 | grep 'Speed:')
0249 chosen_speed=${chosen_speed%"Mb/s"*}
0250 chosen_speed=${chosen_speed
0251 ((chosen_speed == max_speed))
0252 check_err $? "h1 advertise $speed_to_advertise, h2 sync to speed $chosen_speed"
0253
0254 log_test "check highest speed"
0255
0256 ethtool -s $h2 autoneg on
0257 ethtool -s $h1 autoneg on
0258 }
0259
0260 different_speeds_autoneg_on()
0261 {
0262
0263
0264 RET=0
0265
0266 local -a speeds=($(different_speeds_get $h1 $h2 1 1))
0267 local speed1=${speeds[0]}
0268 local speed2=${speeds[1]}
0269
0270 speed1=$(hex_speed_value_get $speed1)
0271 speed2=$(hex_speed_value_get $speed2)
0272
0273 ethtool_set $h1 advertise $speed1
0274 ethtool_set $h2 advertise $speed2
0275
0276 if (($RET)); then
0277 setup_wait_dev_with_timeout $h1
0278 setup_wait_dev_with_timeout $h2
0279 ping_do $h1 192.0.2.2
0280 check_fail $? "ping with different speeds autoneg on"
0281 fi
0282
0283 log_test "advertise different speeds autoneg on"
0284
0285 ethtool -s $h2 autoneg on
0286 ethtool -s $h1 autoneg on
0287 }
0288
0289 trap cleanup EXIT
0290
0291 setup_prepare
0292 setup_wait
0293
0294 declare -gA speed_values
0295 eval "speed_values=($(speeds_arr_get))"
0296
0297 tests_run
0298
0299 exit $EXIT_STATUS