p4c
p4c copied to clipboard
p4c ebpf backend
can anyone share me the source code of p4 that can be translated to ebpf code using ebpf_model.p4 architecture . As i am new to this area and dont have much idea about it, it will be really helpful . Thanks in advance!!
You can try any program from testdata/p4_16_samples/ *_ebpf.p4
Correct, the tests are collected here in CMake: https://github.com/p4lang/p4c/blob/main/backends/ebpf/CMakeLists.txt#L178
You can run a test like this:
backends/ebpf/run-ebpf-test.py -t kernel -c "build/p4c-ebpf" /mnt/storage/Projekte/gauntlet/modules/p4c "$@" testdata/p4_16_samples/action_call_table_ebpf.p4
under the hood this script invokes
p4c/build/p4c-ebpf --Werror -I./p4include --target kernel -o build/tmpfolder/test.c testdata/p4_16_samples/action_call_table_ebpf.p4
Note that you need the appropriate kernel version and the dependencies listed in the eBPF back end in order to make this work.
thanks for responding i have one more issue, while trying to run the test-cases for p4tc samples with tc backend then i got the following errors, can you please help me how to resolve it .
/usr/share/p4c/p4include/tc/pna.p4(871): [--Werror=type-error] error: package PNA_NIC package PNA_NIC<MH, MM>( ^^^^^^^ ---- Actual error: add.p4(113): Cannot unify 'inout' parameter 'hdr' with 'in' parameter 'main_hdr' because they have different directions inout headers_t hdr, // from main control ^^^ /usr/share/p4c/p4include/tc/pna.p4(867) in MH main_hdr, ^^^^^^^^ ---- Originating from: add.p4(127): Type of argument 'MainDeparserImpl' (control MainDeparserImpl) does not match type of parameter 'main_deparser' (control MainDeparserT<...>) MainDeparserImpl() ^^^^^^^^^^^^^^^^^^ add.p4(111) control MainDeparserImpl( ^^^^^^^^^^^^^^^^ /usr/share/p4c/p4include/tc/pna.p4(874) MainDeparserT<MH, MM> main_deparser); ^^^^^^^^^^^^^ /usr/share/p4c/p4include/tc/pna.p4(874) MainDeparserT<MH, MM> main_deparser); ^^^^^^^^^^^^^^^^^^^^^ ---- Originating from: add.p4(128): Constructor invocation '<Method call>' does not match declaration 'PNA_NIC' ) main;
You need a different compiler for this. Likely p4c-pna-p4tc
instead.