Using tc in Linux and dumthenet in FreeBSD to limit bandwidth

bandwidthtraffic-shaping

We have a network product that runs on Linux and needs to be tested in reduced bandwidth networks.

We have been able to use 'tc' (traffic control) in Linux and dummynet in FreeBSD to inject delay (latency) with predictable behavior.

But when we try to throttle the bandwidth with either of these, it does not seem to have much effect.

Here is an example of trying to use 'tc' to set the bandwidth to 512Kbps:

tc qdisc change dev eth0 root tbf rate 512kbit burst 1540

But when we run 'scp' over that connection we see speeds that are way higher than we expect.

Here are results of setting various bandwidths in both dummynet and tc. You can see that it has SOME effect but not very much.

BW             _______DUMMYNET__________        __________ TC __________
10Mbps         1m,3.489s        4.0MB/s         1m,2.732s       4.1MB/s
8Mbps          1m,3.461s        4.0MB/          1m,2.728s       4.1MB/s
6Mbps          1m,3.905s        4.0MB/s         1m,2.710s       4.0MB/s
1Mbps          1m, 3.261s       4.0MB/s         1m,2.680s       4.0MB/s
512Kbps        1m,26.175s       3.0MB/s         1m 25.409s      3.0MB/s
256Kbps        2m,39.079s       1.6MB/s         2m 53.004s      1.5MB/s
128Kbps        5m, 3.501s       852.7KB/s       5m, 50.491s     739.7KB/s
64Kbps         9m,48.907s       463.3KB/s       9m,53.105s      436.5KB/s

I don't have the syntax we've used for DUMMYNET handy but I'll post it later.

Best Answer

There is a question on serverfault that I answered with a more extensive example of using tc and iptables to do traffic limiting. This example comes from a setup we have on our mirror server and it works very well.

Related Question