sporex
Posts: 23
Joined: Thu Jan 23, 2014 3:25 pm

Raspi as a simple WAN emulator

Sat Feb 15, 2020 1:30 pm

I was looking for a simple solution to emulate WAN impairments like latency and packet loss. The WAN emulator shall be inserted in the LAN cabling between two hosts. So what is needed is:
- a Raspi
- an additional USB NIC
- bridge-utils
- Linux traffic control (tc) which should be included in debian jessie by default
But first of all I have to give credit to the following sites that pointed me in the right direction:
https://translate.google.de/translate?h ... &sandbox=1 (translate it to the language of your choice)
https://raspberrypi.stackexchange.com/q ... eth1/72298

Then we have to configure the bridge between eth0 and the USB NIC (eth1):

Code: Select all

/etc/network/interfaces

Code: Select all

[# do NOT autoconfigure bridge ports/enslaved interfaces!
iface eth0 inet manual
iface eth0 inet6 manual
iface eth1 inet manual
iface eth1 inet6 manual

# autoconfigure bridge interface, add bridge ports
auto br0
iface br0 inet dhcp
bridge_ports eth0 eth1
Next step is to assign an IP adress to the bridge (either static or DHCP):

Code: Select all

/etc/dhcpcd.conf

Code: Select all

[denyinterfaces eth0 eth1
interface br0
  static ip_address=...
  ...

After reboot you can insert the emulator in the link between two hosts and traffic should pass smoothly between eth0 and eth1.
The bridge is then accessible through SSH (I only tried static IP) and the traffic control can be configured:
For instance :

Code: Select all

# tc qdisc add dev eth0 root netem delay 100ms loss 5% 
will introduce 100ms of latency and a packet loss of 5% from eth0>eth1
For the reverse direction use

Code: Select all

# tc qdisc add dev eth1 root netem delay 100ms loss 5% 

Code: Select all

# tc qdisc del dev eth0 root
Will clear the impairements on the link.
For me latency and packet loss is sufficient but netem has many other features. Read here:
https://www.excentis.com/blog/use-linux ... ent-part-1
In that way I was able to simulate WAN impairments for a VoIP application.
Perhaps this is useful for others.

ejolson
Posts: 4278
Joined: Tue Mar 18, 2014 11:47 am

Re: Raspi as a simple WAN emulator

Sat Feb 15, 2020 3:43 pm

sporex wrote:
Sat Feb 15, 2020 1:30 pm
I was looking for a simple solution to emulate WAN impairments like latency and packet loss. The WAN emulator shall be inserted in the LAN cabling between two hosts. So what is needed is:
- a Raspi
- an additional USB NIC
- bridge-utils
- Linux traffic control (tc) which should be included in debian jessie by default
But first of all I have to give credit to the following sites that pointed me in the right direction:
https://translate.google.de/translate?h ... &sandbox=1 (translate it to the language of your choice)
https://raspberrypi.stackexchange.com/q ... eth1/72298

Then we have to configure the bridge between eth0 and the USB NIC (eth1):

Code: Select all

/etc/network/interfaces

Code: Select all

[# do NOT autoconfigure bridge ports/enslaved interfaces!
iface eth0 inet manual
iface eth0 inet6 manual
iface eth1 inet manual
iface eth1 inet6 manual

# autoconfigure bridge interface, add bridge ports
auto br0
iface br0 inet dhcp
bridge_ports eth0 eth1
Next step is to assign an IP adress to the bridge (either static or DHCP):

Code: Select all

/etc/dhcpcd.conf

Code: Select all

[denyinterfaces eth0 eth1
interface br0
  static ip_address=...
  ...

After reboot you can insert the emulator in the link between two hosts and traffic should pass smoothly between eth0 and eth1.
The bridge is then accessible through SSH (I only tried static IP) and the traffic control can be configured:
For instance :

Code: Select all

# tc qdisc add dev eth0 root netem delay 100ms loss 5% 
will introduce 100ms of latency and a packet loss of 5% from eth0>eth1
For the reverse direction use

Code: Select all

# tc qdisc add dev eth1 root netem delay 100ms loss 5% 

Code: Select all

# tc qdisc del dev eth0 root
Will clear the impairements on the link.
For me latency and packet loss is sufficient but netem has many other features. Read here:
https://www.excentis.com/blog/use-linux ... ent-part-1
In that way I was able to simulate WAN impairments for a VoIP application.
Perhaps this is useful for others.
Thanks for posting. I tried this back in the early days of the Pi 3B+ to simulate the effect of delays with flow control off on packet loss. I never got the delays to perform in a realistic way. Thanks for posting instructions. Have you checked the delay setting is really working?

sporex
Posts: 23
Joined: Thu Jan 23, 2014 3:25 pm

Re: Raspi as a simple WAN emulator

Sat Feb 15, 2020 4:28 pm

Yes, I verified with PING and wireshark. Both confirmed that latency and packet loss are correctly implemented.

Return to “Networking and servers”