This is a backend for p4_16 compiler p4c. This backends compiles p4_16 programs into SAI headers, and should be acommpanied with a vendor provided backend for the SAI adapter implementation. This should allow for easy integration of new programmable pipelines with SAI supporting NOS, like SONiC.
This repo defines the SAI target architecture, which consists of a parser, deparser and 4 programable pipelines, in between fixed pipelines, which are defined in accordance with SAI behvaioral model: here black boxes are fixed pipelines, and green ones are programmable.
The archtiecture defines the pipelines, and also SAI headers, metadata available at each stage, and the externs (actions which are supported by a SAI target), which can all be seen in p4include
Following: p4c build instructions.
git clone https://github.com/p4lang/p4c.git
git checkout 6d265b2d15b927db522c08f36a60fe23784e8357
git submodule update --init --recursive
- in p4c/extensions (make new dir if needed) '''ln -s <sai_p4_compiler_git_path>/backend/ sai'''
Building should also take place in a subdirectory named build
.
in p4c repo:
./bootstrap.sh
[optional: remove all other backends by adding -DENABLE_BMV2=OFF -DENABLE_EBPF=OFF -DENABLE_P4TEST=OFF -DENABLE_P4C_GRAPHS=OFF to cmake in bootstrap.sh]
cd build
make -j4
sudo make install
Coding a p4 program, should be done according to the languange specifications, as published in the official website. One can write Match-action tables to each one of the 4 programable piplines, according to sai_model.p4, and the defined target architecture.
One example, is given in p4src
p4c-sai PATH_TO_P4 -o OUTPUT_JSON (all output will go in the same dir as json) e.g., compiling example.p4:
mkdir -p sai_p4_compiler/output/example
p4c-sai sai_p4_compiler/p4src/example/example.p4 -o sai_p4_compiler/output/example/example.json
all output will be spilled to sai_p4_compiler/output/example/