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

Dingyuan Hu h-dy at outlook.com
Fri Oct 27 03:16:55 EDT 2017


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" <p4-dev-bounces at lists.p4.org on behalf of rmiguel at lasige.di.fc.ul.pt> 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