P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::P4Tools::P4Testgen::TableStepper Class Reference

Implements small-step operational semantics for tables. More...

#include <table_stepper.h>

Inheritance diagram for P4::P4Tools::P4Testgen::TableStepper:
[legend]

Public Member Functions

 TableStepper (ExprStepper *stepper, const IR::P4Table *table)
 
bool eval ()
 

Static Public Member Functions

static const IR::StateVariable & getTableActionVar (const IR::P4Table *table)
 
static const IR::StateVariable & getTableHitVar (const IR::P4Table *table)
 
static const IR::StateVariable & getTableResultVar (const IR::P4Table *table)
 
static const IR::StateVariable & getTableStateVariable (const IR::Type *type, const IR::P4Table *table, cstring name, std::optional< int > idx1_opt=std::nullopt, std::optional< int > idx2_opt=std::nullopt)
 

Protected Member Functions

void addDefaultAction (std::optional< const IR::Expression * > tableMissCondition)
 tableMissCondition is true.
 
std::vector< const IR::ActionListElement * > buildTableActionList ()
 Helper function that collects the list of actions contained in the table.
 
virtual void checkTargetProperties (const std::vector< const IR::ActionListElement * > &tableActionList)
 
const IR::Expression * computeHit (TableMatchMap *matches)
 
virtual const IR::Expression * computeTargetMatchType (const TableUtils::KeyProperties &keyProperties, TableMatchMap *matches, const IR::Expression *hitCondition)
 
void evalTableCall ()
 
const IR::Expression * evalTableConstEntries ()
 
void evalTableControlEntries (const std::vector< const IR::ActionListElement * > &tableActionList)
 
void evalTaintedTable ()
 
virtual void evalTargetTable (const std::vector< const IR::ActionListElement * > &tableActionList)
 
const ExecutionStategetExecutionState ()
 
const ProgramInfogetProgramInfo ()
 
ExprStepper::Result getResult ()
 
bool resolveTableKeys ()
 
void setTableDefaultEntries (const std::vector< const IR::ActionListElement * > &tableActionList)
 

Static Protected Member Functions

static const IR::StringLiteral * getTableActionString (const IR::MethodCallExpression *actionCall)
 

Protected Attributes

TableUtils::TableProperties properties
 Basic table properties that are set when initializing the TableStepper.
 
ExprStepperstepper
 Reference to the calling expression stepper.
 
const IR::P4Table * table
 The table for this particular stepper.
 

Detailed Description

Implements small-step operational semantics for tables.

Member Function Documentation

◆ checkTargetProperties()

void P4::P4Tools::P4Testgen::TableStepper::checkTargetProperties ( const std::vector< const IR::ActionListElement * > & tableActionList)
protectedvirtual

Collects properties that may be set per table. Target back end may have different semantics for table execution that need to be collect before evaluation the table.

Reimplemented in P4::P4Tools::P4Testgen::Bmv2::Bmv2V1ModelTableStepper, P4::P4Tools::P4Testgen::EBPF::EBPFTableStepper, and P4::P4Tools::P4Testgen::Pna::SharedPnaTableStepper.

◆ computeHit()

const IR::Expression * P4::P4Tools::P4Testgen::TableStepper::computeHit ( TableMatchMap * matches)
protected

A helper function that computes whether a control-plane/table-key hits or not. This does not handle constant entries, it is specialized for control plane entries. The function also tracks the list of field matches created to achieve a hit. We later use this to insert table entries using the STF/PTF framework.

◆ computeTargetMatchType()

const IR::Expression * P4::P4Tools::P4Testgen::TableStepper::computeTargetMatchType ( const TableUtils::KeyProperties & keyProperties,
TableMatchMap * matches,
const IR::Expression * hitCondition )
protectedvirtual

This function allows target back ends to add their own match types. For example, some back ends implement the "optional" match type, which either hits as exact match or does not match at all. The table stepper first checks these custom match types. If these do not match it steps through the default implementation. If it does not match either, a P4C_UNIMPLEMENTED is thrown.

Reimplemented in P4::P4Tools::P4Testgen::Bmv2::Bmv2V1ModelTableStepper, and P4::P4Tools::P4Testgen::Pna::SharedPnaTableStepper.

◆ eval()

bool P4::P4Tools::P4Testgen::TableStepper::eval ( )

Table implementations in P4 are rather flexible. Eval is a delegation function that chooses the right implementation depending on the properties of the table. For example, immutable tables can not be programmed using the control plane. If an table key is tainted, we can also not predict, which action is tainted. Some frameworks may have implementation details such as annotations, action profiles/selectors that may alter semantics, too.

