[P4-dev] Reg: Packet Replication

Muthuraman Elangovan muthuraman.e at hotmail.com
Wed Nov 30 04:38:14 EST 2016

Thanks for the detailed explanation about two different approach.

I will try it out with second approach and let you know if i have doubt on it.

From: Antonin Bas <antonin at barefootnetworks.com>
Sent: Wednesday, November 30, 2016 3:50 AM
To: Muthuraman Elangovan
Cc: p4-dev at lists.p4.org
Subject: Re: [P4-dev] Reg: Packet Replication

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.

GitHub - p4lang/behavioral-model: Rewrite of the ...<https://github.com/p4lang/behavioral-model>
behavioral-model - Rewrite of the behavioral model as a C++ project without auto-generated code (except for the PD interface)

- 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 here: https://github.com/p4lang/behavioral-model/blob/master/docs/simple_switch.md

behavioral-model - Rewrite of the behavioral model as a C++ project without auto-generated code (except for the PD interface)

    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<mailto: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.



P4-dev mailing list
P4-dev at lists.p4.org<mailto:P4-dev at lists.p4.org>

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

More information about the P4-dev mailing list