[P4-dev] Reg: Packet Replication

Antonin Bas antonin at barefootnetworks.com
Tue Nov 29 14:50:51 EST 2016

Hi Muthuraman,

There are 2 ways of replicating packets in P4 / bmv2:

- using one of the clone primitives. These are described in the P4
specification: http://p4.org/wp-content/uploads/2016/11/p4-spec-latest.pdf.
Only clone_ingress_pkt_to_egress and clone_egress_pkt_to_egress are
supported by the behavioral-model software switch (
https://github.com/p4lang/behavioral-model). When cloning a packet, you
create an additional copy of it which is then injected in the queue between
the ingress and egress pipelines. Depending on which primitive you are
using, you are either cloning the ingress packet, i.e. the packet as it was
when it arrived at the switch, or the egress packet, i.e. the packet as it
is after being processed by the switch. clone_ingress_pkt_to_egress needs
to be called in the ingress pipeline while clone_egress_pkt_to_egress needs
to be called in the egress pipeline. Calling these action primitives
multiple times is useless as you can only create one clone per packet.
However, you can do "cascading cloning" and call a clone primitive on the
clone of the original packet... When using a clone primitive in your P4
program, you still have to map mirror ids (referred to as clone_spec in the
P4 spec) to actual port numbers at runtime, to indicate which egress port
should be used for the cloned packet. This can be done using the
"mirroring_add" command in the simple_switch CLI.

- using the packet replication engine to do multicast. This one is trickier
to use because the packet replication engine needs to be programmed. This
is what you would typically use to implement broadcast in a L2 switch. Here
are the requirements to use multicast:
    a) define the appropriate intrinsic metadata fields in your P4 program:
header_type intrinsic_metadata_t {
    fields {
        mcast_grp : 16;
        egress_rid : 16;
metadata intrinsic_metadata_t intrinsic_metadata;

More information on simple_switch intrinsic metadata fields can be found

    b) set intrinsic_metadata.mcast_grp to a non-zero value in the *ingress*
pipeline of your P4 program
modify_field(intrinsic_metadata.mcast_grp, 1);

    c) program the packet replication engine accordingly. Using the
simple_switch runtime CLI, you would use the following commands:
mc_mgrp_create 1           // create a multicast group with id 1 (because I
am using 1 in b))
mc_node_create 0 1        // create a multicast node with a rid
(replication id) of 0, which includes physical port 1 -> the switch will
return a handle of 0
mc_node_create 1 2        // create a multicast node with a rid
(replication id) of 1, which includes physical port 2 -> the switch will
return a handle of 1
mc_node_associate 1 0   // associate the multicast node with handle 0 to
mcast group 1
mc_node_associate 1 1   // associate the multicast node with handle 1 to
mcast group 1
With the above commands, setting intrinsic_metadata.mcast_grp to 1 will
replicate the packets across physical ports 1 and 2. You can create
additional nodes for other physical ports.

Let us know if you have further questions.


On Mon, Nov 28, 2016 at 10:27 PM, Muthuraman Elangovan <
muthuraman.e at hotmail.com> wrote:

> Hi All,
> I like to know how to replicate a packet on p4 switch.
> The h1 will send a packet(like ipv4) to h2 and also I want to replicate
> that packet to h3 and h4.
> The hosts h1, h2, h3 and h4 connected to switch s1.
> Regards,
> Muthuraman
> _______________________________________________
> P4-dev mailing list
> P4-dev at lists.p4.org
> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20161129/f47f8383/attachment-0002.html>

More information about the P4-dev mailing list