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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/net/veth.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/sh
  2 # SPDX-License-Identifier: GPL-2.0
  3 
  4 BPF_FILE="xdp_dummy.bpf.o"
  5 readonly STATS="$(mktemp -p /tmp ns-XXXXXX)"
  6 readonly BASE=`basename $STATS`
  7 readonly SRC=2
  8 readonly DST=1
  9 readonly DST_NAT=100
 10 readonly NS_SRC=$BASE$SRC
 11 readonly NS_DST=$BASE$DST
 12 
 13 # "baremetal" network used for raw UDP traffic
 14 readonly BM_NET_V4=192.168.1.
 15 readonly BM_NET_V6=2001:db8::
 16 
 17 readonly CPUS=`nproc`
 18 ret=0
 19 
 20 cleanup() {
 21         local ns
 22         local jobs
 23         readonly jobs="$(jobs -p)"
 24         [ -n "${jobs}" ] && kill -1 ${jobs} 2>/dev/null
 25         rm -f $STATS
 26 
 27         for ns in $NS_SRC $NS_DST; do
 28                 ip netns del $ns 2>/dev/null
 29         done
 30 }
 31 
 32 trap cleanup EXIT
 33 
 34 create_ns() {
 35         local ns
 36 
 37         for ns in $NS_SRC $NS_DST; do
 38                 ip netns add $ns
 39                 ip -n $ns link set dev lo up
 40         done
 41 
 42         ip link add name veth$SRC type veth peer name veth$DST
 43 
 44         for ns in $SRC $DST; do
 45                 ip link set dev veth$ns netns $BASE$ns up
 46                 ip -n $BASE$ns addr add dev veth$ns $BM_NET_V4$ns/24
 47                 ip -n $BASE$ns addr add dev veth$ns $BM_NET_V6$ns/64 nodad
 48         done
 49         echo "#kernel" > $BASE
 50         chmod go-rw $BASE
 51 }
 52 
 53 __chk_flag() {
 54         local msg="$1"
 55         local target=$2
 56         local expected=$3
 57         local flagname=$4
 58 
 59         local flag=`ip netns exec $BASE$target ethtool -k veth$target |\
 60                     grep $flagname | awk '{print $2}'`
 61 
 62         printf "%-60s" "$msg"
 63         if [ "$flag" = "$expected" ]; then
 64                 echo " ok "
 65         else
 66                 echo " fail - expected $expected found $flag"
 67                 ret=1
 68         fi
 69 }
 70 
 71 chk_gro_flag() {
 72         __chk_flag "$1" $2 $3 generic-receive-offload
 73 }
 74 
 75 chk_tso_flag() {
 76         __chk_flag "$1" $2 $3 tcp-segmentation-offload
 77 }
 78 
 79 chk_channels() {
 80         local msg="$1"
 81         local target=$2
 82         local rx=$3
 83         local tx=$4
 84 
 85         local dev=veth$target
 86 
 87         local cur_rx=`ip netns exec $BASE$target ethtool -l $dev |\
 88                 grep RX: | tail -n 1 | awk '{print $2}' `
 89                 local cur_tx=`ip netns exec $BASE$target ethtool -l $dev |\
 90                 grep TX: | tail -n 1 | awk '{print $2}'`
 91         local cur_combined=`ip netns exec $BASE$target ethtool -l $dev |\
 92                 grep Combined: | tail -n 1 | awk '{print $2}'`
 93 
 94         printf "%-60s" "$msg"
 95         if [ "$cur_rx" = "$rx" -a "$cur_tx" = "$tx" -a "$cur_combined" = "n/a" ]; then
 96                 echo " ok "
 97         else
 98                 echo " fail rx:$rx:$cur_rx tx:$tx:$cur_tx combined:n/a:$cur_combined"
 99         fi
100 }
101 
102 chk_gro() {
103         local msg="$1"
104         local expected=$2
105 
106         ip netns exec $BASE$SRC ping -qc 1 $BM_NET_V4$DST >/dev/null
107         NSTAT_HISTORY=$STATS ip netns exec $NS_DST nstat -n
108 
109         printf "%-60s" "$msg"
110         ip netns exec $BASE$DST ./udpgso_bench_rx -C 1000 -R 10 &
111         local spid=$!
112         sleep 0.1
113 
114         ip netns exec $NS_SRC ./udpgso_bench_tx -4 -s 13000 -S 1300 -M 1 -D $BM_NET_V4$DST
115         local retc=$?
116         wait $spid
117         local rets=$?
118         if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
119                 echo " fail client exit code $retc, server $rets"
120                 ret=1
121                 return
122         fi
123 
124         local pkts=`NSTAT_HISTORY=$STATS ip netns exec $NS_DST nstat IpInReceives | \
125                     awk '{print $2}' | tail -n 1`
126         if [ "$pkts" = "$expected" ]; then
127                 echo " ok "
128         else
129                 echo " fail - got $pkts packets, expected $expected "
130                 ret=1
131         fi
132 }
133 
134 __change_channels()
135 {
136         local cur_cpu
137         local end=$1
138         local cur
139         local i
140 
141         while true; do
142                 printf -v cur '%(%s)T'
143                 [ $cur -le $end ] || break
144 
145                 for i in `seq 1 $CPUS`; do
146                         ip netns exec $NS_SRC ethtool -L veth$SRC rx $i tx $i
147                         ip netns exec $NS_DST ethtool -L veth$DST rx $i tx $i
148                 done
149 
150                 for i in `seq 1 $((CPUS - 1))`; do
151                         cur_cpu=$((CPUS - $i))
152                         ip netns exec $NS_SRC ethtool -L veth$SRC rx $cur_cpu tx $cur_cpu
153                         ip netns exec $NS_DST ethtool -L veth$DST rx $cur_cpu tx $cur_cpu
154                 done
155         done
156 }
157 
158 __send_data() {
159         local end=$1
160 
161         while true; do
162                 printf -v cur '%(%s)T'
163                 [ $cur -le $end ] || break
164 
165                 ip netns exec $NS_SRC ./udpgso_bench_tx -4 -s 1000 -M 300 -D $BM_NET_V4$DST
166         done
167 }
168 
169 do_stress() {
170         local end
171         printf -v end '%(%s)T'
172         end=$((end + $STRESS))
173 
174         ip netns exec $NS_SRC ethtool -L veth$SRC rx 3 tx 3
175         ip netns exec $NS_DST ethtool -L veth$DST rx 3 tx 3
176 
177         ip netns exec $NS_DST ./udpgso_bench_rx &
178         local rx_pid=$!
179 
180         echo "Running stress test for $STRESS seconds..."
181         __change_channels $end &
182         local ch_pid=$!
183         __send_data $end &
184         local data_pid_1=$!
185         __send_data $end &
186         local data_pid_2=$!
187         __send_data $end &
188         local data_pid_3=$!
189         __send_data $end &
190         local data_pid_4=$!
191 
192         wait $ch_pid $data_pid_1 $data_pid_2 $data_pid_3 $data_pid_4
193         kill -9 $rx_pid
194         echo "done"
195 
196         # restore previous setting
197         ip netns exec $NS_SRC ethtool -L veth$SRC rx 2 tx 2
198         ip netns exec $NS_DST ethtool -L veth$DST rx 2 tx 1
199 }
200 
201 usage() {
202         echo "Usage: $0 [-h] [-s <seconds>]"
203         echo -e "\t-h: show this help"
204         echo -e "\t-s: run optional stress tests for the given amount of seconds"
205 }
206 
207 STRESS=0
208 while getopts "hs:" option; do
209         case "$option" in
210         "h")
211                 usage $0
212                 exit 0
213                 ;;
214         "s")
215                 STRESS=$OPTARG
216                 ;;
217         esac
218 done
219 
220 if [ ! -f ${BPF_FILE} ]; then
221         echo "Missing ${BPF_FILE}. Run 'make' first"
222         exit 1
223 fi
224 
225 [ $CPUS -lt 2 ] && echo "Only one CPU available, some tests will be skipped"
226 [ $STRESS -gt 0 -a $CPUS -lt 3 ] && echo " stress test will be skipped, too"
227 
228 create_ns
229 chk_gro_flag "default - gro flag" $SRC off
230 chk_gro_flag "        - peer gro flag" $DST off
231 chk_tso_flag "        - tso flag" $SRC on
232 chk_tso_flag "        - peer tso flag" $DST on
233 chk_gro "        - aggregation" 1
234 ip netns exec $NS_SRC ethtool -K veth$SRC tx-udp-segmentation off
235 chk_gro "        - aggregation with TSO off" 10
236 cleanup
237 
238 create_ns
239 ip netns exec $NS_DST ethtool -K veth$DST gro on
240 chk_gro_flag "with gro on - gro flag" $DST on
241 chk_gro_flag "        - peer gro flag" $SRC off
242 chk_tso_flag "        - tso flag" $SRC on
243 chk_tso_flag "        - peer tso flag" $DST on
244 ip netns exec $NS_SRC ethtool -K veth$SRC tx-udp-segmentation off
245 ip netns exec $NS_DST ethtool -K veth$DST rx-udp-gro-forwarding on
246 chk_gro "        - aggregation with TSO off" 1
247 cleanup
248 
249 create_ns
250 ip -n $NS_DST link set dev veth$DST up
251 ip -n $NS_DST link set dev veth$DST xdp object ${BPF_FILE} section xdp
252 chk_gro_flag "gro vs xdp while down - gro flag off" $DST off
253 ip -n $NS_DST link set dev veth$DST down
254 chk_gro_flag "                      - after down" $DST off
255 ip -n $NS_DST link set dev veth$DST xdp off
256 chk_gro_flag "                      - after xdp off" $DST off
257 ip -n $NS_DST link set dev veth$DST up
258 chk_gro_flag "                      - after up" $DST off
259 ip -n $NS_SRC link set dev veth$SRC xdp object ${BPF_FILE} section xdp
260 chk_gro_flag "                      - after peer xdp" $DST off
261 cleanup
262 
263 create_ns
264 ip -n $NS_DST link set dev veth$DST up
265 ip -n $NS_DST link set dev veth$DST xdp object ${BPF_FILE} section xdp
266 ip netns exec $NS_DST ethtool -K veth$DST generic-receive-offload on
267 chk_gro_flag "gro vs xdp while down - gro flag on" $DST on
268 ip -n $NS_DST link set dev veth$DST down
269 chk_gro_flag "                      - after down" $DST on
270 ip -n $NS_DST link set dev veth$DST xdp off
271 chk_gro_flag "                      - after xdp off" $DST on
272 ip -n $NS_DST link set dev veth$DST up
273 chk_gro_flag "                      - after up" $DST on
274 ip -n $NS_SRC link set dev veth$SRC xdp object ${BPF_FILE} section xdp
275 chk_gro_flag "                      - after peer xdp" $DST on
276 cleanup
277 
278 create_ns
279 chk_channels "default channels" $DST 1 1
280 
281 ip -n $NS_DST link set dev veth$DST down
282 ip netns exec $NS_DST ethtool -K veth$DST gro on
283 chk_gro_flag "with gro enabled on link down - gro flag" $DST on
284 chk_gro_flag "        - peer gro flag" $SRC off
285 chk_tso_flag "        - tso flag" $SRC on
286 chk_tso_flag "        - peer tso flag" $DST on
287 ip -n $NS_DST link set dev veth$DST up
288 ip netns exec $NS_SRC ethtool -K veth$SRC tx-udp-segmentation off
289 ip netns exec $NS_DST ethtool -K veth$DST rx-udp-gro-forwarding on
290 chk_gro "        - aggregation with TSO off" 1
291 cleanup
292 
293 create_ns
294 
295 CUR_TX=1
296 CUR_RX=1
297 if [ $CPUS -gt 1 ]; then
298         ip netns exec $NS_DST ethtool -L veth$DST tx 2
299         chk_channels "setting tx channels" $DST 1 2
300         CUR_TX=2
301 fi
302 
303 if [ $CPUS -gt 2 ]; then
304         ip netns exec $NS_DST ethtool -L veth$DST rx 3 tx 3
305         chk_channels "setting both rx and tx channels" $DST 3 3
306         CUR_RX=3
307         CUR_TX=3
308 fi
309 
310 ip netns exec $NS_DST ethtool -L veth$DST combined 2 2>/dev/null
311 chk_channels "bad setting: combined channels" $DST $CUR_RX $CUR_TX
312 
313 ip netns exec $NS_DST ethtool -L veth$DST tx $((CPUS + 1)) 2>/dev/null
314 chk_channels "setting invalid channels nr" $DST $CUR_RX $CUR_TX
315 
316 if [ $CPUS -gt 1 ]; then
317         # this also tests queues nr reduction
318         ip netns exec $NS_DST ethtool -L veth$DST rx 1 tx 2 2>/dev/null
319         ip netns exec $NS_SRC ethtool -L veth$SRC rx 1 tx 2 2>/dev/null
320         printf "%-60s" "bad setting: XDP with RX nr less than TX"
321         ip -n $NS_DST link set dev veth$DST xdp object ${BPF_FILE} \
322                 section xdp 2>/dev/null &&\
323                 echo "fail - set operation successful ?!?" || echo " ok "
324 
325         # the following tests will run with multiple channels active
326         ip netns exec $NS_SRC ethtool -L veth$SRC rx 2
327         ip netns exec $NS_DST ethtool -L veth$DST rx 2
328         ip -n $NS_DST link set dev veth$DST xdp object ${BPF_FILE} \
329                 section xdp 2>/dev/null
330         printf "%-60s" "bad setting: reducing RX nr below peer TX with XDP set"
331         ip netns exec $NS_DST ethtool -L veth$DST rx 1 2>/dev/null &&\
332                 echo "fail - set operation successful ?!?" || echo " ok "
333         CUR_RX=2
334         CUR_TX=2
335 fi
336 
337 if [ $CPUS -gt 2 ]; then
338         printf "%-60s" "bad setting: increasing peer TX nr above RX with XDP set"
339         ip netns exec $NS_SRC ethtool -L veth$SRC tx 3 2>/dev/null &&\
340                 echo "fail - set operation successful ?!?" || echo " ok "
341         chk_channels "setting invalid channels nr" $DST 2 2
342 fi
343 
344 ip -n $NS_DST link set dev veth$DST xdp object ${BPF_FILE} section xdp 2>/dev/null
345 chk_gro_flag "with xdp attached - gro flag" $DST off
346 chk_gro_flag "        - peer gro flag" $SRC off
347 chk_tso_flag "        - tso flag" $SRC off
348 chk_tso_flag "        - peer tso flag" $DST on
349 ip netns exec $NS_DST ethtool -K veth$DST rx-udp-gro-forwarding on
350 chk_gro "        - no aggregation" 10
351 ip netns exec $NS_DST ethtool -K veth$DST generic-receive-offload on
352 chk_gro_flag "        - gro flag with GRO on" $DST on
353 chk_gro "        - aggregation" 1
354 
355 
356 ip -n $NS_DST link set dev veth$DST down
357 ip -n $NS_SRC link set dev veth$SRC down
358 chk_gro_flag "        - after dev off, flag" $DST on
359 chk_gro_flag "        - peer flag" $SRC off
360 
361 ip netns exec $NS_DST ethtool -K veth$DST gro on
362 ip -n $NS_DST link set dev veth$DST xdp off
363 chk_gro_flag "        - after gro on xdp off, gro flag" $DST on
364 chk_gro_flag "        - peer gro flag" $SRC off
365 chk_tso_flag "        - tso flag" $SRC on
366 chk_tso_flag "        - peer tso flag" $DST on
367 
368 if [ $CPUS -gt 1 ]; then
369         ip netns exec $NS_DST ethtool -L veth$DST tx 1
370         chk_channels "decreasing tx channels with device down" $DST 2 1
371 fi
372 
373 ip -n $NS_DST link set dev veth$DST up
374 ip -n $NS_SRC link set dev veth$SRC up
375 chk_gro "        - aggregation" 1
376 
377 if [ $CPUS -gt 1 ]; then
378         [ $STRESS -gt 0 -a $CPUS -gt 2 ] && do_stress
379 
380         ip -n $NS_DST link set dev veth$DST down
381         ip -n $NS_SRC link set dev veth$SRC down
382         ip netns exec $NS_DST ethtool -L veth$DST tx 2
383         chk_channels "increasing tx channels with device down" $DST 2 2
384         ip -n $NS_DST link set dev veth$DST up
385         ip -n $NS_SRC link set dev veth$SRC up
386 fi
387 
388 ip netns exec $NS_DST ethtool -K veth$DST gro off
389 ip netns exec $NS_SRC ethtool -K veth$SRC tx-udp-segmentation off
390 chk_gro "aggregation again with default and TSO off" 10
391 
392 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