1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0 3 4readonly STATS="$(mktemp -p /tmp ns-XXXXXX)" 5readonly BASE=`basename $STATS` 6readonly SRC=2 7readonly DST=1 8readonly DST_NAT=100 9readonly NS_SRC=$BASE$SRC 10readonly NS_DST=$BASE$DST 11 12# "baremetal" network used for raw UDP traffic 13readonly BM_NET_V4=192.168.1. 14readonly BM_NET_V6=2001:db8:: 15 16readonly NPROCS=`nproc` 17ret=0 18 19cleanup() { 20 local ns 21 local jobs 22 readonly jobs="$(jobs -p)" 23 [ -n "${jobs}" ] && kill -1 ${jobs} 2>/dev/null 24 rm -f $STATS 25 26 for ns in $NS_SRC $NS_DST; do 27 ip netns del $ns 2>/dev/null 28 done 29} 30 31trap cleanup EXIT 32 33create_ns() { 34 local ns 35 36 for ns in $NS_SRC $NS_DST; do 37 ip netns add $ns 38 ip -n $ns link set dev lo up 39 done 40 41 ip link add name veth$SRC type veth peer name veth$DST 42 43 for ns in $SRC $DST; do 44 ip link set dev veth$ns netns $BASE$ns up 45 ip -n $BASE$ns addr add dev veth$ns $BM_NET_V4$ns/24 46 ip -n $BASE$ns addr add dev veth$ns $BM_NET_V6$ns/64 nodad 47 done 48 echo "#kernel" > $BASE 49 chmod go-rw $BASE 50} 51 52__chk_flag() { 53 local msg="$1" 54 local target=$2 55 local expected=$3 56 local flagname=$4 57 58 local flag=`ip netns exec $BASE$target ethtool -k veth$target |\ 59 grep $flagname | awk '{print $2}'` 60 61 printf "%-60s" "$msg" 62 if [ "$flag" = "$expected" ]; then 63 echo " ok " 64 else 65 echo " fail - expected $expected found $flag" 66 ret=1 67 fi 68} 69 70chk_gro_flag() { 71 __chk_flag "$1" $2 $3 generic-receive-offload 72} 73 74chk_tso_flag() { 75 __chk_flag "$1" $2 $3 tcp-segmentation-offload 76} 77 78chk_gro() { 79 local msg="$1" 80 local expected=$2 81 82 ip netns exec $BASE$SRC ping -qc 1 $BM_NET_V4$DST >/dev/null 83 NSTAT_HISTORY=$STATS ip netns exec $NS_DST nstat -n 84 85 printf "%-60s" "$msg" 86 ip netns exec $BASE$DST ./udpgso_bench_rx -C 1000 -R 10 & 87 local spid=$! 88 sleep 0.1 89 90 ip netns exec $NS_SRC ./udpgso_bench_tx -4 -s 13000 -S 1300 -M 1 -D $BM_NET_V4$DST 91 local retc=$? 92 wait $spid 93 local rets=$? 94 if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then 95 echo " fail client exit code $retc, server $rets" 96 ret=1 97 return 98 fi 99 100 local pkts=`NSTAT_HISTORY=$STATS ip netns exec $NS_DST nstat IpInReceives | \ 101 awk '{print $2}' | tail -n 1` 102 if [ "$pkts" = "$expected" ]; then 103 echo " ok " 104 else 105 echo " fail - got $pkts packets, expected $expected " 106 ret=1 107 fi 108} 109 110if [ ! -f ../bpf/xdp_dummy.o ]; then 111 echo "Missing xdp_dummy helper. Build bpf selftest first" 112 exit 1 113fi 114 115create_ns 116chk_gro_flag "default - gro flag" $SRC off 117chk_gro_flag " - peer gro flag" $DST off 118chk_tso_flag " - tso flag" $SRC on 119chk_tso_flag " - peer tso flag" $DST on 120chk_gro " - aggregation" 1 121ip netns exec $NS_SRC ethtool -K veth$SRC tx-udp-segmentation off 122chk_gro " - aggregation with TSO off" 10 123cleanup 124 125create_ns 126ip netns exec $NS_DST ethtool -K veth$DST gro on 127chk_gro_flag "with gro on - gro flag" $DST on 128chk_gro_flag " - peer gro flag" $SRC off 129chk_tso_flag " - tso flag" $SRC on 130chk_tso_flag " - peer tso flag" $DST on 131ip netns exec $NS_SRC ethtool -K veth$SRC tx-udp-segmentation off 132ip netns exec $NS_DST ethtool -K veth$DST rx-udp-gro-forwarding on 133chk_gro " - aggregation with TSO off" 1 134cleanup 135 136create_ns 137ip -n $NS_DST link set dev veth$DST down 138ip netns exec $NS_DST ethtool -K veth$DST gro on 139chk_gro_flag "with gro enabled on link down - gro flag" $DST on 140chk_gro_flag " - peer gro flag" $SRC off 141chk_tso_flag " - tso flag" $SRC on 142chk_tso_flag " - peer tso flag" $DST on 143ip -n $NS_DST link set dev veth$DST up 144ip netns exec $NS_SRC ethtool -K veth$SRC tx-udp-segmentation off 145ip netns exec $NS_DST ethtool -K veth$DST rx-udp-gro-forwarding on 146chk_gro " - aggregation with TSO off" 1 147cleanup 148 149create_ns 150ip -n $NS_DST link set dev veth$DST xdp object ../bpf/xdp_dummy.o section xdp_dummy 2>/dev/null 151chk_gro_flag "with xdp attached - gro flag" $DST on 152chk_gro_flag " - peer gro flag" $SRC off 153chk_tso_flag " - tso flag" $SRC off 154chk_tso_flag " - peer tso flag" $DST on 155ip netns exec $NS_DST ethtool -K veth$DST rx-udp-gro-forwarding on 156chk_gro " - aggregation" 1 157 158 159ip -n $NS_DST link set dev veth$DST down 160ip -n $NS_SRC link set dev veth$SRC down 161chk_gro_flag " - after dev off, flag" $DST on 162chk_gro_flag " - peer flag" $SRC off 163 164ip netns exec $NS_DST ethtool -K veth$DST gro on 165ip -n $NS_DST link set dev veth$DST xdp off 166chk_gro_flag " - after gro on xdp off, gro flag" $DST on 167chk_gro_flag " - peer gro flag" $SRC off 168chk_tso_flag " - tso flag" $SRC on 169chk_tso_flag " - peer tso flag" $DST on 170ip -n $NS_DST link set dev veth$DST up 171ip -n $NS_SRC link set dev veth$SRC up 172chk_gro " - aggregation" 1 173 174ip netns exec $NS_DST ethtool -K veth$DST gro off 175ip netns exec $NS_SRC ethtool -K veth$SRC tx-udp-segmentation off 176chk_gro "aggregation again with default and TSO off" 10 177 178exit $ret 179