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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/net/drop_monitor_tests.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 is for checking drop monitor functionality.
  5 source lib.sh
  6 ret=0
  7 
  8 # all tests in this script. Can be overridden with -t option
  9 TESTS="
 10         sw_drops
 11         hw_drops
 12 "
 13 
 14 NETDEVSIM_PATH=/sys/bus/netdevsim/
 15 DEV_ADDR=1337
 16 DEV=netdevsim${DEV_ADDR}
 17 DEVLINK_DEV=netdevsim/${DEV}
 18 
 19 log_test()
 20 {
 21         local rc=$1
 22         local expected=$2
 23         local msg="$3"
 24 
 25         if [ ${rc} -eq ${expected} ]; then
 26                 printf "    TEST: %-60s  [ OK ]\n" "${msg}"
 27                 nsuccess=$((nsuccess+1))
 28         else
 29                 ret=1
 30                 nfail=$((nfail+1))
 31                 printf "    TEST: %-60s  [FAIL]\n" "${msg}"
 32         fi
 33 }
 34 
 35 setup()
 36 {
 37         modprobe netdevsim &> /dev/null
 38 
 39         set -e
 40         setup_ns NS1
 41         $IP link add dummy10 up type dummy
 42 
 43         $NS_EXEC echo "$DEV_ADDR 1" > ${NETDEVSIM_PATH}/new_device
 44         udevadm settle
 45         local netdev=$($NS_EXEC ls ${NETDEVSIM_PATH}/devices/${DEV}/net/)
 46         $IP link set dev $netdev up
 47 
 48         set +e
 49 }
 50 
 51 cleanup()
 52 {
 53         $NS_EXEC echo "$DEV_ADDR" > ${NETDEVSIM_PATH}/del_device
 54         cleanup_ns ${NS1}
 55 }
 56 
 57 sw_drops_test()
 58 {
 59         echo
 60         echo "Software drops test"
 61 
 62         setup
 63 
 64         local dir=$(mktemp -d)
 65 
 66         $TC qdisc add dev dummy10 clsact
 67         $TC filter add dev dummy10 egress pref 1 handle 101 proto ip \
 68                 flower dst_ip 192.0.2.10 action drop
 69 
 70         $NS_EXEC mausezahn dummy10 -a 00:11:22:33:44:55 -b 00:aa:bb:cc:dd:ee \
 71                 -A 192.0.2.1 -B 192.0.2.10 -t udp sp=12345,dp=54321 -c 0 -q \
 72                 -d 100msec &
 73         timeout 5 dwdump -o sw -w ${dir}/packets.pcap
 74         (( $(tshark -r ${dir}/packets.pcap \
 75                 -Y 'ip.dst == 192.0.2.10' 2> /dev/null | wc -l) != 0))
 76         log_test $? 0 "Capturing active software drops"
 77 
 78         rm ${dir}/packets.pcap
 79 
 80         { kill %% && wait %%; } 2>/dev/null
 81         timeout 5 dwdump -o sw -w ${dir}/packets.pcap
 82         (( $(tshark -r ${dir}/packets.pcap \
 83                 -Y 'ip.dst == 192.0.2.10' 2> /dev/null | wc -l) == 0))
 84         log_test $? 0 "Capturing inactive software drops"
 85 
 86         rm -r $dir
 87 
 88         cleanup
 89 }
 90 
 91 hw_drops_test()
 92 {
 93         echo
 94         echo "Hardware drops test"
 95 
 96         setup
 97 
 98         local dir=$(mktemp -d)
 99 
100         $DEVLINK trap set $DEVLINK_DEV trap blackhole_route action trap
101         timeout 5 dwdump -o hw -w ${dir}/packets.pcap
102         (( $(tshark -r ${dir}/packets.pcap \
103                 -Y 'net_dm.hw_trap_name== blackhole_route' 2> /dev/null \
104                 | wc -l) != 0))
105         log_test $? 0 "Capturing active hardware drops"
106 
107         rm ${dir}/packets.pcap
108 
109         $DEVLINK trap set $DEVLINK_DEV trap blackhole_route action drop
110         timeout 5 dwdump -o hw -w ${dir}/packets.pcap
111         (( $(tshark -r ${dir}/packets.pcap \
112                 -Y 'net_dm.hw_trap_name== blackhole_route' 2> /dev/null \
113                 | wc -l) == 0))
114         log_test $? 0 "Capturing inactive hardware drops"
115 
116         rm -r $dir
117 
118         cleanup
119 }
120 
121 ################################################################################
122 # usage
123 
124 usage()
125 {
126         cat <<EOF
127 usage: ${0##*/} OPTS
128 
129         -t <test>   Test(s) to run (default: all)
130                     (options: $TESTS)
131 EOF
132 }
133 
134 ################################################################################
135 # main
136 
137 while getopts ":t:h" opt; do
138         case $opt in
139                 t) TESTS=$OPTARG;;
140                 h) usage; exit 0;;
141                 *) usage; exit 1;;
142         esac
143 done
144 
145 if [ "$(id -u)" -ne 0 ];then
146         echo "SKIP: Need root privileges"
147         exit $ksft_skip;
148 fi
149 
150 if [ ! -x "$(command -v ip)" ]; then
151         echo "SKIP: Could not run test without ip tool"
152         exit $ksft_skip
153 fi
154 
155 if [ ! -x "$(command -v devlink)" ]; then
156         echo "SKIP: Could not run test without devlink tool"
157         exit $ksft_skip
158 fi
159 
160 if [ ! -x "$(command -v tshark)" ]; then
161         echo "SKIP: Could not run test without tshark tool"
162         exit $ksft_skip
163 fi
164 
165 if [ ! -x "$(command -v dwdump)" ]; then
166         echo "SKIP: Could not run test without dwdump tool"
167         exit $ksft_skip
168 fi
169 
170 if [ ! -x "$(command -v udevadm)" ]; then
171         echo "SKIP: Could not run test without udevadm tool"
172         exit $ksft_skip
173 fi
174 
175 if [ ! -x "$(command -v timeout)" ]; then
176         echo "SKIP: Could not run test without timeout tool"
177         exit $ksft_skip
178 fi
179 
180 if [ ! -x "$(command -v mausezahn)" ]; then
181         echo "SKIP: Could not run test without mausezahn tool"
182         exit $ksft_skip
183 fi
184 
185 tshark -G fields 2> /dev/null | grep -q net_dm
186 if [ $? -ne 0 ]; then
187         echo "SKIP: tshark too old, missing net_dm dissector"
188         exit $ksft_skip
189 fi
190 
191 # create netns first so we can get the namespace name
192 setup_ns NS1
193 cleanup &> /dev/null
194 trap cleanup EXIT
195 
196 IP="ip -netns ${NS1}"
197 TC="tc -netns ${NS1}"
198 DEVLINK="devlink -N ${NS1}"
199 NS_EXEC="ip netns exec ${NS1}"
200 
201 for t in $TESTS
202 do
203         case $t in
204         sw_drops|sw)                    sw_drops_test;;
205         hw_drops|hw)                    hw_drops_test;;
206 
207         help) echo "Test names: $TESTS"; exit 0;;
208         esac
209 done
210 
211 if [ "$TESTS" != "none" ]; then
212         printf "\nTests passed: %3d\n" ${nsuccess}
213         printf "Tests failed: %3d\n"   ${nfail}
214 fi
215 
216 exit $ret

~ [ 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