Compiling P4 Code with P4C

At the navigation menu (top blue bar) click on the second link "Compiler" to be redirected to the P4Compiler.

P4 Compiler main screen

The main screen shows:

  • Title: the name of the file to be compiled. There is no need to give the extension .p4 since the file will be saved automatically with the extension. Just input the name of the file. The output file will be the same name with the extension ".json" that will be used as input when creating the Switch with the button "Add Node" in the main page.

  • Code: this is where the P4 code will be inserted. The text includes a line numbering at the left to help debug the code accordingly with the output. Note: in this version, the textarea does not verify the code for errors. Errors will appear after the compilation attempt.

  • Output: shows the messages returned from the P4C compiler. This can be used to debug and identify possible errors in your code.

  • Compile button: after checking if your P4 is correct, click on the "Compile" button to create the .json file. If everything is ok with your code, the message "Code compiled with success" will appear on the "Output" screen.

  • Download Compile File: if you wish, after successfully compiling your code you can download the compiled file. The name will be your title with the extension .json

Possible error:

if you are trying to compile a code and receive the output similar to "command failed:" and "Error response from daemon: Container <id> is not running" is possible that the compiler container is stopped. Execute the command:

$docker start compiler

to start the P4C and try again

Last updated