P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::ControlPlaneAPI Namespace Reference

TODO(antonin): High level goals of the generator go here!! More...

Namespaces

namespace  Helpers
 
namespace  Standard
 Declarations specific to standard architectures (v1model & PSA).
 

Classes

struct  ActionRef
 
struct  ControllerType
 See section "User-defined types" in P4RT specification. More...
 
struct  DefaultAction
 The information about a default action which is needed to serialize it. More...
 
class  FieldIdAllocator
 
class  FlattenHeader
 Flattens a header type "locally", without modifying the IR. More...
 
struct  MatchField
 The information about a match field which is needed to serialize it. More...
 
class  P4InfoMaps
 
class  P4RuntimeAnalyzer
 
struct  P4RuntimeArchHandlerBuilderIface
 
class  P4RuntimeArchHandlerIface
 
class  P4RuntimeEntriesConverter
 
class  P4RuntimeSymbolTable
 
class  P4RuntimeSymbolTableIface
 
class  P4RuntimeSymbolType
 
struct  P4SymbolSuffixSet
 
class  ParseP4RuntimeAnnotations
 Parses P4Runtime-specific annotations. More...
 
struct  TranslationAnnotation
 Payload of @p4runtime_translation annotation. More...
 
class  TypeSpecConverter
 Generates the appropriate p4.P4DataTypeSpec for a given IR::Type node. More...
 

Typedefs

using p4rt_id_t = uint32_t
 

Functions

void collectControlSymbols (P4RuntimeSymbolTable &symbols, P4RuntimeArchHandlerIface *archHandler, const IR::ControlBlock *controlBlock, ReferenceMap *refMap, TypeMap *typeMap)
 
void collectExternSymbols (P4RuntimeSymbolTable &symbols, P4RuntimeArchHandlerIface *archHandler, const IR::ExternBlock *externBlock)
 
void collectParserSymbols (P4RuntimeSymbolTable &symbols, const IR::ParserBlock *parserBlock)
 
void collectTableSymbols (P4RuntimeSymbolTable &symbols, P4RuntimeArchHandlerIface *archHandler, const IR::TableBlock *tableBlock)
 
std::optional< p4rt_id_t > getIdAnnotation (const IR::IAnnotated *node)
 
cstring getTypeName (const IR::Type *type, TypeMap *typeMap)
 
int getTypeWidth (const IR::Type &type, const TypeMap &typeMap)
 
bool hasTranslationAnnotation (const IR::Type *type, TranslationAnnotation *payload)
 
bool isControllerHeader (const IR::Type_Header *type)
 
bool isHidden (const IR::Node *node)
 
std::optional< std::string > stringRepr (const IR::BoolLiteral *constant, int width)
 
std::optional< std::string > stringRepr (const IR::Constant *constant, int width)
 
std::optional< std::string > stringRepr (const TypeMap &typeMap, const IR::Expression *expression)
 
std::optional< std::string > stringReprConstant (big_int value, int width)
 
uint64_t szudzikPairing (p4rt_id_t x, p4rt_id_t y)
 
in the given range

Generic meta function which searches an object by and

Returns
the P4Runtime representation, or nullptr if none is found. TODO: Should this return an optional const reference? The advantage is that the value needs to be explicitly unpacked.
const p4::config::v1::Table * findP4RuntimeTable (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName)
 
const p4::config::v1::Table * findP4RuntimeTable (const p4::config::v1::P4Info &p4Info, p4rt_id_t id)
 
const p4::config::v1::MatchField * findP4RuntimeMatchField (const p4::config::v1::Table &p4Table, cstring controlPlaneName)
 
const p4::config::v1::MatchField * findP4RuntimeMatchField (const p4::config::v1::Table &p4Table, p4rt_id_t id)
 
const p4::config::v1::Action * findP4RuntimeAction (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName)
 
const p4::config::v1::Action * findP4RuntimeAction (const p4::config::v1::P4Info &p4Info, p4rt_id_t id)
 
const p4::config::v1::ActionProfile * findP4RuntimeActionProfile (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName)
 
const p4::config::v1::ActionProfile * findP4RuntimeActionProfile (const p4::config::v1::P4Info &p4Info, p4rt_id_t id)
 
const p4::config::v1::Counter * findP4RuntimeCounter (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName)
 
