# Generating and Cloning packets

**URL:** <https://forum.p4.org/t/generating-and-cloning-packets/351>\
**Category:** Getting Started with P4\
**Created:** [May 31, 2022, 5:24pm UTC](https://forum.p4.org/t/generating-and-cloning-packets/351 "2022-05-31T17:24:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sorosuh](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@sorosuh](https://forum.p4.org/u/sorosuh)\
**Post date:** [May 31, 2022, 5:24pm UTC](https://forum.p4.org/t/generating-and-cloning-packets/351/1 "2022-05-31T17:24:24Z")

</div>

Hello. I am using the open-source p4c compiler with the v1model architecture.  
I like to generate new packets in my programmable switch, but it seems that there is no way to do it. (If there is a way, please let me know!).  
So, the closest way to generate a packet for me is to clone a packet. I am simply calling `clone_preserving_field_list(CloneType.I2E, 5, 1);` in my Ingress pipeline. Although I see the clone function is called (“Cloning packet at ingress”) in the log file of the respective switch, I do not see any outcome. I mean, I do not receive the cloned packets or even any sign of execution of cloned packets in the log file of the respective switch.  
Maybe I am missing something because I could not understand the session parameter. I just simply put 5 as clone session id!

---

<div class="post-metadata">

**Author:** ![sorosuh](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@sorosuh](https://forum.p4.org/u/sorosuh)\
**Post date:** [May 31, 2022, 6:48pm UTC](https://forum.p4.org/t/generating-and-cloning-packets/351/2 "2022-05-31T18:48:11Z")

</div>

Finally, I found the answer!  
I did not know I have to enter another command (mirroring\_add #mirroring\_id #port\_number) in behavioral-model/targets/simple\_switch/simple\_switch\_CLI command line!  
I found an example online to understand it.

---

<div class="post-metadata">

**Author:** ![dnredson](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@dnredson](https://forum.p4.org/u/dnredson)\
**Post date:** [September 26, 2023, 1:12pm UTC](https://forum.p4.org/t/generating-and-cloning-packets/351/3 "2023-09-26T13:12:04Z")

</div>

> [@sorosuh](#):
>
> behavioral-model/targets/simple\_switch/simple\_switch\_CLI

Where did you find the example? I’m trying the same and can’t find it anywhere

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [September 26, 2023, 1:13pm UTC](https://forum.p4.org/t/generating-and-cloning-packets/351/4 "2023-09-26T13:13:57Z")

</div>

I am guessing they might be referring to the documentation here: [https://github.com/p4lang/behavioral-model/blob/main/docs/runtime\_CLI.md#mirroring\_add-mirroring\_add\_mc-mirroring\_delete-mirroring\_get](https://github.com/p4lang/behavioral-model/blob/main/docs/runtime_CLI.md#mirroring_add-mirroring_add_mc-mirroring_delete-mirroring_get)
