{"id":19297211,"url":"https://github.com/vmware-archive/p4c-xdp","last_synced_at":"2025-04-22T08:31:20.755Z","repository":{"id":15651512,"uuid":"76995441","full_name":"vmware-archive/p4c-xdp","owner":"vmware-archive","description":"Backend for the P4 compiler targeting XDP","archived":true,"fork":false,"pushed_at":"2023-01-19T17:26:33.000Z","size":9901,"stargazers_count":171,"open_issues_count":20,"forks_count":26,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-12-19T00:04:27.470Z","etag":null,"topics":["drivers","ebpf","p4c","xdp"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vmware-archive.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-20T22:10:02.000Z","updated_at":"2024-03-28T20:00:04.000Z","dependencies_parsed_at":"2023-02-11T12:45:29.263Z","dependency_job_id":null,"html_url":"https://github.com/vmware-archive/p4c-xdp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmware-archive%2Fp4c-xdp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmware-archive%2Fp4c-xdp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmware-archive%2Fp4c-xdp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmware-archive%2Fp4c-xdp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vmware-archive","download_url":"https://codeload.github.com/vmware-archive/p4c-xdp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250206154,"owners_count":21392195,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["drivers","ebpf","p4c","xdp"],"created_at":"2024-11-09T23:01:48.003Z","updated_at":"2025-04-22T08:31:15.721Z","avatar_url":"https://github.com/vmware-archive.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# p4c-xdp\n\nThis project has been archived.  For a more complete ebpf XDP compiler\nplease see the open-source p4c [repository](https://github.com/p4lang/p4c), in particular the p4c-ebpf \ncompiler. \n\n\n[![Main Build](https://github.com/vmware/p4c-xdp/actions/workflows/test.yml/badge.svg)](https://github.com/vmware/p4c-xdp/actions/workflows/test.yml)\n[![Apache licensed](https://img.shields.io/badge/license-Apache-blue.svg)](https://github.com/vmware/p4c-xdp/blob/master/LICENSE)\n[![GPL licensed](https://img.shields.io/badge/license-GPL-blue.svg)](https://github.com/vmware/p4c-xdp/blob/master/lib/COPYING)\n\nThis work presents a P4 compiler backend targeting XDP, the eXpress Data Path.\nP4 is a domain-specific language describing how packets are processed by the\ndata plane of a programmable network elements, including network interface\ncards, appliances, and virtual switches.  With P4, programmers focus on\ndefining the protocol parsing, matching, and action executions, instead\nof the platform-specific language or implementation details.\n\nXDP is designed for users who want programmability as well as performance.\nXDP allows users to write a C-like  packet processing program and loads into\nthe device driver's receiving queue.  When the device observes an incoming\npacket, before hanging the packet to the Linux stack, the user-defined XDP\nprogram is triggered to execute against the packet payload, making the\ndecision as early as possible.\n\nWe bring together the benefits of the two: P4 and XDP.  To get started,\nfirst you need to setup the P4-16 compiler, then this project\nis an extension to the P4-16. To execute the XDP, you need Linux kernel\nversion \u003e= 4.10.0-rc7+ due to some BPF verifier limitations\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"doc/images/p4xdp-workflow.png\" /\u003e\n\u003c/p\u003e\n\n## Presentations\n- IOVisor Summit 2017\n[slides](https://github.com/vmware/p4c-xdp/blob/master/doc/p4xdp-iovisor17.pdf),\n[demo1](https://youtu.be/On7hEJ6bPVU), [demo2](https://youtu.be/vlp1MzWVOc8), [demo3](https://youtu.be/TibGxCXPNVc)\n- Linux Plumbers' Conference 2018\n[slides](https://github.com/vmware/p4c-xdp/blob/master/doc/p4c-xdp-lpc18-presentation.pdf),\n[paper](https://github.com/vmware/p4c-xdp/blob/master/doc/lpc18.pdf)\n\n## Installation\n### Docker/Vagrant\nPlease see Dockerfile. There is also a public docker image available as u9012063/p4xdp\n```bash\n$ docker pull u9012063/p4xdp\n```\nwill pull the latest image. However, the XDP BPF code has dependency on your kernel version.\nCurrently for some complicated cases we require kernel \u003e= 4.10.0-rc7.  So a vagrant box is\nalso provided with kernel 4.10.0-rc8.\n```bash\n$ vagrant init u9012063/p4xdp\n$ vagrant up\n$ vagrant ssh\nubuntu@ubuntu-xenial:~$ sudo su\nroot@ubuntu-xenial:/home/ubuntu# docker images\nREPOSITORY          TAG                 IMAGE ID            CREATED             SIZE\nu9012063/p4xdp      latest              3c77fbbd84e5        41 hours ago        2.469 GB\nroot@ubuntu-xenial:/home/ubuntu# docker run -it -u root --privileged \u003cIMAGE ID\u003e\n```\nWill boot this VM, pull the docker image, and you can try p4c-xdp.\n\n### P4-16 Compiler\nFirst you need to follow the installation guide of [P4-16](https://github.com/p4lang/p4c/)\nWhen you have P4-16 compiler, then add this project as an extension.\nAssuming you have P4-16 at your dir  ~/p4c/, to setup P4C-XDP:\n```bash\ncd ~/p4c/\nmkdir extensions\ncd extensions\ngit clone https://github.com/vmware/p4c-xdp.git\nln -s ~/p4c p4c-xdp/p4c\n```\nNow that you have cloned p4c-xdp at ~/p4c/extensions/p4c-xdp, the next step is to\nrecompile p4c:\n```bash\ncd ~/p4c/\nmkdir -p build\ncd build/\ncmake ..\nmake\n```\nThis generates a p4c-xdp binary in ~/p4c/build. And install the xdp test target\nin `backends/ebpf/targets`.\nNext create a soft link to the binary:\n```bash\ncd ~/p4c/extensions/p4c-xdp\nln -s ~/p4c/build/p4c-xdp p4c-xdp\n```\nAnd a soft link to the test runtime:\n```bash\ncd ~/p4c/extensions/p4c-xdp\nln -s ~/p4c/backends/ebpf/run-ebpf-test.py run-ebpf-test.py\n\n```\nNow you can run the p4c-xdp tests:\n```\ncd ~/p4c/build/\nmake check-xdp\n```\nThis will check your llvm and clang version,\ncompile all .p4 files, generate .c files, and load them into the kernel\nto be checked by the BPF verifier.\n\n## XDP: eXpress Data Path\nXDP is a packet processing mechanism implemented within the device driver with eBPF.\nCurrently to compile a P4 to C program, use\n```bash\n\t# ./p4c-xdp --target xdp -o \u003coutput_c_file\u003e \u003cinput_p4\u003e\n\t./p4c-xdp --target xdp -o /tmp/xdp1.c xdp1.p4\n```\nthen you need to compile the xdp1.c to eBPF bytecode, xdp1.o, then load it\ninto your driver. To compile a single .c file\n```bash\nclang -Wno-unused-value -Wno-pointer-sign \\\n\t\t-Wno-compare-distinct-pointer-types \\\n\t\t-Wno-gnu-variable-sized-type-not-at-end \\\n\t\t-Wno-tautological-compare \\\n\t\t-O2 -emit-llvm -g -c /tmp/xdp1.c -o -| llc -march=bpf -filetype=obj -o /tmp/xdp1.o\n```\nThen load it into the driver with XDP support\n```bash\n    ip link set dev $DEV xdp obj xdp1.o verb\n```\nto unload the XDP object\n```bash\n    ip link set dev $DEV xdp off\n```\n## Sample Code\nPlease see the [tests folder](https://github.com/vmware/p4c-xdp/tree/master/tests)\nSimply run 'make' will start the build\n\n## Related BPF/XDP work\n * Dive into BPF: a list of reading material, Quentin Monnet [link](https://qmonnet.github.io/whirl-offload/2016/09/01/dive-into-bpf/)\n * BPF: Next Generation of Programmable Datapath by Thomas Graf, OVS Conf 2016 [video](https://www.youtube.com/watch?v=QJfmmoH2nSQ\u0026t=1046s)\n * Fast Programmable Networks \u0026 Encapsulated Protocols, David S. Miller, netdev 1.2 [video](https://www.youtube.com/watch?v=NlMQ0i09HMU)\n\n## License\nThe p4c-xdp/lib/\\* contains BPF loader licensed under the [General Public License, Version 2.0](lib/COPYING). The rest of p4c-xdp components are licensed under the [Apache License, Version 2.0](LICENSE).\n\n## TODO\n* Remove the private kernel patch requirement when latest kernel with BPF fixed is ready\n* Apply the workaround of BPF\\_MAX\\_STACK\n* Control plane example using perf\\_event\\_output\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmware-archive%2Fp4c-xdp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvmware-archive%2Fp4c-xdp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmware-archive%2Fp4c-xdp/lists"}