const p4::config::v1::Counter * findP4RuntimeCounter (const p4::config::v1::P4Info &p4Info, p4rt_id_t id)
 
const p4::config::v1::DirectCounter * findP4RuntimeDirectCounter (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName)
 
const p4::config::v1::DirectCounter * findP4RuntimeDirectCounter (const p4::config::v1::P4Info &p4Info, p4rt_id_t id)
 
const p4::config::v1::Meter * findP4RuntimeMeter (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName)
 
const p4::config::v1::Meter * findP4RuntimeMeter (const p4::config::v1::P4Info &p4Info, p4rt_id_t id)
 
const p4::config::v1::DirectMeter * findP4RuntimeDirectMeter (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName)
 
const p4::config::v1::DirectMeter * findP4RuntimeDirectMeter (const p4::config::v1::P4Info &p4Info, p4rt_id_t id)
 
const p4::config::v1::ControllerPacketMetadata * findP4RuntimeControllerPacketMetadata (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName)
 
const p4::config::v1::ControllerPacketMetadata * findP4RuntimeControllerPacketMetadata (const p4::config::v1::P4Info &p4Info, p4rt_id_t id)
 
const p4::config::v1::ValueSet * findP4RuntimeValueSet (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName)
 
const p4::config::v1::ValueSet * findP4RuntimeValueSet (const p4::config::v1::P4Info &p4Info, p4rt_id_t id)
 
const p4::config::v1::Register * findP4RuntimeRegister (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName)
 
const p4::config::v1::Register * findP4RuntimeRegister (const p4::config::v1::P4Info &p4Info, p4rt_id_t id)
 
const p4::config::v1::Digest * findP4RuntimeDigest (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName)
 
const p4::config::v1::Digest * findP4RuntimeDigest (const p4::config::v1::P4Info &p4Info, p4rt_id_t id)
 
const p4::config::v1::Extern * findP4RuntimeExtern (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName)
 
const p4::config::v1::Extern * findP4RuntimeExtern (const p4::config::v1::P4Info &p4Info, p4rt_id_t id)
 
std::optional< p4rt_id_t > getP4RuntimeId (const p4::config::v1::P4Info &p4Info, const P4RuntimeSymbolType &type, cstring controlPlaneName)
 
template<typename It >
auto findP4InfoObject (const It &first, const It &last, cstring controlPlaneName) -> const typename std::iterator_traits< It >::value_type *
 
template<typename It >
auto findP4InfoObject (const It &first, const It &last, p4rt_id_t id) -> const typename std::iterator_traits< It >::value_type *
 

Variables

const p4rt_id_t INVALID_ID = ::p4::config::v1::P4Ids::UNSPECIFIED
 

Detailed Description

TODO(antonin): High level goals of the generator go here!!

TODO: Consider migrating this API to the top-level control-plane folder. The reason we have not already done this is because that folder already provides similar utility functions. However, these functions are tied to the P4RuntimeTableIface, which is fairly inflexible. We just need an API that can perform lookup operations on a P4Info or P4RuntimeAPI object.


Class Documentation

◆ P4::ControlPlaneAPI::ActionRef

struct P4::ControlPlaneAPI::ActionRef
Class Members
const IAnnotated * annotations
const cstring name

◆ P4::ControlPlaneAPI::DefaultAction

struct P4::ControlPlaneAPI::DefaultAction

The information about a default action which is needed to serialize it.

Class Members
const P4Action * action
const Vector< Argument > * arguments
const bool isConst

◆ P4::ControlPlaneAPI::MatchField

struct P4::ControlPlaneAPI::MatchField

The information about a match field which is needed to serialize it.

Class Members
typedef MatchType MatchType p4configv1::MatchField::MatchType
typedef MatchField MatchTypes p4configv1::MatchField
Class Members
const IAnnotated * annotations
const uint32_t bitwidth
const p4rt_id_t id
const cstring name
const cstring other_match_type
const MatchType type
const cstring type_name

◆ P4::ControlPlaneAPI::TranslationAnnotation

struct P4::ControlPlaneAPI::TranslationAnnotation

Payload of @p4runtime_translation annotation.

Class Members
ControllerType controller_type
string original_type_uri

Function Documentation

◆ findP4InfoObject()

