The idea: one packet, many receivers
A video source wants to reach many viewers on the same LAN. With unicast it would send one copy per viewer. With IP multicast it sends one packet to a group address, here 239.1.1.1, and the network makes the copies. Two things must then be solved. The router must learn whether anyone on the LAN wants the group: that is IGMP, the Internet Group Management Protocol. And the switch must decide which ports get the copies: a plain switch sends them everywhere, a switch with IGMP snooping sends them only where they are wanted.
Group addresses and MAC addresses
Multicast groups use the IPv4 range 224.0.0.0/4. Addresses in 224.0.0.0/24 are for the local link only: 224.0.0.1 means all systems, 224.0.0.2 all routers. 239.0.0.0/8 is for groups used inside one organisation, like the video group on this page. On Ethernet, a group maps to a MAC address: the prefix 01:00:5e, one zero bit, then the low 23 bits of the IP address. So 239.1.1.1 becomes 01:00:5e:01:01:01. Five bits of the IP address are lost, so 32 groups share each MAC address.
Joining: the Membership Report
When an app on a host joins a group (the socket option IP_ADD_MEMBERSHIP), the kernel sends a Membership Report (IGMPv2 type 0x16) to the group address itself. All IGMP messages have IP TTL 1 and the Router Alert option: they never leave the LAN. The router R1 marks the group as Members Present and starts a group timer of 260 s, the Group Membership Interval (2 × 125 s + 10 s). RFC 2236 also asks the host to repeat the report once after up to 10 s in case it was lost; the page does not draw that repeat (Demo: two hosts join, video goes only to them).
Queries and report suppression
A host may vanish without saying goodbye, so the router asks again. One router per LAN is the querier (the one with the lowest IP address). Every 125 s (the Query Interval) it sends a General Query, type 0x11 with group 0.0.0.0, to 224.0.0.1. The query carries a Max Resp Time of 10 s. Each member starts a timer with a random delay up to that time and becomes a Delaying Member. The first timer to fire sends a report. The router only needs to know that some member exists, so in IGMPv2 every other member that hears that report cancels its own timer: report suppression. One report per group per query is enough (Demo: General Query and report suppression).
| Message | Type | Sent to | Sent by |
|---|---|---|---|
| General Query | 0x11, group 0.0.0.0 | 224.0.0.1 | querier, every 125 s |
| Group-Specific Query | 0x11, group 239.1.1.1 | 239.1.1.1 | querier, after a Leave |
| v2 Membership Report | 0x16 | 239.1.1.1 | member host |
| Leave Group | 0x17 | 224.0.0.2 | leaving host |
Leaving: the Group-Specific Query
When a host leaves (IP_DROP_MEMBERSHIP), it sends a Leave Group (type 0x17) to 224.0.0.2, all routers. The router cannot tell if that was the last member, so it moves the group to Checking Membership and sends a Group-Specific Query to the group, with a Max Resp Time of 1 s (the Last Member Query Interval). It sends up to 2 of them (the Last Member Query Count), 1 s apart. If any member answers, the group goes back to Members Present and the second query is not sent (Demo: H1 leaves, H3 keeps the group). If nobody answers, the router deletes the group after 2 s, and the stream stops within seconds instead of after 260 s (Demo: the last member leaves, the stream stops).
IGMP snooping
To a plain switch, a multicast MAC address is like the broadcast address: it never learns it from a source address, so it floods the frame out of every port. Every host gets the video, and the ones that never joined throw it away in their network card after it has already used their link (Demo: no snooping, the video floods every port). A switch with IGMP snooping (RFC 4541) reads the IGMP messages that pass through it:
- a Query tells it which port leads to the router (the router port, port 1 here); queries are still flooded;
- a Report adds its port to the group's list; the report is passed only to the router port;
- a Leave is passed to the router port; the port is removed if no report comes back on it after the router's Group-Specific Queries;
- data for the group goes only to the listed ports and the router port.
Because reports now go only to the router, the other members never hear them, and report suppression stops happening: every member answers each query. That is what the switch needs, since it must see at least one report on every member port (Demo: with snooping, every member answers).
IGMPv3
IGMPv3 (RFC 3376) adds source filtering: a host can say "239.1.1.1, but only from 10.0.0.10" (INCLUDE mode) or "from anyone except …" (EXCLUDE mode). That makes source-specific multicast (SSM, 232.0.0.0/8) possible. v3 reports (type 0x22) go to 224.0.0.22, carry a list of group records, and have no report suppression: each host answers for itself, which also suits snooping switches. Leaving is a report that changes the group to INCLUDE with no sources.
Beyond the LAN: PIM
IGMP only runs between hosts and their first router. To get a stream from a source on another network, routers use a multicast routing protocol, usually PIM (Protocol Independent Multicast): the router that hears a report sends a PIM Join towards the source or a rendezvous point, and a distribution tree grows hop by hop. On this page the source is on the same LAN, so R1 gets a copy of the video but has no PIM join from another router and does not route it on.
See also the Ethernet switch for how a switch learns unicast MAC addresses and why it floods what it does not know, ARP for broadcast on the same LAN, VLANs, which limit flooding by splitting one switch into several LANs, and TCP vs UDP: multicast traffic is UDP.
What the page leaves out
The querier election between two routers and the Other Querier Present timer, IGMPv1 hosts and routers on the same LAN (compatibility timers), the repeated unsolicited report, startup queries, IGMPv3 records and source lists, snooping details such as fast-leave, the snooping querier, flooding of unregistered groups (some switches flood a group with no members; this page sends it only to the router port) and the 224.0.0.x range that is always flooded, MLD (the IPv6 version of IGMP), and PIM itself.