I’m attempting to use P4 to parse DTN Bundle Protocol bundles, which relies heavily on Self-Delimiting Numeric Values (SDNVs). SDNVs are described here.
In summary SDNVs encodes a number into series of bytes where the MSB indicates whether there is still more to go (MSB 0 means this is the last byte). Therefore the length of a field encoded with SDNV isn’t known until the last byte is encountered (In Bundle Protocol the maximum allowed length is 64 bits).
Is it possible to parse bundles using P4’s current varbit capabilities?
The only standard way supported to parse/extract a varbit header is via the 2-argument extract method, which requires that you pass it the length of the header to be extracted. For SDNVs, you do not know this length until after you have scanned ahead to see which byte has its most significant bit to mean “the end of the SDNV”.
I suppose you could technically write a P4 parser that uses the lookahead operation to try to find the end of the SDNV, calculate its length, and then use one extract call on that calculated length to extract the SDNV. It seems likely that the BMv2 software switch might be able to support such P4 parser code, but it would be fairly unusual P4 code that might not be supported on lower-cost-per-Tbps P4-programmable devices like NICs and switches. You would need to check with the vendor of the device whether they could support it.