template<typename It >
auto P4::ControlPlaneAPI::findP4InfoObject ( const It & first,
const It & last,
p4rt_id_t id ) -> const typename std::iterator_traits<It>::value_type *

Generic meta function which searches an object by @id in the given range and

Returns
the P4Runtime representation, or nullptr if none is found. TODO: Should this return an optional const reference? The advantage is that the value needs to be explicitly unpacked.

◆ findP4RuntimeAction() [1/2]

const p4::config::v1::Action * P4::ControlPlaneAPI::findP4RuntimeAction ( const p4::config::v1::P4Info & p4Info,
cstring controlPlaneName )

Try to find the P4Info description for the given action.

Returns
nullptr if the action is not present in the P4Info object.

◆ findP4RuntimeAction() [2/2]

const p4::config::v1::Action * P4::ControlPlaneAPI::findP4RuntimeAction ( const p4::config::v1::P4Info & p4Info,
p4rt_id_t id )

Try to find the P4Info description for the given action.

Returns
nullptr if the action is not present in the P4Info object.

◆ findP4RuntimeActionProfile() [1/2]

const p4::config::v1::ActionProfile * P4::ControlPlaneAPI::findP4RuntimeActionProfile ( const p4::config::v1::P4Info & p4Info,
cstring controlPlaneName )

Try to find the P4Info description for the given action profile.

Returns
nullptr if the action is not present in the P4Info object.

◆ findP4RuntimeActionProfile() [2/2]

const p4::config::v1::ActionProfile * P4::ControlPlaneAPI::findP4RuntimeActionProfile ( const p4::config::v1::P4Info & p4Info,
p4rt_id_t id )

Try to find the P4Info description for the given action profile.

Returns
nullptr if the action is not present in the P4Info object.

◆ findP4RuntimeControllerPacketMetadata() [1/2]

const p4::config::v1::ControllerPacketMetadata * P4::ControlPlaneAPI::findP4RuntimeControllerPacketMetadata ( const p4::config::v1::P4Info & p4Info,
cstring controlPlaneName )

Try to find the P4Info description for the given controller packet metadata.

Returns
nullptr if the controller packet metadata is not present in the P4Info object.

◆ findP4RuntimeControllerPacketMetadata() [2/2]

const p4::config::v1::ControllerPacketMetadata * P4::ControlPlaneAPI::findP4RuntimeControllerPacketMetadata ( const p4::config::v1::P4Info & p4Info,
p4rt_id_t id )

Try to find the P4Info description for the given controller packet metadata.

Returns
nullptr if the controller packet metadata is not present in the P4Info object.

◆ findP4RuntimeCounter() [1/2]

const p4::config::v1::Counter * P4::ControlPlaneAPI::findP4RuntimeCounter ( const p4::config::v1::P4Info & p4Info,
cstring controlPlaneName )

Try to find the P4Info description for the given counter.

Returns
nullptr if the counter is not present in the P4Info object.

◆ findP4RuntimeCounter() [2/2]

const p4::config::v1::Counter * P4::ControlPlaneAPI::findP4RuntimeCounter ( const p4::config::v1::P4Info & p4Info,
p4rt_id_t id )

Try to find the P4Info description for the given counter.

Returns
nullptr if the counter is not present in the P4Info object.

◆ findP4RuntimeDigest() [1/2]

const p4::config::v1::Digest * P4::ControlPlaneAPI::findP4RuntimeDigest ( const p4::config::v1::P4Info & p4Info,
cstring controlPlaneName )

Try to find the P4Info description for the given digest.

Returns
nullptr if the digest is not present in the P4Info object.

◆ findP4RuntimeDigest() [2/2]

const p4::config::v1::Digest * P4::ControlPlaneAPI::findP4RuntimeDigest ( const p4::config::v1::P4Info & p4Info,
p4rt_id_t id )

Try to find the P4Info description for the given digest.

Returns
nullptr if the digest is not present in the P4Info object.

◆ findP4RuntimeDirectCounter() [1/2]

const p4::config::v1::DirectCounter * P4::ControlPlaneAPI::findP4RuntimeDirectCounter ( const p4::config::v1::P4Info & p4Info,
cstring controlPlaneName )

Try to find the P4Info description for the given direct counter.

Returns
nullptr if the direct counter is not present in the P4Info object.

◆ findP4RuntimeDirectCounter() [2/2]