◆ evalTableCall()

void P4::P4Tools::P4Testgen::TableStepper::evalTableCall ( )
protected

When we hit a table.apply() method call expression we transition into the table call phase. Handling table calls is fairly involved as we need to respect the control plane manipulating these tables. This is why we are using several helper functions.

Parameters
tablethe table we invoke.

◆ evalTableConstEntries()

const IR::Expression * P4::P4Tools::P4Testgen::TableStepper::evalTableConstEntries ( )
protected

Tables may have constant match-action entries. This usually implies that the table is immutable. This helper function unrolls all entries and aligns the table key with the match provided by the constant entry.

Parameters
tablethe table we invoke.
Returns
tableMissCondition reference to the current constraints of the miss condition. Any constant entry we hit implies that the table is hit, and the default action is not executed.

◆ evalTableControlEntries()

void P4::P4Tools::P4Testgen::TableStepper::evalTableControlEntries ( const std::vector< const IR::ActionListElement * > & tableActionList)
protected

This helper function evaluates potential insertion from the control plane. We use variables variables to mimic an operator inserting entries. We only cover ONE entry per table for now.

Parameters
tablethe table we invoke.

◆ evalTaintedTable()

void P4::P4Tools::P4Testgen::TableStepper::evalTaintedTable ( )
protected

This is a special function that handles the case where the key of a table is tainted. This means that the entire execution of the table is tainted. We can dramatically simplify execution here and we also do not need control plane entries. The tricky part is that we still need execute all possible actions and taint whatever they may write, iff the table has constant entries.

◆ evalTargetTable()

void P4::P4Tools::P4Testgen::TableStepper::evalTargetTable ( const std::vector< const IR::ActionListElement * > & tableActionList)
protectedvirtual

This function allows target back ends to implement their own interpretation of table execution. How a table is evaluated is target-specific.

Reimplemented in P4::P4Tools::P4Testgen::Bmv2::Bmv2V1ModelTableStepper, P4::P4Tools::P4Testgen::EBPF::EBPFTableStepper, and P4::P4Tools::P4Testgen::Pna::SharedPnaTableStepper.

◆ getExecutionState()

const ExecutionState * P4::P4Tools::P4Testgen::TableStepper::getExecutionState ( )
protected
Returns
the execution state of the friend class ExpressionStepper.

◆ getProgramInfo()

const ProgramInfo * P4::P4Tools::P4Testgen::TableStepper::getProgramInfo ( )
protected
Returns
the program info of the friend class ExpressionStepper.

◆ getResult()

ExprStepper::Result P4::P4Tools::P4Testgen::TableStepper::getResult ( )
protected
Returns
the result pointer of the friend class ExpressionStepper.

◆ getTableActionString()

const IR::StringLiteral * P4::P4Tools::P4Testgen::TableStepper::getTableActionString ( const IR::MethodCallExpression * actionCall)
staticprotected

Sets the action taken by the given table. The arguments in the given MethodCallExpression are assumed to be symbolic values.

◆ getTableActionVar()

const IR::StateVariable & P4::P4Tools::P4Testgen::TableStepper::getTableActionVar ( const IR::P4Table * table)
static
Returns
the state variable that tracks the index of the action taken by the given table.

This variable is initially set to the number of actions in the table, indicating that no action has been selected. It is set by setTableAction and read by getTableAction.

◆ getTableHitVar()

const IR::StateVariable & P4::P4Tools::P4Testgen::TableStepper::getTableHitVar ( const IR::P4Table * table)
static
Returns
the boolean-typed state variable that tracks whether a table has resulted in a hit. The value of this variable is false if the table misses or is not reached.

◆ getTableStateVariable()

const IR::StateVariable & P4::P4Tools::P4Testgen::TableStepper::getTableStateVariable ( const IR::Type * type,
const IR::P4Table * table,
cstring name,
std::optional< int > idx1_opt = std::nullopt,
std::optional< int > idx2_opt = std::nullopt )
static
Returns
the variables variable with the given type, for tracking an aspect of the given table. The returned variable will be named p4t*variables.table.t.name.idx1.idx2, where t is the name of the given table. The "idx1" and "idx2" components are produced only if idx1 and idx2 are given, respectively.

◆ resolveTableKeys()

bool P4::P4Tools::P4Testgen::TableStepper::resolveTableKeys ( )
protected

A helper function to iteratively resolve table keys into symbolic values. This function returns false, if no key needs to be resolved. If keys are tainted or a key needs to be resolved, this function returns true.