Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 
0003 # Global interface:
0004 #  $put -- port under test (e.g. $swp2)
0005 #  collect_stats($streams...) -- A function to get stats for individual streams
0006 #  ets_start_traffic($band) -- Start traffic for this band
0007 #  ets_change_qdisc($op, $dev, $nstrict, $quanta...) -- Add or change qdisc
0008 
0009 # WS describes the Qdisc configuration. It has one value per band (so the
0010 # number of array elements indicates the number of bands). If the value is
0011 # 0, it is a strict band, otherwise the it's a DRR band and the value is
0012 # that band's quantum.
0013 declare -a WS
0014 
0015 qdisc_describe()
0016 {
0017         local nbands=${#WS[@]}
0018         local nstrict=0
0019         local i
0020 
0021         for ((i = 0; i < nbands; i++)); do
0022                 if ((!${WS[$i]})); then
0023                         : $((nstrict++))
0024                 fi
0025         done
0026 
0027         echo -n "ets bands $nbands"
0028         if ((nstrict)); then
0029                 echo -n " strict $nstrict"
0030         fi
0031         if ((nstrict < nbands)); then
0032                 echo -n " quanta"
0033                 for ((i = nstrict; i < nbands; i++)); do
0034                         echo -n " ${WS[$i]}"
0035                 done
0036         fi
0037 }
0038 
0039 __strict_eval()
0040 {
0041         local desc=$1; shift
0042         local d=$1; shift
0043         local total=$1; shift
0044         local above=$1; shift
0045 
0046         RET=0
0047 
0048         if ((! total)); then
0049                 check_err 1 "No traffic observed"
0050                 log_test "$desc"
0051                 return
0052         fi
0053 
0054         local ratio=$(echo "scale=2; 100 * $d / $total" | bc -l)
0055         if ((above)); then
0056                 test $(echo "$ratio > 95.0" | bc -l) -eq 1
0057                 check_err $? "Not enough traffic"
0058                 log_test "$desc"
0059                 log_info "Expected ratio >95% Measured ratio $ratio"
0060         else
0061                 test $(echo "$ratio < 5" | bc -l) -eq 1
0062                 check_err $? "Too much traffic"
0063                 log_test "$desc"
0064                 log_info "Expected ratio <5% Measured ratio $ratio"
0065         fi
0066 }
0067 
0068 strict_eval()
0069 {
0070         __strict_eval "$@" 1
0071 }
0072 
0073 notraf_eval()
0074 {
0075         __strict_eval "$@" 0
0076 }
0077 
0078 __ets_dwrr_test()
0079 {
0080         local -a streams=("$@")
0081 
0082         local low_stream=${streams[0]}
0083         local seen_strict=0
0084         local -a t0 t1 d
0085         local stream
0086         local total
0087         local i
0088 
0089         echo "Testing $(qdisc_describe), streams ${streams[@]}"
0090 
0091         for stream in ${streams[@]}; do
0092                 ets_start_traffic $stream
0093         done
0094 
0095         sleep 10
0096 
0097         t0=($(collect_stats "${streams[@]}"))
0098 
0099         sleep 10
0100 
0101         t1=($(collect_stats "${streams[@]}"))
0102         d=($(for ((i = 0; i < ${#streams[@]}; i++)); do
0103                  echo $((${t1[$i]} - ${t0[$i]}))
0104              done))
0105         total=$(echo ${d[@]} | sed 's/ /+/g' | bc)
0106 
0107         for ((i = 0; i < ${#streams[@]}; i++)); do
0108                 local stream=${streams[$i]}
0109                 if ((seen_strict)); then
0110                         notraf_eval "band $stream" ${d[$i]} $total
0111                 elif ((${WS[$stream]} == 0)); then
0112                         strict_eval "band $stream" ${d[$i]} $total
0113                         seen_strict=1
0114                 elif ((stream == low_stream)); then
0115                         # Low stream is used as DWRR evaluation reference.
0116                         continue
0117                 else
0118                         multipath_eval "bands $low_stream:$stream" \
0119                                        ${WS[$low_stream]} ${WS[$stream]} \
0120                                        ${d[0]} ${d[$i]}
0121                 fi
0122         done
0123 
0124         for stream in ${streams[@]}; do
0125                 stop_traffic
0126         done
0127 }
0128 
0129 ets_dwrr_test_012()
0130 {
0131         __ets_dwrr_test 0 1 2
0132 }
0133 
0134 ets_dwrr_test_01()
0135 {
0136         __ets_dwrr_test 0 1
0137 }
0138 
0139 ets_dwrr_test_12()
0140 {
0141         __ets_dwrr_test 1 2
0142 }
0143 
0144 ets_qdisc_setup()
0145 {
0146         local dev=$1; shift
0147         local nstrict=$1; shift
0148         local -a quanta=("$@")
0149 
0150         local ndwrr=${#quanta[@]}
0151         local nbands=$((nstrict + ndwrr))
0152         local nstreams=$(if ((nbands > 3)); then echo 3; else echo $nbands; fi)
0153         local priomap=$(seq 0 $((nstreams - 1)))
0154         local i
0155 
0156         WS=($(
0157                 for ((i = 0; i < nstrict; i++)); do
0158                         echo 0
0159                 done
0160                 for ((i = 0; i < ndwrr; i++)); do
0161                         echo ${quanta[$i]}
0162                 done
0163         ))
0164 
0165         ets_change_qdisc $dev $nstrict "$priomap" ${quanta[@]}
0166 }
0167 
0168 ets_set_dwrr_uniform()
0169 {
0170         ets_qdisc_setup $put 0 3300 3300 3300
0171 }
0172 
0173 ets_set_dwrr_varying()
0174 {
0175         ets_qdisc_setup $put 0 5000 3500 1500
0176 }
0177 
0178 ets_set_strict()
0179 {
0180         ets_qdisc_setup $put 3
0181 }
0182 
0183 ets_set_mixed()
0184 {
0185         ets_qdisc_setup $put 1 5000 2500 1500
0186 }
0187 
0188 ets_change_quantum()
0189 {
0190         tc class change dev $put classid 10:2 ets quantum 8000
0191         WS[1]=8000
0192 }
0193 
0194 ets_set_dwrr_two_bands()
0195 {
0196         ets_qdisc_setup $put 0 5000 2500
0197 }
0198 
0199 ets_test_strict()
0200 {
0201         ets_set_strict
0202         ets_dwrr_test_01
0203         ets_dwrr_test_12
0204 }
0205 
0206 ets_test_mixed()
0207 {
0208         ets_set_mixed
0209         ets_dwrr_test_01
0210         ets_dwrr_test_12
0211 }
0212 
0213 ets_test_dwrr()
0214 {
0215         ets_set_dwrr_uniform
0216         ets_dwrr_test_012
0217         ets_set_dwrr_varying
0218         ets_dwrr_test_012
0219         ets_change_quantum
0220         ets_dwrr_test_012
0221         ets_set_dwrr_two_bands
0222         ets_dwrr_test_01
0223 }