146 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4ALL_TESTS="5 rmon_rx_histogram6 rmon_tx_histogram7"8 9NUM_NETIFS=210lib_dir=$(dirname "$0")11source "$lib_dir"/../../../net/forwarding/lib.sh12 13ETH_FCS_LEN=414ETH_HLEN=$((6+6+2))15 16declare -A netif_mtu17 18ensure_mtu()19{20 local iface=$1; shift21 local len=$1; shift22 local current=$(ip -j link show dev $iface | jq -r '.[0].mtu')23 local required=$((len - ETH_HLEN - ETH_FCS_LEN))24 25 if [ $current -lt $required ]; then26 ip link set dev $iface mtu $required || return 127 fi28}29 30bucket_test()31{32 local iface=$1; shift33 local neigh=$1; shift34 local set=$1; shift35 local bucket=$1; shift36 local len=$1; shift37 local num_rx=1000038 local num_tx=2000039 local expected=40 local before=41 local after=42 local delta=43 44 # Mausezahn does not include FCS bytes in its length - but the45 # histogram counters do46 len=$((len - ETH_FCS_LEN))47 len=$((len > 0 ? len : 0))48 49 before=$(ethtool --json -S $iface --groups rmon | \50 jq -r ".[0].rmon[\"${set}-pktsNtoM\"][$bucket].val")51 52 # Send 10k one way and 20k in the other, to detect counters53 # mapped to the wrong direction54 $MZ $neigh -q -c $num_rx -p $len -a own -b bcast -d 10us55 $MZ $iface -q -c $num_tx -p $len -a own -b bcast -d 10us56 57 after=$(ethtool --json -S $iface --groups rmon | \58 jq -r ".[0].rmon[\"${set}-pktsNtoM\"][$bucket].val")59 60 delta=$((after - before))61 62 expected=$([ $set = rx ] && echo $num_rx || echo $num_tx)63 64 # Allow some extra tolerance for other packets sent by the stack65 [ $delta -ge $expected ] && [ $delta -le $((expected + 100)) ]66}67 68rmon_histogram()69{70 local iface=$1; shift71 local neigh=$1; shift72 local set=$1; shift73 local nbuckets=074 local step=75 76 RET=077 78 while read -r -a bucket; do79 step="$set-pkts${bucket[0]}to${bucket[1]} on $iface"80 81 for if in $iface $neigh; do82 if ! ensure_mtu $if ${bucket[0]}; then83 log_test_xfail "$if does not support the required MTU for $step"84 return85 fi86 done87 88 if ! bucket_test $iface $neigh $set $nbuckets ${bucket[0]}; then89 check_err 1 "$step failed"90 return 191 fi92 log_test "$step"93 nbuckets=$((nbuckets + 1))94 done < <(ethtool --json -S $iface --groups rmon | \95 jq -r ".[0].rmon[\"${set}-pktsNtoM\"][]|[.low, .high]|@tsv" 2>/dev/null)96 97 if [ $nbuckets -eq 0 ]; then98 log_test_xfail "$iface does not support $set histogram counters"99 return100 fi101}102 103rmon_rx_histogram()104{105 rmon_histogram $h1 $h2 rx106 rmon_histogram $h2 $h1 rx107}108 109rmon_tx_histogram()110{111 rmon_histogram $h1 $h2 tx112 rmon_histogram $h2 $h1 tx113}114 115setup_prepare()116{117 h1=${NETIFS[p1]}118 h2=${NETIFS[p2]}119 120 for iface in $h1 $h2; do121 netif_mtu[$iface]=$(ip -j link show dev $iface | jq -r '.[0].mtu')122 ip link set dev $iface up123 done124}125 126cleanup()127{128 pre_cleanup129 130 for iface in $h2 $h1; do131 ip link set dev $iface \132 mtu ${netif_mtu[$iface]} \133 down134 done135}136 137check_ethtool_counter_group_support138trap cleanup EXIT139 140setup_prepare141setup_wait142 143tests_run144 145exit $EXIT_STATUS146