Skip to content

Creating a new T4P4S project on P4Pi

Sandor Laki edited this page Aug 25, 2022 · 4 revisions

Creating a new T4P4S project on P4Pi

P4Pi is currently uses T4P4S as a P4 compiler and execution framework. There are many options to compile and run a new P4 project on the T4P4S GitHub repository. In this page, we only describe the easiest way to start a new P4 project.

The T4P4S compiler is available in the folder /root/t4p4s.

Step 1 - Copy your P4 files to P4Pi

Using SCP you can copy your P4 source files to the P4Pi node or alternativelly you can create new P4 files locally on the node. By default, T4P4S will search for the source files in the examples folder (/root/t4p4s/examples/p4edge/).

In the following example, we simply create a copy of an existing P4 program with a new name (myprog.p4). Note that first you should open an SSH connection to the P4Pi node and then you can use the following commands:

sudo su
cd /root/t4p4s/examples/p4edge
mkdir myprog
scp ..@..:myprog.p4 myprog/myprog.p4

Step 2 - Define the configuration options for your program

In the root folder of T4P4S, you can find an examples.cfg configuration file. Similarly to other examples, an entry for the new program (myprog) needs to be added. You can simply copy-and-paste one of the example lines.

Add the following line to /root/t4p4s/examples/p4edge/pi-examples.cfg:

myprog                                arch=dpdk hugepages=1024 model=v1model smem vethmode pieal piports

Step 3 - Launch your new program

Assuming that T4P4S is the enabled backend, if not, please check how to enable T4P4S on P4Pi. You can execute your program either through the web terminal or manually with the following commands (in the SSH terminal):

sudo su
echo 'myprog' > /root/t4p4s-switch
systemctl restart t4p4s.service

Step 4 - Running P4Runtime shell for your program

Similarly to other examples, you can use the same script to launch the P4 Runtime shell:

sudo t4p4s-p4rtshell myprog

The command will generate p4info files needed for P4Runtime Shell and provide the appropriate arguments to the shell.

Manual execution of your program with verbose output

For testing purposes, it is often helpful if you can see what happens during the execution of the P4 pipeline. To this end, you should launch T4P4S manually.

First, the T4P4S service needs to be stopped:

sudo systemctl stop t4p4s.service

Then you can run the t4p4s.sh script with additional parameters to generate verbose output:

sudo su
cd /root/t4p4s
./t4p4s.sh :myprog p4rt verbose dbg

The verbose output shows all the performed actions for each packet, including parsing steps, table lookups, action exectutions, deparsing, etc.

Debugging P4 switch program with gdb

To debug runtime errors advanced users can use the gdb debugger. The compiled programs are located under the /root/t4p4s/build folder.

cd /root/t4p4s/build/myprog@std/build
sudo gdb ./myprog
gdb shell>> r -c 0xc -n 4 --no-pci --vdev net_pcap0,rx_iface_in=veth0,tx_iface=veth0,tx_iface=veth0 --vdev net_pcap1,rx_iface_in=veth1,tx_iface=veth1,tx_iface=veth1 -- -p 0x3 --config "\"(0,0,2)(1,0,3)\""

Note that the P4 program needs to be compiled manually with option dbg:

sudo su
cd /root/t4p4s
./t4p4s.sh :myprog p4rt dbg
Clone this wiki locally