Coder Social home page Coder Social logo

larryderhummer / p4c-xdp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vmware-archive/p4c-xdp

0.0 1.0 0.0 9.67 MB

Backend for the P4 compiler targeting XDP

License: Apache License 2.0

Makefile 1.50% C++ 20.43% Shell 0.93% C 37.81% P4 34.86% CMake 1.74% Dockerfile 0.98% Python 1.76%

p4c-xdp's Introduction

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

Presentations

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 init u9012063/p4xdp
$ 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
ln -s ~/p4c p4c-xdp/p4c

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. And install the xdp test target in backends/ebpf/targets. 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 test runtime:

cd ~/p4c/extensions/p4c-xdp
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, use

	# ./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 load it 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 load it into the 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

p4c-xdp's People

Contributors

williamtu avatar fruffy avatar chengchuntu avatar hiroyuki-sato avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.