How to simulate bandwidth and delay in localhost with dummynet (ipfw)

1.5k views Asked by At

I am using a web server in localhost:8080 and I'm trying to use dummynet (ipfw) to simulate latency and low bandwidth to that server but somehow I cannot get it to work.

When I use the command

sudo ipfw add pipe 1 all from any to any
sudo ipfw pipe 1 config bw 400Kbit/s delay 100ms

and then ping the localhost

ping localhost

I get these results:

PING localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=686.512 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=848.309 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=409.890 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=410.988 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=424.014 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=411.002 ms
64 bytes from 127.0.0.1: icmp_seq=6 ttl=64 time=409.175 ms
64 bytes from 127.0.0.1: icmp_seq=7 ttl=64 time=417.517 ms

My problems are:

  1. Why is the ping round trip time (~400ms) is about 4 times larger than my specified delay (100ms)

  2. The bandwidth limiting does not seem to work also. When I try to download a 6Mb test file from the address http://localhost:8080/Testfile in Chrome, I get the file instantly, not in my desired rate

1

There are 1 answers

0
lvanzyl On

Can't answer #1, but for #2 - you may have clearer results testing your download from another machine in your network.

You would have installed the dummynet drivers for your network card. My theory is if your browser is contacting localhost, it may bypass that network card (or the hooks in which dummynet is injecting latency?)

Basically, I haven't been able to get dummynet to inject latency to anything on the same server. I have two services for instance, and they communicate with each other instantly. Anything else on another machine gets latency injected.

You can try Fiddler - http://helephant.com/2012/07/11/simulating-network-latency-with-fiddler/ - which seems to inject latency on localhost as well.