Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 # Copyright(c) 2020 Intel Corporation, Weqaar Janjua <weqaar.a.janjua@intel.com>
0004 
0005 # AF_XDP selftests based on veth
0006 #
0007 # End-to-end AF_XDP over Veth test
0008 #
0009 # Topology:
0010 # ---------
0011 #                 -----------
0012 #               _ | Process | _
0013 #              /  -----------  \
0014 #             /        |        \
0015 #            /         |         \
0016 #      -----------     |     -----------
0017 #      | Thread1 |     |     | Thread2 |
0018 #      -----------     |     -----------
0019 #           |          |          |
0020 #      -----------     |     -----------
0021 #      |  xskX   |     |     |  xskY   |
0022 #      -----------     |     -----------
0023 #           |          |          |
0024 #      -----------     |     ----------
0025 #      |  vethX  | --------- |  vethY |
0026 #      -----------   peer    ----------
0027 #           |          |          |
0028 #      namespaceX      |     namespaceY
0029 #
0030 # AF_XDP is an address family optimized for high performance packet processing,
0031 # it is XDP’s user-space interface.
0032 #
0033 # An AF_XDP socket is linked to a single UMEM which is a region of virtual
0034 # contiguous memory, divided into equal-sized frames.
0035 #
0036 # Refer to AF_XDP Kernel Documentation for detailed information:
0037 # https://www.kernel.org/doc/html/latest/networking/af_xdp.html
0038 #
0039 # Prerequisites setup by script:
0040 #
0041 #   Set up veth interfaces as per the topology shown ^^:
0042 #   * setup two veth interfaces and one namespace
0043 #   ** veth<xxxx> in root namespace
0044 #   ** veth<yyyy> in af_xdp<xxxx> namespace
0045 #   ** namespace af_xdp<xxxx>
0046 #   *** xxxx and yyyy are randomly generated 4 digit numbers used to avoid
0047 #       conflict with any existing interface
0048 #   * tests the veth and xsk layers of the topology
0049 #
0050 # See the source xskxceiver.c for information on each test
0051 #
0052 # Kernel configuration:
0053 # ---------------------
0054 # See "config" file for recommended kernel config options.
0055 #
0056 # Turn on XDP sockets and veth support when compiling i.e.
0057 #       Networking support -->
0058 #               Networking options -->
0059 #                       [ * ] XDP sockets
0060 #
0061 # Executing Tests:
0062 # ----------------
0063 # Must run with CAP_NET_ADMIN capability.
0064 #
0065 # Run:
0066 #   sudo ./test_xsk.sh
0067 #
0068 # If running from kselftests:
0069 #   sudo make run_tests
0070 #
0071 # Run with verbose output:
0072 #   sudo ./test_xsk.sh -v
0073 #
0074 # Run and dump packet contents:
0075 #   sudo ./test_xsk.sh -D
0076 
0077 . xsk_prereqs.sh
0078 
0079 while getopts "vD" flag
0080 do
0081         case "${flag}" in
0082                 v) verbose=1;;
0083                 D) dump_pkts=1;;
0084         esac
0085 done
0086 
0087 TEST_NAME="PREREQUISITES"
0088 
0089 URANDOM=/dev/urandom
0090 [ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit $ksft_fail; }
0091 
0092 VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
0093 VETH0=ve${VETH0_POSTFIX}
0094 VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
0095 VETH1=ve${VETH1_POSTFIX}
0096 NS0=root
0097 NS1=af_xdp${VETH1_POSTFIX}
0098 MTU=1500
0099 
0100 trap ctrl_c INT
0101 
0102 function ctrl_c() {
0103         cleanup_exit ${VETH0} ${VETH1} ${NS1}
0104         exit 1
0105 }
0106 
0107 setup_vethPairs() {
0108         if [[ $verbose -eq 1 ]]; then
0109                 echo "setting up ${VETH0}: namespace: ${NS0}"
0110         fi
0111         ip netns add ${NS1}
0112         ip link add ${VETH0} numtxqueues 4 numrxqueues 4 type veth peer name ${VETH1} numtxqueues 4 numrxqueues 4
0113         if [ -f /proc/net/if_inet6 ]; then
0114                 echo 1 > /proc/sys/net/ipv6/conf/${VETH0}/disable_ipv6
0115         fi
0116         if [[ $verbose -eq 1 ]]; then
0117                 echo "setting up ${VETH1}: namespace: ${NS1}"
0118         fi
0119 
0120         if [[ $busy_poll -eq 1 ]]; then
0121                 echo 2 > /sys/class/net/${VETH0}/napi_defer_hard_irqs
0122                 echo 200000 > /sys/class/net/${VETH0}/gro_flush_timeout
0123                 echo 2 > /sys/class/net/${VETH1}/napi_defer_hard_irqs
0124                 echo 200000 > /sys/class/net/${VETH1}/gro_flush_timeout
0125         fi
0126 
0127         ip link set ${VETH1} netns ${NS1}
0128         ip netns exec ${NS1} ip link set ${VETH1} mtu ${MTU}
0129         ip link set ${VETH0} mtu ${MTU}
0130         ip netns exec ${NS1} ip link set ${VETH1} up
0131         ip netns exec ${NS1} ip link set dev lo up
0132         ip link set ${VETH0} up
0133 }
0134 
0135 validate_root_exec
0136 validate_veth_support ${VETH0}
0137 validate_ip_utility
0138 setup_vethPairs
0139 
0140 retval=$?
0141 if [ $retval -ne 0 ]; then
0142         test_status $retval "${TEST_NAME}"
0143         cleanup_exit ${VETH0} ${VETH1} ${NS1}
0144         exit $retval
0145 fi
0146 
0147 if [[ $verbose -eq 1 ]]; then
0148         ARGS+="-v "
0149 fi
0150 
0151 if [[ $dump_pkts -eq 1 ]]; then
0152         ARGS="-D "
0153 fi
0154 
0155 test_status $retval "${TEST_NAME}"
0156 
0157 ## START TESTS
0158 
0159 statusList=()
0160 
0161 TEST_NAME="XSK_SELFTESTS_SOFTIRQ"
0162 
0163 exec_xskxceiver
0164 
0165 cleanup_exit ${VETH0} ${VETH1} ${NS1}
0166 TEST_NAME="XSK_SELFTESTS_BUSY_POLL"
0167 busy_poll=1
0168 
0169 setup_vethPairs
0170 exec_xskxceiver
0171 
0172 ## END TESTS
0173 
0174 cleanup_exit ${VETH0} ${VETH1} ${NS1}
0175 
0176 failures=0
0177 echo -e "\nSummary:"
0178 for i in "${!statusList[@]}"
0179 do
0180         if [ ${statusList[$i]} -ne 0 ]; then
0181                 test_status ${statusList[$i]} ${nameList[$i]}
0182                 failures=1
0183         fi
0184 done
0185 
0186 if [ $failures -eq 0 ]; then
0187         echo "All tests successful!"
0188 fi