The code and configuration files in this repository enable a raspberry pi to open a wlan which can be throttled by REST API calls. We use raspberry pis with traffic shaper to measure the performance of web applications with mobile devices and WebPagetest.
As WLAN adapter we use an "Edimax EW-7811Un".
-
Add a user trafficshaper
sudo useradd trafficshaper
-
Grant sudo rights by adding to /etc/sudoers
trafficshaper ALL=(ALL) NOPASSWD: ALL
-
Download module
cd ~ wget http://webpy.org/static/web.py-0.37.tar.gz
-
Install
tar -zxvf web.py-0.37.tar.gz cd web.py-0.37 sudo python setup.py install
-
Install hostapd
sudo apt-get install hostapd
-
Replace binary /usr/sbin/hostapd with hostapd file from this repository (usr/sbin/hostapd)
-
Replace line
#DAEMON_CONF
in file /etc/Default/hostapd with
DAEMON_CONF="/etc/hostapd/hostapd.conf"
-
Config file /etc/hostpad/hostapd.conf should contain the folllowing:
interface=wlan0 driver=rtl871xdrv ssid=[SSID-of-your-wlan] hw_mode=g channel=6 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=[ssid-pasword] wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
Adapt "ssid" and "wpa_passphrase" if necessary.
Service hostapd should be started with each reboot now.
-
Install dnsmasq
sudo apt-get install dnsmasq
-
Copy files etc/resolv.conf und etc/dnsmasq.conf of this repository to /etc/-Folder
-
Restart service
sudo service dnsmasq restart
Service dnsmasq should be started with each reboot now.
-
Copy the following files from this repository to /opt/trafficshaper
rest.py trafficshaper_init.sh configure_traffic_control.sh
-
Add trafficshaper scripts to autostart
-
Copy template trafficshaper from this repository to /etc/init.d/
-
Make scripts executable (chmod +x)
chmod +x /opt/trafficshaper/*.*
-
Add scripts to run-level
update-rc.d trafficshaper defaults
-
With each start of raspberry pi throttling starts with default values for the following parameters:
- bwdown download bandwidth (kbit/s)
- bwup upload bandwidth (kbit/s)
- latencydown latency delay download (ms)
- latencyup latency delay upload (ms)
- plrdown Packet loss rate download
- plrup Packet loss rate upload
One can change default throttling in last three lines of file /opt/trafficshaper/rest.py
Parameters of REST API call get explained if you call
http://<IP adress-of-raspberry-pi>:8080/
Example call:
http://localhost:8080/set_shaping?bwdown=4000&bwup=2000&latencydown=40&latencyup=50&plrdown=0.0&plrup=1
This call would set...
- a bandwidth of 4.000 kBit/s downstream,
- a bandwidth of 2.000 kBit/s upstream,
- 40ms latency delay for downstream,
- 50ms latency delay for upstream,
- 0,0% packet loss rate downstream and
- 1,0% packet loss rate upstream.
So round trip time of single tcp packets would get extended by 90ms. One percent of packets get lost on this round trip.