P4C
The P4 Compiler
Loading...
Searching...
No Matches
Behavioral Model Backend

This is a back-end which generates code for the Behavioral Model version 2 (BMv2).

It can accept either P4_14 programs, or P4_16 programs written for the v1model.p4 switch model.

Dependencies

To run and test this back-end you need some additional tools:

  • the BMv2 behavioral model itself. Installation instructions are available here. You may need to update your dynamic libraries after installing bmv2: sudo ldconfig
  • the Python scapy library sudo pip3 install scapy

Unsupported P4_16 language features

Here are some unsupported features we are aware of. We will update this list as more features get supported in the bmv2 compiler backend and as we discover more issues.

  • explicit transition to reject in parse state
  • compound action parameters (can only be bit<> or int<>)
  • functions or methods with a compound return type
    struct s_t {
    bit<8> f0;
    bit<8> f1;
    };
    extern s_t my_extern_function();
    controlc c() {
    apply { s_t s1 = my_extern_function(); }
    }
  • user-defined extern types / methods which are not defined in v1model.p4
  • stacks of header unions

BMv2 "pna_nic" Backend

The backends/bmv2/pna_nic directory contains components specific to the BMv2's PNA NIC (Portable NIC Architecture) backend in the P4C compiler. The files in this folder depend on each other, on the files in the bmv2/common and portable_common directories. Most of the classes are inherited from the classes in the portable_common directory.

Output Binary: p4c-bm2-pna

File(s) Description
pnaProgramStructure.h, pnaProgramStructure.cpp Defines and implements the program structure (metadata, parsers, controls, and deparsers) and parsing logic specific to the BMv2's PNA NIC backend.
midend.h, midend.cpp Defines the mid-end processing of the PNA NIC compiler. Performs various transformations and optimizations on the program's Intermediate Representation (IR).
options.h, options.cpp Manages the command-line options for the PNA NIC compiler.
pnaNic.h, pnaNic.cpp Provides backend implementation to the BMv2's PNA NIC compiler.
main.cpp Sets up compilation environment, integrates various components, and executes the PNA NIC compiler.
version.h.cmake Defines macros containing version information for the PNA NIC compiler.

portable_common

The portable_common directory contains reusable components common to both the psa_switch and pna_nic backends.

File Name Description
midend.h, midend.cpp Defines the common mid-end processing of both the psa_switch and pna_nic backends.
options.h, options.cpp Defines the common command-line options of both the psa_switch and pna_nic backends.
portable.h, portable.cpp Defines common functionalities that generate representations of P4 programs.
portableProgramStructure.h, portableProgramStructure.cpp Defines and implements the common program structure of both the psa_switch and pna_nic backends. _These files are located in the backends/common directory.