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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/net/udpgro_fwd.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 source net_helper.sh
  5 
  6 BPF_FILE="xdp_dummy.bpf.o"
  7 readonly BASE="ns-$(mktemp -u XXXXXX)"
  8 readonly SRC=2
  9 readonly DST=1
 10 readonly DST_NAT=100
 11 readonly NS_SRC=$BASE$SRC
 12 readonly NS_DST=$BASE$DST
 13 
 14 # "baremetal" network used for raw UDP traffic
 15 readonly BM_NET_V4=192.168.1.
 16 readonly BM_NET_V6=2001:db8::
 17 
 18 # "overlay" network used for UDP over UDP tunnel traffic
 19 readonly OL_NET_V4=172.16.1.
 20 readonly OL_NET_V6=2001:db8:1::
 21 readonly NPROCS=`nproc`
 22 
 23 cleanup() {
 24         local ns
 25         local -r jobs="$(jobs -p)"
 26         [ -n "${jobs}" ] && kill -1 ${jobs} 2>/dev/null
 27 
 28         for ns in $NS_SRC $NS_DST; do
 29                 ip netns del $ns 2>/dev/null
 30         done
 31 }
 32 
 33 trap cleanup EXIT
 34 
 35 create_ns() {
 36         local net
 37         local ns
 38 
 39         for ns in $NS_SRC $NS_DST; do
 40                 ip netns add $ns
 41                 ip -n $ns link set dev lo up
 42 
 43                 # disable route solicitations to decrease 'noise' traffic
 44                 ip netns exec $ns sysctl -qw net.ipv6.conf.default.router_solicitations=0
 45                 ip netns exec $ns sysctl -qw net.ipv6.conf.all.router_solicitations=0
 46         done
 47 
 48         ip link add name veth$SRC type veth peer name veth$DST
 49 
 50         for ns in $SRC $DST; do
 51                 ip link set dev veth$ns netns $BASE$ns
 52                 ip -n $BASE$ns link set dev veth$ns up
 53                 ip -n $BASE$ns addr add dev veth$ns $BM_NET_V4$ns/24
 54                 ip -n $BASE$ns addr add dev veth$ns $BM_NET_V6$ns/64 nodad
 55         done
 56         ip -n $NS_DST link set veth$DST xdp object ${BPF_FILE} section xdp 2>/dev/null
 57 }
 58 
 59 create_vxlan_endpoint() {
 60         local -r netns=$1
 61         local -r bm_dev=$2
 62         local -r bm_rem_addr=$3
 63         local -r vxlan_dev=$4
 64         local -r vxlan_id=$5
 65         local -r vxlan_port=4789
 66 
 67         ip -n $netns link set dev $bm_dev up
 68         ip -n $netns link add dev $vxlan_dev type vxlan id $vxlan_id \
 69                                 dstport $vxlan_port remote $bm_rem_addr
 70         ip -n $netns link set dev $vxlan_dev up
 71 }
 72 
 73 create_vxlan_pair() {
 74         local ns
 75 
 76         create_ns
 77 
 78         for ns in $SRC $DST; do
 79                 # note that 3 - $SRC == $DST and 3 - $DST == $SRC
 80                 create_vxlan_endpoint $BASE$ns veth$ns $BM_NET_V4$((3 - $ns)) vxlan$ns 4
 81                 ip -n $BASE$ns addr add dev vxlan$ns $OL_NET_V4$ns/24
 82         done
 83         for ns in $SRC $DST; do
 84                 create_vxlan_endpoint $BASE$ns veth$ns $BM_NET_V6$((3 - $ns)) vxlan6$ns 6
 85                 ip -n $BASE$ns addr add dev vxlan6$ns $OL_NET_V6$ns/24 nodad
 86         done
 87 
 88         # preload neighbur cache, do avoid some noisy traffic
 89         local addr_dst=$(ip -j -n $BASE$DST link show dev vxlan6$DST  |jq -r '.[]["address"]')
 90         local addr_src=$(ip -j -n $BASE$SRC link show dev vxlan6$SRC  |jq -r '.[]["address"]')
 91         ip -n $BASE$DST neigh add dev vxlan6$DST lladdr $addr_src $OL_NET_V6$SRC
 92         ip -n $BASE$SRC neigh add dev vxlan6$SRC lladdr $addr_dst $OL_NET_V6$DST
 93 }
 94 
 95 is_ipv6() {
 96         if [[ $1 =~ .*:.* ]]; then
 97                 return 0
 98         fi
 99         return 1
100 }
101 
102 run_test() {
103         local -r msg=$1
104         local -r dst=$2
105         local -r pkts=$3
106         local -r vxpkts=$4
107         local bind=$5
108         local rx_args=""
109         local rx_family="-4"
110         local family=-4
111         local filter=IpInReceives
112         local ipt=iptables
113 
114         printf "%-40s" "$msg"
115 
116         if is_ipv6 $dst; then
117                 # rx program does not support '-6' and implies ipv6 usage by default
118                 rx_family=""
119                 family=-6
120                 filter=Ip6InReceives
121                 ipt=ip6tables
122         fi
123 
124         rx_args="$rx_family"
125         [ -n "$bind" ] && rx_args="$rx_args -b $bind"
126 
127         # send a single GSO packet, segmented in 10 UDP frames.
128         # Always expect 10 UDP frames on RX side as rx socket does
129         # not enable GRO
130         ip netns exec $NS_DST $ipt -A INPUT -p udp --dport 4789
131         ip netns exec $NS_DST $ipt -A INPUT -p udp --dport 8000
132         ip netns exec $NS_DST ./udpgso_bench_rx -C 2000 -R 100 -n 10 -l 1300 $rx_args &
133         local spid=$!
134         wait_local_port_listen "$NS_DST" 8000 udp
135         ip netns exec $NS_SRC ./udpgso_bench_tx $family -M 1 -s 13000 -S 1300 -D $dst
136         local retc=$?
137         wait $spid
138         local rets=$?
139         if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
140                 echo " fail client exit code $retc, server $rets"
141                 ret=1
142                 return
143         fi
144 
145         local rcv=`ip netns exec $NS_DST $ipt"-save" -c | grep 'dport 8000' | \
146                                                           sed -e 's/\[//' -e 's/:.*//'`
147         if [ $rcv != $pkts ]; then
148                 echo " fail - received $rcv packets, expected $pkts"
149                 ret=1
150                 return
151         fi
152 
153         local vxrcv=`ip netns exec $NS_DST $ipt"-save" -c | grep 'dport 4789' | \
154                                                             sed -e 's/\[//' -e 's/:.*//'`
155 
156         # upper net can generate a little noise, allow some tolerance
157         if [ $vxrcv -lt $vxpkts -o $vxrcv -gt $((vxpkts + 3)) ]; then
158                 echo " fail - received $vxrcv vxlan packets, expected $vxpkts"
159                 ret=1
160                 return
161         fi
162         echo " ok"
163 }
164 
165 run_bench() {
166         local -r msg=$1
167         local -r dst=$2
168         local family=-4
169 
170         printf "%-40s" "$msg"
171         if [ $NPROCS -lt 2 ]; then
172                 echo " skip - needed 2 CPUs found $NPROCS"
173                 return
174         fi
175 
176         is_ipv6 $dst && family=-6
177 
178         # bind the sender and the receiver to different CPUs to try
179         # get reproducible results
180         ip netns exec $NS_DST bash -c "echo 2 > /sys/class/net/veth$DST/queues/rx-0/rps_cpus"
181         ip netns exec $NS_DST taskset 0x2 ./udpgso_bench_rx -C 2000 -R 100  &
182         local spid=$!
183         wait_local_port_listen "$NS_DST" 8000 udp
184         ip netns exec $NS_SRC taskset 0x1 ./udpgso_bench_tx $family -l 3 -S 1300 -D $dst
185         local retc=$?
186         wait $spid
187         local rets=$?
188         if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
189                 echo " fail client exit code $retc, server $rets"
190                 ret=1
191                 return
192         fi
193 }
194 
195 for family in 4 6; do
196         BM_NET=$BM_NET_V4
197         OL_NET=$OL_NET_V4
198         IPT=iptables
199         SUFFIX=24
200         VXDEV=vxlan
201         PING=ping
202 
203         if [ $family = 6 ]; then
204                 BM_NET=$BM_NET_V6
205                 OL_NET=$OL_NET_V6
206                 SUFFIX="64 nodad"
207                 VXDEV=vxlan6
208                 IPT=ip6tables
209                 # Use ping6 on systems where ping doesn't handle IPv6
210                 ping -w 1 -c 1 ::1 > /dev/null 2>&1 || PING="ping6"
211         fi
212 
213         echo "IPv$family"
214 
215         create_ns
216         run_test "No GRO" $BM_NET$DST 10 0
217         cleanup
218 
219         create_ns
220         ip netns exec $NS_DST ethtool -K veth$DST generic-receive-offload on
221         ip netns exec $NS_DST ethtool -K veth$DST rx-gro-list on
222         run_test "GRO frag list" $BM_NET$DST 1 0
223         cleanup
224 
225         # UDP GRO fwd skips aggregation when find an udp socket with the GRO option
226         # if there is an UDP tunnel in the running system, such lookup happen
227         # take place.
228         # use NAT to circumvent GRO FWD check
229         create_ns
230         ip -n $NS_DST addr add dev veth$DST $BM_NET$DST_NAT/$SUFFIX
231         ip netns exec $NS_DST ethtool -K veth$DST generic-receive-offload on
232         ip netns exec $NS_DST ethtool -K veth$DST rx-udp-gro-forwarding on
233         ip netns exec $NS_DST $IPT -t nat -I PREROUTING -d $BM_NET$DST_NAT \
234                                         -j DNAT --to-destination $BM_NET$DST
235         run_test "GRO fwd" $BM_NET$DST_NAT 1 0 $BM_NET$DST
236         cleanup
237 
238         create_ns
239         run_bench "UDP fwd perf" $BM_NET$DST
240         ip netns exec $NS_DST ethtool -K veth$DST rx-udp-gro-forwarding on
241         run_bench "UDP GRO fwd perf" $BM_NET$DST
242         cleanup
243 
244         create_vxlan_pair
245         ip netns exec $NS_DST ethtool -K veth$DST generic-receive-offload on
246         ip netns exec $NS_DST ethtool -K veth$DST rx-gro-list on
247         run_test "GRO frag list over UDP tunnel" $OL_NET$DST 10 10
248         cleanup
249 
250         # use NAT to circumvent GRO FWD check
251         create_vxlan_pair
252         ip -n $NS_DST addr add dev $VXDEV$DST $OL_NET$DST_NAT/$SUFFIX
253         ip netns exec $NS_DST ethtool -K veth$DST generic-receive-offload on
254         ip netns exec $NS_DST ethtool -K veth$DST rx-udp-gro-forwarding on
255         ip netns exec $NS_DST $IPT -t nat -I PREROUTING -d $OL_NET$DST_NAT \
256                                         -j DNAT --to-destination $OL_NET$DST
257 
258         # load arp cache before running the test to reduce the amount of
259         # stray traffic on top of the UDP tunnel
260         ip netns exec $NS_SRC $PING -q -c 1 $OL_NET$DST_NAT >/dev/null
261         run_test "GRO fwd over UDP tunnel" $OL_NET$DST_NAT 10 10 $OL_NET$DST
262         cleanup
263 done
264 
265 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