aboutsummaryrefslogtreecommitdiffstats
path: root/extras
diff options
context:
space:
mode:
authorBenoît Ganne <bganne@cisco.com>2020-06-12 08:47:34 +0200
committerDamjan Marion <dmarion@me.com>2020-08-31 17:16:56 +0000
commit4a76d6f6da035220917097bc047b08bc58254803 (patch)
tree10399485df66c0ebeeaa32edbb7a1022b8baa9b3 /extras
parentbfed7c047d2807f835cd7b9ef0330d314ac0ebc5 (diff)
af_xdp: AF_XDP input plugin
Type: feature Change-Id: I85aa4ad6b68c1aa0e51938002dc691a4b11c545c Signed-off-by: Damjan Marion <damarion@cisco.com> Signed-off-by: Benoît Ganne <bganne@cisco.com>
Diffstat (limited to 'extras')
-rw-r--r--extras/bpf/Makefile17
-rw-r--r--extras/bpf/af_xdp.bpf.c88
2 files changed, 105 insertions, 0 deletions
diff --git a/extras/bpf/Makefile b/extras/bpf/Makefile
new file mode 100644
index 00000000000..77b06434237
--- /dev/null
+++ b/extras/bpf/Makefile
@@ -0,0 +1,17 @@
+CC?=clang
+# where to find bpf includes?
+BPF_ROOT?=/usr/include
+#BPF_ROOT?=/opt/vpp/external/x86_64/include
+
+CFLAGS:=-O3 -g -Wextra -Wall -target bpf
+# Workaround for Ubuntu/Debian for asm/types.h
+CFLAGS+= -I/usr/include/x86_64-linux-gnu
+CFLAGS+= -I$(BPF_ROOT)
+#CFLAGS+= -DDEBUG
+
+all: af_xdp.bpf.o
+
+clean:
+ $(RM) af_xdp.bpf.o
+
+.PHONY: all clean
diff --git a/extras/bpf/af_xdp.bpf.c b/extras/bpf/af_xdp.bpf.c
new file mode 100644
index 00000000000..eddd2b0e509
--- /dev/null
+++ b/extras/bpf/af_xdp.bpf.c
@@ -0,0 +1,88 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0 OR Apache-2.0
+ * Dual-licensed under GPL version 2.0 or Apache License version 2.0
+ * Copyright (c) 2020 Cisco and/or its affiliates.
+ */
+#include <linux/bpf.h>
+#include <linux/in.h>
+#include <linux/if_ether.h>
+#include <linux/ip.h>
+#include <linux/udp.h>
+#include <bpf/bpf_helpers.h>
+
+/*
+ * when compiled, debug print can be viewed with eg.
+ * sudo cat /sys/kernel/debug/tracing/trace_pipe
+ */
+#ifdef DEBUG
+#define s__(n) # n
+#define s_(n) s__(n)
+#define x_(fmt) __FILE__ ":" s_(__LINE__) ": " fmt "\n"
+#define DEBUG_PRINT_(fmt, ...) do { \
+ const char fmt__[] = fmt; \
+ bpf_trace_printk(fmt__, sizeof(fmt), ## __VA_ARGS__); } while(0)
+#define DEBUG_PRINT(fmt, ...) DEBUG_PRINT_ (x_(fmt), ## __VA_ARGS__)
+#else /* DEBUG */
+#define DEBUG_PRINT(fmt, ...)
+#endif /* DEBUG */
+
+#define ntohs(x) __constant_ntohs(x)
+
+SEC("maps")
+struct bpf_map_def xsks_map = {
+ .type = BPF_MAP_TYPE_XSKMAP,
+ .key_size = sizeof(int),
+ .value_size = sizeof(int),
+ .max_entries = 64, /* max 64 queues per device */
+};
+
+SEC("xdp_sock")
+int xdp_sock_prog(struct xdp_md *ctx) {
+ const void *data = (void *)(long)ctx->data;
+ const void *data_end = (void *)(long)ctx->data_end;
+
+ DEBUG_PRINT("rx %ld bytes packet", (long)data_end - (long)data);
+
+ /* smallest packet we are interesting in is ip-ip */
+ if (data + sizeof(struct ethhdr) + 2 * sizeof(struct iphdr) > data_end) {
+ DEBUG_PRINT("packet too small");
+ return XDP_PASS;
+ }
+
+ const struct ethhdr *eth = data;
+ if (eth->h_proto != ntohs(ETH_P_IP)) {
+ DEBUG_PRINT("unsupported eth proto %x", (int)eth->h_proto);
+ return XDP_PASS;
+ }
+
+ const struct iphdr *ip = (void *)(eth + 1);
+ switch (ip->protocol) {
+ case IPPROTO_UDP: {
+ const struct udphdr *udp = (void *)(ip + 1);
+ if (udp->dest != ntohs(4789)) { /* VxLAN dest port */
+ DEBUG_PRINT("unsupported udp dst port %x", (int)udp->dest);
+ return XDP_PASS;
+ }
+ }
+ case IPPROTO_IPIP:
+ case IPPROTO_ESP:
+ break;
+ default:
+ DEBUG_PRINT("unsupported ip proto %x", (int)ip->protocol);
+ return XDP_PASS;
+ }
+
+ int qid = ctx->rx_queue_index;
+ if (!bpf_map_lookup_elem(&xsks_map, &qid))
+ {
+ DEBUG_PRINT("no socket found");
+ return XDP_PASS;
+ }
+
+ DEBUG_PRINT("going to socket %d", qid);
+ return bpf_redirect_map(&xsks_map, qid, 0);
+}
+
+/* actually Dual GPLv2/Apache2, but GPLv2 as far as kernel is concerned */
+SEC("license")
+char _license[] = "GPL";
/a> 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
# Copyright (c) 2019 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

*** Settings ***
| Resource | resources/libraries/robot/shared/default.robot
| ...
| Force Tags | 3_NODE_SINGLE_LINK_TOPO | PERFTEST | HW_ENV | NDRPDR
| ... | NIC_Intel-X710 | ETH | IP4FWD | BASE | VHOST | 1VM | VHOST_1024
| ... | NF_TESTPMD
| ...
| Suite Setup | Setup suite single link | performance
| Suite Teardown | Tear down suite | performance
| Test Setup | Setup test
| Test Teardown | Tear down test | performance | vhost
| ...
| Test Template | Local Template
| ...
| Documentation | *RFC2544: Pkt throughput IPv4 test cases with vhost*
| ...
| ... | *[Top] Network Topologies:* TG-DUT1-DUT2-TG 3-node circular topology
| ... | with single links between nodes.
| ... | *[Enc] Packet Encapsulations:* Eth-IPv4 for IPv4 routing.
| ... | *[Cfg] DUT configuration:* DUT1 and DUT2 are configured with IPv4
| ... | routing and two static IPv4 /24 route entries. Qemu VNFs are \
| ... | connected to VPP via vhost-user interfaces. Guest is running testpmd \
| ... | interconnecting vhost-user interfaces, rxd/txd=1024. DUT1/DUT2 is \
| ... | tested with ${nic_name}.
| ... | *[Ver] TG verification:* TG finds and reports throughput NDR (Non Drop\
| ... | Rate) with zero packet loss tolerance and throughput PDR (Partial Drop\
| ... | Rate) with non-zero packet loss tolerance (LT) expressed in percentage\
| ... | of packets transmitted. NDR and PDR are discovered for different\
| ... | Ethernet L2 frame sizes using MLRsearch library.\
| ... | Test packets are generated by TG on links to DUTs. TG traffic profile
| ... | contains two L3 flow-groups (flow-group per direction, 253 flows per
| ... | flow-group) with all packets containing Ethernet header, IPv4 header
| ... | with IP protocol=61 and static payload. MAC addresses are matching MAC
| ... | addresses of the TG node interfaces.
| ... | *[Ref] Applicable standard specifications:* RFC2544.

*** Variables ***
| @{plugins_to_enable}= | dpdk_plugin.so
| ${osi_layer}= | L3
| ${nic_name}= | Intel-X710
| ${overhead}= | ${0}
| ${nf_dtcr}= | ${1}
| ${nf_dtc}= | ${1}
| ${nf_chains}= | ${1}
| ${nf_nodes}= | ${1}
# Traffic profile:
| ${traffic_profile}= | trex-sl-3n-ethip4-ip4src253

*** Keywords ***
| Local Template
| | [Documentation]
| | ... | [Cfg] DUT runs IPv4 routing config.
| | ... | Each DUT uses ${phy_cores} physical core(s) for worker threads.
| | ... | [Ver] Measure NDR and PDR values using MLRsearch algorithm.\
| | ...
| | ... | *Arguments:*
| | ... | - frame_size - Framesize in Bytes in integer or string (IMIX_v4_1).
| | ... | Type: integer, string
| | ... | - phy_cores - Number of physical cores. Type: integer
| | ... | - rxq - Number of RX queues, default value: ${None}. Type: integer
| | ...
| | [Arguments] | ${frame_size} | ${phy_cores} | ${rxq}=${None}
| | ...
| | Set Test Variable | \${frame_size}
| | ...
| | Given Add worker threads and rxqueues to all DUTs | ${phy_cores} | ${rxq}
| | And Add PCI devices to all DUTs
| | And Set Max Rate And Jumbo And Handle Multi Seg
| | And Apply startup configuration on all VPP DUTs
| | When Initialize IPv4 forwarding with vhost in 3-node circular topology
| | ... | nf_nodes=${nf_nodes} | testpmd_mac=${TRUE}
| | And Configure chains of NFs connected via vhost-user
| | ... | nf_chains=${nf_chains} | nf_nodes=${nf_nodes} | jumbo=${jumbo}
| | ... | use_tuned_cfs=${False} | auto_scale=${True} | vnf=testpmd_mac
| | Then Find NDR and PDR intervals using optimized search

*** Test Cases ***
| tc01-64B-1c-ethip4-ip4base-eth-2vhostvr1024-1vm-ndrpdr
| | [Tags] | 64B | 1C
| | frame_size=${64} | phy_cores=${1}

| tc02-64B-2c-ethip4-ip4base-eth-2vhostvr1024-1vm-ndrpdr
| | [Tags] | 64B | 2C
| | frame_size=${64} | phy_cores=${2}

| tc03-64B-4c-ethip4-ip4base-eth-2vhostvr1024-1vm-ndrpdr
| | [Tags] | 64B | 4C
| | frame_size=${64} | phy_cores=${4}

| tc04-1518B-1c-ethip4-ip4base-eth-2vhostvr1024-1vm-ndrpdr
| | [Tags] | 1518B | 1C
| | frame_size=${1518} | phy_cores=${1}

| tc05-1518B-2c-ethip4-ip4base-eth-2vhostvr1024-1vm-ndrpdr
| | [Tags] | 1518B | 2C
| | frame_size=${1518} | phy_cores=${2}

| tc06-1518B-4c-ethip4-ip4base-eth-2vhostvr1024-1vm-ndrpdr
| | [Tags] | 1518B | 4C
| | frame_size=${1518} | phy_cores=${4}

| tc07-9000B-1c-ethip4-ip4base-eth-2vhostvr1024-1vm-ndrpdr
| | [Tags] | 9000B | 1C
| | frame_size=${9000} | phy_cores=${1}

| tc08-9000B-2c-ethip4-ip4base-eth-2vhostvr1024-1vm-ndrpdr
| | [Tags] | 9000B | 2C
| | frame_size=${9000} | phy_cores=${2}

| tc09-9000B-4c-ethip4-ip4base-eth-2vhostvr1024-1vm-ndrpdr
| | [Tags] | 9000B | 4C
| | frame_size=${9000} | phy_cores=${4}

| tc10-IMIX-1c-ethip4-ip4base-eth-2vhostvr1024-1vm-ndrpdr
| | [Tags] | IMIX | 1C
| | frame_size=IMIX_v4_1 | phy_cores=${1}

| tc11-IMIX-2c-ethip4-ip4base-eth-2vhostvr1024-1vm-ndrpdr
| | [Tags] | IMIX | 2C
| | frame_size=IMIX_v4_1 | phy_cores=${2}

| tc12-IMIX-4c-ethip4-ip4base-eth-2vhostvr1024-1vm-ndrpdr
| | [Tags] | IMIX | 4C
| | frame_size=IMIX_v4_1 | phy_cores=${4}