qos_lib.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # SPDX-License-Identifier: GPL-2.0
  2. check_rate()
  3. {
  4. local rate=$1; shift
  5. local min=$1; shift
  6. local what=$1; shift
  7. if ((rate > min)); then
  8. return 0
  9. fi
  10. echo "$what $(humanize $ir) < $(humanize $min)" > /dev/stderr
  11. return 1
  12. }
  13. measure_rate()
  14. {
  15. local sw_in=$1; shift # Where the traffic ingresses the switch
  16. local host_in=$1; shift # Where it ingresses another host
  17. local counter=$1; shift # Counter to use for measurement
  18. local what=$1; shift
  19. local interval=10
  20. local i
  21. local ret=0
  22. # Dips in performance might cause momentary ingress rate to drop below
  23. # 1Gbps. That wouldn't saturate egress and MC would thus get through,
  24. # seemingly winning bandwidth on account of UC. Demand at least 2Gbps
  25. # average ingress rate to somewhat mitigate this.
  26. local min_ingress=2147483648
  27. for i in {5..0}; do
  28. local t0=$(ethtool_stats_get $host_in $counter)
  29. local u0=$(ethtool_stats_get $sw_in $counter)
  30. sleep $interval
  31. local t1=$(ethtool_stats_get $host_in $counter)
  32. local u1=$(ethtool_stats_get $sw_in $counter)
  33. local ir=$(rate $u0 $u1 $interval)
  34. local er=$(rate $t0 $t1 $interval)
  35. if check_rate $ir $min_ingress "$what ingress rate"; then
  36. break
  37. fi
  38. # Fail the test if we can't get the throughput.
  39. if ((i == 0)); then
  40. ret=1
  41. fi
  42. done
  43. echo $ir $er
  44. return $ret
  45. }