bmv2
Designing your own switch target with bmv2
Public Types | Public Member Functions | List of all members
bm::PHV Class Reference

Public Types

using header_name_iterator = HeaderNamesMap::iterator
 
using const_header_name_iterator = HeaderNamesMap::const_iterator
 
using header_iterator = std::vector< Header >::iterator
 Used to iterate over headers in ascending id order. More...
 
using const_header_iterator = std::vector< Header >::const_iterator
 Used to iterate over headers in ascending id order. More...
 

Public Member Functions

Headerget_header (header_id_t header_index)
 Access the Header with id header_index, with no bound checking. More...
 
const Headerget_header (header_id_t header_index) const
 Access the Header with id header_index, with no bound checking. More...
 
Headerget_header (const std::string &header_name)
 
const Headerget_header (const std::string &header_name) const
 
bool has_header (const std::string &header_name) const
 Returns true if there exists a Header with name header_name in this PHV. More...
 
Fieldget_field (header_id_t header_index, int field_offset)
 
const Fieldget_field (header_id_t header_index, int field_offset) const
 
Fieldget_field (const std::string &field_name)
 
const Fieldget_field (const std::string &field_name) const
 
bool has_field (const std::string &field_name) const
 
HeaderStackget_header_stack (header_stack_id_t header_stack_index)
 
const HeaderStackget_header_stack (header_stack_id_t header_stack_index) const
 
HeaderUnionget_header_union (header_union_id_t header_union_index)
 
const HeaderUnionget_header_union (header_union_id_t header_union_index) const
 
HeaderUnionStackget_header_union_stack (header_union_stack_id_t header_union_stack_index)
 
const HeaderUnionStackget_header_union_stack (header_union_stack_id_t header_union_stack_index) const
 
void reset ()
 Mark all Header instances in the PHV as invalid. More...
 
void reset_header_stacks ()
 
void reset_metadata ()
 
void reset_headers ()
 Reset all header fields to 0. More...
 
void set_written_to (bool written_to_value)
 
 PHV (const PHV &other)=delete
 Deleted copy constructor. More...
 
PHVoperator= (const PHV &other)=delete
 Deleted copy assignment operator. More...
 
 PHV (PHV &&other)=default
 Default move constructor. More...
 
PHVoperator= (PHV &&other)=default
 Default move assignment operator. More...
 
void copy_headers (const PHV &src)
 
header_name_iterator header_name_begin ()
 
const_header_name_iterator header_name_begin () const
 
header_name_iterator header_name_end ()
 
const_header_name_iterator header_name_end () const
 
header_iterator header_begin ()
 
const_header_iterator header_begin () const
 
header_iterator header_end ()
 Returns an iterator to the last element in the PHV. See header_begin(). More...
 
const_header_iterator header_end () const
 Returns an iterator to the last element in the PHV. See header_begin(). More...
 
size_t num_headers () const
 Returns the number of headers included in the PHV. More...
 
const std::string get_field_name (header_id_t header_index, int field_offset) const
 

Detailed Description

Each Packet instance owns a PHV instance, used to store all the data extracted from the packet by parsing. It essentially consists of a vector of Header instances, each one of these Header instance itself consisting of a vector of Field instances. The PHV also owns the HeaderStack instances for the packet.

Because PHV objects are expensive to construct, we maintain a pool of them. Every time a new Packet is constructed, we retrieve one PHV from the pool (construct a new one if the pool is empty). When the Packet is destroyed, we release its PHV to the pool. Because the PHV depends on the P4 Context, there is actually one PHV pool per Contex. If the Context of a Packet changes, its current PHV is released to the old pool and a new PHV is obtained from the new pool. Because we use a pool system, a Packet may receive a PHV which still contains "state" (e.g. field values) from its previous Packet owner. This is why we expose methods like reset(), reset_header_stacks() and reset_metadata().

Member Typedef Documentation

◆ const_header_iterator

