Linux Audio

Check our new training course

Linux debugging, profiling, tracing and performance analysis training

Apr 14-17, 2025
Register
Loading...
v6.13.7
  1#!/bin/bash
  2# SPDX-License-Identifier: GPL-2.0
  3# Copyright(c) 2020 Intel Corporation, Weqaar Janjua <weqaar.a.janjua@intel.com>
  4
  5# AF_XDP selftests based on veth
  6#
  7# End-to-end AF_XDP over Veth test
  8#
  9# Topology:
 10# ---------
 11#                 -----------
 12#               _ | Process | _
 13#              /  -----------  \
 14#             /        |        \
 15#            /         |         \
 16#      -----------     |     -----------
 17#      | Thread1 |     |     | Thread2 |
 18#      -----------     |     -----------
 19#           |          |          |
 20#      -----------     |     -----------
 21#      |  xskX   |     |     |  xskY   |
 22#      -----------     |     -----------
 23#           |          |          |
 24#      -----------     |     ----------
 25#      |  vethX  | --------- |  vethY |
 26#      -----------   peer    ----------
 
 
 27#
 28# AF_XDP is an address family optimized for high performance packet processing,
 29# it is XDP’s user-space interface.
 30#
 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.
 33#
 34# Refer to AF_XDP Kernel Documentation for detailed information:
 35# https://www.kernel.org/doc/html/latest/networking/af_xdp.html
 36#
 37# Prerequisites setup by script:
 38#
 39#   Set up veth interfaces as per the topology shown ^^:
 40#   * setup two veth interfaces
 41#   ** veth<xxxx>
 42#   ** veth<yyyy>
 
 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
 46#
 47# See the source xskxceiver.c for information on each test
 48#
 49# Kernel configuration:
 50# ---------------------
 51# See "config" file for recommended kernel config options.
 52#
 53# Turn on XDP sockets and veth support when compiling i.e.
 54# 	Networking support -->
 55# 		Networking options -->
 56# 			[ * ] XDP sockets
 57#
 58# Executing Tests:
 59# ----------------
 60# Must run with CAP_NET_ADMIN capability.
 61#
 62# Run:
 63#   sudo ./test_xsk.sh
 64#
 65# If running from kselftests:
 66#   sudo make run_tests
 67#
 68# Run with verbose output:
 69#   sudo ./test_xsk.sh -v
 70#
 71# Set up veth interfaces and leave them up so xskxceiver can be launched in a debugger:
 72#   sudo ./test_xsk.sh -d
 73#
 74# Run test suite for physical device in loopback mode
 75#   sudo ./test_xsk.sh -i IFACE
 76#
 77# Run test suite in a specific mode only [skb,drv,zc]
 78#   sudo ./test_xsk.sh -m MODE
 79#
 80# List available tests
 81#   ./test_xsk.sh -l
 82#
 83# Run a specific test from the test suite
 84#   sudo ./test_xsk.sh -t TEST_NAME
 85#
 86# Display the available command line options
 87#   ./test_xsk.sh -h
 88
 89. xsk_prereqs.sh
 90
 91ETH=""
 92
 93while getopts "vi:dm:lt:h" flag
 94do
 95	case "${flag}" in
 96		v) verbose=1;;
 97		d) debug=1;;
 98		i) ETH=${OPTARG};;
 99		m) MODE=${OPTARG};;
100		l) list=1;;
101		t) TEST=${OPTARG};;
102		h) help=1;;
103	esac
104done
105
106TEST_NAME="PREREQUISITES"
107
108URANDOM=/dev/urandom
109[ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit $ksft_fail; }
110
111VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
112VETH0=ve${VETH0_POSTFIX}
113VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
114VETH1=ve${VETH1_POSTFIX}
 
 
115MTU=1500
116
117trap ctrl_c INT
118
119function ctrl_c() {
120        cleanup_exit ${VETH0} ${VETH1}
121	exit 1
122}
123
124setup_vethPairs() {
125	if [[ $verbose -eq 1 ]]; then
126	        echo "setting up ${VETH0}"
127	fi
 
128	ip link add ${VETH0} numtxqueues 4 numrxqueues 4 type veth peer name ${VETH1} numtxqueues 4 numrxqueues 4
129	if [ -f /proc/net/if_inet6 ]; then
130		echo 1 > /proc/sys/net/ipv6/conf/${VETH0}/disable_ipv6
131		echo 1 > /proc/sys/net/ipv6/conf/${VETH1}/disable_ipv6
132	fi
133	if [[ $verbose -eq 1 ]]; then
134	        echo "setting up ${VETH1}"
135	fi
136
137	if [[ $busy_poll -eq 1 ]]; then
138	        echo 2 > /sys/class/net/${VETH0}/napi_defer_hard_irqs
139		echo 200000 > /sys/class/net/${VETH0}/gro_flush_timeout
140		echo 2 > /sys/class/net/${VETH1}/napi_defer_hard_irqs
141		echo 200000 > /sys/class/net/${VETH1}/gro_flush_timeout
142	fi
143
144	ip link set ${VETH1} mtu ${MTU}
 
145	ip link set ${VETH0} mtu ${MTU}
146	ip link set ${VETH1} up
 
147	ip link set ${VETH0} up
148}
149
150if [[ $list -eq 1 ]]; then
151        ./${XSKOBJ} -l
152        exit
153fi
154
155if [[ $help -eq 1 ]]; then
156	./${XSKOBJ}
157        exit
158fi
159
160if [ ! -z $ETH ]; then
161	VETH0=${ETH}
162	VETH1=${ETH}
 
