0001
0002
0003
0004
0005
0006
0007 ALL_TESTS="
0008 test_root
0009 test_port_tbf
0010 test_etsprio
0011 test_etsprio_port_tbf
0012 "
0013 NUM_NETIFS=1
0014 lib_dir=$(dirname $0)/../../../net/forwarding
0015 source $lib_dir/lib.sh
0016
0017 check_not_offloaded()
0018 {
0019 local handle=$1; shift
0020 local h
0021 local offloaded
0022
0023 h=$(qdisc_stats_get $h1 "$handle" .handle)
0024 [[ $h == '"'$handle'"' ]]
0025 check_err $? "Qdisc with handle $handle does not exist"
0026
0027 offloaded=$(qdisc_stats_get $h1 "$handle" .offloaded)
0028 [[ $offloaded == true ]]
0029 check_fail $? "Qdisc with handle $handle offloaded, but should not be"
0030 }
0031
0032 check_all_offloaded()
0033 {
0034 local handle=$1; shift
0035
0036 if [[ ! -z $handle ]]; then
0037 local offloaded=$(qdisc_stats_get $h1 "$handle" .offloaded)
0038 [[ $offloaded == true ]]
0039 check_err $? "Qdisc with handle $handle not offloaded"
0040 fi
0041
0042 local unoffloaded=$(tc q sh dev $h1 invisible |
0043 grep -v offloaded |
0044 sed s/root/parent\ root/ |
0045 cut -d' ' -f 5)
0046 [[ -z $unoffloaded ]]
0047 check_err $? "Qdiscs with following parents not offloaded: $unoffloaded"
0048
0049 pre_cleanup
0050 }
0051
0052 with_ets()
0053 {
0054 local handle=$1; shift
0055 local locus=$1; shift
0056
0057 tc qdisc add dev $h1 $locus handle $handle \
0058 ets bands 8 priomap 7 6 5 4 3 2 1 0
0059 "$@"
0060 tc qdisc del dev $h1 $locus
0061 }
0062
0063 with_prio()
0064 {
0065 local handle=$1; shift
0066 local locus=$1; shift
0067
0068 tc qdisc add dev $h1 $locus handle $handle \
0069 prio bands 8 priomap 7 6 5 4 3 2 1 0
0070 "$@"
0071 tc qdisc del dev $h1 $locus
0072 }
0073
0074 with_red()
0075 {
0076 local handle=$1; shift
0077 local locus=$1; shift
0078
0079 tc qdisc add dev $h1 $locus handle $handle \
0080 red limit 1000000 min 200000 max 300000 probability 0.5 avpkt 1500
0081 "$@"
0082 tc qdisc del dev $h1 $locus
0083 }
0084
0085 with_tbf()
0086 {
0087 local handle=$1; shift
0088 local locus=$1; shift
0089
0090 tc qdisc add dev $h1 $locus handle $handle \
0091 tbf rate 400Mbit burst 128K limit 1M
0092 "$@"
0093 tc qdisc del dev $h1 $locus
0094 }
0095
0096 with_pfifo()
0097 {
0098 local handle=$1; shift
0099 local locus=$1; shift
0100
0101 tc qdisc add dev $h1 $locus handle $handle pfifo limit 100K
0102 "$@"
0103 tc qdisc del dev $h1 $locus
0104 }
0105
0106 with_bfifo()
0107 {
0108 local handle=$1; shift
0109 local locus=$1; shift
0110
0111 tc qdisc add dev $h1 $locus handle $handle bfifo limit 100K
0112 "$@"
0113 tc qdisc del dev $h1 $locus
0114 }
0115
0116 with_drr()
0117 {
0118 local handle=$1; shift
0119 local locus=$1; shift
0120
0121 tc qdisc add dev $h1 $locus handle $handle drr
0122 "$@"
0123 tc qdisc del dev $h1 $locus
0124 }
0125
0126 with_qdiscs()
0127 {
0128 local handle=$1; shift
0129 local parent=$1; shift
0130 local kind=$1; shift
0131 local next_handle=$((handle * 2))
0132 local locus;
0133
0134 if [[ $kind == "--" ]]; then
0135 local cmd=$1; shift
0136 $cmd $(printf %x: $parent) "$@"
0137 else
0138 if ((parent == 0)); then
0139 locus=root
0140 else
0141 locus=$(printf "parent %x:1" $parent)
0142 fi
0143
0144 with_$kind $(printf %x: $handle) "$locus" \
0145 with_qdiscs $next_handle $handle "$@"
0146 fi
0147 }
0148
0149 get_name()
0150 {
0151 local parent=$1; shift
0152 local name=$(echo "" "${@^^}" | tr ' ' -)
0153
0154 if ((parent != 0)); then
0155 kind=$(qdisc_stats_get $h1 $parent: .kind)
0156 kind=${kind%\"}
0157 kind=${kind
0158 name="-${kind^^}$name"
0159 fi
0160
0161 echo root$name
0162 }
0163
0164 do_test_offloaded()
0165 {
0166 local handle=$1; shift
0167 local parent=$1; shift
0168
0169 RET=0
0170 with_qdiscs $handle $parent "$@" -- check_all_offloaded
0171 log_test $(get_name $parent "$@")" offloaded"
0172 }
0173
0174 do_test_nooffload()
0175 {
0176 local handle=$1; shift
0177 local parent=$1; shift
0178
0179 local name=$(echo "${@^^}" | tr ' ' -)
0180 local kind
0181
0182 RET=0
0183 with_qdiscs $handle $parent "$@" -- check_not_offloaded
0184 log_test $(get_name $parent "$@")" not offloaded"
0185 }
0186
0187 do_test_combinations()
0188 {
0189 local handle=$1; shift
0190 local parent=$1; shift
0191
0192 local cont
0193 local leaf
0194 local fifo
0195
0196 for cont in "" ets prio; do
0197 for leaf in "" red tbf "red tbf" "tbf red"; do
0198 for fifo in "" pfifo bfifo; do
0199 if [[ -z "$cont$leaf$fifo" ]]; then
0200 continue
0201 fi
0202 do_test_offloaded $handle $parent \
0203 $cont $leaf $fifo
0204 done
0205 done
0206 done
0207
0208 for cont in ets prio; do
0209 for leaf in red tbf; do
0210 do_test_nooffload $handle $parent $cont red tbf $leaf
0211 do_test_nooffload $handle $parent $cont tbf red $leaf
0212 done
0213 for leaf in "red red" "tbf tbf"; do
0214 do_test_nooffload $handle $parent $cont $leaf
0215 done
0216 done
0217
0218 do_test_nooffload $handle $parent drr
0219 }
0220
0221 test_root()
0222 {
0223 do_test_combinations 1 0
0224 }
0225
0226 test_port_tbf()
0227 {
0228 with_tbf 1: root \
0229 do_test_combinations 8 1
0230 }
0231
0232 do_test_etsprio()
0233 {
0234 local parent=$1; shift
0235 local tbfpfx=$1; shift
0236 local cont
0237
0238 for cont in ets prio; do
0239 RET=0
0240 with_$cont 8: "$parent" \
0241 with_red 11: "parent 8:1" \
0242 with_red 12: "parent 8:2" \
0243 with_tbf 13: "parent 8:3" \
0244 with_tbf 14: "parent 8:4" \
0245 check_all_offloaded
0246 log_test "root$tbfpfx-ETS-{RED,TBF} offloaded"
0247
0248 RET=0
0249 with_$cont 8: "$parent" \
0250 with_red 81: "parent 8:1" \
0251 with_tbf 811: "parent 81:1" \
0252 with_tbf 84: "parent 8:4" \
0253 with_red 841: "parent 84:1" \
0254 check_all_offloaded
0255 log_test "root$tbfpfx-ETS-{RED-TBF,TBF-RED} offloaded"
0256
0257 RET=0
0258 with_$cont 8: "$parent" \
0259 with_red 81: "parent 8:1" \
0260 with_tbf 811: "parent 81:1" \
0261 with_bfifo 8111: "parent 811:1" \
0262 with_tbf 82: "parent 8:2" \
0263 with_red 821: "parent 82:1" \
0264 with_bfifo 8211: "parent 821:1" \
0265 check_all_offloaded
0266 log_test "root$tbfpfx-ETS-{RED-TBF-bFIFO,TBF-RED-bFIFO} offloaded"
0267 done
0268 }
0269
0270 test_etsprio()
0271 {
0272 do_test_etsprio root ""
0273 }
0274
0275 test_etsprio_port_tbf()
0276 {
0277 with_tbf 1: root \
0278 do_test_etsprio "parent 1:1" "-TBF"
0279 }
0280
0281 cleanup()
0282 {
0283 tc qdisc del dev $h1 root &>/dev/null
0284 }
0285
0286 trap cleanup EXIT
0287 h1=${NETIFS[p1]}
0288 tests_run
0289
0290 exit $EXIT_STATUS