2 # SPDX-License-Identifier: GPL-2.0
4 BPF_FILE
="xdp_dummy.bpf.o"
5 readonly STATS
="$(mktemp -p /tmp ns-XXXXXX)"
6 readonly BASE
=`basename $STATS`
10 readonly NS_SRC
=$BASE$SRC
11 readonly NS_DST
=$BASE$DST
13 # "baremetal" network used for raw UDP traffic
14 readonly BM_NET_V4
=192.168.1.
15 readonly BM_NET_V6
=2001:db8
::
23 readonly jobs="$(jobs -p)"
24 [ -n "${jobs}" ] && kill -1 ${jobs} 2>/dev
/null
27 for ns
in $NS_SRC $NS_DST; do
28 ip netns del
$ns 2>/dev
/null
37 for ns
in $NS_SRC $NS_DST; do
39 ip
-n $ns link
set dev lo up
42 ip link add name veth
$SRC type veth peer name veth
$DST
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
57 local flag
=`ip netns exec $BASE$target ethtool -k veth$target |\
58 grep $flagname | awk '{print $2}'`
61 if [ "$flag" = "$expected" ]; then
64 echo " fail - expected $expected found $flag"
70 __chk_flag
"$1" $2 $3 generic-receive-offload
74 __chk_flag
"$1" $2 $3 tcp-segmentation-offload
85 local cur_rx
=`ip netns exec $BASE$target ethtool -l $dev |\
86 grep RX: | tail -n 1 | awk '{print $2}' `
87 local cur_tx
=`ip netns exec $BASE$target ethtool -l $dev |\
88 grep TX: | tail -n 1 | awk '{print $2}'`
89 local cur_combined
=`ip netns exec $BASE$target ethtool -l $dev |\
90 grep Combined: | tail -n 1 | awk '{print $2}'`
93 if [ "$cur_rx" = "$rx" -a "$cur_tx" = "$tx" -a "$cur_combined" = "n/a" ]; then
96 echo " fail rx:$rx:$cur_rx tx:$tx:$cur_tx combined:n/a:$cur_combined"
104 ip netns
exec $BASE$SRC ping -qc 1 $BM_NET_V4$DST >/dev
/null
105 NSTAT_HISTORY
=$STATS ip netns
exec $NS_DST nstat
-n
107 printf "%-60s" "$msg"
108 ip netns
exec $BASE$DST .
/udpgso_bench_rx
-C 1000 -R 10 &
112 ip netns
exec $NS_SRC .
/udpgso_bench_tx
-4 -s 13000 -S 1300 -M 1 -D $BM_NET_V4$DST
116 if [ ${rets} -ne 0 ] ||
[ ${retc} -ne 0 ]; then
117 echo " fail client exit code $retc, server $rets"
122 local pkts
=`NSTAT_HISTORY=$STATS ip netns exec $NS_DST nstat IpInReceives | \
123 awk '{print $2}' | tail -n 1`
124 if [ "$pkts" = "$expected" ]; then
127 echo " fail - got $pkts packets, expected $expected "
140 printf -v cur
'%(%s)T'
141 [ $cur -le $end ] ||
break
143 for i
in `seq 1 $CPUS`; do
144 ip netns
exec $NS_SRC ethtool
-L veth
$SRC rx
$i tx
$i
145 ip netns
exec $NS_DST ethtool
-L veth
$DST rx
$i tx
$i
148 for i
in `seq 1 $((CPUS - 1))`; do
149 cur_cpu
=$
((CPUS
- $i))
150 ip netns
exec $NS_SRC ethtool
-L veth
$SRC rx
$cur_cpu tx
$cur_cpu
151 ip netns
exec $NS_DST ethtool
-L veth
$DST rx
$cur_cpu tx
$cur_cpu
160 printf -v cur
'%(%s)T'
161 [ $cur -le $end ] ||
break
163 ip netns
exec $NS_SRC .
/udpgso_bench_tx
-4 -s 1000 -M 300 -D $BM_NET_V4$DST
169 printf -v end
'%(%s)T'
170 end
=$
((end
+ $STRESS))
172 ip netns
exec $NS_SRC ethtool
-L veth
$SRC rx
3 tx
3
173 ip netns
exec $NS_DST ethtool
-L veth
$DST rx
3 tx
3
175 ip netns
exec $NS_DST .
/udpgso_bench_rx
&
178 echo "Running stress test for $STRESS seconds..."
179 __change_channels
$end &
190 wait $ch_pid $data_pid_1 $data_pid_2 $data_pid_3 $data_pid_4
194 # restore previous setting
195 ip netns
exec $NS_SRC ethtool
-L veth
$SRC rx
2 tx
2
196 ip netns
exec $NS_DST ethtool
-L veth
$DST rx
2 tx
1
200 echo "Usage: $0 [-h] [-s <seconds>]"
201 echo -e "\t-h: show this help"
202 echo -e "\t-s: run optional stress tests for the given amount of seconds"
206 while getopts "hs:" option
; do
218 if [ ! -f ${BPF_FILE} ]; then
219 echo "Missing ${BPF_FILE}. Run 'make' first"
223 [ $CPUS -lt 2 ] && echo "Only one CPU available, some tests will be skipped"
224 [ $STRESS -gt 0 -a $CPUS -lt 3 ] && echo " stress test will be skipped, too"
227 chk_gro_flag
"default - gro flag" $SRC off
228 chk_gro_flag
" - peer gro flag" $DST off
229 chk_tso_flag
" - tso flag" $SRC on
230 chk_tso_flag
" - peer tso flag" $DST on
231 chk_gro
" - aggregation" 1
232 ip netns
exec $NS_SRC ethtool
-K veth
$SRC tx-udp-segmentation off
233 chk_gro
" - aggregation with TSO off" 10
237 ip netns
exec $NS_DST ethtool
-K veth
$DST gro on
238 chk_gro_flag
"with gro on - gro flag" $DST on
239 chk_gro_flag
" - peer gro flag" $SRC off
240 chk_tso_flag
" - tso flag" $SRC on
241 chk_tso_flag
" - peer tso flag" $DST on
242 ip netns
exec $NS_SRC ethtool
-K veth
$SRC tx-udp-segmentation off
243 ip netns
exec $NS_DST ethtool
-K veth
$DST rx-udp-gro-forwarding on
244 chk_gro
" - aggregation with TSO off" 1
248 ip
-n $NS_DST link
set dev veth
$DST up
249 ip
-n $NS_DST link
set dev veth
$DST xdp object
${BPF_FILE} section xdp
250 chk_gro_flag
"gro vs xdp while down - gro flag off" $DST off
251 ip
-n $NS_DST link
set dev veth
$DST down
252 chk_gro_flag
" - after down" $DST off
253 ip
-n $NS_DST link
set dev veth
$DST xdp off
254 chk_gro_flag
" - after xdp off" $DST off
255 ip
-n $NS_DST link
set dev veth
$DST up
256 chk_gro_flag
" - after up" $DST off
257 ip
-n $NS_SRC link
set dev veth
$SRC xdp object
${BPF_FILE} section xdp
258 chk_gro_flag
" - after peer xdp" $DST off
262 ip
-n $NS_DST link
set dev veth
$DST up
263 ip
-n $NS_DST link
set dev veth
$DST xdp object
${BPF_FILE} section xdp
264 ip netns
exec $NS_DST ethtool
-K veth
$DST generic-receive-offload on
265 chk_gro_flag
"gro vs xdp while down - gro flag on" $DST on
266 ip
-n $NS_DST link
set dev veth
$DST down
267 chk_gro_flag
" - after down" $DST on
268 ip
-n $NS_DST link
set dev veth
$DST xdp off
269 chk_gro_flag
" - after xdp off" $DST on
270 ip
-n $NS_DST link
set dev veth
$DST up
271 chk_gro_flag
" - after up" $DST on
272 ip
-n $NS_SRC link
set dev veth
$SRC xdp object
${BPF_FILE} section xdp
273 chk_gro_flag
" - after peer xdp" $DST on
277 chk_channels
"default channels" $DST 1 1
279 ip
-n $NS_DST link
set dev veth
$DST down
280 ip netns
exec $NS_DST ethtool
-K veth
$DST gro on
281 chk_gro_flag
"with gro enabled on link down - gro flag" $DST on
282 chk_gro_flag
" - peer gro flag" $SRC off
283 chk_tso_flag
" - tso flag" $SRC on
284 chk_tso_flag
" - peer tso flag" $DST on
285 ip
-n $NS_DST link
set dev veth
$DST up
286 ip netns
exec $NS_SRC ethtool
-K veth
$SRC tx-udp-segmentation off
287 ip netns
exec $NS_DST ethtool
-K veth
$DST rx-udp-gro-forwarding on
288 chk_gro
" - aggregation with TSO off" 1
295 if [ $CPUS -gt 1 ]; then
296 ip netns
exec $NS_DST ethtool
-L veth
$DST tx
2
297 chk_channels
"setting tx channels" $DST 1 2
301 if [ $CPUS -gt 2 ]; then
302 ip netns
exec $NS_DST ethtool
-L veth
$DST rx
3 tx
3
303 chk_channels
"setting both rx and tx channels" $DST 3 3
308 ip netns
exec $NS_DST ethtool
-L veth
$DST combined
2 2>/dev
/null
309 chk_channels
"bad setting: combined channels" $DST $CUR_RX $CUR_TX
311 ip netns
exec $NS_DST ethtool
-L veth
$DST tx $
((CPUS
+ 1)) 2>/dev
/null
312 chk_channels
"setting invalid channels nr" $DST $CUR_RX $CUR_TX
314 if [ $CPUS -gt 1 ]; then
315 # this also tests queues nr reduction
316 ip netns
exec $NS_DST ethtool
-L veth
$DST rx
1 tx
2 2>/dev
/null
317 ip netns
exec $NS_SRC ethtool
-L veth
$SRC rx
1 tx
2 2>/dev
/null
318 printf "%-60s" "bad setting: XDP with RX nr less than TX"
319 ip
-n $NS_DST link
set dev veth
$DST xdp object
${BPF_FILE} \
320 section xdp
2>/dev
/null
&&\
321 echo "fail - set operation successful ?!?" ||
echo " ok "
323 # the following tests will run with multiple channels active
324 ip netns
exec $NS_SRC ethtool
-L veth
$SRC rx
2
325 ip netns
exec $NS_DST ethtool
-L veth
$DST rx
2
326 ip
-n $NS_DST link
set dev veth
$DST xdp object
${BPF_FILE} \
327 section xdp
2>/dev
/null
328 printf "%-60s" "bad setting: reducing RX nr below peer TX with XDP set"
329 ip netns
exec $NS_DST ethtool
-L veth
$DST rx
1 2>/dev
/null
&&\
330 echo "fail - set operation successful ?!?" ||
echo " ok "
335 if [ $CPUS -gt 2 ]; then
336 printf "%-60s" "bad setting: increasing peer TX nr above RX with XDP set"
337 ip netns
exec $NS_SRC ethtool
-L veth
$SRC tx
3 2>/dev
/null
&&\
338 echo "fail - set operation successful ?!?" ||
echo " ok "
339 chk_channels
"setting invalid channels nr" $DST 2 2
342 ip
-n $NS_DST link
set dev veth
$DST xdp object
${BPF_FILE} section xdp
2>/dev
/null
343 chk_gro_flag
"with xdp attached - gro flag" $DST off
344 chk_gro_flag
" - peer gro flag" $SRC off
345 chk_tso_flag
" - tso flag" $SRC off
346 chk_tso_flag
" - peer tso flag" $DST on
347 ip netns
exec $NS_DST ethtool
-K veth
$DST rx-udp-gro-forwarding on
348 chk_gro
" - no aggregation" 10
349 ip netns
exec $NS_DST ethtool
-K veth
$DST generic-receive-offload on
350 chk_gro_flag
" - gro flag with GRO on" $DST on
351 chk_gro
" - aggregation" 1
354 ip
-n $NS_DST link
set dev veth
$DST down
355 ip
-n $NS_SRC link
set dev veth
$SRC down
356 chk_gro_flag
" - after dev off, flag" $DST on
357 chk_gro_flag
" - peer flag" $SRC off
359 ip netns
exec $NS_DST ethtool
-K veth
$DST gro on
360 ip
-n $NS_DST link
set dev veth
$DST xdp off
361 chk_gro_flag
" - after gro on xdp off, gro flag" $DST on
362 chk_gro_flag
" - peer gro flag" $SRC off
363 chk_tso_flag
" - tso flag" $SRC on
364 chk_tso_flag
" - peer tso flag" $DST on
366 if [ $CPUS -gt 1 ]; then
367 ip netns
exec $NS_DST ethtool
-L veth
$DST tx
1
368 chk_channels
"decreasing tx channels with device down" $DST 2 1
371 ip
-n $NS_DST link
set dev veth
$DST up
372 ip
-n $NS_SRC link
set dev veth
$SRC up
373 chk_gro
" - aggregation" 1
375 if [ $CPUS -gt 1 ]; then
376 [ $STRESS -gt 0 -a $CPUS -gt 2 ] && do_stress
378 ip
-n $NS_DST link
set dev veth
$DST down
379 ip
-n $NS_SRC link
set dev veth
$SRC down
380 ip netns
exec $NS_DST ethtool
-L veth
$DST tx
2
381 chk_channels
"increasing tx channels with device down" $DST 2 2
382 ip
-n $NS_DST link
set dev veth
$DST up
383 ip
-n $NS_SRC link
set dev veth
$SRC up
386 ip netns
exec $NS_DST ethtool
-K veth
$DST gro off
387 ip netns
exec $NS_SRC ethtool
-K veth
$SRC tx-udp-segmentation off
388 chk_gro
"aggregation again with default and TSO off" 10