Skip to content

03 Lucid tofino compiler

jsonch edited this page Nov 17, 2023 · 2 revisions

Compiling to the Tofino

./dptc prog.dpt -o prog_build compiles the lucid program prog.dpt into a P4-tofino project in the prog_build directory. The three most important files in the build directory are:

  • lucid.p4 -- the P4 program.
  • lucid.py -- a python control script used to install compiler-generated multicast rules for event duplication (e.g., generate_ports). This script must be run from inside of the tofino's bfshell agent, e.g., with $SDE/run_bfshell.sh -b lucid.py.
  • globals.json -- a json file mapping each global defined in the Lucid program to an object in the resulting P4 program, along with additional type information. This file makes it easier to write custom control programs for Lucid data planes.

Tofino restrictions

The tofino backend has a few additional restrictions on Lucid programs.

  1. Each control flow of a handler may only call generate_port once and generate_ports once. This is necessary for the Lucid compiler to guarantee that generate_port and generate_ports can always be implemented without requiring recirculations. In P4, a generate_port(p, ...) compiles into setting the unicast output port of the current packet to p, while generate_ports({p1, p2, ..., pn}, ...); compiles into setting the multicast group of the current packet to a Lucid-created group containing ports p1, p2, ..., pn. Note that the base generate function, which always sends the event to the local recirculation port, may be used an unlimited number of times in a control flow.

  2. A handler is only allowed to generate one instance of each event in each control flow.

  3. Every event parameter must either start or end on a byte boundary.

Example programs

The programs in examples/tofino_apps/src are regularly compiled and tested on the Tofino's ASIC reference model.

Clone this wiki locally