163else
164	validate_root_exec
165	validate_veth_support ${VETH0}
166	validate_ip_utility
167	setup_vethPairs
168
169	retval=$?
170	if [ $retval -ne 0 ]; then
171		test_status $retval "${TEST_NAME}"
172		cleanup_exit ${VETH0} ${VETH1}
173		exit $retval
174	fi
175fi
176
177
178if [[ $verbose -eq 1 ]]; then
179	ARGS+="-v "
180fi
181
182if [ -n "$MODE" ]; then
183	ARGS+="-m ${MODE} "
184fi
185
186if [ -n "$TEST" ]; then
187	ARGS+="-t ${TEST} "
188fi
189
190retval=$?
191test_status $retval "${TEST_NAME}"
192
193## START TESTS
194
195statusList=()
196
197TEST_NAME="XSK_SELFTESTS_${VETH0}_SOFTIRQ"
198
199if [[ $debug -eq 1 ]]; then
200    echo "-i" ${VETH0} "-i" ${VETH1}
201    exit
202fi
203
204exec_xskxceiver
205
206if [ -z $ETH ]; then
207	cleanup_exit ${VETH0} ${VETH1}
208else
209	cleanup_iface ${ETH} ${MTU}
210fi
211
212if [[ $list -eq 1 ]]; then
213    exit
214fi
215
216TEST_NAME="XSK_SELFTESTS_${VETH0}_BUSY_POLL"
217busy_poll=1
218
219if [ -z $ETH ]; then
220	setup_vethPairs
221fi
222exec_xskxceiver
223
224## END TESTS
225
226if [ -z $ETH ]; then
227	cleanup_exit ${VETH0} ${VETH1}
228else
229	cleanup_iface ${ETH} ${MTU}
230fi
231
232failures=0
233echo -e "\nSummary:"
234for i in "${!statusList[@]}"
235do
236	if [ ${statusList[$i]} -ne 0 ]; then
237	        test_status ${statusList[$i]} ${nameList[$i]}
238		failures=1
239	fi
240done
241
242if [ $failures -eq 0 ]; then
243        echo "All tests successful!"
244fi
v6.2
  1#!/bin/bash
  2# SPDX-License-Identifier: GPL-2.0
  3# Copyright(c) 2020 Intel Corporation, Weqaar Janjua <weqaar.a.janjua@intel.com>
  4
  5# AF_XDP selftests based on veth
  6#
  7# End-to-end AF_XDP over Veth test
  8#
  9# Topology:
 10# ---------
 11#                 -----------
 12#               _ | Process | _
 13#              /  -----------  \
 14#             /        |        \
 15#            /         |         \
 16#      -----------     |     -----------
 17#      | Thread1 |     |     | Thread2 |
 18#      -----------     |     -----------
 19#           |          |          |
 20#      -----------     |     -----------
 21#      |  xskX   |     |     |  xskY   |
 22#      -----------     |     -----------
 23#           |          |          |
 24#      -----------     |     ----------
 25#      |  vethX  | --------- |  vethY |
 26#      -----------   peer    ----------
 27#           |          |          |
 28#      namespaceX      |     namespaceY
 29#
 30# AF_XDP is an address family optimized for high performance packet processing,
 31# it is XDP’s user-space interface.
 32#
 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.
 35#
 36# Refer to AF_XDP Kernel Documentation for detailed information:
 37# https://www.kernel.org/doc/html/latest/networking/af_xdp.html
 38#
 39# Prerequisites setup by script:
 40#
 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#   *** xxxx and yyyy are randomly generated 4 digit numbers used to avoid
 47#       conflict with any existing interface
 48#   * tests the veth and xsk layers of the topology
 49#
 50# See the source xskxceiver.c for information on each test
 51#
 52# Kernel configuration:
 53# ---------------------
 54# See "config" file for recommended kernel config options.
 55#
 56# Turn on XDP sockets and veth support when compiling i.e.
 57# 	Networking support -->
 58# 		Networking options -->
 59# 			[ * ] XDP sockets
 60#
 61# Executing Tests:
 62# ----------------
 63# Must run with CAP_NET_ADMIN capability.
 64#
 65# Run:
 66#   sudo ./test_xsk.sh
 67#
 68# If running from kselftests:
 69#   sudo make run_tests
 70#
 71# Run with verbose output:
 72#   sudo ./test_xsk.sh -v
 73#
 74# Run and dump packet contents:
 75#   sudo ./test_xsk.sh -D
 76#
 77# Run test suite for physical device in loopback mode
 78#   sudo ./test_xsk.sh -i IFACE
 
 
 
 
 
 
 
 
 
 
 
 
 79
 80. xsk_prereqs.sh
 81
 82ETH=""
 83
 84while getopts "vDi:" flag
 85do
 86	case "${flag}" in
 87		v) verbose=1;;
 88		D) dump_pkts=1;;
 89		i) ETH=${OPTARG};;
 
 
 
 
 90	esac
 91done
 92
 93TEST_NAME="PREREQUISITES"
 94
 95URANDOM=/dev/urandom
 96[ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit $ksft_fail; }
 97
 98VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
 99VETH0=ve${VETH0_POSTFIX}
100VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
101VETH1=ve${VETH1_POSTFIX}
102NS0=root
103NS1=af_xdp${VETH1_POSTFIX}
104MTU=1500
105
106trap ctrl_c INT
107
108function ctrl_c() {
109        cleanup_exit ${VETH0} ${VETH1} ${NS1}
110	exit 1
111}
112
113setup_vethPairs() {
114	if [[ $verbose -eq 1 ]]; then
115	        echo "setting up ${VETH0}: namespace: ${NS0}"
116	fi
117	ip netns add ${NS1}
118	ip link add ${VETH0} numtxqueues 4 numrxqueues 4 type veth peer name ${VETH1} numtxqueues 4 numrxqueues 4
119	if [ -f /proc/net/if_inet6 ]; then
120		echo 1 > /proc/sys/net/ipv6/conf/${VETH0}/disable_ipv6
 
121	fi
122	if [[ $verbose -eq 1 ]]; then
123	        echo "setting up ${VETH1}: namespace: ${NS1}"
124	fi
125
126	if [[ $busy_poll -eq 1 ]]; then
127	        echo 2 > /sys/class/net/${VETH0}/napi_defer_hard_irqs
128		echo 200000 > /sys/class/net/${VETH0}/gro_flush_timeout
129		echo 2 > /sys/class/net/${VETH1}/napi_defer_hard_irqs
130		echo 200000 > /sys/class/net/${VETH1}/gro_flush_timeout
131	fi
132
133	ip link set ${VETH1} netns ${NS1}
134	ip netns exec ${NS1} ip link set ${VETH1} mtu ${MTU}
135	ip link set ${VETH0} mtu ${MTU}
136	ip netns exec ${NS1} ip link set ${VETH1} up
137	ip netns exec ${NS1} ip link set dev lo up
138	ip link set ${VETH0} up
139}
140
 
 
 
 
 
 
 
 
 
 
141if [ ! -z $ETH ]; then
142	VETH0=${ETH}
143	VETH1=${ETH}
144	NS1=""
145else
146	validate_root_exec
147	validate_veth_support ${VETH0}
148	validate_ip_utility
149	setup_vethPairs
150
151	retval=$?
152	if [ $retval -ne 0 ]; then
153		test_status $retval "${TEST_NAME}"
154		cleanup_exit ${VETH0} ${VETH1} ${NS1}
155		exit $retval
156	fi
157fi
158
159
160if [[ $verbose -eq 1 ]]; then
161	ARGS+="-v "
162fi
163
164if [[ $dump_pkts -eq 1 ]]; then
165	ARGS="-D "
 
 
 
 
166fi
167
168retval=$?
169test_status $retval "${TEST_NAME}"
170
171## START TESTS
172
173statusList=()
174
175TEST_NAME="XSK_SELFTESTS_${VETH0}_SOFTIRQ"
176
 
 
 
 
 
177exec_xskxceiver
178
179if [ -z $ETH ]; then
180	cleanup_exit ${VETH0} ${VETH1} ${NS1}
 
 
181fi
 
 
 
 
 
182TEST_NAME="XSK_SELFTESTS_${VETH0}_BUSY_POLL"
183busy_poll=1
184
185if [ -z $ETH ]; then
186	setup_vethPairs
187fi
188exec_xskxceiver
189
190## END TESTS
191
192if [ -z $ETH ]; then
193	cleanup_exit ${VETH0} ${VETH1} ${NS1}
 
 
194fi
195
196failures=0
197echo -e "\nSummary:"
198for i in "${!statusList[@]}"
199do
200	if [ ${statusList[$i]} -ne 0 ]; then
201	        test_status ${statusList[$i]} ${nameList[$i]}
202		failures=1
203	fi
204done
205
206if [ $failures -eq 0 ]; then
207        echo "All tests successful!"
208fi