-
-
Notifications
You must be signed in to change notification settings - Fork 568
af_xdp tests for Linux 4.19
First of all, please install 4.19 kernel for your Ubuntu machine this way
I will use Ubuntu 18.04.
In this guide I will build example AF_XDP application without using any bundled make files from kernel to get more understanding what's going on inside.
We need compilers:
sudo apt-get update
sudo apt-get install -y clang llvm gcc make
Pull source code:
cd
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.19.tar.xz
tar -xf linux-4.19.tar.xz
cd linux-4.19
Build bpf library:
sudo apt-get install -y libelf-dev
cd /root/linux-4.19/tools/lib/bpf
make
mkdir /opt/libbpf
cp libbpf.so libbpf.a /opt/libbpf
mkdir -p /opt/libbpf/include/bpf
cp bpf.h libbpf.h /opt/libbpf/include/bpf
I use this unpretty way for fixing compilation errors because I can't use include from new kernel due to minor make-kpkg bug:
cp ~/linux-4.19/include/uapi/linux/if_xdp.h /usr/include/linux/if_xdp.h
cp ~/linux-4.19/include/uapi/linux/if_link.h /usr/include/linux/if_link.h
cp ~/linux-4.19/include/uapi/linux/bpf.h /usr/include/linux/bpf.h
And finally build main example for AF_XDP from developers:
cd /root/linux-4.19/samples/bpf
gcc xdpsock_user.c -o xdpsock_user -lpthread -L/opt/libbpf -lbpf -lelf -I/opt/libbpf/include -I/root/linux-4.19/tools/testing/selftests/bpf
Build BPF tool (keep your mind sane! Build command has huge number of tricky things, I copy'n'pasted it from official examples):
clang -c xdpsock_kern.c -I/root/linux-4.19/include -I/root/linux-4.19/tools/testing/selftests/bpf -D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign -Wno-compare-distinct-pointer-types -Wno-gnu-variable-sized-type-not-at-end -Wno-address-of-packed-member -Wno-tautological-compare -Wno-unknown-warning-option -O2 -emit-llvm -c -o -| llc -march=bpf -filetype=obj -o xdpsock_user_kern.o
Also, you must change this structure, first 16 bytes should specify ethernet addresses (MAC destination / MAC source):
static const char pkt_data[] =
"\xec\x0d\x9a\x84\x40\xb6\xec\x0d\x9a\x84\x40\xda\x08\x00\x45\x00"
"\x00\x2e\x00\x00\x00\x00\x40\x11\x88\x97\x05\x08\x07\x08\xc8\x14"
"\x1e\x04\x10\x92\x10\x92\x00\x1a\x6d\xa3\x34\x33\x1f\x69\x40\x6b"
"\x54\x59\xb6\x14\x2d\x11\x44\xbf\xaf\xd9\xbe\xaa";
To implement processing properly, you must target all traffic to queue 16 using flow director (I used Mellanox CX-4 and you can use ixgbe also):
ethtool -N enP9p144s0f0 flow-type udp4 src-port 4242 dst-port 4242 action 16
Run receiver tool:
LD_LIBRARY_PATH=/opt/libbpf ./xdpsock_user --rxdrop --interface enP9p144s0f0 --queue=16
Traffic generation command:
LD_LIBRARY_PATH=/opt/libbpf ./xdpsock_user --txonly --interface enP9p144s0f0
Expected output for traffic generator:
sock0@enP9p144s0f0:0 txonly
pps pkts 0.10
rx 0 0
tx 0 292,352,353
Receiver side:
sock0@enP9p144s0f0:16 rxdrop
pps pkts 0.23
rx 0 297,753,014
tx 0 0