WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / test_xsk.sh
blob88a7483eaae4001ce9995a572f58b85aaf8f0eed
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright(c) 2020 Intel Corporation, Weqaar Janjua <weqaar.a.janjua@intel.com>
5 # AF_XDP selftests based on veth
7 # End-to-end AF_XDP over Veth test
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
30 # AF_XDP is an address family optimized for high performance packet processing,
31 # it is XDP’s user-space interface.
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.
36 # Refer to AF_XDP Kernel Documentation for detailed information:
37 # https://www.kernel.org/doc/html/latest/networking/af_xdp.html
39 # Prerequisites setup by script:
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
51 # See the source xdpxceiver.c for information on each test
53 # Kernel configuration:
54 # ---------------------
55 # See "config" file for recommended kernel config options.
57 # Turn on XDP sockets and veth support when compiling i.e.
58 # Networking support -->
59 # Networking options -->
60 # [ * ] XDP sockets
62 # Executing Tests:
63 # ----------------
64 # Must run with CAP_NET_ADMIN capability.
66 # Run (full color-coded output):
67 # sudo ./test_xsk.sh -c
69 # If running from kselftests:
70 # sudo make colorconsole=1 run_tests
72 # Run (full output without color-coding):
73 # sudo ./test_xsk.sh
75 . xsk_prereqs.sh
77 while getopts c flag
79 case "${flag}" in
80 c) colorconsole=1;;
81 esac
82 done
84 TEST_NAME="PREREQUISITES"
86 URANDOM=/dev/urandom
87 [ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit 1 1; }
89 VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
90 VETH0=ve${VETH0_POSTFIX}
91 VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
92 VETH1=ve${VETH1_POSTFIX}
93 NS0=root
94 NS1=af_xdp${VETH1_POSTFIX}
95 MTU=1500
97 setup_vethPairs() {
98 echo "setting up ${VETH0}: namespace: ${NS0}"
99 ip netns add ${NS1}
100 ip link add ${VETH0} type veth peer name ${VETH1}
101 if [ -f /proc/net/if_inet6 ]; then
102 echo 1 > /proc/sys/net/ipv6/conf/${VETH0}/disable_ipv6
104 echo "setting up ${VETH1}: namespace: ${NS1}"
105 ip link set ${VETH1} netns ${NS1}
106 ip netns exec ${NS1} ip link set ${VETH1} mtu ${MTU}
107 ip link set ${VETH0} mtu ${MTU}
108 ip netns exec ${NS1} ip link set ${VETH1} up
109 ip link set ${VETH0} up
112 validate_root_exec
113 validate_veth_support ${VETH0}
114 validate_ip_utility
115 setup_vethPairs
117 retval=$?
118 if [ $retval -ne 0 ]; then
119 test_status $retval "${TEST_NAME}"
120 cleanup_exit ${VETH0} ${VETH1} ${NS1}
121 exit $retval
124 echo "${VETH0}:${VETH1},${NS1}" > ${SPECFILE}
126 validate_veth_spec_file
128 echo "Spec file created: ${SPECFILE}"
130 test_status $retval "${TEST_NAME}"
132 ## START TESTS
134 statusList=()
136 ### TEST 1
137 TEST_NAME="XSK KSELFTEST FRAMEWORK"
139 echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Generic mode"
140 vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
142 retval=$?
143 if [ $retval -eq 0 ]; then
144 echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Native mode"
145 vethXDPnative ${VETH0} ${VETH1} ${NS1}
148 retval=$?
149 test_status $retval "${TEST_NAME}"
150 statusList+=($retval)
152 ### TEST 2
153 TEST_NAME="SKB NOPOLL"
155 vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
157 params=("-S")
158 execxdpxceiver params
160 retval=$?
161 test_status $retval "${TEST_NAME}"
162 statusList+=($retval)
164 ### TEST 3
165 TEST_NAME="SKB POLL"
167 vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
169 params=("-S" "-p")
170 execxdpxceiver params
172 retval=$?
173 test_status $retval "${TEST_NAME}"
174 statusList+=($retval)
176 ### TEST 4
177 TEST_NAME="DRV NOPOLL"
179 vethXDPnative ${VETH0} ${VETH1} ${NS1}
181 params=("-N")
182 execxdpxceiver params
184 retval=$?
185 test_status $retval "${TEST_NAME}"
186 statusList+=($retval)
188 ### TEST 5
189 TEST_NAME="DRV POLL"
191 vethXDPnative ${VETH0} ${VETH1} ${NS1}
193 params=("-N" "-p")
194 execxdpxceiver params
196 retval=$?
197 test_status $retval "${TEST_NAME}"
198 statusList+=($retval)
200 ### TEST 6
201 TEST_NAME="SKB SOCKET TEARDOWN"
203 vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
205 params=("-S" "-T")
206 execxdpxceiver params
208 retval=$?
209 test_status $retval "${TEST_NAME}"
210 statusList+=($retval)
212 ### TEST 7
213 TEST_NAME="DRV SOCKET TEARDOWN"
215 vethXDPnative ${VETH0} ${VETH1} ${NS1}
217 params=("-N" "-T")
218 execxdpxceiver params
220 retval=$?
221 test_status $retval "${TEST_NAME}"
222 statusList+=($retval)
224 ### TEST 8
225 TEST_NAME="SKB BIDIRECTIONAL SOCKETS"
227 vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
229 params=("-S" "-B")
230 execxdpxceiver params
232 retval=$?
233 test_status $retval "${TEST_NAME}"
234 statusList+=($retval)
236 ### TEST 9
237 TEST_NAME="DRV BIDIRECTIONAL SOCKETS"
239 vethXDPnative ${VETH0} ${VETH1} ${NS1}
241 params=("-N" "-B")
242 execxdpxceiver params
244 retval=$?
245 test_status $retval "${TEST_NAME}"
246 statusList+=($retval)
248 ## END TESTS
250 cleanup_exit ${VETH0} ${VETH1} ${NS1}
252 for _status in "${statusList[@]}"
254 if [ $_status -ne 0 ]; then
255 test_exit $ksft_fail 0
257 done
259 test_exit $ksft_pass 0