~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/test_tc_edt.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0
  3 #
  4 # This test installs a TC bpf program that throttles a TCP flow
  5 # with dst port = 9000 down to 5MBps. Then it measures actual
  6 # throughput of the flow.
  7 
  8 BPF_FILE="test_tc_edt.bpf.o"
  9 if [[ $EUID -ne 0 ]]; then
 10         echo "This script must be run as root"
 11         echo "FAIL"
 12         exit 1
 13 fi
 14 
 15 # check that nc, dd, and timeout are present
 16 command -v nc >/dev/null 2>&1 || \
 17         { echo >&2 "nc is not available"; exit 1; }
 18 command -v dd >/dev/null 2>&1 || \
 19         { echo >&2 "nc is not available"; exit 1; }
 20 command -v timeout >/dev/null 2>&1 || \
 21         { echo >&2 "timeout is not available"; exit 1; }
 22 
 23 readonly NS_SRC="ns-src-$(mktemp -u XXXXXX)"
 24 readonly NS_DST="ns-dst-$(mktemp -u XXXXXX)"
 25 
 26 readonly IP_SRC="172.16.1.100"
 27 readonly IP_DST="172.16.2.100"
 28 
 29 cleanup()
 30 {
 31         ip netns del ${NS_SRC}
 32         ip netns del ${NS_DST}
 33 }
 34 
 35 trap cleanup EXIT
 36 
 37 set -e  # exit on error
 38 
 39 ip netns add "${NS_SRC}"
 40 ip netns add "${NS_DST}"
 41 ip link add veth_src type veth peer name veth_dst
 42 ip link set veth_src netns ${NS_SRC}
 43 ip link set veth_dst netns ${NS_DST}
 44 
 45 ip -netns ${NS_SRC} addr add ${IP_SRC}/24  dev veth_src
 46 ip -netns ${NS_DST} addr add ${IP_DST}/24  dev veth_dst
 47 
 48 ip -netns ${NS_SRC} link set dev veth_src up
 49 ip -netns ${NS_DST} link set dev veth_dst up
 50 
 51 ip -netns ${NS_SRC} route add ${IP_DST}/32  dev veth_src
 52 ip -netns ${NS_DST} route add ${IP_SRC}/32  dev veth_dst
 53 
 54 # set up TC on TX
 55 ip netns exec ${NS_SRC} tc qdisc add dev veth_src root fq
 56 ip netns exec ${NS_SRC} tc qdisc add dev veth_src clsact
 57 ip netns exec ${NS_SRC} tc filter add dev veth_src egress \
 58         bpf da obj ${BPF_FILE} sec cls_test
 59 
 60 
 61 # start the listener
 62 ip netns exec ${NS_DST} bash -c \
 63         "nc -4 -l -p 9000 >/dev/null &"
 64 declare -i NC_PID=$!
 65 sleep 1
 66 
 67 declare -ir TIMEOUT=20
 68 declare -ir EXPECTED_BPS=5000000
 69 
 70 # run the load, capture RX bytes on DST
 71 declare -ir RX_BYTES_START=$( ip netns exec ${NS_DST} \
 72         cat /sys/class/net/veth_dst/statistics/rx_bytes )
 73 
 74 set +e
 75 ip netns exec ${NS_SRC} bash -c "timeout ${TIMEOUT} dd if=/dev/zero \
 76         bs=1000 count=1000000 > /dev/tcp/${IP_DST}/9000 2>/dev/null"
 77 set -e
 78 
 79 declare -ir RX_BYTES_END=$( ip netns exec ${NS_DST} \
 80         cat /sys/class/net/veth_dst/statistics/rx_bytes )
 81 
 82 declare -ir ACTUAL_BPS=$(( ($RX_BYTES_END - $RX_BYTES_START) / $TIMEOUT ))
 83 
 84 echo $TIMEOUT $ACTUAL_BPS $EXPECTED_BPS | \
 85         awk '{printf "elapsed: %d sec; bps difference: %.2f%%\n",
 86                 $1, ($2-$3)*100.0/$3}'
 87 
 88 # Pass the test if the actual bps is within 1% of the expected bps.
 89 # The difference is usually about 0.1% on a 20-sec test, and ==> zero
 90 # the longer the test runs.
 91 declare -ir RES=$( echo $ACTUAL_BPS $EXPECTED_BPS | \
 92          awk 'function abs(x){return ((x < 0.0) ? -x : x)}
 93               {if (abs(($1-$2)*100.0/$2) > 1.0) { print "1" }
 94                 else { print "0"} }' )
 95 if [ "${RES}" == "0" ] ; then
 96         echo "PASS"
 97 else
 98         echo "FAIL"
 99         exit 1
100 fi

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php