Description
It'd be handy to be able to specify, in one place, the preferred string representation of selected data types, e.g. IPv4 should be represented as dotted-decimal, etc. Use-cases would be to enable P4Runtime clients (CLIs, GUIs) and even server-side debug logs to format data in the appropriate human-readable format. Various ad hoc techniques are already solving this problem one way or another (custom annotations in P4 code; annotation APIs in vendor runtime libraries; etc.). A standardized way of solving this would be very useful. The oft-heard response to this perennial issue has been "use an annotation," so we might as well begin defining some standardized ones and present to the LDWG as a proposal for a new reserved annotation.
I hereby propose to:
- define a new reserved annotation, e.g.
@repr(format)
in the P4-16 language spec. I chose this based on the familiar Python__repr__
attribute (plus it's short). it can be anything we like but it should be concise! format
can be one of:ipv4
- IPv4 dotted decimal, e.g.192.168.1.1
ipv6
- IPv6 quad notation e.g.1234:5678::abcd
cidr
- Ternary/LPM value as an IP Prefix e.g.192.168.1.0/24
or2001:db8::/48
auto-selected based on size (32 bits or 128 bits)mac
- MAC address, e.g.01:23:45:67:89:ab
dec
- decimal e.g.4095
hex
- hexadecimal e.g.0xdeadbeef
bin
- binary e.g.01011010
bool
- boolean, e.g.true
ascii
- ASCII text, e.g.Hello
These annotations would appear in P4Info and can be consumed by clients as well as servers to use or not at their discretion. The only impact of this proposal would be to reserve and document a new annotation in the P4-16 language spec.