2020-12-08 05:53:29 +08:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
# Copyright(c) 2020 Intel Corporation, Weqaar Janjua <weqaar.a.janjua@intel.com>
|
|
|
|
|
|
|
|
|
|
# AF_XDP selftests based on veth
|
|
|
|
|
#
|
|
|
|
|
# End-to-end AF_XDP over Veth test
|
|
|
|
|
#
|
|
|
|
|
# Topology:
|
|
|
|
|
# ---------
|
2020-12-08 05:53:30 +08:00
|
|
|
|
# -----------
|
|
|
|
|
# _ | Process | _
|
|
|
|
|
# / ----------- \
|
|
|
|
|
# / | \
|
|
|
|
|
# / | \
|
|
|
|
|
# ----------- | -----------
|
|
|
|
|
# | Thread1 | | | Thread2 |
|
|
|
|
|
# ----------- | -----------
|
|
|
|
|
# | | |
|
|
|
|
|
# ----------- | -----------
|
|
|
|
|
# | xskX | | | xskY |
|
2020-12-08 05:53:29 +08:00
|
|
|
|
# ----------- | -----------
|
|
|
|
|
# | | |
|
|
|
|
|
# ----------- | ----------
|
|
|
|
|
# | vethX | --------- | vethY |
|
|
|
|
|
# ----------- peer ----------
|
|
|
|
|
# | | |
|
|
|
|
|
# namespaceX | namespaceY
|
|
|
|
|
#
|
|
|
|
|
# AF_XDP is an address family optimized for high performance packet processing,
|
|
|
|
|
# it is XDP’s user-space interface.
|
|
|
|
|
#
|
|
|
|
|
# An AF_XDP socket is linked to a single UMEM which is a region of virtual
|
|
|
|
|
# contiguous memory, divided into equal-sized frames.
|
|
|
|
|
#
|
|
|
|
|
# Refer to AF_XDP Kernel Documentation for detailed information:
|
|
|
|
|
# https://www.kernel.org/doc/html/latest/networking/af_xdp.html
|
|
|
|
|
#
|
|
|
|
|
# Prerequisites setup by script:
|
|
|
|
|
#
|
|
|
|
|
# Set up veth interfaces as per the topology shown ^^:
|
|
|
|
|
# * setup two veth interfaces and one namespace
|
|
|
|
|
# ** veth<xxxx> in root namespace
|
|
|
|
|
# ** veth<yyyy> in af_xdp<xxxx> namespace
|
|
|
|
|
# ** namespace af_xdp<xxxx>
|
|
|
|
|
# *** xxxx and yyyy are randomly generated 4 digit numbers used to avoid
|
|
|
|
|
# conflict with any existing interface
|
|
|
|
|
# * tests the veth and xsk layers of the topology
|
|
|
|
|
#
|
2020-12-08 05:53:30 +08:00
|
|
|
|
# See the source xdpxceiver.c for information on each test
|
|
|
|
|
#
|
2020-12-08 05:53:29 +08:00
|
|
|
|
# Kernel configuration:
|
|
|
|
|
# ---------------------
|
|
|
|
|
# See "config" file for recommended kernel config options.
|
|
|
|
|
#
|
|
|
|
|
# Turn on XDP sockets and veth support when compiling i.e.
|
|
|
|
|
# Networking support -->
|
|
|
|
|
# Networking options -->
|
|
|
|
|
# [ * ] XDP sockets
|
|
|
|
|
#
|
|
|
|
|
# Executing Tests:
|
|
|
|
|
# ----------------
|
|
|
|
|
# Must run with CAP_NET_ADMIN capability.
|
|
|
|
|
#
|
2021-08-25 17:37:07 +08:00
|
|
|
|
# Run:
|
|
|
|
|
# sudo ./test_xsk.sh
|
2020-12-08 05:53:29 +08:00
|
|
|
|
#
|
|
|
|
|
# If running from kselftests:
|
2021-08-25 17:37:07 +08:00
|
|
|
|
# sudo make run_tests
|
2021-02-24 00:23:01 +08:00
|
|
|
|
#
|
|
|
|
|
# Run with verbose output:
|
|
|
|
|
# sudo ./test_xsk.sh -v
|
2021-02-24 00:23:02 +08:00
|
|
|
|
#
|
|
|
|
|
# Run and dump packet contents:
|
|
|
|
|
# sudo ./test_xsk.sh -D
|
2020-12-08 05:53:29 +08:00
|
|
|
|
|
|
|
|
|
. xsk_prereqs.sh
|
|
|
|
|
|
2022-05-10 19:55:56 +08:00
|
|
|
|
while getopts "vD" flag
|
2020-12-08 05:53:29 +08:00
|
|
|
|
do
|
|
|
|
|
case "${flag}" in
|
2021-02-24 00:23:01 +08:00
|
|
|
|
v) verbose=1;;
|
2021-02-24 00:23:02 +08:00
|
|
|
|
D) dump_pkts=1;;
|
2020-12-08 05:53:29 +08:00
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
TEST_NAME="PREREQUISITES"
|
|
|
|
|
|
|
|
|
|
URANDOM=/dev/urandom
|
2022-05-10 19:55:59 +08:00
|
|
|
|
[ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit $ksft_fail; }
|
2020-12-08 05:53:29 +08:00
|
|
|
|
|
|
|
|
|
VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
|
|
|
|
|
VETH0=ve${VETH0_POSTFIX}
|
|
|
|
|
VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
|
|
|
|
|
VETH1=ve${VETH1_POSTFIX}
|
|
|
|
|
NS0=root
|
|
|
|
|
NS1=af_xdp${VETH1_POSTFIX}
|
|
|
|
|
MTU=1500
|
|
|
|
|
|
|
|
|
|
setup_vethPairs() {
|
2021-02-24 00:23:01 +08:00
|
|
|
|
if [[ $verbose -eq 1 ]]; then
|
|
|
|
|
echo "setting up ${VETH0}: namespace: ${NS0}"
|
|
|
|
|
fi
|
2020-12-08 05:53:29 +08:00
|
|
|
|
ip netns add ${NS1}
|
2021-03-30 06:43:13 +08:00
|
|
|
|
ip link add ${VETH0} numtxqueues 4 numrxqueues 4 type veth peer name ${VETH1} numtxqueues 4 numrxqueues 4
|
2020-12-08 05:53:29 +08:00
|
|
|
|
if [ -f /proc/net/if_inet6 ]; then
|
|
|
|
|
echo 1 > /proc/sys/net/ipv6/conf/${VETH0}/disable_ipv6
|
|
|
|
|
fi
|
2021-02-24 00:23:01 +08:00
|
|
|
|
if [[ $verbose -eq 1 ]]; then
|
|
|
|
|
echo "setting up ${VETH1}: namespace: ${NS1}"
|
|
|
|
|
fi
|
2022-05-10 19:55:58 +08:00
|
|
|
|
|
|
|
|
|
if [[ $busy_poll -eq 1 ]]; then
|
|
|
|
|
echo 2 > /sys/class/net/${VETH0}/napi_defer_hard_irqs
|
|
|
|
|
echo 200000 > /sys/class/net/${VETH0}/gro_flush_timeout
|
|
|
|
|
echo 2 > /sys/class/net/${VETH1}/napi_defer_hard_irqs
|
|
|
|
|
echo 200000 > /sys/class/net/${VETH1}/gro_flush_timeout
|
|
|
|
|
fi
|
|
|
|
|
|
2020-12-08 05:53:29 +08:00
|
|
|
|
ip link set ${VETH1} netns ${NS1}
|
|
|
|
|
ip netns exec ${NS1} ip link set ${VETH1} mtu ${MTU}
|
|
|
|
|
ip link set ${VETH0} mtu ${MTU}
|
|
|
|
|
ip netns exec ${NS1} ip link set ${VETH1} up
|
2021-03-30 06:43:13 +08:00
|
|
|
|
ip netns exec ${NS1} ip link set dev lo up
|
2020-12-08 05:53:29 +08:00
|
|
|
|
ip link set ${VETH0} up
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
validate_root_exec
|
|
|
|
|
validate_veth_support ${VETH0}
|
|
|
|
|
validate_ip_utility
|
|
|
|
|
setup_vethPairs
|
|
|
|
|
|
|
|
|
|
retval=$?
|
|
|
|
|
if [ $retval -ne 0 ]; then
|
|
|
|
|
test_status $retval "${TEST_NAME}"
|
|
|
|
|
cleanup_exit ${VETH0} ${VETH1} ${NS1}
|
|
|
|
|
exit $retval
|
|
|
|
|
fi
|
|
|
|
|
|
2021-02-24 00:23:01 +08:00
|
|
|
|
if [[ $verbose -eq 1 ]]; then
|
2022-05-10 19:55:58 +08:00
|
|
|
|
ARGS+="-v "
|
2021-02-24 00:23:01 +08:00
|
|
|
|
fi
|
2020-12-08 05:53:29 +08:00
|
|
|
|
|
2021-02-24 00:23:02 +08:00
|
|
|
|
if [[ $dump_pkts -eq 1 ]]; then
|
2022-05-10 19:55:58 +08:00
|
|
|
|
ARGS="-D "
|
2021-02-24 00:23:02 +08:00
|
|
|
|
fi
|
|
|
|
|
|
2020-12-08 05:53:29 +08:00
|
|
|
|
test_status $retval "${TEST_NAME}"
|
|
|
|
|
|
|
|
|
|
## START TESTS
|
|
|
|
|
|
|
|
|
|
statusList=()
|
|
|
|
|
|
2022-05-10 19:55:58 +08:00
|
|
|
|
TEST_NAME="XSK_SELFTESTS_SOFTIRQ"
|
|
|
|
|
|
|
|
|
|
execxdpxceiver
|
|
|
|
|
|
|
|
|
|
cleanup_exit ${VETH0} ${VETH1} ${NS1}
|
|
|
|
|
TEST_NAME="XSK_SELFTESTS_BUSY_POLL"
|
|
|
|
|
busy_poll=1
|
|
|
|
|
|
|
|
|
|
setup_vethPairs
|
2021-02-24 00:23:03 +08:00
|
|
|
|
execxdpxceiver
|
2020-12-08 05:53:33 +08:00
|
|
|
|
|
2020-12-08 05:53:29 +08:00
|
|
|
|
## END TESTS
|
|
|
|
|
|
|
|
|
|
cleanup_exit ${VETH0} ${VETH1} ${NS1}
|
|
|
|
|
|
2022-05-10 19:55:59 +08:00
|
|
|
|
failures=0
|
|
|
|
|
echo -e "\nSummary:"
|
|
|
|
|
for i in "${!statusList[@]}"
|
2020-12-08 05:53:29 +08:00
|
|
|
|
do
|
2022-05-10 19:55:59 +08:00
|
|
|
|
if [ ${statusList[$i]} -ne 0 ]; then
|
|
|
|
|
test_status ${statusList[$i]} ${nameList[$i]}
|
|
|
|
|
failures=1
|
2020-12-08 05:53:29 +08:00
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
2022-05-10 19:55:59 +08:00
|
|
|
|
if [ $failures -eq 0 ]; then
|
|
|
|
|
echo "All tests successful!"
|
|
|
|
|
fi
|