[P4-dev] Implementation on marking a particular flow

Antonin Bas antonin at barefootnetworks.com
Thu Dec 22 14:43:09 EST 2016


Hi Xiao,

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
> pipeline.
>
> 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
register).
I am not sure exactly what they mean by "the protocol" :)
You should refer to this example:
https://github.com/p4lang/tutorials/tree/master/SIGCOMM_2016/heavy_hitter.
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
packets
You can copy the content of a register to a metadata field using the
register_read primitive.


>
>
> Thanks in advance.
>
> Regards,
>
> Xiao
>
>
>
> _______________________________________________
> P4-dev mailing list
> P4-dev at lists.p4.org
> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
>



-- 
Antonin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20161222/cd86b4da/attachment-0002.html>


More information about the P4-dev mailing list