UPD throttling for apps based on WebRTC.

Uday Reddy
Nerd For Tech
Published in
3 min readOct 26, 2018

Since the raise of webRTC technology many apps have been providing video-call which is pretty amazing. Developers all over the world have been building POC to test out. There’s not much in depth knowledge as to how things work under the hood, results in uncertain behaviour of the apps.

We first need to understand is that WebRTC technology uses UDP to commence communication instead of TCP. To quickly understand the difference between TCP and UDP is “TCP packets send acknowledgement to the sender and UDP doesn’t”. This makes UDP best candidate for video calling.

Many of us are used to chrome’s “Network Throttling Profiles”, this helps in emulating slow network connections but this is limited to TCP connections. Meaning you can’t use this to throttle UDP connections, in other words you cant create latency in the video call.

Comcast to the rescue

Comcast helps us emulate slower network connections. If you are on mac you can straightaway use ipfw and pfctl to inject failure.On Linux, we use iptables and tc. Comcast is merely a thin wrapper around these controls. Windows support may be possible with wipfw or even the native network stack, but this has not yet been implemented in Comcast and may be at a later date.

Installation:

Step1: Install go and set the GOPATH variable.
Installation for ubuntu

sudo apt-get install gccgo-go

Add below code in ~/.bashrc and dont forget to run bashrc file.

export GOPATH=’<folder in you home>’
export PATH=$PATH:$GOPATH

Step2: Install comcast.

go get github.com/tylertreat/comcast

Comcast is installed in the folder you mentioned in GOPATH in bashrc .

Next we need to slow down upload speed of UDP packets.
To test it now open up your app and start streaming you video. Get the port numbers where the UDP are sent from.(Assuming you are running on chrome)

sudo netstat -tulpn | grep chrome

Note the two port numbers 38212 & 47733

Open up another browser and watch the publisher’s video and if your internet connection is great it should be visible without any problem.

Lets finally run the command which slows the UDP flow:

./comcast --device=wlan2 --latency=1000 --target-bw=50 --default-bw=50 --packet-loss=80% --target-addr=8.8.8.8,10.0.0.0 --target-proto=udp --target-port=38212,47733

Be sure to change --device option to your network device, I’m on wifi so its wlan2 . Also, observe that the port numbers we noted earlier are mentioned in --target-port parameter.

I hope your users won't feel like John Travolta.

Happy debugging.

--

--