Broadcast in L2 switch

Hello all,

I want to implement broadcast in L2 switch, i was able to find 3 fields that are related to this,which are egress_port, egress_rid, mcast_grp but i don’t know how to use them. Can someone help me with this?

There are many distinct values of mcast_grp (in BMv2 I think at least in the range from [1,65535], but I do not recall the maximum number it supports). If you assign a non-0 value to that field in your ingress P4 code, then when the packet reaches the end of ingress, it will be replicated as many times as the configuration of that mcast_grp value has been configured by your control plane software, and to the desired list of output ports.

This simple demo program and PTF test is not exactly what you want, but it does demonstrate a P4 program that assigns non-0 values to the mcast_grp field, and the PTF Python test demonstrates sending P4Runtime API messages to the switch that modify the configuration of the multicast group used by the P4 program, before the test packets are sent through the switch: p4-guide/demo7 at master · jafingerhut/p4-guide · GitHub

I have a running P4 program which implements a L2 learning switch, along with a simple P4Runtime controller for it there: p4runtime-go-client/cmd/l2_switch at main · antoninbas/p4runtime-go-client · GitHub.

Thank you guys, you helped me a lot.