Skip to content

Latest commit

 

History

History
189 lines (155 loc) · 6.72 KB

NetworkConditionsTesting.md

File metadata and controls

189 lines (155 loc) · 6.72 KB

#Bad Network This wiki describes the setup procedure for testing various IP level network conditions using commodity hardware.

This guide could also be used to fulfil a variety of routing purposes, e.g. testing network conditions in other regions over VPN. Skip the [Traffic Control (network conditions)](#Traffic Control %28network conditions%29) section in that case.

Hardware and software (overview)

  • A computer (desktop or laptop)
  • At least one USB port
  • At least one Ethernet port
  • Any linux kernel/distribution that has
    • Support for NAT using iptables
    • Support for tc (traffic control)
  • A router with WiFi routing support
  • An android phone with internet sharing over USB support, or a 3G internet dongle.
  • Cables for all of the above
  • A device to be tested, can be:
  • Connected via WiFi to the router
  • Connected via Ethernet to the router

##Actual Hardware / Software

  • Router: Netgear WNR3500Lv2
  • Computer: HP EliteBook Laptop
  • Ubuntu 13.04
  • 3G modem: Sony Xperia S
  • Android 4.1
  • TestDevice: Sony Xperia Z
  • Android 4.2

Connection overview

Definitions

|Internet|   An android phone, 3G/4G dongle, or internet connected LAN used to connect to the internet.

|Computer|   A computer used to route data between the |Internet| network and the |Router|
                network using NAT. The computer will also be responsible for altering
                the network conditions between the networks.

|Router|     The router used to supply network, WiFi or Ethernet, access to the test
                device |TestDevice|.

|TestDevice| Any device to run applications on, will connect to the internet using
                WiFi or Ethernet from the |Router|.

The setup is
|Internet|--usb cable--|Computer|--ethernet port--ethernet cable--WAN port--|Router|--wifi or ethernet--|TestDevice|
              < NAT >                        < NAT & tc >

The |Computer| will be given the IP address 192.168.1.2 and will communicate over Ethernet with the |Router| WAN port. The |Router| will get the IP address 192.168.1.1. The router will share its network via DHCP in the 10.0.0.2 and up range. The router can be accessed on the intranet address 10.0.0.1.

Setup

Find out 3G DNS

Disconnect all network connections from the |Computer|, any way you like, either via software (in Ubuntu 10.04 do it with the Network Manager Applet) disconnect, or pull the cord/turn off WiFi altogether.

Connect the |Internet| device to the |Computer|. If |Internet| is an Android phone, set up network connection sharing by going into Settings > More... > Tethering & portable hotspot > (CHECK) USB tethering.

Run the following command:

$ cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.42.129

The above is the DNS server of the |Internet| network.

Setup Router

WAN Setup:

  • Router IP address: 192.168.1.1
  • Subnet mask: 255.255.255.0
  • Gateway IP address: 192.168.1.2
  • Primary DNS: 192.168.42.129 (taken from reading /etc/resolv.conf in the previous step)
  • Secondary DNS: 8.8.4.4 (this is one of Google's public DNS servers)

LAN DHCP Setup:

  • Router IP address: 10.0.0.1
  • Subnet mask: 255.255.255.0
  • DHCP range: 10.0.0.2 - 10.0.0.254

Setup Computer

Setup the |Computer| any way you like. I use the Ubuntu Network Manager and setup a profile for static ip for eth0. The end result should be:

  • IP address: 192.168.1.2
  • Subnet mask: 255.255.255.0
  • Gateway: 0.0.0.0
  • No DNS servers or other settings.

NAT

Below are two scripts. One for setting up NAT routing on your |Computer| and one for clearing it when your are done. Run them in a terminal with elevated privileges.

$ sudo -i

It is assumed that the |Router| is connected to the |Computer| using '''eth0''', and that the |Internet| (modem) is connected to the |Computer| using '''usb0'''.

nat.sh:

# tell the kernel to allow NATing
echo 1 > /proc/sys/net/ipv4/ip_forward
# add routing
iptables -A FORWARD -o usb0 -i eth0 -s 192.168.1.1/24 -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -F POSTROUTING
iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE

nat_clean.sh:

iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
echo 0 > /proc/sys/net/ipv4/ip_forward

Setup TestDevice

Simply connect to the |Router| network via WiFi (check your router for WiFi password). If you are using Ethernet, simply connect your ethernet cable to the router's intranet port.

##Traffic Control (network conditions) Using the tc command a number of network conditions can be simulated. A script library might be added here later, but for now this will suffice:

$ tc qdisc add dev eth0 root netem loss 30% 25% delay 500ms 400ms 40%

Rules can be changed on the fly, by substituting change for add:

$ tc qdisc change dev eth0 root netem loss 10% 5% delay 10ms 5ms 15%

Rules can be listed:

$ tc -s qdisc ls dev eth0

And rules can be removed like so:

$ tc qdisc del dev eth0 root

Here is a quick overview of the meaning of the parameters.

tc qdisc change eth0 root netem [parameters]
loss <percent lost> <variance> <correlation>
delay <ms delay> <variance> <correlation>

The parameters and are optional

More can be found by checking the man page

$ man tc

Observe that if you want to limit the upload speed you have to apply the same commands to usb0.

$ tc qdisc add dev eth0 root netem loss 30% 25% delay 500ms 400ms 40%
$ tc qdisc add dev usb0 root netem loss 30% 25% delay 500ms 400ms 40%

##Example Settings Using the settings:

$ tc qdisc change dev eth0 root netem loss 5% 1% delay 500ms 100ms 40%

Gives a real life situation of about 1200 ms ping and a download rate about 200 kbps.

Increasing the loss to 10% decreases the download speed to about 150 kbps.

Other Examples

  • Crawl everything to a slow, really slow, some data still gets through.
$ tc qdisc change dev eth0 root netem loss random 30% delay 100ms 300ms 10% corrupt 10% 15% duplicate 10% 10%
  • Pretty long loading times, but not unreasonable. Most things work 100%
$ tc qdisc change dev eth0 root netem loss random 10% corrupt 10% 10% duplicate 10% 10%
  • Pretty bad
$ tc qdisc change dev eth0 root netem loss random 35% delay 3000ms 300ms 20% corrupt 15% 15% duplicate 10% 10%

A note on the internet connection / modem

Since the phone-modem is heavily impacted by weather conditions it would be wise to test the settings with speedtest before running test scenarios to ensure a similar environment.

Sources

  1. http://lartc.org/manpages/tc.txt
  2. http://swik.net/netem/Examples+of+Use
  3. https://help.ubuntu.com/community/Internet/ConnectionSharing