p4lang / p4c

P4_16 reference compiler
https://p4.org/
Apache License 2.0
679 stars 444 forks source link

Problems using p4c-ebpf #1860

Open racast opened 5 years ago

racast commented 5 years ago

Hi guys,

I tried to create a small project using p4c and ebpf. I have two errors that I don't know how to resolve. Can someone help me ? Here's the console cmd :

p4c-ebpf app_ebpf.p4 -o app_ebpf.c /usr/local/share/p4c/p4include/core.p4(23): [--Werror=legacy] error: Type error not supported error { ^ /usr/local/share/p4c/p4include/v1model.p4(75): [--Werror=legacy] error: Type error does not have a fixed witdh error parser_error; ^^^^^ In file: /home/pcamille/tools/p4c/ir/visitor.cpp:267 Compiler Bug: IR loop detected

Racast

hesingh commented 5 years ago

If you have not written a new P4 program to work with p4c and ebpf, you should not see this error. You may have some dependency not installed. To work with ebpf, once needs more software installed. See

https://github.com/p4lang/p4c/blob/master/backends/ebpf/README.md

and

$ sudo apt-get install clang llvm libpcap-dev libelf-dev iproute2 net-tools
$ sudo pip install pyroute2 ply scapy==2.4.0
racast commented 5 years ago

I have check and re-done the install. I still have the problems. I figured out that the error linked to the error type is raised when I include the v1model and the ebpf_model. The IR loop is linked to my parser but I don't know where is the problem. I think I don't use correctly the verify_checksum function. project.zip

hesingh commented 5 years ago

If one is using the ebpf backend, one has to only use the ebpf_model.p4 file. You cannot also include v1model.p4. I removed including v1model from your program, and compiled. Now, only the checksum used by your code is not found. If you want to use checksum functionality, use the bmv2 backend.

p4c/build$ ./p4c-ebpf --std p4-16 ./foo.p4 
./foo.p4(56): [--Werror=not-found] error: verify_checksum: Not found declaration
     verify_checksum(true,p.ip,p.ip.hdrChecksum,HashAlgorithm.crc32);
     ^^^^^^^^^^^^^^^
./foo.p4(56): [--Werror=not-found] error: HashAlgorithm: Not found declaration
     verify_checksum(true,p.ip,p.ip.hdrChecksum,HashAlgorithm.crc32);
                                                ^^^^^^^^^^^^^
racast commented 5 years ago

Thank you very much. I will try it.

mihaibudiu commented 5 years ago

Yes, unfortunately ebpf_model does not have a verify_checksum function. You can probably implement one yourself in P4. The XDP back-end has a ebpf_ipv4_checksum function (http://github.com/vmware/p4c-xdp). The ebpf and xdp back-ends are not very well maintained, I am afraid. We never have enough time to add more features...

racast commented 5 years ago

So far the checksum function is not my main concern. I still have this kind of errors during the compilations :

/usr/local/share/p4c/p4include/core.p4(23): [--Werror=legacy] error: Type error not supported error { ^ /usr/local/share/p4c/p4include/v1model.p4(75): [--Werror=legacy] error: Type error does not have a fixed witdh error parser_error; ^^^^^ [--Werror=legacy] error: error: not yet implemented

I don't know how it can be troublesome.

mihaibudiu commented 5 years ago

I guess this means that the error type is not yet handled by the back-end. If you need this feature please file an issue and I will try to fix it as soon as possible.

racast commented 5 years ago

For the moment I won't use it.

mihaibudiu commented 5 years ago

In fact the parser error cannot be used as ebpf_model is defined: if the parser signals any error the program terminates and the packet is dropped. We would need to change the model if we want the user to process the parser errors.