Welcome to the P4 Sandbox!

The P4 sandbox is powered by Petr4, developed at Cornell University in the Networking Lab, led by Nate Foster. Additional information about Petr4 and how it powers our sandbox is found at the bottom of this page.

You can explore P4 code evaluation with an input packet and observe the resulting output packet and port number. Experiment by replacing the P4 Program textbox and/or the Input Packet textbox with your own values. Click the Evaluate button and see the results! We will be adding more examples, so check back in the future as well.

POPL 2021 Talk

This example is a subset of the demo shown in the video below. It provides a simple case of a packet routed through three ports. The input packet header (in hex: “01 02 00 03 00 04 01 AA BB”) specifies start (01), a hop out port 2 (02 00), a hop out port 3 (03 00), and a hop out port 4 (04 01, with 01 as the hop terminator). “AA BB” in the input header is allowed by the ACL table in the P4 program; see line 70 in the code box. The rest of the input packet is the data, “4f 48 20 4d 59 59 20 49 20 4b 4e 4f 57 20 57 48 59”. Don’t worry about formatting because Petr4 ignores whitespace.

Click the Evaluate! button, and the output packet (in hex) is displayed, followed by the port number (as a string). Notice that Petr4 removed the first hop (02 00) from the packet because it is complete.

Now copy the output packet, excluding the port number, and paste it in the input packet textbox, overwriting everything else in the input packet textbox.

Click the Evaluate! button again for the 2nd hop.

As you did previously, copy the output packet, excluding the port number, and overwrite the entire input packet textbox. Then click the Evaluate! button for the 3rd hop.

The process is complete, as indicated by 00 at the beginning of the packet.

You can experiment with the input packet and code by following along in the demo or by using your imagination.

Interested in learning more about the Cornell Petr4 project that powers this sandbox?

Play Video