I’m new to P4 and I have a specific requirement:
When a packet arrives at the data plane, I want to send some related information of the packet to the control plane, while still allowing the original packet to continue with its normal forwarding behavior.
From my understanding, I might be able to use clone_preserving_field_list
to achieve this, possibly in combination with PacketIn
and PacketOut
. However, I’m a bit unclear on the exact steps and best practices for this use case.
Also, are there any official documents, examples, or tutorials that explain this scenario?
Any help would be greatly appreciated!
Thanks in advance.
Yes, cloning (aka mirroring) a packet is a good approach if you want to process the original packet “normally” (whatever that happens to mean in your P4 program), but also create a copy that you treat differently, e.g. send it to a different place, perhaps with different headers.
Here is a link to a public example P4 program that demonstrates using PacketIn from switch to controller, and PacketOut messages from controller to switch: p4-guide/ptf-tests/packetinout at master · jafingerhut/p4-guide · GitHub
Note: It does not use any clone operations. It demonstrates the ability of a P4 program to receive a packet, and send exactly one copy of that packet to the controller via PacketIn, without cloning it. So that program is not exactly what you need, but at least it demonstrates the PacketIn and PacketOut features in detail.