p4c-ebpf --arch psa -o OUTPUT.c test.p4
TODO specify difference between with and without --xdp
You can compile a P4-16 PSA program for eBPF in a single step using:
make -f backends/ebpf/runtime/kernel.mk BPFOBJ=out.o P4FILE=<P4-PROGRAM>.p4 P4C=p4c-ebpf psa
You can also perform compilation step by step:
TODO at the moment is not working fine, investigate.
$ p4c-ebpf --arch psa --target kernel -o out.c main.p4
$ clang -Ibackends/ebpf/runtime -Ibackends/ebpf/runtime/usr/include -O2 -g -c -emit-llvm -o out.bc out.c
$ llc -march=bpf -mcpu=generic -filetype=obj -o out.o out.bc
TODO Note about relative path that make sense to clang otherwise https://github.com/NIKSS-vSwitch/nikss/issues/101#issue-1724077656 solution https://github.com/NIKSS-vSwitch/nikss/issues/101#issuecomment-1564308258
Note that you can use -mcpu
flag to define the eBPF instruction set. Visit this blog post to learn more about eBPF instruction sets.
The above steps generate out.o
BPF object file that can be loaded to the kernel.
To load eBPF programs generated by P4-eBPF compiler run:
$ nikss-ctl pipeline load id <PIPELINE-ID> out.o
Note you migth need to use sudo
PIPELINE-ID is a user-defined value used to uniquely identify PSA-eBPF pipeline (we are going to support for multiple PSA-eBPF pipelines running in parallel). In the next step, for each interface that should be attached to PSA-eBPF run:
$ nikss-ctl add-port pipe <PIPELINE-ID> dev <INTF>
Note you migth need to use sudo
The PSA implementation for eBPF backend generates standard BPF objects that can be inspected using bpftool.
To troubleshoot PSA-eBPF program you will probably need bpftool. Follow the steps below to install it.
You should be able to see bpftool help:
$ bpftool help
Usage: bpftool [OPTIONS] OBJECT { COMMAND | help }
bpftool batch file FILE
bpftool version
OBJECT := { prog | map | link | cgroup | perf | net | feature | btf | gen | struct_ops | iter }
OPTIONS := { {-j|--json} [{-p|--pretty}] | {-f|--bpffs} |
{-m|--mapcompat} | {-n|--nomount} }
You can install it via:
sudo apt install linux-tools-common
Refer to the bpftool guide for more examples how to use it.