p4utils.utils.compiler module

class p4utils.utils.compiler.BF_P4C(p4_src, sde, sde_install, build_dir=None, build_script='~/tools/p4_build.sh', **kwargs)[source]

Bases: object

This compiler reads the P4 program and generates the configuration files used by Tofinos.

Parameters:
  • p4_src (str) – path of the source P4 file to compile
  • build_dir (str) – directory where the Tofino’s configuration is built
  • build_script (str) – directory where the Tofino’s build script can be found
  • sde (str) – Tofino SDE path ($SDE)
  • sde_install (str) – Tofino SDE install path ($SDE_INSTALL)
clean()[source]

Removes output files and set compiler as uncompiled.

compile()[source]

Compiles the P4 file and generates the configuration files.

get_p4name()[source]

Returns the JSON configuration filepath.

new_source()[source]

Checks whether a new source was provided to the compiler.

Returns:True if the source P4 file has changed since the last time it was compiled, False otherwise.
Return type:bool
exception p4utils.utils.compiler.CompilationError[source]

Bases: Exception

exception p4utils.utils.compiler.NotCompiledError[source]

Bases: Exception

class p4utils.utils.compiler.P4C(p4_src, p4c_bin=None, outdir=None, opts='--target bmv2 --arch v1model --std p4-16', p4rt=False, **kwargs)[source]

Bases: object

This compiler reads the P4 program and generates the configuration files used by switches.

Parameters:
  • p4_src (str) – path of the source P4 file to compile
  • p4c_bin (str) – path to the compiler binary
  • outdir (str) – directory containing all the output files. If set to None, then every output is stored in the directory of p4_src
  • opts (str) – p4c compilation options
  • p4rt (bool) – generate the P4Info file used to establish P4Runtime connection to simple_switch_grpc
clean()[source]

Removes output files and set compiler as uncompiled.

compile()[source]

Compiles the P4 file and generates the configuration files.

get_json_out()[source]

Returns the JSON configuration filepath.

get_p4rt_out()[source]

Returns the P4Info configuration filepath.

new_source()[source]

Checks whether a new source was provided to the compiler.

Returns:True if the source P4 file has changed since the last time it was compiled, False otherwise.
Return type:bool
p4c_bin = 'p4c'[source]
classmethod set_binary(p4c_bin)[source]

Sets class default binary.

exception p4utils.utils.compiler.P4InfoDisabled[source]

Bases: Exception