There is a myriad of webpages about this question. But here is just my way of look at it. Multicast customization is not too tricky, but I’d like to explain how and why it works.
What is the multicast traffic?
Multicast is a kind of data shipment from one source to many destination points. Is there any difference between broadcast and multicast? Yes, absolutely. Multicast traffic is going to be shipped only by demand. The broadcast is going to be sent to every node in the same segment. That way of network bandwidth use is much more flexible and economic. Also multicast has only one copy at the special branch of network and it’s going to be severed only on the fork. While broadcast is generated by principle “one host – one copy”. The similarity between these ways of network connection – they are both transmitted within LAN.
Multicast technology based on UDP protocol. That way allows to send data as quickly as possible. There is no need to leverage a TCP instead. By TCPlost packets should be sent again. For dynamical transmission it doesn’t have a real sense, because packets with later order were already handled. UDP connection is not reliable, but it can provide a dynamic data transmission. That’s why multicast has to be shipped by UDP.
Why do we need a multicast?
There are some kinds of technological life which have to pass their data rapidly and massively. There could be audio/video conferences, IPTV, database replication structure and so forth. And there is still no limit to use.
How to stream multicast?
By RFC 5771 standard, there is a huge adress reserves for multicast streaming. The range of IP addresses is between 224.0.0.0–239.255.255.255 (shortly 224.0.0.0/4). IPV6 analog – ff00:: –f fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (or ff00::/8). Feel free to take any address from this range and assign UDP port with any available number (5000, for example).
Once in a while I have to stream media data as a multicast. For this goals I can suggest:
ffmpeg -re -i source.ts -vcodec libx264 -acodec aac -f mpegts "udp://234.5.5.5:5000"
ffmpeg –re –i source.ts –vcodec libx264 –acodec aac –f mpegts “udp://234.5.5.5:5000”
2. tsplay (as a part of tstools utilities)
tsplay source.ts 234.5.5.5:5000
3. VLC (yes, it also can make a stream and transcode it). You need a GUI configuration to stream, for advanced research go to this page.
Just take any media source and try it by yourself. Also remember that your destination point must be a part of your local network. Otherwise it will be failed, because global hosts cannot listen multicast over their network.
Hope that your mind has got started to understand this network technology. Let’s get down to the practice.
Multicast configuration
1. Enable multicast caption on aimed interface.
ifconfig eth0 multicast
2. Add new route to multicast IP addresses range through the same interface.
route -n add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
We’ve got an opportunity to listen packets which sends across your local network. Linux provides to configure it pretty straightforward. Let’s imagine that we have to get packets from 234.5.5.5 IP address on 5000 UDP port. But how can we check that we get a multicast from exact address and exact port?
Verify multicast connection
1. Try to sniff multicast traffic by tcpdump
tcpdump -i eth0 ip multicast
If it gives any captured packets – multicast support on interface configured properly. This command is suitable for our fictional task:
tcpdump -c 10 dst host 234.5.5.5 and port 5000 and multicast
Here is the expected output:
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes 15:20:58.818832 IP 43.232.net.50000 > 234.5.5.5.5000: UDP, length 1316 15:20:58.824080 IP 43.232.net.50000 > 234.5.5.5.5000: UDP, length 1316 15:20:58.829467 IP 43.232.net.50000 > 234.5.5.5.5000: UDP, length 1316 15:20:58.835816 IP 43.232.net.50000 > 234.5.5.5.5000: UDP, length 1316 15:20:58.841053 IP 43.232.net.50000 > 234.5.5.5.5000: UDP, length 1316 15:20:58.846617 IP 43.232.net.50000 > 234.5.5.5.5000: UDP, length 1316 15:20:58.852052 IP 43.232.net.50000 > 234.5.5.5.5000: UDP, length 1316 15:20:58.857893 IP 43.232.net.50000 > 234.5.5.5.5000: UDP, length 1316 15:20:58.863787 IP 43.232.net.50000 > 234.5.5.5.5000: UDP, length 1316 15:20:58.869017 IP 43.232.net.50000 > 234.5.5.5.5000: UDP, length 1316 10 packets captured 70 packets received by filter 4 packets dropped by kernel
You can also get the list of all multicast sources in your network for security reasons.
>tcpdump -n -c 100000 multicast | perl -n -e 'chomp; m/> (\d+.\d+.\d+.\d+).(\d+)/; print "udp://$1:$2\n"' | sort | uniq
2. Check the connection with multicast source by netstat command
netstat -a -u -n | grep 234.5.5.5
The stdout of this command should be like this:
udp 0 0 234.5.5.5:5000 0.0.0.0:*
I tried to embrace simple tasks like catch up multicast packets from determined source. My next post about multicast will be devoted to WowzaStreamingEngine configuration. Appreciated to StreamBuilder command for their cognitive article about this point.
Thank you very informative!
LikeLike