# Multicast to \*all\* ports

**URL:** https://forum.p4.org/t/multicast-to-all-ports/781
**Category:** Uncategorized
**Created:** [May 18, 2023, 2:09pm UTC](https://forum.p4.org/t/multicast-to-all-ports/781 "2023-05-18T14:09:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kesnar](https://avatars.discourse-cdn.com/v4/letter/k/8baadc/32.png) [@kesnar](https://forum.p4.org/u/kesnar)
#### Post date: [May 18, 2023, 2:09pm UTC](https://forum.p4.org/t/multicast-to-all-ports/781/1 "2023-05-18T14:09:08Z")

</div>

Hello all,

I have found how to implement a multicast in P4 by setting the `standard_metadata.mcast_grp` field to a specific group and also binding various egress ports to specific multicast groups.  
i.e. in P4Runtime:

```auto
multicast_group_entry {
multicast_group_id: 1
replicas {
egress_port: 1
}
replicas {
egress_port: 2
}
}

```

My problem is that the above way requires to know the number of ports beforehand. Is there a way for a global multicast?  
For example, is there a default multicast group that contains all the ports?  
Or, is there a way to get the ports, thus use a script to create the group?

---

<div class="post-metadata">

### Author: ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)
#### Post date: [May 18, 2023, 2:33pm UTC](https://forum.p4.org/t/multicast-to-all-ports/781/2 "2023-05-18T14:33:43Z")

</div>

I know of no way to do a global multicast without knowing the list of port ids before-hand.

It is _common_ when writing production-quality networking control software, though, to have a way (or develop one) where you know the complete list of ports.

---

<div class="post-metadata">

### Author: ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)
#### Post date: [May 18, 2023, 2:36pm UTC](https://forum.p4.org/t/multicast-to-all-ports/781/3 "2023-05-18T14:36:28Z")

</div>

When using simple\_switch\_grpc as the software switch, the set of ports can be different each time you start it, by using different command line options to map the port numbers to veth or physical Ethernet ports. I am not aware of any existing API you can call to request that list of ports from the controller software to simple\_switch\_grpc. All the information is available in some data structures in simple\_switch\_grpc’s memory to provide that data, if someone wanted to implement such an API.
