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 # namespaceX | namespaceY
30 # AF_XDP is an address family optimized for high performance packet processing,
31 # it is XDP’s user-space interface.
33 # An AF_XDP socket is linked to a single UMEM which is a region of virtual
34 # contiguous memory, divided into equal-sized frames.
36 # Refer to AF_XDP Kernel Documentation for detailed information:
37 # https://www.kernel.org/doc/html/latest/networking/af_xdp.html
39 # Prerequisites setup by script:
41 # Set up veth interfaces as per the topology shown ^^:
42 # * setup two veth interfaces and one namespace
43 # ** veth<xxxx> in root namespace
44 # ** veth<yyyy> in af_xdp<xxxx> namespace
45 # ** namespace af_xdp<xxxx>
46 # * create a spec file veth.spec that includes this run-time configuration
47 # *** xxxx and yyyy are randomly generated 4 digit numbers used to avoid
48 # conflict with any existing interface
49 # * tests the veth and xsk layers of the topology
51 # See the source xdpxceiver.c for information on each test
53 # Kernel configuration:
54 # ---------------------
55 # See "config" file for recommended kernel config options.
57 # Turn on XDP sockets and veth support when compiling i.e.
58 # Networking support -->
59 # Networking options -->
64 # Must run with CAP_NET_ADMIN capability.
66 # Run (full color-coded output):
67 # sudo ./test_xsk.sh -c
69 # If running from kselftests:
70 # sudo make colorconsole=1 run_tests
72 # Run (full output without color-coding):
84 TEST_NAME
="PREREQUISITES"
87 [ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit 1 1; }
89 VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
90 VETH0=ve${VETH0_POSTFIX}
91 VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
92 VETH1=ve${VETH1_POSTFIX}
94 NS1=af_xdp${VETH1_POSTFIX}
98 echo "setting up
${VETH0}: namespace
: ${NS0}"
100 ip link add ${VETH0} type veth peer name ${VETH1}
101 if [ -f /proc/net/if_inet6 ]; then
102 echo 1 > /proc/sys/net/ipv6/conf/${VETH0}/disable_ipv6
104 echo "setting up
${VETH1}: namespace
: ${NS1}"
105 ip link set ${VETH1} netns ${NS1}
106 ip netns exec ${NS1} ip link set ${VETH1} mtu ${MTU}
107 ip link set ${VETH0} mtu ${MTU}
108 ip netns exec ${NS1} ip link set ${VETH1} up
109 ip link set ${VETH0} up
113 validate_veth_support ${VETH0}
118 if [ $retval -ne 0 ]; then
119 test_status $retval "${TEST_NAME}"
120 cleanup_exit ${VETH0} ${VETH1} ${NS1}
124 echo "${VETH0}:${VETH1},${NS1}" > ${SPECFILE}
126 validate_veth_spec_file
128 echo "Spec file created: ${SPECFILE}"
130 test_status
$retval "${TEST_NAME}"
137 TEST_NAME
="XSK KSELFTEST FRAMEWORK"
139 echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Generic mode"
140 vethXDPgeneric
${VETH0} ${VETH1} ${NS1}
143 if [ $retval -eq 0 ]; then
144 echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Native mode"
145 vethXDPnative
${VETH0} ${VETH1} ${NS1}
149 test_status
$retval "${TEST_NAME}"
150 statusList
+=($retval)
153 TEST_NAME
="SKB NOPOLL"
155 vethXDPgeneric
${VETH0} ${VETH1} ${NS1}
158 execxdpxceiver params
161 test_status
$retval "${TEST_NAME}"
162 statusList
+=($retval)
167 vethXDPgeneric
${VETH0} ${VETH1} ${NS1}
170 execxdpxceiver params
173 test_status
$retval "${TEST_NAME}"
174 statusList
+=($retval)
177 TEST_NAME
="DRV NOPOLL"
179 vethXDPnative
${VETH0} ${VETH1} ${NS1}
182 execxdpxceiver params
185 test_status
$retval "${TEST_NAME}"
186 statusList
+=($retval)
191 vethXDPnative
${VETH0} ${VETH1} ${NS1}
194 execxdpxceiver params
197 test_status
$retval "${TEST_NAME}"
198 statusList
+=($retval)
201 TEST_NAME
="SKB SOCKET TEARDOWN"
203 vethXDPgeneric
${VETH0} ${VETH1} ${NS1}
206 execxdpxceiver params
209 test_status
$retval "${TEST_NAME}"
210 statusList
+=($retval)
213 TEST_NAME
="DRV SOCKET TEARDOWN"
215 vethXDPnative
${VETH0} ${VETH1} ${NS1}
218 execxdpxceiver params
221 test_status
$retval "${TEST_NAME}"
222 statusList
+=($retval)
225 TEST_NAME
="SKB BIDIRECTIONAL SOCKETS"
227 vethXDPgeneric
${VETH0} ${VETH1} ${NS1}
230 execxdpxceiver params
233 test_status
$retval "${TEST_NAME}"
234 statusList
+=($retval)
237 TEST_NAME
="DRV BIDIRECTIONAL SOCKETS"
239 vethXDPnative
${VETH0} ${VETH1} ${NS1}
242 execxdpxceiver params
245 test_status
$retval "${TEST_NAME}"
246 statusList
+=($retval)
250 cleanup_exit
${VETH0} ${VETH1} ${NS1}
252 for _status
in "${statusList[@]}"
254 if [ $_status -ne 0 ]; then
255 test_exit
$ksft_fail 0
259 test_exit
$ksft_pass 0