bfrt_helper.fields
Base Fields
JSONSerialisable
Field
- class Field(self, value=0)[source]
Bases:
JSONSerialisable
Base class for all BfRt Helper field objects.
A field is datatype and value defined within a P4 program. Such fields can be manipulated using gRPC, however requires translation from the client side as types can have arbitrary bitwidths.
Internally, the value is stored as an integer, since bitwise operations are easier to apply.
- Raises:
InvalidValue – Raised if the value assigned to the object is greater than the maximum permissable value
- to_bytes()[source]
Converts internal value to a byte array representing the contents
When marshalling to gRPC, the byte representation is used.
Predefined Fields
DevPort
DigestType
- class DigestType(self, value=0)[source]
Bases:
Field
Representation of a digest as defined in the BfRt spec.
A digest is used to send messages from the Tofino hardware to the runtime components. The 3 bit field can be used to inform the controller of any special semantics for a given message, for instance what type it is, or what data it includes. For instance, you could send a message containing an IP address, but change the digest type depending on whether it was IPv4 or IPv6.
Another example would be notifying the controller of any new MAC addresses seen on the wire.
In any case, this would not typically be used to send messages, but instead is useful for storing when received.
- bitwidth = 3
EgressSpec
IPv4Address
- class IPv4Address(self, address: str)[source]
Bases:
Field
Utility class for better representing IP addresses in a more pleasing way.
Can accept string representations and internally convert them to the required integer type, and vice versa when printing as a string. When the value is sent to the gRPC interface, it will be converted to a byte array as required.
Uses the
ipaddress
module.- Parameters:
address (str) – Dotted decimal IPv4 address string
- bitwidth = 32
Layer2Port
MACAddress
- class MACAddress(self, address)[source]
Bases:
Field
Utility class for better representing IP addresses in a more pleasing way.
Can accept string representations and internally convert them to the required integer type, and vice versa when printing as a string. When the value is sent to the gRPC interface, it will be converted to a byte array as required.
Internally uses string manipulation and integer casting for serialisation from and to integer value.
- Parameters:
address (str) – Colon seperated 6 byte hexadecimal address string.
- bitwidth = 48