0001
0002
0003 check_rate()
0004 {
0005 local rate=$1; shift
0006 local min=$1; shift
0007 local what=$1; shift
0008
0009 if ((rate > min)); then
0010 return 0
0011 fi
0012
0013 echo "$what $(humanize $ir) < $(humanize $min)" > /dev/stderr
0014 return 1
0015 }
0016
0017 measure_rate()
0018 {
0019 local sw_in=$1; shift
0020 local host_in=$1; shift
0021 local counter=$1; shift
0022 local what=$1; shift
0023
0024 local interval=10
0025 local i
0026 local ret=0
0027
0028
0029
0030
0031
0032 local min_ingress=2147483648
0033
0034 for i in {5..0}; do
0035 local t0=$(ethtool_stats_get $host_in $counter)
0036 local u0=$(ethtool_stats_get $sw_in $counter)
0037 sleep $interval
0038 local t1=$(ethtool_stats_get $host_in $counter)
0039 local u1=$(ethtool_stats_get $sw_in $counter)
0040
0041 local ir=$(rate $u0 $u1 $interval)
0042 local er=$(rate $t0 $t1 $interval)
0043
0044 if check_rate $ir $min_ingress "$what ingress rate"; then
0045 break
0046 fi
0047
0048
0049 if ((i == 0)); then
0050 ret=1
0051 fi
0052 done
0053
0054 echo $ir $er
0055 return $ret
0056 }
0057
0058 bail_on_lldpad()
0059 {
0060 if systemctl is-active --quiet lldpad; then
0061
0062 cat >/dev/stderr <<-EOF
0063 WARNING: lldpad is running
0064
0065 lldpad will likely configure DCB, and this test will
0066 configure Qdiscs. mlxsw does not support both at the
0067 same time, one of them is arbitrarily going to overwrite
0068 the other. That will cause spurious failures (or,
0069 unlikely, passes) of this test.
0070 EOF
0071
0072 if [[ -z $ALLOW_LLDPAD ]]; then
0073 cat >/dev/stderr <<-EOF
0074
0075 If you want to run the test anyway, please set
0076 an environment variable ALLOW_LLDPAD to a
0077 non-empty string.
0078 EOF
0079 exit 1
0080 else
0081 return
0082 fi
0083 fi
0084 }