bmv2
Designing your own switch target with bmv2
|
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 | |
Header & | get_header (header_id_t header_index) |
Access the Header with id header_index , with no bound checking. More... | |
const Header & | get_header (header_id_t header_index) const |
Access the Header with id header_index , with no bound checking. More... | |
Header & | get_header (const std::string &header_name) |
const Header & | get_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... | |
Field & | get_field (header_id_t header_index, int field_offset) |
const Field & | get_field (header_id_t header_index, int field_offset) const |
Field & | get_field (const std::string &field_name) |
const Field & | get_field (const std::string &field_name) const |
bool | has_field (const std::string &field_name) const |
HeaderStack & | get_header_stack (header_stack_id_t header_stack_index) |
const HeaderStack & | get_header_stack (header_stack_id_t header_stack_index) const |
HeaderUnion & | get_header_union (header_union_id_t header_union_index) |
const HeaderUnion & | get_header_union (header_union_id_t header_union_index) const |
HeaderUnionStack & | get_header_union_stack (header_union_stack_id_t header_union_stack_index) |
const HeaderUnionStack & | get_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... | |
PHV & | operator= (const PHV &other)=delete |
Deleted copy assignment operator. More... | |
PHV (PHV &&other)=default | |
Default move constructor. More... | |
PHV & | operator= (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 |
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().
using bm::PHV::const_header_iterator = std::vector<Header>::const_iterator |
Used to iterate over headers in ascending id order.
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.
using bm::PHV::header_iterator = std::vector<Header>::iterator |
Used to iterate over headers in ascending id order.
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.
|
delete |
Deleted copy constructor.
|
default |
Default move constructor.
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:
src
header is validsrc
header is metadatasrc
header iff it is a valid packet header or a metadata header
|
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.
|
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.
|
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.
|
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.
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>.
|
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.
|
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.
|
inline |
Access the Header with id header_index
, with no bound checking.
|
inline |
Access the Header with id header_index
, with no bound checking.
|
inline |
Access the HeaderStack with id header_stack_index
, with no bound checking.
|
inline |
Access the HeaderStack with id header_stack_index
, with no bound checking.
|
inline |
Access the HeaderUnion with id header_union_index
, with no bound checking.
|
inline |
Access the HeaderUnion with id header_union_index
, with no bound checking.
|
inline |
Access the HeaderUnionStack with id header_union_stack_index
, with no bound checking.
|
inline |
|
inline |
|
inline |
|
inline |
Returns an iterator to the first header in the PHV.
|
inline |
Returns an iterator to the first header in the PHV.
|
inline |
Returns an iterator to the last element in the PHV. See header_begin().
|
inline |
Returns an iterator to the last element in the PHV. See header_begin().
|
inline |
Returns an iterator to the first header in the "name -> header reference" map maintained by the PHV.
|
inline |
Returns an iterator to the first header in the "name -> header reference" map maintained by the PHV.
|
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.
|
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.
|
inline |
Returns the number of headers included in the PHV.
void bm::PHV::reset_header_stacks | ( | ) |
Reset the state (i.e. make them empty) of all HeaderStack instances in the PHV.
void bm::PHV::reset_headers | ( | ) |
Reset all header fields to 0
.
void bm::PHV::reset_metadata | ( | ) |
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
.