Configuring a router to drop packets, introduce latency, corrupt data

Solution 1:

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.

Solution 2:

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.