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 | # --------- |
| 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 | |
| 66 | while getopts c flag |
| 67 | do |
| 68 | case "${flag}" in |
| 69 | c) colorconsole=1;; |
| 70 | esac |
| 71 | done |
| 72 | |
| 73 | TEST_NAME="PREREQUISITES" |
| 74 | |
| 75 | URANDOM=/dev/urandom |
| 76 | [ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit 1 1; } |
| 77 | |
| 78 | VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4) |
| 79 | VETH0=ve${VETH0_POSTFIX} |
| 80 | VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4) |
| 81 | VETH1=ve${VETH1_POSTFIX} |
| 82 | NS0=root |
| 83 | NS1=af_xdp${VETH1_POSTFIX} |
| 84 | MTU=1500 |
| 85 | |
| 86 | setup_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 | |
| 101 | validate_root_exec |
| 102 | validate_veth_support ${VETH0} |
| 103 | validate_ip_utility |
| 104 | setup_vethPairs |
| 105 | |
| 106 | retval=$? |
| 107 | if [ $retval -ne 0 ]; then |
| 108 | test_status $retval "${TEST_NAME}" |
| 109 | cleanup_exit ${VETH0} ${VETH1} ${NS1} |
| 110 | exit $retval |
| 111 | fi |
| 112 | |
| 113 | echo "${VETH0}:${VETH1},${NS1}" > ${SPECFILE} |
| 114 | |
| 115 | validate_veth_spec_file |
| 116 | |
| 117 | echo "Spec file created: ${SPECFILE}" |
| 118 | |
| 119 | test_status $retval "${TEST_NAME}" |
| 120 | |
| 121 | ## START TESTS |
| 122 | |
| 123 | statusList=() |
| 124 | |
| 125 | ### TEST 1 |
| 126 | TEST_NAME="XSK KSELFTEST FRAMEWORK" |
| 127 | |
| 128 | echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Generic mode" |
| 129 | vethXDPgeneric ${VETH0} ${VETH1} ${NS1} |
| 130 | |
| 131 | retval=$? |
| 132 | if [ $retval -eq 0 ]; then |
| 133 | echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Native mode" |
| 134 | vethXDPnative ${VETH0} ${VETH1} ${NS1} |
| 135 | fi |
| 136 | |
| 137 | retval=$? |
| 138 | test_status $retval "${TEST_NAME}" |
| 139 | statusList+=($retval) |
| 140 | |
| 141 | ## END TESTS |
| 142 | |
| 143 | cleanup_exit ${VETH0} ${VETH1} ${NS1} |
| 144 | |
| 145 | for _status in "${statusList[@]}" |
| 146 | do |
| 147 | if [ $_status -ne 0 ]; then |
| 148 | test_exit $ksft_fail 0 |
| 149 | fi |
| 150 | done |
| 151 | |
| 152 | test_exit $ksft_pass 0 |