[P4-dev] implementation of Multicasting in BMV2

Montazeri Ghahjavarestani, Alireza alireza.montazeri at usask.ca
Mon Apr 24 13:22:13 EDT 2017


Hi All,


I have a question about implementation of multicasting for P4. I could find the following P4-dev topic regarding how to multicast packets in a P4 code. However, I was wondering if you could give me some details about how multicasting is implemented/supported in the P4 interpreter (bmv2). I see in the P4-14 specifications that multicasting is implemented in Buffering Mechanism. Could you also please tell me what files in bmv2 implement multicasting as well as Buffering Mechanism?


Regards,

Alireza

________________________________

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.
[https://avatars0.githubusercontent.com/u/10765181?v=3&s=400]<https://github.com/p4lang/behavioral-model>

GitHub - p4lang/behavioral-model: Rewrite of the ...<https://github.com/p4lang/behavioral-model>
github.com
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
[https://avatars0.githubusercontent.com/u/10765181?v=3&s=400]<https://github.com/p4lang/behavioral-model/blob/master/docs/simple_switch.md>

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

Antonin

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.



Regards,

Muthuraman

_______________________________________________
P4-dev mailing list
P4-dev at lists.p4.org<mailto:P4-dev at lists.p4.org>
http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org



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

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


More information about the P4-dev mailing list