2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright(c) 2020 Intel Corporation, Weqaar Janjua <weqaar.a.janjua@intel.com>
5 # AF_XDP selftests based on veth
7 # End-to-end AF_XDP over Veth test
16 # ----------- | -----------
17 # | Thread1 | | | Thread2 |
18 # ----------- | -----------
20 # ----------- | -----------
22 # ----------- | -----------
24 # ----------- | ----------
25 # | vethX | --------- | vethY |
26 # ----------- peer ----------
28 # AF_XDP is an address family optimized for high performance packet processing,
29 # it is XDP’s user-space interface.
31 # An AF_XDP socket is linked to a single UMEM which is a region of virtual
32 # contiguous memory, divided into equal-sized frames.
34 # Refer to AF_XDP Kernel Documentation for detailed information:
35 # https://www.kernel.org/doc/html/latest/networking/af_xdp.html
37 # Prerequisites setup by script:
39 # Set up veth interfaces as per the topology shown ^^:
40 # * setup two veth interfaces
43 # *** xxxx and yyyy are randomly generated 4 digit numbers used to avoid
44 # conflict with any existing interface
45 # * tests the veth and xsk layers of the topology
47 # See the source xskxceiver.c for information on each test
49 # Kernel configuration:
50 # ---------------------
51 # See "config" file for recommended kernel config options.
53 # Turn on XDP sockets and veth support when compiling i.e.
54 # Networking support -->
55 # Networking options -->
60 # Must run with CAP_NET_ADMIN capability.
65 # If running from kselftests:
68 # Run with verbose output:
69 # sudo ./test_xsk.sh -v
71 # Run and dump packet contents:
72 # sudo ./test_xsk.sh -D
74 # Set up veth interfaces and leave them up so xskxceiver can be launched in a debugger:
75 # sudo ./test_xsk.sh -d
77 # Run test suite for physical device in loopback mode
78 # sudo ./test_xsk.sh -i IFACE
84 while getopts "vDi:d" flag
94 TEST_NAME="PREREQUISITES"
97 [ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit $ksft_fail; }
99 VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
100 VETH0=ve${VETH0_POSTFIX}
101 VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
102 VETH1=ve${VETH1_POSTFIX}
108 cleanup_exit ${VETH0} ${VETH1}
113 if [[ $verbose -eq 1 ]]; then
114 echo "setting up ${VETH0}"
116 ip link add ${VETH0} numtxqueues 4 numrxqueues 4 type veth peer name ${VETH1} numtxqueues 4 numrxqueues 4
117 if [ -f /proc/net/if_inet6 ]; then
118 echo 1 > /proc/sys/net/ipv6/conf/${VETH0}/disable_ipv6
119 echo 1 > /proc/sys/net/ipv6/conf/${VETH1}/disable_ipv6
121 if [[ $verbose -eq 1 ]]; then
122 echo "setting up ${VETH1}"
125 if [[ $busy_poll -eq 1 ]]; then
126 echo 2 > /sys/class/net/${VETH0}/napi_defer_hard_irqs
127 echo 200000 > /sys/class/net/${VETH0}/gro_flush_timeout
128 echo 2 > /sys/class/net/${VETH1}/napi_defer_hard_irqs
129 echo 200000 > /sys/class/net/${VETH1}/gro_flush_timeout
132 ip link set ${VETH1} mtu ${MTU}
133 ip link set ${VETH0} mtu ${MTU}
134 ip link set ${VETH1} up
135 ip link set ${VETH0} up
138 if [ ! -z $ETH ]; then
143 validate_veth_support ${VETH0}
148 if [ $retval -ne 0 ]; then
149 test_status $retval "${TEST_NAME}"
150 cleanup_exit ${VETH0} ${VETH1}
156 if [[ $verbose -eq 1 ]]; then
160 if [[ $dump_pkts -eq 1 ]]; then
165 test_status $retval "${TEST_NAME}"
171 TEST_NAME="XSK_SELFTESTS_${VETH0}_SOFTIRQ"
173 if [[ $debug -eq 1 ]]; then
174 echo "-i" ${VETH0} "-i" ${VETH1}
181 cleanup_exit ${VETH0} ${VETH1}
183 TEST_NAME="XSK_SELFTESTS_${VETH0}_BUSY_POLL"
194 cleanup_exit ${VETH0} ${VETH1}
199 for i in "${!statusList[@]}"
201 if [ ${statusList[$i]} -ne 0 ]; then
202 test_status ${statusList[$i]} ${nameList[$i]}
207 if [ $failures -eq 0 ]; then
208 echo "All tests successful!"