Weqaar Janjua | a890525 | 2020-12-07 21:53:29 +0000 | [diff] [blame] | 1 | #!/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 Janjua | facb7cb | 2020-12-07 21:53:30 +0000 | [diff] [blame] | 11 | # ----------- |
| 12 | # _ | Process | _ |
| 13 | # / ----------- \ |
| 14 | # / | \ |
| 15 | # / | \ |
| 16 | # ----------- | ----------- |
| 17 | # | Thread1 | | | Thread2 | |
| 18 | # ----------- | ----------- |
| 19 | # | | | |
| 20 | # ----------- | ----------- |
| 21 | # | xskX | | | xskY | |
Weqaar Janjua | a890525 | 2020-12-07 21:53:29 +0000 | [diff] [blame] | 22 | # ----------- | ----------- |
| 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 Janjua | facb7cb | 2020-12-07 21:53:30 +0000 | [diff] [blame] | 51 | # See the source xdpxceiver.c for information on each test |
| 52 | # |
Weqaar Janjua | a890525 | 2020-12-07 21:53:29 +0000 | [diff] [blame] | 53 | # 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 Karlsson | ecde606 | 2021-02-23 16:23:01 +0000 | [diff] [blame] | 74 | # |
| 75 | # Run with verbose output: |
| 76 | # sudo ./test_xsk.sh -v |
Ciara Loftus | d2b0dfd | 2021-02-23 16:23:02 +0000 | [diff] [blame] | 77 | # |
| 78 | # Run and dump packet contents: |
| 79 | # sudo ./test_xsk.sh -D |
Weqaar Janjua | a890525 | 2020-12-07 21:53:29 +0000 | [diff] [blame] | 80 | |
| 81 | . xsk_prereqs.sh |
| 82 | |
Ciara Loftus | d2b0dfd | 2021-02-23 16:23:02 +0000 | [diff] [blame] | 83 | while getopts "cvD" flag |
Weqaar Janjua | a890525 | 2020-12-07 21:53:29 +0000 | [diff] [blame] | 84 | do |
| 85 | case "${flag}" in |
| 86 | c) colorconsole=1;; |
Magnus Karlsson | ecde606 | 2021-02-23 16:23:01 +0000 | [diff] [blame] | 87 | v) verbose=1;; |
Ciara Loftus | d2b0dfd | 2021-02-23 16:23:02 +0000 | [diff] [blame] | 88 | D) dump_pkts=1;; |
Weqaar Janjua | a890525 | 2020-12-07 21:53:29 +0000 | [diff] [blame] | 89 | esac |
| 90 | done |
| 91 | |
| 92 | TEST_NAME="PREREQUISITES" |
| 93 | |
| 94 | URANDOM=/dev/urandom |
| 95 | [ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit 1 1; } |
| 96 | |
| 97 | VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4) |
| 98 | VETH0=ve${VETH0_POSTFIX} |
| 99 | VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4) |
| 100 | VETH1=ve${VETH1_POSTFIX} |
| 101 | NS0=root |
| 102 | NS1=af_xdp${VETH1_POSTFIX} |
| 103 | MTU=1500 |
| 104 | |
| 105 | setup_vethPairs() { |
Magnus Karlsson | ecde606 | 2021-02-23 16:23:01 +0000 | [diff] [blame] | 106 | if [[ $verbose -eq 1 ]]; then |
| 107 | echo "setting up ${VETH0}: namespace: ${NS0}" |
| 108 | fi |
Weqaar Janjua | a890525 | 2020-12-07 21:53:29 +0000 | [diff] [blame] | 109 | ip netns add ${NS1} |
Maciej Fijalkowski | 27e1ca2 | 2021-03-30 00:43:13 +0200 | [diff] [blame] | 110 | ip link add ${VETH0} numtxqueues 4 numrxqueues 4 type veth peer name ${VETH1} numtxqueues 4 numrxqueues 4 |
Weqaar Janjua | a890525 | 2020-12-07 21:53:29 +0000 | [diff] [blame] | 111 | if [ -f /proc/net/if_inet6 ]; then |
| 112 | echo 1 > /proc/sys/net/ipv6/conf/${VETH0}/disable_ipv6 |
| 113 | fi |
Magnus Karlsson | ecde606 | 2021-02-23 16:23:01 +0000 | [diff] [blame] | 114 | if [[ $verbose -eq 1 ]]; then |
| 115 | echo "setting up ${VETH1}: namespace: ${NS1}" |
| 116 | fi |
Weqaar Janjua | a890525 | 2020-12-07 21:53:29 +0000 | [diff] [blame] | 117 | 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 Fijalkowski | 27e1ca2 | 2021-03-30 00:43:13 +0200 | [diff] [blame] | 121 | ip netns exec ${NS1} ip link set dev lo up |
Weqaar Janjua | a890525 | 2020-12-07 21:53:29 +0000 | [diff] [blame] | 122 | ip link set ${VETH0} up |
| 123 | } |
| 124 | |
| 125 | validate_root_exec |
| 126 | validate_veth_support ${VETH0} |
| 127 | validate_ip_utility |
| 128 | setup_vethPairs |
| 129 | |
| 130 | retval=$? |
| 131 | if [ $retval -ne 0 ]; then |
| 132 | test_status $retval "${TEST_NAME}" |
| 133 | cleanup_exit ${VETH0} ${VETH1} ${NS1} |
| 134 | exit $retval |
| 135 | fi |
| 136 | |
| 137 | echo "${VETH0}:${VETH1},${NS1}" > ${SPECFILE} |
| 138 | |
| 139 | validate_veth_spec_file |
| 140 | |
Magnus Karlsson | ecde606 | 2021-02-23 16:23:01 +0000 | [diff] [blame] | 141 | if [[ $verbose -eq 1 ]]; then |
| 142 | echo "Spec file created: ${SPECFILE}" |
| 143 | VERBOSE_ARG="-v" |
| 144 | fi |
Weqaar Janjua | a890525 | 2020-12-07 21:53:29 +0000 | [diff] [blame] | 145 | |
Ciara Loftus | d2b0dfd | 2021-02-23 16:23:02 +0000 | [diff] [blame] | 146 | if [[ $dump_pkts -eq 1 ]]; then |
| 147 | DUMP_PKTS_ARG="-D" |
| 148 | fi |
| 149 | |
Weqaar Janjua | a890525 | 2020-12-07 21:53:29 +0000 | [diff] [blame] | 150 | test_status $retval "${TEST_NAME}" |
| 151 | |
| 152 | ## START TESTS |
| 153 | |
| 154 | statusList=() |
| 155 | |
Ciara Loftus | d3e3bf5 | 2021-02-23 16:23:03 +0000 | [diff] [blame] | 156 | TEST_NAME="XSK KSELFTESTS" |
Weqaar Janjua | a890525 | 2020-12-07 21:53:29 +0000 | [diff] [blame] | 157 | |
Ciara Loftus | d3e3bf5 | 2021-02-23 16:23:03 +0000 | [diff] [blame] | 158 | execxdpxceiver |
Weqaar Janjua | 7d20441 | 2020-12-07 21:53:33 +0000 | [diff] [blame] | 159 | |
| 160 | retval=$? |
| 161 | test_status $retval "${TEST_NAME}" |
| 162 | statusList+=($retval) |
| 163 | |
Weqaar Janjua | a890525 | 2020-12-07 21:53:29 +0000 | [diff] [blame] | 164 | ## END TESTS |
| 165 | |
| 166 | cleanup_exit ${VETH0} ${VETH1} ${NS1} |
| 167 | |
| 168 | for _status in "${statusList[@]}" |
| 169 | do |
| 170 | if [ $_status -ne 0 ]; then |
| 171 | test_exit $ksft_fail 0 |
| 172 | fi |
| 173 | done |
| 174 | |
| 175 | test_exit $ksft_pass 0 |