Skip to content

Commit

Permalink
AF_XDP-forwarding: move xsk_fwd to bpf-examples
Browse files Browse the repository at this point in the history
Move the xsk_fwd example application from the Linux repo to
bpf-examples. This sample demonstrates the ability to share a umem
between multiple sockets by implementing a simple packet forwarding
application. It also has a buffer pool manager for allocating and
freeing packet buffers.

Signed-off-by: Magnus Karlsson <[email protected]>
  • Loading branch information
magnus-karlsson committed Sep 21, 2022
1 parent c0565f3 commit dbf4feb
Show file tree
Hide file tree
Showing 4 changed files with 1,131 additions and 0 deletions.
9 changes: 9 additions & 0 deletions AF_XDP-forwarding/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)

USER_TARGETS := xsk_fwd

LDLIBS += -lpthread

LIB_DIR = ../lib

include $(LIB_DIR)/common.mk
28 changes: 28 additions & 0 deletions AF_XDP-forwarding/README.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#+Title: AF_XDP socket multi-threaded forwarding sample application

This sample code could originally be found in the Linux source code
tree under samples/bpf. It illustrates the packet forwarding between
multiple AF_XDP sockets in multi-threading environment. All the
threads and sockets are sharing a common buffer pool, with each socket
having its own private buffer cache. The sockets are created with the
xsk_socket__create_shared() function, which allows multiple AF_XDP
sockets to share the same UMEM object.

Example 1: Single thread handling two sockets. Packets received from
socket A (on top of interface IFA, queue QA) are forwarded to socket B
(on top of interface IFB, queue QB) and vice-versa. The thread is
affinitized to CPU core C:

#+BEGIN_SRC sh
./xsk_fwd -i IFA -q QA -i IFB -q QB -c C
#+END_SRC

Example 2: Two threads, each handling two sockets. Packets from socket
A are sent to socket B (by thread X), packets from socket B are sent
to socket A (by thread X); packets from socket C are sent to socket D
(by thread Y), packets from socket D are sent to socket C (by thread
Y). The two threads are bound to CPU cores CX and CY:

#+BEGIN_SRC sh
./xdp_fwd -i IFA -q QA -i IFB -q QB -i IFC -q QC -i IFD -q QD -c CX -c CY
#+END_SRC
Loading

0 comments on commit dbf4feb

Please sign in to comment.