blob: cae4c5574c4cf9e59a3289104e5aec242f6983bc [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# ---------
11# ----------- -----------
12# | xskX | --------- | xskY |
13# ----------- | -----------
14# | | |
15# ----------- | ----------
16# | vethX | --------- | vethY |
17# ----------- peer ----------
18# | | |
19# namespaceX | namespaceY
20#
21# AF_XDP is an address family optimized for high performance packet processing,
22# it is XDP’s user-space interface.
23#
24# An AF_XDP socket is linked to a single UMEM which is a region of virtual
25# contiguous memory, divided into equal-sized frames.
26#
27# Refer to AF_XDP Kernel Documentation for detailed information:
28# https://www.kernel.org/doc/html/latest/networking/af_xdp.html
29#
30# Prerequisites setup by script:
31#
32# Set up veth interfaces as per the topology shown ^^:
33# * setup two veth interfaces and one namespace
34# ** veth<xxxx> in root namespace
35# ** veth<yyyy> in af_xdp<xxxx> namespace
36# ** namespace af_xdp<xxxx>
37# * create a spec file veth.spec that includes this run-time configuration
38# *** xxxx and yyyy are randomly generated 4 digit numbers used to avoid
39# conflict with any existing interface
40# * tests the veth and xsk layers of the topology
41#
42# Kernel configuration:
43# ---------------------
44# See "config" file for recommended kernel config options.
45#
46# Turn on XDP sockets and veth support when compiling i.e.
47# Networking support -->
48# Networking options -->
49# [ * ] XDP sockets
50#
51# Executing Tests:
52# ----------------
53# Must run with CAP_NET_ADMIN capability.
54#
55# Run (full color-coded output):
56# sudo ./test_xsk.sh -c
57#
58# If running from kselftests:
59# sudo make colorconsole=1 run_tests
60#
61# Run (full output without color-coding):
62# sudo ./test_xsk.sh
63
64. xsk_prereqs.sh
65
66while getopts c flag
67do
68 case "${flag}" in
69 c) colorconsole=1;;
70 esac
71done
72
73TEST_NAME="PREREQUISITES"
74
75URANDOM=/dev/urandom
76[ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit 1 1; }
77
78VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
79VETH0=ve${VETH0_POSTFIX}
80VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
81VETH1=ve${VETH1_POSTFIX}
82NS0=root
83NS1=af_xdp${VETH1_POSTFIX}
84MTU=1500
85
86setup_vethPairs() {
87 echo "setting up ${VETH0}: namespace: ${NS0}"
88 ip netns add ${NS1}
89 ip link add ${VETH0} type veth peer name ${VETH1}
90 if [ -f /proc/net/if_inet6 ]; then
91 echo 1 > /proc/sys/net/ipv6/conf/${VETH0}/disable_ipv6
92 fi
93 echo "setting up ${VETH1}: namespace: ${NS1}"
94 ip link set ${VETH1} netns ${NS1}
95 ip netns exec ${NS1} ip link set ${VETH1} mtu ${MTU}
96 ip link set ${VETH0} mtu ${MTU}
97 ip netns exec ${NS1} ip link set ${VETH1} up
98 ip link set ${VETH0} up
99}
100
101validate_root_exec
102validate_veth_support ${VETH0}
103validate_ip_utility
104setup_vethPairs
105
106retval=$?
107if [ $retval -ne 0 ]; then
108 test_status $retval "${TEST_NAME}"
109 cleanup_exit ${VETH0} ${VETH1} ${NS1}
110 exit $retval
111fi
112
113echo "${VETH0}:${VETH1},${NS1}" > ${SPECFILE}
114
115validate_veth_spec_file
116
117echo "Spec file created: ${SPECFILE}"
118
119test_status $retval "${TEST_NAME}"
120
121## START TESTS
122
123statusList=()
124
125### TEST 1
126TEST_NAME="XSK KSELFTEST FRAMEWORK"
127
128echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Generic mode"
129vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
130
131retval=$?
132if [ $retval -eq 0 ]; then
133 echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Native mode"
134 vethXDPnative ${VETH0} ${VETH1} ${NS1}
135fi
136
137retval=$?
138test_status $retval "${TEST_NAME}"
139statusList+=($retval)
140
141## END TESTS
142
143cleanup_exit ${VETH0} ${VETH1} ${NS1}
144
145for _status in "${statusList[@]}"
146do
147 if [ $_status -ne 0 ]; then
148 test_exit $ksft_fail 0
149 fi
150done
151
152test_exit $ksft_pass 0