Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
sudo: required
language: bash
dist: bionic
services:
- docker

env:
global:
- PROJECT_NAME='libbpf'
- AUTHOR_EMAIL="$(git log -1 --pretty=\"%aE\")"
- REPO_ROOT="$TRAVIS_BUILD_DIR"
- CI_ROOT="$REPO_ROOT/travis-ci"
- VMTEST_ROOT="$CI_ROOT/vmtest"

addons:
apt:
packages:
- qemu-kvm
- zstd
- binutils-dev
- elfutils
- libcap-dev
- libelf-dev
- libdw-dev
- python3-docutils

jobs:
include:
- stage: Builds & Tests
name: Kernel LATEST + selftests
language: bash
env: KERNEL=LATEST
script: $CI_ROOT/vmtest/run_vmtest.sh || travis_terminate 1
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -19127,6 +19127,7 @@ F: include/uapi/linux/if_xdp.h
F: net/xdp/
F: samples/bpf/xdpsock*
F: tools/lib/bpf/xsk*
F: tools/testing/selftests/xsk/

XEN BLOCK SUBSYSTEM
M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ TARGETS += tpm2
TARGETS += user
TARGETS += vm
TARGETS += x86
TARGETS += xsk
TARGETS += zram
#Please keep the TARGETS list alphabetically sorted
# Run "make quicktest=1 run_tests" or
Expand Down
34 changes: 34 additions & 0 deletions tools/testing/selftests/xsk/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SPDX-License-Identifier: GPL-2.0
# Copyright(c) 2020 Intel Corporation.

CFLAGS += -O2 -g -std=gnu99 -Wall -I../../../../usr/include/

XSKDIR := $(realpath ./xdpprogs)
XSKOBJ := xdpxceiver

TEST_PROGS := TEST_PREREQUISITES.sh \
TEST_XSK_SKB_NOPOLL.sh \
TEST_XSK_SKB_POLL.sh \
TEST_XSK_DRV_NOPOLL.sh \
TEST_XSK_DRV_POLL.sh \
TEST_XSK_SKB_TEARDOWN.sh \
TEST_XSK_DRV_TEARDOWN.sh \
TEST_XSK_SKB_BIDIRECTIONAL.sh \
TEST_XSK_DRV_BIDIRECTIONAL.sh
TEST_FILES := prereqs.sh xskenv.sh
TEST_TRANSIENT_FILES := veth.spec
TEST_PROGS_EXTENDED := $(XSKDIR)/$(XSKOBJ)

all: $(TEST_PROGS_EXTENDED)

KSFT_KHDR_INSTALL := 1
include ../lib.mk

$(TEST_PROGS_EXTENDED): $(XSKDIR)/$(XSKOBJ)

$(XSKDIR)/$(XSKOBJ):
cd $(XSKDIR) && $(MAKE)

override define CLEAN
cd $(XSKDIR) && $(MAKE) clean
endef
125 changes: 125 additions & 0 deletions tools/testing/selftests/xsk/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
Copyright (c) 2020 Intel Corporation, Weqaar Janjua <weqaar.a.janjua@intel.com>

AF_XDP selftests based on veth

# End-to-end AF_XDP over Veth test
#
# Topology:
# ---------
# -----------
# _ | Process | _
# / ----------- \
# / | \
# / | \
# ----------- | -----------
# | Thread1 | | | Thread2 |
# ----------- | -----------
# | | |
# ----------- | -----------
# | xskX | | | xskY |
# ----------- | -----------
# | | |
# ----------- | ----------
# | vethX | --------- | vethY |
# ----------- peer ----------
# | | |
# namespaceX | namespaceY

AF_XDP is an address family optimized for high performance packet processing,
it is XDP’s user-space interface.

An AF_XDP socket is linked to a single UMEM which is a region of virtual
contiguous memory, divided into equal-sized frames.

Refer to AF_XDP Kernel Documentation for detailed information:
https://www.kernel.org/doc/html/latest/networking/af_xdp.html

The test program contains two threads, each thread is single socket with
a unique UMEM. It validates in-order packet delivery and packet content
by sending packets to each other.

