227 lines · bash
1# SPDX-License-Identifier: GPL-2.02 3# Global interface:4# $put -- port under test (e.g. $swp2)5# collect_stats($streams...) -- A function to get stats for individual streams6# ets_start_traffic($band) -- Start traffic for this band7# ets_change_qdisc($op, $dev, $nstrict, $quanta...) -- Add or change qdisc8 9# WS describes the Qdisc configuration. It has one value per band (so the10# number of array elements indicates the number of bands). If the value is11# 0, it is a strict band, otherwise the it's a DRR band and the value is12# that band's quantum.13declare -a WS14 15qdisc_describe()16{17 local nbands=${#WS[@]}18 local nstrict=019 local i20 21 for ((i = 0; i < nbands; i++)); do22 if ((!${WS[$i]})); then23 : $((nstrict++))24 fi25 done26 27 echo -n "ets bands $nbands"28 if ((nstrict)); then29 echo -n " strict $nstrict"30 fi31 if ((nstrict < nbands)); then32 echo -n " quanta"33 for ((i = nstrict; i < nbands; i++)); do34 echo -n " ${WS[$i]}"35 done36 fi37}38 39__strict_eval()40{41 local desc=$1; shift42 local d=$1; shift43 local total=$1; shift44 local above=$1; shift45 46 RET=047 48 if ((! total)); then49 check_err 1 "No traffic observed"50 log_test "$desc"51 return52 fi53 54 local ratio=$(echo "scale=2; 100 * $d / $total" | bc -l)55 if ((above)); then56 test $(echo "$ratio > 95.0" | bc -l) -eq 157 check_err $? "Not enough traffic"58 log_test "$desc"59 log_info "Expected ratio >95% Measured ratio $ratio"60 else61 test $(echo "$ratio < 5" | bc -l) -eq 162 check_err $? "Too much traffic"63 log_test "$desc"64 log_info "Expected ratio <5% Measured ratio $ratio"65 fi66}67 68strict_eval()69{70 __strict_eval "$@" 171}72 73notraf_eval()74{75 __strict_eval "$@" 076}77 78__ets_dwrr_test()79{80 local -a streams=("$@")81 82 local low_stream=${streams[0]}83 local seen_strict=084 local -a t0 t1 d85 local stream86 local total87 local i88 89 echo "Testing $(qdisc_describe), streams ${streams[@]}"90 91 for stream in ${streams[@]}; do92 ets_start_traffic $stream93 done94 95 sleep 1096 97 t0=($(collect_stats "${streams[@]}"))98 99 sleep 10100 101 t1=($(collect_stats "${streams[@]}"))102 d=($(for ((i = 0; i < ${#streams[@]}; i++)); do103 echo $((${t1[$i]} - ${t0[$i]}))104 done))105 total=$(echo ${d[@]} | sed 's/ /+/g' | bc)106 107 for ((i = 0; i < ${#streams[@]}; i++)); do108 local stream=${streams[$i]}109 if ((seen_strict)); then110 notraf_eval "band $stream" ${d[$i]} $total111 elif ((${WS[$stream]} == 0)); then112 strict_eval "band $stream" ${d[$i]} $total113 seen_strict=1114 elif ((stream == low_stream)); then115 # Low stream is used as DWRR evaluation reference.116 continue117 else118 multipath_eval "bands $low_stream:$stream" \119 ${WS[$low_stream]} ${WS[$stream]} \120 ${d[0]} ${d[$i]}121 fi122 done123 124 for stream in ${streams[@]}; do125 stop_traffic126 done127}128 129ets_dwrr_test_012()130{131 __ets_dwrr_test 0 1 2132}133 134ets_dwrr_test_01()135{136 __ets_dwrr_test 0 1137}138 139ets_dwrr_test_12()140{141 __ets_dwrr_test 1 2142}143 144ets_qdisc_setup()145{146 local dev=$1; shift147 local nstrict=$1; shift148 local -a quanta=("$@")149 150 local ndwrr=${#quanta[@]}151 local nbands=$((nstrict + ndwrr))152 local nstreams=$(if ((nbands > 3)); then echo 3; else echo $nbands; fi)153 local priomap=$(seq 0 $((nstreams - 1)))154 local i155 156 WS=($(157 for ((i = 0; i < nstrict; i++)); do158 echo 0159 done160 for ((i = 0; i < ndwrr; i++)); do161 echo ${quanta[$i]}162 done163 ))164 165 ets_change_qdisc $dev $nstrict "$priomap" ${quanta[@]}166}167 168ets_set_dwrr_uniform()169{170 ets_qdisc_setup $put 0 3300 3300 3300171}172 173ets_set_dwrr_varying()174{175 ets_qdisc_setup $put 0 5000 3500 1500176}177 178ets_set_strict()179{180 ets_qdisc_setup $put 3181}182 183ets_set_mixed()184{185 ets_qdisc_setup $put 1 5000 2500 1500186}187 188ets_change_quantum()189{190 tc class change dev $put classid 10:2 ets quantum 8000191 WS[1]=8000192}193 194ets_set_dwrr_two_bands()195{196 ets_qdisc_setup $put 0 5000 2500197}198 199ets_test_strict()200{201 ets_set_strict202 xfail_on_slow ets_dwrr_test_01203 xfail_on_slow ets_dwrr_test_12204}205 206ets_test_mixed()207{208 ets_set_mixed209 xfail_on_slow ets_dwrr_test_01210 xfail_on_slow ets_dwrr_test_12211}212 213ets_test_dwrr()214{215 ets_set_dwrr_uniform216 xfail_on_slow ets_dwrr_test_012217 218 ets_set_dwrr_varying219 xfail_on_slow ets_dwrr_test_012220 221 ets_change_quantum222 xfail_on_slow ets_dwrr_test_012223 224 ets_set_dwrr_two_bands225 xfail_on_slow ets_dwrr_test_01226}227