Sunday, September 14, 2008

TTL of Multicast Packets in Linux

One of the key enabling technology for Mobile TV is IP Multicasting. IP Multicast allows the distribution of streaming multimedia content with efficient bandwidth utilization.

So it was, during a DVB-H implementation project, one of the software tool that I had to develop is called a "Multicast Proxy". What the tool does basically is listen to a multicast address, and forward all the received packets to a different multicast address. Java came to the rescue. J2SE comes with class which makes receiving and sending multicast packets very simple to do.

Typically multicast and broadcast packets are treated with cautions by the OS. This is because both carry the risk of flooding the network. Hence the OS usually set the TTL (Time To Live) attribute of the those packets to 1. This attribute defines the maximum number of hops the packets can go through (1 means the packet can only be received in originating LAN). However, in my network I needed a larger TTL, since the packets must go through several hops. Thankfully the MulticastSocket class already provides a method called setTimeToLive. In my notebook (under Windows), it worked fine and everytyhing was hunky-dory.

Yet, as is always the case, problem occured the code was deployed to the production machine which was running on Ubuntu. Everything seemed to be working except no packets reached the receiving hosts. After banging my head against the wall for a while, I found that the packets can only be received in the same LAN segment. Apparently the TTL of those packets was still 1. Somehow the OS ignores the TTL setting from the java application. I needed to bang my head for another while until I found the solution by Googling.

Luckily, Some linux systems provide a way to configure the TTL of the IP packets using iptables command (works on Linux kernel 2.4 - 2.6, CMIIMW). In my case I used the following command:

iptables -t mangle -A OUTPUT -j TTL --ttl-set 32

The above line sets the TTL for all outgoing IP packets to 32. I know I should've set the TTL only for outgoing Multicast packets only, but I'm too lazy to dig deeper into iptables manual. Besides, my problem is now solved. Here's a tutorial on iptables if you're interested to learn (a lot!) more.

No comments:

Post a Comment