using bm::PHV::const_header_iterator = std::vector<Header>::const_iterator

Used to iterate over headers in ascending id order.

◆ const_header_name_iterator

using bm::PHV::const_header_name_iterator = HeaderNamesMap::const_iterator

Used to iterate over headers and access their names. The order may be different from the header id order.

◆ header_iterator

using bm::PHV::header_iterator = std::vector<Header>::iterator

Used to iterate over headers in ascending id order.

◆ header_name_iterator

using bm::PHV::header_name_iterator = HeaderNamesMap::iterator

Used to iterate over headers and access their names. The order may be different from the header id order.

Constructor & Destructor Documentation

◆ PHV() [1/2]

bm::PHV::PHV ( const PHV other)
delete

Deleted copy constructor.

◆ PHV() [2/2]

bm::PHV::PHV ( PHV &&  other)
default

Default move constructor.

Member Function Documentation

◆ copy_headers()

void bm::PHV::copy_headers ( const PHV src)

Copy the headers of src PHV to this PHV. The two PHV instances need to belong to the same Context. Every header:

  • is marked valid iff the corresponding src header is valid
  • is marked as metadata iff the corresponding src header is metadata
  • receives the same field values as the corresponding src header iff it is a valid packet header or a metadata header

◆ get_field() [1/4]

Field& bm::PHV::get_field ( const std::string &  field_name)
inline

Access the Field with name field_name. If field_name does not match any known fields, an std::out_of_range exception will be thrown. field_name must follow the "hdr.f" format.

◆ get_field() [2/4]

const Field& bm::PHV::get_field ( const std::string &  field_name) const
inline

Access the Field with name field_name. If field_name does not match any known fields, an std::out_of_range exception will be thrown. field_name must follow the "hdr.f" format.

◆ get_field() [3/4]

Field& bm::PHV::get_field ( header_id_t  header_index,
int  field_offset 
)
inline

Access the Field at offset field_offset in the Header with id header_index. See PHV::get_header(header_id_t header_index) and Header::get_field(int field_offset) for more information.

◆ get_field() [4/4]

const Field& bm::PHV::get_field ( header_id_t  header_index,
int  field_offset 
) const
inline

Access the Field at offset field_offset in the Header with id header_index. See PHV::get_header(header_id_t header_index) and Header::get_field(int field_offset) for more information.

◆ get_field_name()

const std::string bm::PHV::get_field_name ( header_id_t  header_index,
int  field_offset 
) const

Returns the full name of the field as a new string. The name is of the form <hdr_name>.<f_name>.

◆ get_header() [1/4]

Header& bm::PHV::get_header ( const std::string &  header_name)
inline

Access the Header with name header_name. If header_name does not match any known headers, an std::out_of_range exception will be thrown.

◆ get_header() [2/4]

const Header& bm::PHV::get_header ( const std::string &  header_name) const
inline

Access the Header with name header_name. If header_name does not match any known headers, an std::out_of_range exception will be thrown.

◆ get_header() [3/4]

Header& bm::PHV::get_header ( header_id_t  header_index)
inline

Access the Header with id header_index, with no bound checking.

◆ get_header() [4/4]

const Header& bm::PHV::get_header ( header_id_t  header_index) const
inline

Access the Header with id header_index, with no bound checking.

◆ get_header_stack() [1/2]

HeaderStack& bm::PHV::get_header_stack ( header_stack_id_t  header_stack_index)
inline

Access the HeaderStack with id header_stack_index, with no bound checking.

◆ get_header_stack() [2/2]

const HeaderStack& bm::PHV::get_header_stack ( header_stack_id_t  header_stack_index) const
inline

Access the HeaderStack with id header_stack_index, with no bound checking.

◆ get_header_union() [1/2]

HeaderUnion& bm::PHV::get_header_union ( header_union_id_t  header_union_index)
inline

Access the HeaderUnion with id header_union_index, with no bound checking.

◆ get_header_union() [2/2]

