Wednesday, September 29, 2010

How to Ratelimit Physical Port (L2)


If you have a LAN (PC or Network)and you want to restrict the amount of data rate the LAN receives/transmits, with tc (Traffic Control) command you can achieve this very easily. All you need is that you need to make sure entire traffic passes throug a Linux machine in Bridge configuration.

You might want to type in the following command at your terminal.

# tc qdisc add dev eth0 root tbf rate 0.5mbit burst 5kb latency 70ms minburst 1540

This implements a 512kbps 'pipe'. In other words, entire LAN segment shown in the diagram gets to share 512kbps.

This command also implements bucket size of 5KBytes.

Packets would wait for 70milli seconds before they get dropped.

Applications
1) This is useful in lab environments where a DUT is to be tested with restricted bandwidth. DUT could be a base station simulator or any other network element.
2) In case you want to simulate the congestion or choked bandwidth within LAN, this comes handy to simulate a smaller pipe.