I want to test a very bad TCP/IP connection, how can I simulate this.
Setting up two virtual interfaces with a bridge between them. Packets must be badly mangled in transition.
http://en.wikipedia.org/wiki/TUN/TAP
TAP (as in network tap) simulates an Ethernet device and it operates with layer 2 packets such as Ethernet frames. TUN (as in network TUNnel) simulates a network layer device and it operates with layer 3 packets such as IP packets. TAP is used to create a network bridge, while TUN is used with routing.
Packets sent by an operating system via a TUN/TAP device are delivered to a user-space program that attaches itself to the device. A user-space program may also pass packets into a TUN/TAP device. In this case TUN/TAP device delivers (or "injects") these packets to the operating system network stack thus emulating their reception from an external source.
Thus, problem is here that we need to write a user-space program.
Standard packet mangling is limited to changing the TOS, DSCP and TTL values.
Raw sockets could help, as well as a custom kernel device driver, see also [1]. But this requires a lot of hacking.
Scapy is a powerful interactive packet manipulation program. Sample chapter on Scapy.
Network Emulator (NETEM) is a Linux kernel configuration if you want to emulate network delay, loss, and packet re-ordering. This is often useful to simulate networks when testing applications or protocols.