Standard metadata is defined by the architecture and contains the following fields:
- drop
- This field can be used to drop a packet. The drop field defaults
to a value of 0 when a new packet arrives. You can update this field in P4 at
any stage in the Parser or Match-Action. At the input of the Deparser, the drop
field is evaluated and the packet dropped if the drop field has a value of 1. In
the case of a dropped packet, the user metadata can still optionally be output
from Vitis Networking P4 (see Metadata for more information). Note: Because this drop field is evaluated at the input to the Deparser, the corresponding packets are dropped before any headers are emitted into the packet stream and therefore without any potential reduction on packet stream bandwidth.
- ingress_timestamp
- There is a 64-bit timestamp counter in Vitis Networking P4 that increments every clock cycle from startup. For each new packet that arrives at the Parser input, this standard metadata field is populated with the timestamp counter value. This timestamp value can then be used at any stage in the Parser or Match-Action of the P4 code.
- parsed_bytes
- This field is automatically updated throughout the Parser so that it can be assigned to user metadata field(s) at various points in the Parser, to get several different offset values. The field at the end of the Parser provides the number of header bytes were successfully extracted during the Parser execution. It is equivalent to the “nextBitIndex” pointer referred to in the P4 Language Specification (see Resource Optimizations), but the value is given in bytes rather than bits. It is also equivalent to the byte offset where the packet payload begins following the packet headers.
- parser_error
- This field contains a parsing error code. This value is automatically updated by the Parser to be used in the Match-Action of the P4 code. The error codes are identified in the following table.
| Error Code | Type | Description |
|---|---|---|
| 0 | NoError | No error. |
| 1 | PacketTooShort | Not enough bits in packet for 'extract'. |
| 2 | NoMatch | 'select' expression has no matches. |
| 3 | StackOutOfBounds | Reference to an invalid element of a header stack. |
| 4 | HeaderTooShort | Extracting too many bits into a varbit field. |
| 5 | ParserTimeout | Parser execution time limit exceeded. Note: This
error type is not currently used by the Vitis
Networking P4 architecture.
|
| 6 | HeaderDepthLimitExceeded | Extracting a header that exceeds the Header Depth Limit packet offset of 8191 bytes. In this case, the header is marked as invalid and the parser execution is terminated for that packet. |
| 7-99 | user defined | New errors can be defined by the user with the use of the 'error' structure. User-defined errors can only be triggered with verify statements. |
Whenever a verify statement is triggered, parsing terminates immediately and the parser_error field is updated with the error ID that was triggered. This field can be accessed in the Match-Action of the P4 code and multiple actions can be taken based on the error. For example, to drop the packet:
if (smeta.parser_error != error.NoError) {
smeta.drop = 1;
return;
}
Note: VNP4 treats the accept and reject
parsing states in exactly the same way, without any architecture-specific
distinction. Packets are not automatically dropped when the parser reaches the
reject state. You can optionally drop packets or perform other actions in the
Match-Action control block based on the parser_error metadata, as shown
above.