Simulating a low-bandwidth, high-latency network connection on Linux

19

16

I'd like to simulate a high-latency, low-bandwidth network connection on my Linux machine.

Limiting bandwidth has been discussed before, e.g. here, but I can't find any posts which address limiting both bandwidth and latency.

I can get either high latency or low bandwidth using tc. But I haven't been able to combine these into a single connection. In particular, the example rate control script here doesn't work for me:

# tc qdisc add dev lo root handle 1:0 netem delay 100ms 
# tc qdisc add dev lo parent 1:1 handle 10: tbf rate 256kbit buffer 1600 limit 3000
RTNETLINK answers: Operation not supported

How can I create a low-bandwidth, high-latency connection, using tc or any other readily-available tool?

Justin L.

Posted 2010-05-31T05:19:54.203

Reputation: 653

1have you tried combining approaches from your links, eg. use tc for latency and trickle for bandwidth? (It's uglier than just using tc, but might still work;) – Andy – 2010-05-31T05:35:33.013

That's a good idea (and, indeed, trickle will even add latency), but unfortunately Firefox doesn't load under trickle, and that's what I need to test. – Justin L. – 2010-05-31T19:01:44.240

Answers

15

Aha! It works if we reverse the order of the commands.

tc qdisc add dev lo root handle 1: htb default 12 
tc class add dev lo parent 1:1 classid 1:12 htb rate 20kbps ceil 20kbps 
tc qdisc add dev lo parent 1:12 netem delay 1000ms 

https://lists.linux-foundation.org/pipermail/netem/2010-May/001388.html

Justin L.

Posted 2010-05-31T05:19:54.203

Reputation: 653

Anyone interested as to why, it seems that the netem qdisc cannot be a parent, so you have to rearrange the hierarchy to have it as a leaf node. – Andy – 2010-06-02T06:32:07.767

3

Note that the bandwidth limit is in one direction only (outgoing). You have to do additional work to make it happen in both directions (apparently using ifb). http://www.linuxfoundation.org/collaborate/workgroups/networking/netem#Emulating_wide_area_network_delays

– Roger Binns – 2012-11-30T06:37:28.480

Came across this when trying to grok tc. From what I've read the first line creates 1:0, but the second line refers to 1:1? (probably my understanding which is wrong - but I've peered at lots of pages trying to understand how classes/qtdiscs are numbered) – symcbean – 2013-04-08T22:03:25.010

1

It's not free, but the Charles Web Debugging Proxy can simulate low bandwidth high latency connections

http://www.charlesproxy.com/documentation/proxying/throttling/

Matthew Lock

Posted 2010-05-31T05:19:54.203

Reputation: 4 254

Interestingly enough, I'm actually doing this for web debugging. But surely there must be a way to do this without spending money. :) – Justin L. – 2010-05-31T05:26:15.843

Sadly Charles doesn't seem to work with local traffic. It dies when I try to access 192.168.1.1 through the proxy. – Justin L. – 2010-05-31T07:15:06.750

2

Or just use WANEm, for free: http://wanem.sourceforge.net/

– Nathan Kidd – 2011-01-27T17:00:41.573