[P4-dev] Difference between `clone` and `clone3` in v1model

Rui Miguel rmiguel at lasige.di.fc.ul.pt
Sat Oct 28 09:12:51 EDT 2017

Hi again!

Under this scheme, I don't believe you can simultaneously change egress_spec and clone. Both A and A' must leave through the same outgoing port.

Depending on what your purposes are, you can also employ a cheat that affronts the ingress/egress logic a little, which is to edit simple_switch.cpp to make the switch submit the clone not to egress_port, but to egress_spec:
Thus, the packet arrives at egress, you set its egress_spec (which does nothing for the original), then use clone().

~ Rui Miguel
----------------original message-----------------
From: "Dingyuan Hu" h-dy at outlook.com 
To: "Rui Miguel" rmiguel at lasige.di.fc.ul.pt 
CC: "p4-dev lists.p4.org" 
Date: Fri, 27 Oct 2017 07:16:55 +0000
> Hi Rui,
> Thanks for your reply. I have another question.
> I have a Packet A, and I clone it in ingress. So, I can get A and A’ in egress.
> How to set different `egress_spec` for A and A’ ?
> P4 not allowed change `egress_spec` (and `egress_port`) in egress and I can’t 
> change A’ because it is generated after ingress.
> Thanks,
> Dingyuan Hu
> ---
> On 27/10/2017, 06:02, "P4-dev on behalf of Rui Miguel" 
> wrote:
> Hello Dingyuan!
> I'm not entirely sure about all the informations below; others may confirm or 
> correct my statements.
> - "session" might be there to be interpreted by the control plane. In the case of 
> BMv2 simple_switch, it does nothing else by default. Also, both variations of 
> clone() call with session=0 do nothing (I believe session is added to 
> standard_metadata.clone_spec, and simple_switch evaluates whether it needs 
> to clone by performing the statement "if (clone_spec)", which yields 0, or 
> false, in such case).
> - clone3<T> is supposed to pass user-defined metadata to the cloned packet. You 
> should call clone3<T>() and replace T by the type of the metadata type you 
> defined. I.e., if your ingress pipeline is control IPipe(inout pkt_t pkt, inout 
> MYMETA_t, ...), then you should call clone3<MYMETA_t>(...). When the clone 
> enters ingress (or egress), it will preserve all the data in MYMETA_t from the 
> original.
> I don't know what happens if you try to pass another type.
> - About the CloneType. At least one of the reasons is practical: BMv2 
> simple_switch does not implement I2I or E2I, so there's no way it would work even 
> if they were present in the enum definition. The P4-14 spec does define such 
> primitives, but they are unsupported by simple_switch.
> Just a final hint: remember clone(), clone3(), recirculate() and resubmit() do 
> not have immediate effects; the magic only happens at the end of the pipeline 
> (ingress or egress).
> ~ Rui Miguel

More information about the P4-dev mailing list