245 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03# Copyright(c) 2020 Intel Corporation, Weqaar Janjua <weqaar.a.janjua@intel.com>4 5# AF_XDP selftests based on veth6#7# End-to-end AF_XDP over Veth test8#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 virtual32# 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.html36#37# Prerequisites setup by script:38#39# Set up veth interfaces as per the topology shown ^^:40# * setup two veth interfaces41# ** veth<xxxx>42# ** veth<yyyy>43# *** xxxx and yyyy are randomly generated 4 digit numbers used to avoid44# conflict with any existing interface45# * tests the veth and xsk layers of the topology46#47# See the source xskxceiver.c for information on each test48#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 sockets57#58# Executing Tests:59# ----------------60# Must run with CAP_NET_ADMIN capability.61#62# Run:63# sudo ./test_xsk.sh64#65# If running from kselftests:66# sudo make run_tests67#68# Run with verbose output:69# sudo ./test_xsk.sh -v70#71# Set up veth interfaces and leave them up so xskxceiver can be launched in a debugger:72# sudo ./test_xsk.sh -d73#74# Run test suite for physical device in loopback mode75# sudo ./test_xsk.sh -i IFACE76#77# Run test suite in a specific mode only [skb,drv,zc]78# sudo ./test_xsk.sh -m MODE79#80# List available tests81# ./test_xsk.sh -l82#83# Run a specific test from the test suite84# sudo ./test_xsk.sh -t TEST_NAME85#86# Display the available command line options87# ./test_xsk.sh -h88 89. xsk_prereqs.sh90 91ETH=""92 93while getopts "vi:dm:lt:h" flag94do95 case "${flag}" in96 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 esac104done105 106TEST_NAME="PREREQUISITES"107 108URANDOM=/dev/urandom109[ ! -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=1500116 117trap ctrl_c INT118 119function ctrl_c() {120 cleanup_exit ${VETH0} ${VETH1}121 exit 1122}123 124setup_vethPairs() {125 if [[ $verbose -eq 1 ]]; then126 echo "setting up ${VETH0}"127 fi128 ip link add ${VETH0} numtxqueues 4 numrxqueues 4 type veth peer name ${VETH1} numtxqueues 4 numrxqueues 4129 if [ -f /proc/net/if_inet6 ]; then130 echo 1 > /proc/sys/net/ipv6/conf/${VETH0}/disable_ipv6131 echo 1 > /proc/sys/net/ipv6/conf/${VETH1}/disable_ipv6132 fi133 if [[ $verbose -eq 1 ]]; then134 echo "setting up ${VETH1}"135 fi136 137 if [[ $busy_poll -eq 1 ]]; then138 echo 2 > /sys/class/net/${VETH0}/napi_defer_hard_irqs139 echo 200000 > /sys/class/net/${VETH0}/gro_flush_timeout140 echo 2 > /sys/class/net/${VETH1}/napi_defer_hard_irqs141 echo 200000 > /sys/class/net/${VETH1}/gro_flush_timeout142 fi143 144 ip link set ${VETH1} mtu ${MTU}145 ip link set ${VETH0} mtu ${MTU}146 ip link set ${VETH1} up147 ip link set ${VETH0} up148}149 150if [[ $list -eq 1 ]]; then151 ./${XSKOBJ} -l152 exit153fi154 155if [[ $help -eq 1 ]]; then156 ./${XSKOBJ}157 exit158fi159 160if [ ! -z $ETH ]; then161 VETH0=${ETH}162 VETH1=${ETH}163else164 validate_root_exec165 validate_veth_support ${VETH0}166 validate_ip_utility167 setup_vethPairs168 169 retval=$?170 if [ $retval -ne 0 ]; then171 test_status $retval "${TEST_NAME}"172 cleanup_exit ${VETH0} ${VETH1}173 exit $retval174 fi175fi176 177 178if [[ $verbose -eq 1 ]]; then179 ARGS+="-v "180fi181 182if [ -n "$MODE" ]; then183 ARGS+="-m ${MODE} "184fi185 186if [ -n "$TEST" ]; then187 ARGS+="-t ${TEST} "188fi189 190retval=$?191test_status $retval "${TEST_NAME}"192 193## START TESTS194 195statusList=()196 197TEST_NAME="XSK_SELFTESTS_${VETH0}_SOFTIRQ"198 199if [[ $debug -eq 1 ]]; then200 echo "-i" ${VETH0} "-i" ${VETH1}201 exit202fi203 204exec_xskxceiver205 206if [ -z $ETH ]; then207 cleanup_exit ${VETH0} ${VETH1}208else209 cleanup_iface ${ETH} ${MTU}210fi211 212if [[ $list -eq 1 ]]; then213 exit214fi215 216TEST_NAME="XSK_SELFTESTS_${VETH0}_BUSY_POLL"217busy_poll=1218 219if [ -z $ETH ]; then220 setup_vethPairs221fi222exec_xskxceiver223 224## END TESTS225 226if [ -z $ETH ]; then227 cleanup_exit ${VETH0} ${VETH1}228else229 cleanup_iface ${ETH} ${MTU}230fi231 232failures=0233echo -e "\nSummary:"234for i in "${!statusList[@]}"235do236 if [ ${statusList[$i]} -ne 0 ]; then237 test_status ${statusList[$i]} ${nameList[$i]}238 failures=1239 fi240done241 242if [ $failures -eq 0 ]; then243 echo "All tests successful!"244fi245