blob: 46633a3bfb0b6df9122cc63f1fa2531070c2e72d [file] [log] [blame]
Weqaar Janjuaa8905252020-12-07 21:53:29 +00001#!/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# ---------
Weqaar Janjuafacb7cb2020-12-07 21:53:30 +000011# -----------
12# _ | Process | _
13# / ----------- \
14# / | \
15# / | \
16# ----------- | -----------
17# | Thread1 | | | Thread2 |
18# ----------- | -----------
19# | | |
20# ----------- | -----------
21# | xskX | | | xskY |
Weqaar Janjuaa8905252020-12-07 21:53:29 +000022# ----------- | -----------
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# * 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
50#
Weqaar Janjuafacb7cb2020-12-07 21:53:30 +000051# See the source xdpxceiver.c for information on each test
52#
Weqaar Janjuaa8905252020-12-07 21:53:29 +000053# Kernel configuration:
54# ---------------------
55# See "config" file for recommended kernel config options.
56#
57# Turn on XDP sockets and veth support when compiling i.e.
58# Networking support -->
59# Networking options -->
60# [ * ] XDP sockets
61#
62# Executing Tests:
63# ----------------
64# Must run with CAP_NET_ADMIN capability.
65#
66# Run (full color-coded output):
67# sudo ./test_xsk.sh -c
68#
69# If running from kselftests:
70# sudo make colorconsole=1 run_tests
71#
72# Run (full output without color-coding):
73# sudo ./test_xsk.sh
Magnus Karlssonecde6062021-02-23 16:23:01 +000074#
75# Run with verbose output:
76# sudo ./test_xsk.sh -v
Ciara Loftusd2b0dfd2021-02-23 16:23:02 +000077#
78# Run and dump packet contents:
79# sudo ./test_xsk.sh -D
Weqaar Janjuaa8905252020-12-07 21:53:29 +000080
81. xsk_prereqs.sh
82
Ciara Loftusd2b0dfd2021-02-23 16:23:02 +000083while getopts "cvD" flag
Weqaar Janjuaa8905252020-12-07 21:53:29 +000084do
85 case "${flag}" in
86 c) colorconsole=1;;
Magnus Karlssonecde6062021-02-23 16:23:01 +000087 v) verbose=1;;
Ciara Loftusd2b0dfd2021-02-23 16:23:02 +000088 D) dump_pkts=1;;
Weqaar Janjuaa8905252020-12-07 21:53:29 +000089 esac
90done
91
92TEST_NAME="PREREQUISITES"
93
94URANDOM=/dev/urandom
95[ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit 1 1; }
96
97VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
98VETH0=ve${VETH0_POSTFIX}
99VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
100VETH1=ve${VETH1_POSTFIX}
101NS0=root
102NS1=af_xdp${VETH1_POSTFIX}
103MTU=1500
104
105setup_vethPairs() {
Magnus Karlssonecde6062021-02-23 16:23:01 +0000106 if [[ $verbose -eq 1 ]]; then
107 echo "setting up ${VETH0}: namespace: ${NS0}"
108 fi
Weqaar Janjuaa8905252020-12-07 21:53:29 +0000109 ip netns add ${NS1}
Maciej Fijalkowski27e1ca22021-03-30 00:43:13 +0200110 ip link add ${VETH0} numtxqueues 4 numrxqueues 4 type veth peer name ${VETH1} numtxqueues 4 numrxqueues 4
Weqaar Janjuaa8905252020-12-07 21:53:29 +0000111 if [ -f /proc/net/if_inet6 ]; then
112 echo 1 > /proc/sys/net/ipv6/conf/${VETH0}/disable_ipv6
113 fi
Magnus Karlssonecde6062021-02-23 16:23:01 +0000114 if [[ $verbose -eq 1 ]]; then
115 echo "setting up ${VETH1}: namespace: ${NS1}"
116 fi
Weqaar Janjuaa8905252020-12-07 21:53:29 +0000117 ip link set ${VETH1} netns ${NS1}
118 ip netns exec ${NS1} ip link set ${VETH1} mtu ${MTU}
119 ip link set ${VETH0} mtu ${MTU}
120 ip netns exec ${NS1} ip link set ${VETH1} up
Maciej Fijalkowski27e1ca22021-03-30 00:43:13 +0200121 ip netns exec ${NS1} ip link set dev lo up
Weqaar Janjuaa8905252020-12-07 21:53:29 +0000122 ip link set ${VETH0} up
123}
124
125validate_root_exec
126validate_veth_support ${VETH0}
127validate_ip_utility
128setup_vethPairs
129
130retval=$?
131if [ $retval -ne 0 ]; then
132 test_status $retval "${TEST_NAME}"
133 cleanup_exit ${VETH0} ${VETH1} ${NS1}
134 exit $retval
135fi
136
137echo "${VETH0}:${VETH1},${NS1}" > ${SPECFILE}
138
139validate_veth_spec_file
140
Magnus Karlssonecde6062021-02-23 16:23:01 +0000141if [[ $verbose -eq 1 ]]; then
142 echo "Spec file created: ${SPECFILE}"
143 VERBOSE_ARG="-v"
144fi
Weqaar Janjuaa8905252020-12-07 21:53:29 +0000145
Ciara Loftusd2b0dfd2021-02-23 16:23:02 +0000146if [[ $dump_pkts -eq 1 ]]; then
147 DUMP_PKTS_ARG="-D"
148fi
149
Weqaar Janjuaa8905252020-12-07 21:53:29 +0000150test_status $retval "${TEST_NAME}"
151
152## START TESTS
153
154statusList=()
155
Ciara Loftusd3e3bf52021-02-23 16:23:03 +0000156TEST_NAME="XSK KSELFTESTS"
Weqaar Janjuaa8905252020-12-07 21:53:29 +0000157
Ciara Loftusd3e3bf52021-02-23 16:23:03 +0000158execxdpxceiver
Weqaar Janjua7d204412020-12-07 21:53:33 +0000159
160retval=$?
161test_status $retval "${TEST_NAME}"
162statusList+=($retval)
163
Weqaar Janjuaa8905252020-12-07 21:53:29 +0000164## END TESTS
165
166cleanup_exit ${VETH0} ${VETH1} ${NS1}
167
168for _status in "${statusList[@]}"
169do
170 if [ $_status -ne 0 ]; then
171 test_exit $ksft_fail 0
172 fi
173done
174
175test_exit $ksft_pass 0