[P4-dev] Difference between `clone` and `clone3` in v1model
rmiguel at lasige.di.fc.ul.pt
Thu Oct 26 18:01:35 EDT 2017
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
From: "Dingyuan Hu" h-dy at outlook.com
Date: Wed, 25 Oct 2017 00:18:33 +0000
> Hi all,
> I notices in v1model.p4, there are two clone methods without comment.
> extern void clone(in CloneType type, in bit<32> session);
> extern void clone3<T>(in CloneType type, in bit<32> session, in T data);
> - What does `session` means?
> - What is difference between clone and clone3<T>?
> I think clone3<T> can clone packet with extra data, it's right? And how can I get
> Another question:
> - In emun CloneType, there are only two kind of types (I2E,E2E). Why not four (plus
> Can I just clone packet to ingress?
> I can't find answer in P4_14 SPEC.
> Dingyuan Hu
> P4-dev mailing list
> P4-dev at lists.p4.org
More information about the P4-dev