Prerequisites setup by script TEST_PREREQUISITES.sh:

Set up veth interfaces as per the topology shown ^^:
* setup two veth interfaces and one namespace
** veth<xxxx> in root namespace
** veth<yyyy> in af_xdp<xxxx> namespace
** namespace af_xdp<xxxx>
* create a spec file veth.spec that includes this run-time configuration
that is read by test scripts - filenames prefixed with TEST_XSK_
*** xxxx and yyyy are randomly generated 4 digit numbers used to avoid
conflict with any existing interface

Tests Information:
------------------
These selftests test AF_XDP SKB and Native/DRV modes using veth
Virtual Ethernet interfaces.

The following tests are run:

1. AF_XDP SKB mode
Generic mode XDP is driver independent, used when the driver does
not have support for XDP. Works on any netdevice using sockets and
generic XDP path. XDP hook from netif_receive_skb().
a. nopoll - soft-irq processing
b. poll - using poll() syscall
c. Socket Teardown
Create a Tx and a Rx socket, Tx from one socket, Rx on another. Destroy
both sockets, then repeat multiple times. Only nopoll mode is used
d. Bi-directional sockets
Configure sockets as bi-directional tx/rx sockets, sets up fill and
completion rings on each socket, tx/rx in both directions. Only nopoll
mode is used

2. AF_XDP DRV/Native mode
Works on any netdevice with XDP_REDIRECT support, driver dependent. Processes
packets before SKB allocation. Provides better performance than SKB. Driver
hook available just after DMA of buffer descriptor.
a. nopoll
b. poll
c. Socket Teardown
d. Bi-directional sockets
* Only copy mode is supported because veth does not currently support
zero-copy mode

Total tests: 8.

Flow:
* Single process spawns two threads: Tx and Rx
* Each of these two threads attach to a veth interface within their assigned
namespaces
* Each thread Creates one AF_XDP socket connected to a unique umem for each
veth interface
* Tx thread Transmits 10k packets from veth<xxxx> to veth<yyyy>
* Rx thread verifies if all 10k packets were received and delivered in-order,
and have the right content

Enable/disable debug mode:
--------------------------
To enable L2 - L4 headers and payload dump of each packet on STDOUT, add
parameter -D to params array in TEST_XSK_<TEST>.sh, i.e. params=("-S" "-D")

Kernel configuration:
---------------------
See "config" file for recommended kernel config options.

Turn on XDP sockets and veth support when compiling i.e.
Networking support -->
Networking options -->
[ * ] XDP sockets

Executing Tests:
----------------
Must run with CAP_NET_ADMIN capability.

Run (summary only):
sudo make summary=1 run_tests

Run (full color-coded output):
sudo make colorconsole=1 run_tests

Run (full output without color-coding):
sudo make run_tests

Clean:
make clean
53 changes: 53 additions & 0 deletions tools/testing/selftests/xsk/TEST_PREREQUISITES.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright(c) 2020 Intel Corporation.

. prereqs.sh

TEST_NAME="PREREQUISITES"

URANDOM=/dev/urandom
[ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit 1 1; }

VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
VETH0=ve${VETH0_POSTFIX}
VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
VETH1=ve${VETH1_POSTFIX}
NS1=af_xdp${VETH1_POSTFIX}
IPADDR_VETH0=192.168.222.1/30
IPADDR_VETH1=192.168.222.2/30
MTU=1500

setup_vethPairs() {
echo "setting up ${VETH0}: root: ${IPADDR_VETH0}"
ip netns add ${NS1}
ip link add ${VETH0} type veth peer name ${VETH1}
ip addr add dev ${VETH0} ${IPADDR_VETH0}
echo "setting up ${VETH1}: ${NS1}: ${IPADDR_VETH1}"
ip link set ${VETH1} netns ${NS1}
ip netns exec ${NS1} ip addr add dev ${VETH1} ${IPADDR_VETH1}
ip netns exec ${NS1} ip link set ${VETH1} mtu ${MTU}
ip netns exec ${NS1} ip link set ${VETH1} up
ip link set ${VETH0} mtu ${MTU}
ip link set ${VETH0} up
}

