Backend for the P4 compiler targeting XDP
Switch branches/tags
Nothing to show
Clone or download
Permalink
Failed to load latest commit information.
doc doc: add pdf file Oct 18, 2018
lib Revert "lib: make bpf.h local" Mar 9, 2017
p4include csum: add csum_replace4 for 4-byte value Mar 1, 2017
tests Integrate the XDP compiler with the parent eBPF compiler test framewo… Sep 20, 2018
.gitignore Update figures in testing section. (#92) Oct 11, 2018
.travis.yml Travis tests. (#78) Oct 1, 2018
AUTHORS license: add license and authors Mar 6, 2017
CMakeLists.txt Integrate the XDP compiler with the parent eBPF compiler test framewo… Sep 20, 2018
Dockerfile Add some more citations (#89) Oct 8, 2018
LICENSE LICENSE: add license file Mar 6, 2017
README.md Travis tests. (#78) Oct 1, 2018
Vagrantfile vagrant: update to kernel 4.11-rc1 Mar 9, 2017
compile-bpf.sh fix a couple bug and add test script Dec 22, 2016
ovs-parse-14.p4 add p4 files Dec 21, 2016
ovs.c ovs.p4: add multiple actions and bitmap support Dec 24, 2016
ovs.p4 ovs.p4: add multiple actions and bitmap support Dec 24, 2016
p4c-xdp.cpp Fix options (#61) Dec 1, 2017
run-bpf.sh ovs.p4: add multiple actions and bitmap support Dec 24, 2016
run-p4c-xdp.sh Fix options (#61) Dec 1, 2017
target.cpp Integrate the XDP compiler with the parent eBPF compiler test framewo… Sep 20, 2018
target.h Integrate the XDP compiler with the parent eBPF compiler test framewo… Sep 20, 2018
test_ebpf_map.c Add ebpf map test Dec 22, 2016
xdpBackend.cpp Fix build failures (#75) Sep 8, 2018
xdpBackend.h Renamed files and project Feb 2, 2017
xdpControl.cpp Updated to match changes in IR Apr 18, 2017
xdpControl.h Support for control-plane Feb 9, 2017
xdpModel.cpp Backported changes to ebpf back-end; reorganized code Jan 16, 2017
xdpModel.h Updated to match changes in IR Apr 18, 2017
xdpProgram.cpp Fix build failures (#75) Sep 8, 2018
xdpProgram.h Moved to cmake (#49) Jul 27, 2017
xdp_target.py Update xdp_target.py (#84) Oct 2, 2018

README.md

p4c-xdp

Build Status Apache licensed GPL licensed

This work presents a P4 compiler backend targeting XDP, the eXpress Data Path. P4 is a domain-specific language describing how packets are processed by the data plane of a programmable network elements, including network interface cards, appliances, and virtual switches. With P4, programmers focus on defining the protocol parsing, matching, and action executions, instead of the platform-specific language or implementation details.

XDP is designed for users who want programmability as well as performance. XDP allows users to write a C-like packet processing program and loads into the device driver's receiving queue. When the device observes an incoming packet, before hanging the packet to the Linux stack, the user-defined XDP program is triggered to execute against the packet payload, making the decision as early as possible.

We bring together the benefits of the two: P4 and XDP. To get started, first you need to setup the P4-16 compiler, then this project is an extension to the P4-16. To execute the XDP, you need Linux kernel version >= 4.10.0-rc7+ due to some BPF verifier limitations

Presentation

Installation

Docker/Vagrant

Please see Dockerfile. There is also a public docker image available as u9012063/p4xdp

$ docker pull u9012063/p4xdp

will pull the latest image. However, the XDP BPF code has dependency on your kernel version. Currently for some complicated cases we require kernel >= 4.10.0-rc7. So a vagrant box is also provided with kernel 4.10.0-rc8.

$ vagrant up
$ vagrant ssh
ubuntu@ubuntu-xenial:~$ sudo su
root@ubuntu-xenial:/home/ubuntu# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
u9012063/p4xdp      latest              3c77fbbd84e5        41 hours ago        2.469 GB
root@ubuntu-xenial:/home/ubuntu# docker run -it -u root --privileged <IMAGE ID>

Will boot this VM, pull the docker image, and you can try p4c-xdp.

P4-16 Compiler

First you need to follow the installation guide of P4-16 When you have P4-16 compiler, then add this project as an extension. Assuming you have P4-16 at your dir ~/p4c/, to setup P4C-XDP:

cd ~/p4c/
mkdir extensions
cd extensions
git clone https://github.com/vmware/p4c-xdp.git

Now that you have cloned p4c-xdp at ~/p4c/extensions/p4c-xdp, the next step is to recompile p4c:

cd ~/p4c/
mkdir -p build
cd build/
cmake ..
make

This generates a p4c-xdp binary in ~/p4c/build. Next create a soft link to the binary:

cd ~/p4c/extensions/p4c-xdp
ln -s ~/p4c/build/p4c-xdp p4c-xdp

And a soft link to the xdp test target and the test runtime:

cd ~/p4c/extensions/p4c-xdp
ln -s ~/p4c/backends/ebpf/targets/xdp_target.py xdp_target.py
ln -s ~/p4c/backends/ebpf/run-ebpf-test.py run-ebpf-test.py

Now you can run the p4c-xdp tests:

cd ~/p4c/build/
make check-xdp

This will check your llvm and clang version, compile all .p4 files, generate .c files, and load them into the kernel to be checked by the BPF verifier.

XDP: eXpress Data Path

XDP is a packet processing mechanism implemented within the device driver with eBPF. Currently to compile a P4 to C program, uses

	# ./p4c-xdp --target xdp -o <output_c_file> <input_p4>
	./p4c-xdp --target xdp -o /tmp/xdp1.c xdp1.p4

then you need to compile the xdp1.c to eBPF bytecode, xdp1.o, then loaded into your driver. To compile a single .c file

clang -Wno-unused-value -Wno-pointer-sign \
		-Wno-compare-distinct-pointer-types \
		-Wno-gnu-variable-sized-type-not-at-end \
		-Wno-tautological-compare \
		-O2 -emit-llvm -g -c /tmp/xdp1.c -o -| llc -march=bpf -filetype=obj -o /tmp/xdp1.o

Then loaded into driver with XDP support

    ip link set dev $DEV xdp obj xdp1.o verb

to unload the XDP object

    ip link set dev $DEV xdp off

Sample Code

Please see the tests folder Simply run 'make' will start the build

Related BPF/XDP work

  • Dive into BPF: a list of reading material, Quentin Monnet link
  • BPF: Next Generation of Programmable Datapath by Thomas Graf, OVS Conf 2016 video
  • Fast Programmable Networks & Encapsulated Protocols, David S. Miller, netdev 1.2 video

License

The p4c-xdp/lib/* contains BPF loader licensed under the General Public License, Version 2.0. The rest of p4c-xdp components are licensed under the Apache License, Version 2.0.

TODO

  • Remove the private kernel patch requirement when latest kernel with BPF fixed is ready
  • Apply the workaround of BPF_MAX_STACK
  • Control plane example using perf_event_output