OSX how to drop packets randomly

mac-osxpacketloss

I am testing the resilience of one of our streaming applications to handle packet losses. On linux machines I normally use iptables to randomly drop packets like this:

iptables -A INPUT -m statistic --mode random --probability 0.1 -j DROP

I need to test this on a server that is currently running OSX. Any ideas how to randomly drop packets on an OSX Server or Mac computer?

/Andy

Best Answer

The tool you're looking for is dnctl. To quote from the manpage:

 plr packet-loss-rate
       Packet loss rate.  Argument packet-loss-rate is a floating-point number between 0 and 1, with 0 meaning no loss, 1 meaning 100% loss.  The loss rate is internally repre-
       sented on 31 bits.

And:

To drop random incoming IPv4 and IPv6 ICMP packets with a probability of 5%, create a pipe:

dnctl pipe 10 config plr 0.05