const p4::config::v1::DirectCounter * P4::ControlPlaneAPI::findP4RuntimeDirectCounter ( const p4::config::v1::P4Info & p4Info,
p4rt_id_t id )

Try to find the P4Info description for the given direct counter.

Returns
nullptr if the direct counter is not present in the P4Info object.

◆ findP4RuntimeDirectMeter() [1/2]

const p4::config::v1::DirectMeter * P4::ControlPlaneAPI::findP4RuntimeDirectMeter ( const p4::config::v1::P4Info & p4Info,
cstring controlPlaneName )

Try to find the P4Info description for the given direct meter.

Returns
nullptr if the direct meter is not present in the P4Info object.

◆ findP4RuntimeDirectMeter() [2/2]

const p4::config::v1::DirectMeter * P4::ControlPlaneAPI::findP4RuntimeDirectMeter ( const p4::config::v1::P4Info & p4Info,
p4rt_id_t id )

Try to find the P4Info description for the given direct meter.

Returns
nullptr if the direct meter is not present in the P4Info object.

◆ findP4RuntimeExtern() [1/2]

const p4::config::v1::Extern * P4::ControlPlaneAPI::findP4RuntimeExtern ( const p4::config::v1::P4Info & p4Info,
cstring controlPlaneName )

Try to find the P4Info description for the given extern.

Returns
nullptr if the extern is not present in the P4Info object.

◆ findP4RuntimeExtern() [2/2]

const p4::config::v1::Extern * P4::ControlPlaneAPI::findP4RuntimeExtern ( const p4::config::v1::P4Info & p4Info,
p4rt_id_t id )

Try to find the P4Info description for the given extern.

Returns
nullptr if the extern is not present in the P4Info object.

◆ findP4RuntimeMatchField() [1/2]

const p4::config::v1::MatchField * P4::ControlPlaneAPI::findP4RuntimeMatchField ( const p4::config::v1::Table & p4Table,
cstring controlPlaneName )

Try to find the P4Info description for the given match field in a particular P4Info table.

Returns
nullptr if the match field is not present in the table.

◆ findP4RuntimeMatchField() [2/2]

const p4::config::v1::MatchField * P4::ControlPlaneAPI::findP4RuntimeMatchField ( const p4::config::v1::Table & p4Table,
p4rt_id_t id )

Try to find the P4Info description for the given match field in a particular P4Info table.

Returns
nullptr if the match field is not present in the table.

◆ findP4RuntimeMeter() [1/2]

const p4::config::v1::Meter * P4::ControlPlaneAPI::findP4RuntimeMeter ( const p4::config::v1::P4Info & p4Info,
cstring controlPlaneName )

Try to find the P4Info description for the given meter.

Returns
nullptr if the meter is not present in the P4Info object.

◆ findP4RuntimeMeter() [2/2]

const p4::config::v1::Meter * P4::ControlPlaneAPI::findP4RuntimeMeter ( const p4::config::v1::P4Info & p4Info,
p4rt_id_t id )

Try to find the P4Info description for the given meter.

Returns
nullptr if the meter is not present in the P4Info object.

◆ findP4RuntimeRegister() [1/2]

const p4::config::v1::Register * P4::ControlPlaneAPI::findP4RuntimeRegister ( const p4::config::v1::P4Info & p4Info,
cstring controlPlaneName )

Try to find the P4Info description for the given register.

Returns
nullptr if the register is not present in the P4Info object.

◆ findP4RuntimeRegister() [2/2]

const p4::config::v1::Register * P4::ControlPlaneAPI::findP4RuntimeRegister ( const p4::config::v1::P4Info & p4Info,
p4rt_id_t id )

Try to find the P4Info description for the given register.

Returns
nullptr if the register is not present in the P4Info object.

◆ findP4RuntimeTable() [1/2]

const p4::config::v1::Table * P4::ControlPlaneAPI::findP4RuntimeTable ( const p4::config::v1::P4Info & p4Info,
cstring controlPlaneName )

Try to find the P4Info description for the given table.

Returns
nullptr if the table is not is not present in the P4Info object.

◆ findP4RuntimeTable() [2/2]

const p4::config::v1::Table * P4::ControlPlaneAPI::findP4RuntimeTable ( const p4::config::v1::P4Info & p4Info,
p4rt_id_t id )

