14

I was wondering if anyone had any experience setting up an environment designed purposefully for poor performance when sending/receiving requests over a network. I'm developing an application and would like to make it robust over extremely poor-performing networks. Does anyone know if it is possible to configure a router to:

  1. intermittently drop packets
  2. intermittently introduce latency in packets
  3. corrupt data in packets (this one isn't required as it would require opening the packet, changing the data, and updating the checksum since the TCP layer would catch this type of issue)

If not possible on a router, would it be possible to configure a computer to act as a router and do this?

Many thanks!

Mark
  • 261
  • 2
  • 10

3 Answers3

18

If you use a Linux box as a router, netfilter has a number of ways of messing with your packet traffic.

The random module can be used to randomly drop packets. For example, this:

iptables -A FORWARD -m random --average 10 -j DROP

will cause the router to randomly drop packets at an average rate of 10%.

You can also corrupt random packets with the XOR target, e.g.

iptables -A FORWARD -m random --average 1 -j XOR --key "junktoxortomypacket"

will corrupt 1% of forwarded packets by XORing them with a key derived from the given string.

Steven Monday
  • 13,599
  • 4
  • 36
  • 45
  • This sounds awesome! Thanks Steven! Have you ever set this up? What Linux distro? – Mark Nov 15 '10 at 04:13
  • I have had success creating routers for small networks using Debian. But really just about any Linux distro with a recent kernel should do just fine, since netfilter is built into the kernel. I have never actually tried creating a "bad" router as described here, but it might be an interesting project for a lazy Sunday afternoon ... – Steven Monday Nov 15 '10 at 04:23
  • If you are using iptables version 1.3.5, the above command might error with message "iptables v1.3.5: Couldn't load match `random'". Below command worked for me - iptables -A FORWARD -m statistic --mode random --probability 0.2 -j DROP – prashantsunkari Oct 27 '15 at 21:49
3

I've successfully used WANem to simulate network conditions of a WAN between Germany and India. WANem ships as a bootable CD or virtual appliance. You just boot it up, configure the desired network properites and then route your traffic through it. Quoting the official description:

WANem is a Wide Area Network Emulator, meant to provide a real experience of a Wide Area Network/Internet, during application development / testing over a LAN environment. Typically application developers develop applications on a LAN while the intended purpose for the same could be, clients accessing the same over the WAN or even the Internet. WANem thus allows the application development team to setup a transparent application gateway which can be used to simulate WAN characteristics like Network delay, Packet loss, Packet corruption, Disconnections, Packet re-ordering, Jitter, etc. WANem can be used to simulate Wide Area Network conditions for Data/Voice traffic and is released under the widely acceptable GPL v2 license.

knweiss
  • 4,015
  • 24
  • 20
2

Set the uplink port to 10Mbps and half duplex if you can. Then use a host on the network to ping the snot out of it. That ought to neuter you decently :D

SpacemanSpiff
  • 8,753
  • 1
  • 24
  • 35
  • Set the packet sizes on the pings to considerably larger than the default, too. This can be a really effective and easy way to simulate saturated/generally bad network links - if you can cripple the specific connection as noted by purposefully setting it's bandwidth to lower than what the 'attacking' machine has. – Andrew Barber Nov 13 '10 at 23:19
  • You could also mess with MTU as well, pick a real oddball size :) – SpacemanSpiff Nov 14 '10 at 02:02