const HeaderUnion& bm::PHV::get_header_union ( header_union_id_t  header_union_index) const
inline

Access the HeaderUnion with id header_union_index, with no bound checking.

◆ get_header_union_stack() [1/2]

HeaderUnionStack& bm::PHV::get_header_union_stack ( header_union_stack_id_t  header_union_stack_index)
inline

Access the HeaderUnionStack with id header_union_stack_index, with no bound checking.

◆ get_header_union_stack() [2/2]

const HeaderUnionStack& bm::PHV::get_header_union_stack ( header_union_stack_id_t  header_union_stack_index) const
inline

◆ has_field()

bool bm::PHV::has_field ( const std::string &  field_name) const
inline

Returns true if there exists a Field with name field_name in this PHV. field_name must follow the "hdr.f" format.

◆ has_header()

bool bm::PHV::has_header ( const std::string &  header_name) const
inline

Returns true if there exists a Header with name header_name in this PHV.

◆ header_begin() [1/2]

header_iterator bm::PHV::header_begin ( )
inline

Returns an iterator to the first header in the PHV.

auto it = phv.header_begin();
const Header &header = *it;

◆ header_begin() [2/2]

const_header_iterator bm::PHV::header_begin ( ) const
inline

Returns an iterator to the first header in the PHV.

auto it = phv.header_begin();
const Header &header = *it;

◆ header_end() [1/2]

header_iterator bm::PHV::header_end ( )
inline

Returns an iterator to the last element in the PHV. See header_begin().

◆ header_end() [2/2]

const_header_iterator bm::PHV::header_end ( ) const
inline

Returns an iterator to the last element in the PHV. See header_begin().

◆ header_name_begin() [1/2]

header_name_iterator bm::PHV::header_name_begin ( )
inline

Returns an iterator to the first header in the "name -> header reference" map maintained by the PHV.

auto it = phv.header_name_begin();
const std::string &header = it->first;
const Header &header = it->second;

◆ header_name_begin() [2/2]

const_header_name_iterator bm::PHV::header_name_begin ( ) const
inline

Returns an iterator to the first header in the "name -> header reference" map maintained by the PHV.

auto it = phv.header_name_begin();
const std::string &header = it->first;
const Header &header = it->second;

◆ header_name_end() [1/2]

header_name_iterator bm::PHV::header_name_end ( )
inline

Returns an iterator to the last element in the "name -> header reference" map maintained by the PHV. See header_name_begin() for more information.

◆ header_name_end() [2/2]

const_header_name_iterator bm::PHV::header_name_end ( ) const
inline

Returns an iterator to the last element in the "name -> header reference" map maintained by the PHV. See header_name_begin() for more information.

◆ num_headers()

size_t bm::PHV::num_headers ( ) const
inline

Returns the number of headers included in the PHV.

◆ operator=() [1/2]

PHV& bm::PHV::operator= ( const PHV other)
delete

Deleted copy assignment operator.

◆ operator=() [2/2]

PHV& bm::PHV::operator= ( PHV &&  other)
default

Default move assignment operator.

◆ reset()

void bm::PHV::reset ( )

Mark all Header instances in the PHV as invalid.

◆ reset_header_stacks()

void bm::PHV::reset_header_stacks ( )

Reset the state (i.e. make them empty) of all HeaderStack instances in the PHV.

◆ reset_headers()

void bm::PHV::reset_headers ( )

Reset all header fields to 0.

◆ reset_metadata()

void bm::PHV::reset_metadata ( )

Reset all metadata fields to 0. If your target assumes that metadata fields are zero-initialized for every incoming packet, you will need to call this on the PHV member of every new Packet you create.

◆ set_written_to()

void bm::PHV::set_written_to ( bool  written_to_value)

Set the written_to flag maintained by each field. This flag can be queried at any time by the target, using the Field interface, and can be used to check whether the field has been modified since written_to was last set to false.


The documentation for this class was generated from the following file: