One of my first professional software projects, as an intern, was I wrote a tool for simulating this type of latency. I modeled it as a set of pipe objects that you could chain together with command line arguments. There was one that would do a fixed delay, another that would introduce random dropped packets, a tee component in case you wanted to send traffic to another port as well, etc.