Skip to content

P4 Compilers and Targets

signorello edited this page Aug 24, 2022 · 5 revisions

P4 Targets supported on P4Pi

A P4 target is a packet-processing system capable of executing a P4 program. P4 is designed to specify only data plane functionality and cannot be used to describe control-plane functionality. Although many targets implement both a control plane and a data plane and P4 programs partially define an interface by which the control plane and the data-plane communicate.

The latest release of P4Pi supports DPDK and BMv2 as P4 targets through two different compilers, T4P4S and p4c respectively. In general T4P4S for DPDK provides better performance but it has no full language support and some additional constraints, while p4c for BMv2 has full support of P4 on the less performant BMv2. In this page, we illustrate the slight differences between running the example files on P4Pi using one target or the other.

Behavioral model (BMv2) through the p4c compiler

BMv2 is the reference P4 software switch. It is designed as a tool for developing and testing P4 data-plane and control-plane software. As such, it is not intended to be used in a production environment and, therefore, its performance in terms of latency and throughput is significantly less than of a production-grade software switch implementations like Open vSwitch.

Among several target switch architectures, BMv2 supports the v1model architecture, which was intended to match the architecture defined in the P4_14 language specification. It extends simple_switch with support for control messages defined by the P4Runtime API specification, but it also supports controllers using the Thrift API.

BMv2 also supports the psa_switch target which implements the Portable Switch Architecture (PSA) (see the P4.org specifications page for the PSA specification document). This target implements ingress and egress pipelines and supports controller-plane messages using the Thrift API.

BMv2 examples

Out-of-the-box examples for BMv2 are stored in the /root/bmv2/examples folder. These examples can be run through either the web interface or ssh as follows (assuming that BMv2 service is enabled):

sudo -i
echo l2switch > /root/t4p4s-switch
systemctl restart bmv2.service

Where l2switch is name of the P4 example. The BMv2 systemd service runs the bmv2-start command. This command reads the name of the example from /root/t4p4s-switch, then it would compile and run it. The resulted json and p4info files will be generated in folder '/root/bmv2/bin'.

DPDK through the T4P4S compiler

The Data Plane Development Kit (DPDK) is a widely used kernel bypass framework for high-speed packet processing. There are currently two compiler implementations for P4: T4P4S and p4c-dpdk. T4P4S is leveraging the front-end of p4c to generate an intermediate representation of a P4 program. It implements core and hardware abstraction layers responsible for target-independent and target-dependent optimizations respectively. It currently supports v1model and PSA architectures, and provides a P4Runtime control-plane.

T4P4S examples

P4Pi includes a number of P4 examples out-of-the-box stored in the /root/t4p4s/examples/p4dege folder. You can run an existing P4 example program through ssh as follows (assuming that T4P4S service is enabled):

sudo -i
echo l2switch > /root/t4p4s-switch
systemctl restart t4p4s.service

Where l2switch is name of the P4 example. The T4P4S systemd service runs the t4p4s-start command. This command reads the name of the T4P4S example from /root/t4p4s-switch, then it would compile and run it.

Switching between T4P4S and BMv2

If you use the P4Pi web interface, no additional steps are needed since the change between services is managed by the platform seamlessly.

In case of running examples manually, you first have to stop and disable the service of the old target, then enable the new target. If the new target is enabled, the example programs can be launched with the commands mentioned above. For example, BMv2 service can be enabled with the following commands:

systemctl stop t4p4s.service
systemctl disable t4p4s.service
systemctl enable bmv2.service

Switching from BMv2 to T4P4S can be done similarly.

systemctl stop bmv2.service
systemctl disable bmv2.service
systemctl enable t4p4s.service
Clone this wiki locally