validate_root_exec
validate_veth_support ${VETH0}
validate_configs
setup_vethPairs

retval=$?
if [ $retval -ne 0 ]; then
test_status $retval "${TEST_NAME}"
cleanup_exit ${VETH0} ${VETH1} ${NS1}
exit $retval
fi

echo "${VETH0}:${VETH1},${NS1}" > ${SPECFILE}

echo "Spec file created: ${SPECFILE}"

test_status $retval "${TEST_NAME}"

exit $retval
15 changes: 15 additions & 0 deletions tools/testing/selftests/xsk/TEST_XSK.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright(c) 2020 Intel Corporation.

. prereqs.sh
. xskenv.sh

TEST_NAME="XSK FRAMEWORK"

test_status $ksft_pass "${TEST_NAME}"

# Must be called in the last test to execute
cleanup_exit ${VETH0} ${VETH1} ${NS1}

test_exit $ksft_pass 0
22 changes: 22 additions & 0 deletions tools/testing/selftests/xsk/TEST_XSK_DRV_BIDIRECTIONAL.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright(c) 2020 Intel Corporation.

#Includes
. prereqs.sh
. xskenv.sh

TEST_NAME="DRV BIDIRECTIONAL SOCKETS"

vethXDPnative ${VETH0} ${VETH1} ${NS1}

params=("-N" "-B")
execxdpxceiver params

retval=$?
test_status $retval "${TEST_NAME}"

# Must be called in the last test to execute
cleanup_exit ${VETH0} ${VETH1} ${NS1}

test_exit $retval 0
18 changes: 18 additions & 0 deletions tools/testing/selftests/xsk/TEST_XSK_DRV_NOPOLL.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright(c) 2020 Intel Corporation.

. prereqs.sh
. xskenv.sh

TEST_NAME="DRV NOPOLL"

vethXDPnative ${VETH0} ${VETH1} ${NS1}

params=("-N")
execxdpxceiver params

retval=$?
test_status $retval "${TEST_NAME}"

test_exit $retval 0
18 changes: 18 additions & 0 deletions tools/testing/selftests/xsk/TEST_XSK_DRV_POLL.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright(c) 2020 Intel Corporation.

. prereqs.sh
. xskenv.sh

TEST_NAME="DRV POLL"

vethXDPnative ${VETH0} ${VETH1} ${NS1}

params=("-N" "-p")
execxdpxceiver params

retval=$?
test_status $retval "${TEST_NAME}"

test_exit $retval 0
18 changes: 18 additions & 0 deletions tools/testing/selftests/xsk/TEST_XSK_DRV_TEARDOWN.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright(c) 2020 Intel Corporation.

. prereqs.sh
. xskenv.sh

TEST_NAME="DRV SOCKET TEARDOWN"

vethXDPnative ${VETH0} ${VETH1} ${NS1}

params=("-N" "-T")
execxdpxceiver params

retval=$?
test_status $retval "${TEST_NAME}"

test_exit $retval 0
19 changes: 19 additions & 0 deletions tools/testing/selftests/xsk/TEST_XSK_SKB_BIDIRECTIONAL.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright(c) 2020 Intel Corporation.

#Includes
. prereqs.sh
. xskenv.sh

TEST_NAME="SKB BIDIRECTIONAL SOCKETS"

vethXDPgeneric ${VETH0} ${VETH1} ${NS1}

params=("-S" "-B")
execxdpxceiver params

retval=$?
test_status $retval "${TEST_NAME}"

test_exit $retval 0
18 changes: 18 additions & 0 deletions tools/testing/selftests/xsk/TEST_XSK_SKB_NOPOLL.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright(c) 2020 Intel Corporation.

. prereqs.sh
. xskenv.sh

TEST_NAME="SKB NOPOLL"

vethXDPgeneric ${VETH0} ${VETH1} ${NS1}

params=("-S")
execxdpxceiver params

retval=$?
test_status $retval "${TEST_NAME}"

test_exit $retval 0
Loading