What is IP Multicasting?
IP multi-casting is a communication mechanism in which data is communicated from server to a set of clients who are interested in receiving that data. Any client can dynamically enter or leave the communication.
Though the overall concept seems very simple but the way it is implemented requires good understanding. So, in this tutorial we will cover the basics of IP multi-casting and how it is achieved.
Multicast IP address
To understand how multi-casting works, one needs to understand the structure of multicast IP address. Multicast IP address form the basis of multicast communication. In terms of classes, it’s the Class D IP addresses that are used as multicast IP addresses.
Here is the structure of Class D IP addresses :
So, it can be easily said that multicast IPs range from 224.0.0.0 to 239.255.255.255. As with the case of ports (where we have well known ports ie 0-1024), there are some reserved multicast IP addresses or well known IP addresses.
For example :
- 224.0.0.1 signifies every system on a subnet
- 224.0.0.2 signifies every router on a subnet
- and so on
In case of multicast communication, the server sends data on a particular multicast IP address and clients who intend to receive that data need to listen on the same multicast address. These clients can be various different networks. A group of clients listening to same multicast address is known as host group.
For those who are interested in this concept, it is helpful to understand how to calculate the IP header checksum.
On one hand, clients can leave and join a multicast group dynamically while on the other side the server does not need to know that identity of clients (joining or leaving). The clients use IGMP protocol for joining a multicast group.
Mapping multicast IP address with ethernet address
There is a specific mapping of IP multicast addresses with the ethernet mac addresses in order for multicast communication to work.
Before understanding the mapping, lets discuss multicast mac addresses :
- An ethernet mac address is of 6 bytes or 48 bits.
- A range of ethernet addresses ie from 00:00:5e:00:00:00 to 00:00:5e:ff:ff:ff is owned by IANA.
- Now, a half of these addresses are reserved for multicast addresses but with one condition that the first byte of a multicast ethernet address should be 01.
- This means that the ethernet addresses 01:00:5e:00:00:00 to 01:00:5e:7f:ff:ff are reserved as multicast ethernet addresses.
Now, here is how this mapping works :
- The lower order 23 bits of a multicast mac address should correspond to IP multicast group ID (see figure above).
- More precisely, this means that lower order 23 bits of multicast IP address should be same as lower order 23 bits of ethernet address.
This leads to another conclusion :
- A multicast group ID is of 28 bits, but only lower 23 bits of a multicast group ID are mapped. This means that the higher order 5 bits of a multicast group ID can be variable.
- This means that 32 different IP multicast group IDs can map to one ethernet address.
- Now, if a process on a system is interested in data packets destined for specific multicast group ID then the IP module or the device driver has to do perform some filtering operation as the interface card with a multicast ethernet address may receive packets of 32 different multicast group IDs.
Multicasting on single network
On a single network, the concept of multitasking works as follows :
- The server sends data packet to specific destination IP address or a multicast IP address.
- Through the mapping described above, the multicast IP address is converted into ethernet address and sent on the network.
- A process on a client that is willing to receive multicast traffic need to specify the same multicast IP address while communicating with the systems IP layer which further configures lower layers to look out for such multicast packets.
- When a multicast packet is received on the system, it is filtered in order to discard unwanted packets as 32 multicast group IDs can correspond to one ethernet address (explained above)
- Please note that there can be multiple processes on single client that want to receive packets with same multicast ID. In this case, the kernel makes sure that each process gets a copy of the packet.
Multicasting across the networks
Things get a bit complex when multicast IP packets have to traverse across networks because of that fact that multiple routers come into the scenario. Each router that comes in path should support multi-casting and should contain forwarding entries for multicast packets. Whenever a client joins a multicast group, a distribution tree is created for it which specifies the path for the multicast traffic corresponding to this multicast connection. Talking about routers, it is helpful to get yourself comfortable with the route command examples.
Multiple routers can be part of a distribution tree and one router can be part of multiple distributions trees. It means that if a router is a part of X distribution trees then it must contain X number of forwarding entries where each entry would correspond to a distribution tree.
Multicasting Vs Broadcasting
Multicasting can be a good alternative to broadcasting in some scenarios like when a client needs a bootstrap server to boot-up. Generally it is done by sending broadcast packets but this results in packet processing by those hosts also that do not provide this service. While if the same is done through multicast messages then the requests would get received by only those hosts that provide this service.