[P4-dev] Implementation on marking a particular flow
antonin at barefootnetworks.com
Thu Dec 22 14:43:09 EST 2016
Please see inline.
On Thu, Dec 22, 2016 at 7:15 AM, HAOJU XIAO <hamkuu at gmail.com> wrote:
> Dear all,
> I am trying to implement a P4 program that can mark the characteristics
> (i.e. some header information) of a packet, so that subsequent packets of
> the same flow can be processed faster under some shortcut processing
> After reading the P4 specification, I’m considering using Register to
> implement this feature. But I was confused by some description, as I quoted
> from the latest specification:
> 7.3 Registers
> Registers are stateful memories whose values can be read and written in
> actions. They are like counters, but can be used in a more general way to
> keep state.
> A simple example use might be to verify that a "first packet" was seen for
> a particular type of flow. A register cell would be allocated to the flow,
> initialized to "clear". When the protocol signalled a "first packet", the
> table would match on this value and update the flow’s cell to "marked".
> Subsequent packets in the flow could would be mapped to the same cell; the
> current cell value would be stored in metadata for the packet and a
> subsequent table could check that the flow was marked as active.
> What I confused about is [When the protocol signalled a "first packet”].
> Can anyone explain the mechanism on signaling a first packet? What does THE
> protocol mean in this case?
> If anyone had implement such feature before, any source code or
> pseudo-code would help.
Usually, you would compute a hash of some of the packet fields (e.g. the
5-tuple). You would use this hash to index into a register and turn the
marked bit on. You may also need the control-plane to come in from time to
time and reset the register to all 0s. You can also use more than one hash
function and implement some kind of bloom-filter.
Unlike tables, registers can be updated from the data plane, so there is no
need for control plane intervention (except to periodically resetting the
I am not sure exactly what they mean by "the protocol" :)
You should refer to this example:
In this example, we count packets belonging to a given flow, but you can
adapt the P4 code to use 1-bit registers.
> Another question (which might be silly question, but I really need to
> clear my confusion):
> Are stateful memories like Counter, Meter, and Register part of the
> metadata in the P4 language?
metadata is per-packet state, while stateful memories are persistent across
You can copy the content of a register to a metadata field using the
> Thanks in advance.
> P4-dev mailing list
> P4-dev at lists.p4.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the P4-dev