P4C
The P4 Compiler
|
P4Smith is an extensible random P4 program generator in the spirit of CSmith. P4Smith generates random, but valid P4 programs for various P4 targets, for example the v1model.p4 architecture on BMv2 or tna.p4
running on Tofino 1. P4Smiths generates programs that are valid according to the latest version of the (P4 specification)[https://p4.org/p4-spec/docs/P4-16-working-spec.html] or the restrictions of the specific target.
P4Smith depends on the P4Tools framework and is automatically installed with P4Tools. Please follow the instructions listed here to install P4Smith. The main binary p4smith
can be found in the build
folder after a successful installation.
P4Smith is available as part of the official P4C docker image. On Debian-based systems, it is also possible to install a P4Smith binary by following these instructions.
P4Smith extensions are instantiations of a particular combination of P4 architecture and the target that executes the P4 code. For example, the v1model.p4
architecture can be executed on the behavioral model. P4Smith extension make use of the core P4Smith framework to generate programs. Several open-source extensions are available.
This random program generator generates random packages and tries to produce all valid P4 code according to the latest P4 specification. Programs should be compiled using p4test.
P4Smith supports generating P4 programs for the v1model
and psa
architecture on BMv2.
The DPDK-SoftNIC is a new target implemented using the Data Plane Development Kit (DPDK). The SoftNIC can be programmed using the P4 pna.p4
architecture.
P4Smith can also generate programs for the tna
architecture on Tofino 1. The programs are intended to be compiled on the proprietary Barefoot Tofino compiler.
To access the possible options for p4smith
use p4smith --help
. To generate a test for a particular target and P4 architecture, run the following command:
Where ARCH
specifies the P4 architecture (e.g., v1model.p4) and TARGET
represents the targeted network device (e.g., BMv2). prog.p4
is the name of the generated program.
P4Smith was originally titled Bludgeon and part of the Gauntlet compiler testing framework. Section 4 of the paper provides a high-level overview of the tool.
If you would like to cite this tool please use this citation format:
Contributions to P4Smith in any form are welcome! Please follow the guidelines listed here to contribute.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.