sch_offload.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Test qdisc offload indication
  5. ALL_TESTS="
  6. test_root
  7. test_port_tbf
  8. test_etsprio
  9. test_etsprio_port_tbf
  10. "
  11. NUM_NETIFS=1
  12. lib_dir=$(dirname $0)/../../../net/forwarding
  13. source $lib_dir/lib.sh
  14. check_not_offloaded()
  15. {
  16. local handle=$1; shift
  17. local h
  18. local offloaded
  19. h=$(qdisc_stats_get $h1 "$handle" .handle)
  20. [[ $h == '"'$handle'"' ]]
  21. check_err $? "Qdisc with handle $handle does not exist"
  22. offloaded=$(qdisc_stats_get $h1 "$handle" .offloaded)
  23. [[ $offloaded == true ]]
  24. check_fail $? "Qdisc with handle $handle offloaded, but should not be"
  25. }
  26. check_all_offloaded()
  27. {
  28. local handle=$1; shift
  29. if [[ ! -z $handle ]]; then
  30. local offloaded=$(qdisc_stats_get $h1 "$handle" .offloaded)
  31. [[ $offloaded == true ]]
  32. check_err $? "Qdisc with handle $handle not offloaded"
  33. fi
  34. local unoffloaded=$(tc q sh dev $h1 invisible |
  35. grep -v offloaded |
  36. sed s/root/parent\ root/ |
  37. cut -d' ' -f 5)
  38. [[ -z $unoffloaded ]]
  39. check_err $? "Qdiscs with following parents not offloaded: $unoffloaded"
  40. pre_cleanup
  41. }
  42. with_ets()
  43. {
  44. local handle=$1; shift
  45. local locus=$1; shift
  46. tc qdisc add dev $h1 $locus handle $handle \
  47. ets bands 8 priomap 7 6 5 4 3 2 1 0
  48. "$@"
  49. tc qdisc del dev $h1 $locus
  50. }
  51. with_prio()
  52. {
  53. local handle=$1; shift
  54. local locus=$1; shift
  55. tc qdisc add dev $h1 $locus handle $handle \
  56. prio bands 8 priomap 7 6 5 4 3 2 1 0
  57. "$@"
  58. tc qdisc del dev $h1 $locus
  59. }
  60. with_red()
  61. {
  62. local handle=$1; shift
  63. local locus=$1; shift
  64. tc qdisc add dev $h1 $locus handle $handle \
  65. red limit 1000000 min 200000 max 300000 probability 0.5 avpkt 1500
  66. "$@"
  67. tc qdisc del dev $h1 $locus
  68. }
  69. with_tbf()
  70. {
  71. local handle=$1; shift
  72. local locus=$1; shift
  73. tc qdisc add dev $h1 $locus handle $handle \
  74. tbf rate 400Mbit burst 128K limit 1M
  75. "$@"
  76. tc qdisc del dev $h1 $locus
  77. }
  78. with_pfifo()
  79. {
  80. local handle=$1; shift
  81. local locus=$1; shift
  82. tc qdisc add dev $h1 $locus handle $handle pfifo limit 100K
  83. "$@"
  84. tc qdisc del dev $h1 $locus
  85. }
  86. with_bfifo()
  87. {
  88. local handle=$1; shift
  89. local locus=$1; shift
  90. tc qdisc add dev $h1 $locus handle $handle bfifo limit 100K
  91. "$@"
  92. tc qdisc del dev $h1 $locus
  93. }
  94. with_drr()
  95. {
  96. local handle=$1; shift
  97. local locus=$1; shift
  98. tc qdisc add dev $h1 $locus handle $handle drr
  99. "$@"
  100. tc qdisc del dev $h1 $locus
  101. }
  102. with_qdiscs()
  103. {
  104. local handle=$1; shift
  105. local parent=$1; shift
  106. local kind=$1; shift
  107. local next_handle=$((handle * 2))
  108. local locus;
  109. if [[ $kind == "--" ]]; then
  110. local cmd=$1; shift
  111. $cmd $(printf %x: $parent) "$@"
  112. else
  113. if ((parent == 0)); then
  114. locus=root
  115. else
  116. locus=$(printf "parent %x:1" $parent)
  117. fi
  118. with_$kind $(printf %x: $handle) "$locus" \
  119. with_qdiscs $next_handle $handle "$@"
  120. fi
  121. }
  122. get_name()
  123. {
  124. local parent=$1; shift
  125. local name=$(echo "" "${@^^}" | tr ' ' -)
  126. if ((parent != 0)); then
  127. kind=$(qdisc_stats_get $h1 $parent: .kind)
  128. kind=${kind%\"}
  129. kind=${kind#\"}
  130. name="-${kind^^}$name"
  131. fi
  132. echo root$name
  133. }
  134. do_test_offloaded()
  135. {
  136. local handle=$1; shift
  137. local parent=$1; shift
  138. RET=0
  139. with_qdiscs $handle $parent "$@" -- check_all_offloaded
  140. log_test $(get_name $parent "$@")" offloaded"
  141. }
  142. do_test_nooffload()
  143. {
  144. local handle=$1; shift
  145. local parent=$1; shift
  146. local name=$(echo "${@^^}" | tr ' ' -)
  147. local kind
  148. RET=0
  149. with_qdiscs $handle $parent "$@" -- check_not_offloaded
  150. log_test $(get_name $parent "$@")" not offloaded"
  151. }
  152. do_test_combinations()
  153. {
  154. local handle=$1; shift
  155. local parent=$1; shift
  156. local cont
  157. local leaf
  158. local fifo
  159. for cont in "" ets prio; do
  160. for leaf in "" red tbf "red tbf" "tbf red"; do
  161. for fifo in "" pfifo bfifo; do
  162. if [[ -z "$cont$leaf$fifo" ]]; then
  163. continue
  164. fi
  165. do_test_offloaded $handle $parent \
  166. $cont $leaf $fifo
  167. done
  168. done
  169. done
  170. for cont in ets prio; do
  171. for leaf in red tbf; do
  172. do_test_nooffload $handle $parent $cont red tbf $leaf
  173. do_test_nooffload $handle $parent $cont tbf red $leaf
  174. done
  175. for leaf in "red red" "tbf tbf"; do
  176. do_test_nooffload $handle $parent $cont $leaf
  177. done
  178. done
  179. do_test_nooffload $handle $parent drr
  180. }
  181. test_root()
  182. {
  183. do_test_combinations 1 0
  184. }
  185. test_port_tbf()
  186. {
  187. with_tbf 1: root \
  188. do_test_combinations 8 1
  189. }
  190. do_test_etsprio()
  191. {
  192. local parent=$1; shift
  193. local tbfpfx=$1; shift
  194. local cont
  195. for cont in ets prio; do
  196. RET=0
  197. with_$cont 8: "$parent" \
  198. with_red 11: "parent 8:1" \
  199. with_red 12: "parent 8:2" \
  200. with_tbf 13: "parent 8:3" \
  201. with_tbf 14: "parent 8:4" \
  202. check_all_offloaded
  203. log_test "root$tbfpfx-ETS-{RED,TBF} offloaded"
  204. RET=0
  205. with_$cont 8: "$parent" \
  206. with_red 81: "parent 8:1" \
  207. with_tbf 811: "parent 81:1" \
  208. with_tbf 84: "parent 8:4" \
  209. with_red 841: "parent 84:1" \
  210. check_all_offloaded
  211. log_test "root$tbfpfx-ETS-{RED-TBF,TBF-RED} offloaded"
  212. RET=0
  213. with_$cont 8: "$parent" \
  214. with_red 81: "parent 8:1" \
  215. with_tbf 811: "parent 81:1" \
  216. with_bfifo 8111: "parent 811:1" \
  217. with_tbf 82: "parent 8:2" \
  218. with_red 821: "parent 82:1" \
  219. with_bfifo 8211: "parent 821:1" \
  220. check_all_offloaded
  221. log_test "root$tbfpfx-ETS-{RED-TBF-bFIFO,TBF-RED-bFIFO} offloaded"
  222. done
  223. }
  224. test_etsprio()
  225. {
  226. do_test_etsprio root ""
  227. }
  228. test_etsprio_port_tbf()
  229. {
  230. with_tbf 1: root \
  231. do_test_etsprio "parent 1:1" "-TBF"
  232. }
  233. cleanup()
  234. {
  235. tc qdisc del dev $h1 root &>/dev/null
  236. }
  237. trap cleanup EXIT
  238. h1=${NETIFS[p1]}
  239. tests_run
  240. exit $EXIT_STATUS