Linux's tc-netem [0] is designed for this:
"The netem queue discipline provides Network Emulation functionality for testing protocols by emulating the properties of real-world networks.
The queue discipline provides one or more network impairments to packets such as: delay, loss, duplication, and packet corruption."