57 lines · bash
1# SPDX-License-Identifier: GPL-2.02 3check_rate()4{5 local rate=$1; shift6 local min=$1; shift7 local what=$1; shift8 9 if ((rate > min)); then10 return 011 fi12 13 echo "$what $(humanize $ir) < $(humanize $min)" > /dev/stderr14 return 115}16 17measure_rate()18{19 local sw_in=$1; shift # Where the traffic ingresses the switch20 local host_in=$1; shift # Where it ingresses another host21 local counter=$1; shift # Counter to use for measurement22 local what=$1; shift23 24 local interval=1025 local i26 local ret=027 28 # Dips in performance might cause momentary ingress rate to drop below29 # 1Gbps. That wouldn't saturate egress and MC would thus get through,30 # seemingly winning bandwidth on account of UC. Demand at least 2Gbps31 # average ingress rate to somewhat mitigate this.32 local min_ingress=214748364833 34 for i in {5..0}; do35 local t0=$(ethtool_stats_get $host_in $counter)36 local u0=$(ethtool_stats_get $sw_in $counter)37 sleep $interval38 local t1=$(ethtool_stats_get $host_in $counter)39 local u1=$(ethtool_stats_get $sw_in $counter)40 41 local ir=$(rate $u0 $u1 $interval)42 local er=$(rate $t0 $t1 $interval)43 44 if check_rate $ir $min_ingress "$what ingress rate"; then45 break46 fi47 48 # Fail the test if we can't get the throughput.49 if ((i == 0)); then50 ret=151 fi52 done53 54 echo $ir $er55 return $ret56}57