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

Rui Miguel rmiguel at lasige.di.fc.ul.pt
Thu Oct 26 18:01:35 EDT 2017


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
 
----------------original message-----------------
From: "Dingyuan Hu" h-dy at outlook.com 
To: "p4-dev" 
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 
> them?
> 
> Another question: 
> https://github.com/p4lang/p4c/blob/3ad8d93f334a34d181e8d9d83100d797b
> ac3f65a/p4include/v1model.p4#L130-L134 
> 
> - In emun CloneType, there are only two kind of types (I2E,E2E). Why not four (plus 
> E2I,I2I).
> Can I just clone packet to ingress?
> 
> I can't find answer in P4_14 SPEC. 
> 
> Thanks,
> Dingyuan Hu
> 
> _______________________________________________
> P4-dev mailing list
> P4-dev at lists.p4.org 
> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
> 






More information about the P4-dev mailing list