Try to find the P4Info description for the given table.

Returns
nullptr if the table is not is not present in the P4Info object.

◆ findP4RuntimeValueSet() [1/2]

const p4::config::v1::ValueSet * P4::ControlPlaneAPI::findP4RuntimeValueSet ( const p4::config::v1::P4Info & p4Info,
cstring controlPlaneName )

Try to find the P4Info description for the given value set.

Returns
nullptr if the value set is not present in the P4Info object.

◆ findP4RuntimeValueSet() [2/2]

const p4::config::v1::ValueSet * P4::ControlPlaneAPI::findP4RuntimeValueSet ( const p4::config::v1::P4Info & p4Info,
p4rt_id_t id )

Try to find the P4Info description for the given value set.

Returns
nullptr if the value set is not present in the P4Info object.

◆ getIdAnnotation()

std::optional< p4rt_id_t > P4::ControlPlaneAPI::getIdAnnotation ( const IR::IAnnotated * node)
Returns
the id allocated to the object through the @id annotation if any, or std::nullopt.

◆ getP4RuntimeId()

std::optional< p4rt_id_t > P4::ControlPlaneAPI::getP4RuntimeId ( const p4::config::v1::P4Info & p4Info,
const P4RuntimeSymbolType & type,
cstring controlPlaneName )

Looks up the P4Runtime id for a P4Runtime symbol. Returns nullptr if the object or the type does not exist.

◆ getTypeName()

cstring P4::ControlPlaneAPI::getTypeName ( const IR::Type * type,
TypeMap * typeMap )

getTypeName returns a cstring for use as type_name for a Type_Newtype. It returns nullptr if @type is not a Type_Newtype.

◆ getTypeWidth()

int P4::ControlPlaneAPI::getTypeWidth ( const IR::Type & type,
const TypeMap & typeMap )

getTypeWidth returns the width in bits for the @type, except if it is a user-defined type with a @p4runtime_translation annotation, in which case it returns W if the type is bit<W>, and 0 otherwise (i.e. if the type is string).

◆ hasTranslationAnnotation()

bool P4::ControlPlaneAPI::hasTranslationAnnotation ( const IR::Type * type,
TranslationAnnotation * payload )

hasTranslationAnnotation returns true iff the type is annotated by a valid p4runtime_translation annotation, in which case it populates the given TranslationAnnotation with the values parsed from the annotation.

◆ isControllerHeader()

bool P4::ControlPlaneAPI::isControllerHeader ( const IR::Type_Header * type)
Returns
true if @type has an @controller_header annotation.

◆ isHidden()

bool P4::ControlPlaneAPI::isHidden ( const IR::Node * node)
Returns
true if @node has an @hidden annotation.

◆ stringRepr() [1/3]

std::optional< std::string > P4::ControlPlaneAPI::stringRepr ( const IR::BoolLiteral * constant,
int width )

Convert a BoolLiteral to the P4Runtime bytes representation by calling stringReprConstant.

◆ stringRepr() [2/3]

std::optional< std::string > P4::ControlPlaneAPI::stringRepr ( const IR::Constant * constant,
int width )

Convert a Constant to the P4Runtime bytes representation by calling stringReprConstant.

◆ stringRepr() [3/3]

std::optional< std::string > P4::ControlPlaneAPI::stringRepr ( const TypeMap & typeMap,
const IR::Expression * expression )

Convert an Expression to the P4Runtime bytes representation. The type map is required to resolve complex expressions such as serializable enums.

◆ stringReprConstant()

std::optional< std::string > P4::ControlPlaneAPI::stringReprConstant ( big_int value,
int width )

Convert a bignum to the P4Runtime bytes representation. The value must fit within the provided @width expressed in bits. Padding will be added as necessary (as the most significant bits).

◆ szudzikPairing()

uint64_t P4::ControlPlaneAPI::szudzikPairing ( p4rt_id_t x,
p4rt_id_t y )

Computes a unique pairing of two input numbers. We use this to generate unique P4Runtime IDs for combinations of tables and key elements, or actions and parameters. https://en.wikipedia.org/wiki/Pairing_function#Other_pairing_functions The maximum szudzikPairing value is 2^64 - 1, which is why we use uint64_t for the p4rt_id_t, which is uint32_t bit.