macOS – Fix Configured Dummynet Not Being Used

catalinamacosNetwork

I would like all UDP traffic on my localhost to have 1% packet loss, 5 ms propagation delay. I thought I could use macOS' built-in dummynet for this.

I ran at the terminal

sudo dnctl pipe 1 config bw 10Mbit/s delay 5 plr 0.01
echo "dummynet out proto udp from any to any pipe 1" | sudo pfctl -f -

sudo pfctl -sa and sudo dnctl list show the expected outputs (the rule seems to have been added).

DUMMYNET RULES:
dummynet out proto udp all pipe 1
00001:  10.000 Mbit/s    5 ms   50 sl.plr 0.010000 0 queues (1 buckets) droptail
    mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000

Now I expect all udp traffic to be slowed.

I am developing a UDP app, testing it on localhost between a client program and a server program. The UDP traffic is clearly not having any dropped packets even though I would like to simulate 1% dropped packets.

Best Answer

By default, pf is not enabled on modern macOS. You'll need to enable it first by running this command:

sudo pfctl -E

If you prefer a graphical interface instead of the command line interfaces for dummynet and pf, you can use Apple's "Network Link Conditioner" instead.

You can find it in the "Additional Tools for Xcode" package. If you have Xcode installed, it can be downloaded from within Xcode - otherwise you can download it directly from Apple's developer page (you do not actually need to have Xcode installed).

After downloading, you'll find it in the Hardware folder as a preference pane you can double click to install.

From the preference pane, you can enable/disable the link conditioner, choose which interface to have an effect on, and specify what you want to simulate (such as limited bandwidth, dropped packets, delays, etc).