-
Notifications
You must be signed in to change notification settings - Fork 10
03 Lucid tofino compiler
./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'sbfshell
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.
The python control script generated by the compiler needs to know what ports you are using to correctly implement the "flood" builtin. Tell the compiler about a port with the --port <dpid>@<speed>
argument. dpid is the port id and speed is the port's speed in Gb/s. Inputs are not checked and are assumed to be tofino compatible. The port argument can be used multiple times to add multiple ports. The compiler also generates code in the python control script to bring up all added ports. The default ports are 128@10, 129@10, 130@10, 131@10.
The compiler assumes that port 196 is the recirculation port. To change this, use --recirc_port <dpid>
.
The tofino backend has a few additional restrictions on Lucid programs.
-
Each control flow of a handler may only call
generate_port
once andgenerate_ports
once. This is necessary for the Lucid compiler to guarantee thatgenerate_port
andgenerate_ports
can always be implemented without requiring recirculations. In P4, agenerate_port(p, ...)
compiles into setting the unicast output port of the current packet top
, whilegenerate_ports({p1, p2, ..., pn}, ...);
compiles into setting the multicast group of the current packet to a Lucid-created group containing portsp1, 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. -
A handler is only allowed to generate one instance of each event in each control flow.
-
Every event parameter must either start or end on a byte boundary.
The programs in examples/tofino_apps/src
are regularly compiled and tested on the Tofino's ASIC reference model.