Simulating a bad internet connection
Asked Answered
W

4

41

I'm developing an embedded device which has access to the internet through LAN. I'm in the testing phase now, and I would like to test how the device performs when the connection to the internet is poor. Currently, the device is connected to a router through a hub, which I use to monitor the packets with Wireshark. What's the best way to throttle down the internet speed of the device to mimic a scenario that may happen?

Can I do it through a PC? Do I need access to the router? If so, is it possible to limit the speed of each IP in the router interface?

Actually, a friend suggested that I will purchase a usb2lan ethernet card, and to bridge the PC lan connection to the embedded device, and then using a software QoS limiter. do you think it will work ?

Wootan answered 6/8, 2012 at 4:28 Comment(7)
This might be better suited for Stack Overflow, you can flag your own question and have it moved.Mishap
@ScottChamberlain This isn't a programming question. At least it doesn't have to be. Anyone who can configure a firewall can simulate a bad network connection (if you have firewall software that supports it, like ipfw + dummynet).Johnnajohnnie
I don't know about LAN but if you ever need that on a wireless network just move your cellphone between the router and the receiver... the interference closely mimics bad packet loss and jitter.Huang
Actually, a friend suggested that I will purchase a usb2lan ethernet card, and to bridge the PC lan connection to the embedded device, and then using a software QoS limiter. do you think it will work ?Wootan
Check out this old SO thread too. May help... #7026751Nerissa
See this duplicate on game dev for more answers: gamedev.stackexchange.com/questions/61483/…Vannoy
possible duplicate of Network tools that simulate slow network connectionJohannisberger
O
18

You can try using "Fiddler"

You have options to simulate bad network (like old modems 33k or 56k)

You need to plug in your device to your PC and turn on the proxy (every request will be transfered through Fiddler)

Then you could test your code with a bad network then see what happening ;)

Osterhus answered 9/4, 2013 at 10:5 Comment(0)
J
24

If you have a Mac handy, Macs have kernel facility called dummynet built in, which you control through ipfw. It allows you to simulate a slow connection, randomly drop packets with certain probabilities, and more.

The same facility exists in Linux and other OSes.

From the dummynet homepage:

As of Feb.2010 we have released the third major version of dummynet, which now runs on all main platforms: FreeBSD, Mac OS X as part of the native distributions, and you can find Linux, OpenWRT and Windows versions here.

It can do a lot for you:

limit the total incoming TCP traffic to 2Mbit/s, and UDP to 300Kbit/s

ipfw add pipe 2 in proto tcp
ipfw add pipe 3 in proto udp
ipfw pipe 2 config bw 2Mbit/s
ipfw pipe 3 config bw 300Kbit/s

limit incoming traffic to 300Kbit/s for each host on network 10.1.2.0/24.

ipfw add pipe 4 src-ip 10.1.2.0/24 in
ipfw pipe 4 config bw 300Kbit/s queue 20 mask dst-ip 0x000000ff

simulate an ADSL link to the moon:

ipfw add pipe 3 out
ipfw add pipe 4 in
ipfw pipe 3 config bw 128Kbit/s queue 10 delay 1000ms
ipfw pipe 4 config bw 640Kbit/s queue 30 delay 1000ms
Johnnajohnnie answered 6/8, 2012 at 5:52 Comment(5)
There's also a network link conditioner control panel which adds a simple UI to it, available with Xcode 4.x.Selfconfessed
ipfw doesn't work on Yosemite any more , any way to simulate slow connection on the new OSX ? ThanksUnfrock
@Unfrock see the other answers/comments that mention the Network Link Conditioner.Johnnajohnnie
@Johnnajohnnie , The thing is that I need to use the command from automated tests , and the NLC doesn't have an external API ...Unfrock
How can i get jitter and trace route ?Cherilyncherilynn
O
18

You can try using "Fiddler"

You have options to simulate bad network (like old modems 33k or 56k)

You need to plug in your device to your PC and turn on the proxy (every request will be transfered through Fiddler)

Then you could test your code with a bad network then see what happening ;)

Osterhus answered 9/4, 2013 at 10:5 Comment(0)
A
16

You may use (almost) any linux distribution from liveCd (like ubuntu, mandriva, others) to run it on any hardware you want, and use the kernel-based tool netem, aka "Network Emulation" with the "iproute2" package tools. It lets you control delays, package loss, corruption, duplication and other possible problems of wide area network.

There is list of most used simulations, like:

  • Rate control using Token Bucket Filter:

    tc qdisc add dev eth0 root handle 1:0 netem delay 100ms
    tc qdisc add dev eth0 parent 1:1 handle 10: tbf rate 256kbit buffer 1600 limit 3000
    
  • Delay all packets by fixed time: tc qdisc add dev eth0 root netem delay 100ms

  • Package loss: tc qdisc change dev eth0 root netem loss 0.1%
Ardine answered 5/4, 2013 at 0:37 Comment(1)
Note that you need to use qdisc add before you can use qdisc change, in case anyone is trying to use that last command on its own.Tensimeter
W
5

This is another OSX solution, have a look at the Network Link Conditioner.

The following quote is ripped from the following blog (All credit for the below should go to Matt Gemmell):

http://mattgemmell.com/2011/07/25/network-link-conditioner-in-lion/

Get the Hardware IO Tools for Xcode. To do this, go into the Xcode menu, then choose “Open Developer Tool” and finally “More Developer Tools…”. You’ll be taken to Apple’s developer downloads site; you should download the “Hardware IO Tools for Xcode”.

The resulting disk image will contain (amongst other things) a preference pane for System Preferences, called “Network Link Conditioner”. Double-click the prefpane file and authenticate to allow it to be installed. You’ll then see the pane in System Preferences.

You can choose from various different types of network conditions using the Profile popup menu.

You can also add profiles of your own by clicking Manage Profiles, either from scratch or via duplicating an existing profile.

Extremely handy for simulating less than optimal network conditions while testing an app. Just don’t forget to switch it off afterwards!

Wagoner answered 7/4, 2013 at 10:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.