Google
 
Showing posts with label bandwidth. Show all posts
Showing posts with label bandwidth. Show all posts

Monday, March 19, 2012

Multiple SSID on OpenWRT with bandwidth limit

If you're a network junkie and not been living under the rocks, you must have heard of OpenWRT. It's a Linux distribution for embedded devices (routers) and gives you power to do things usually impossible or difficult with inbuilt router firmware. Wireless Freedom indeed.

This was my scenario: I had to create two wireless APs for my office, one for the guests (no password but bandwidth limited) and another for non-guest users (password protected but no limit on bandwidth). That way the visitors will have free wireless internet, but with limited bandwidth. The office staffs will have to connect to a password protected wifi for unrestricted bandwidth.

The requirements for the APs are,

Free Wifi for visitors
- SSID: FreeWifi
- Password: none
- Bandwidth limit: 256Kbps uplink, 128Kbps downlink

Office Wifi for staffs
- SSID: OfficeAP
- Password: 1234567890
- Encryption: WPA2
- Bandwidth limit: none

Here's how I did it on OpenWRT. Connect to OpenWRT shell.

1. First create two wireless APs with above configuration. Add the following lines to /etc/config/wireless (Remove any existing 'wifi-iface' configurations)

# Free Wifi
config 'wifi-iface'
        option 'device' 'wifi0'
        option 'ssid' 'FreeWifi'
        option 'mode' 'ap'
        option 'network' 'lan'


# Office Wifi
config 'wifi-iface'
        option 'device' 'wifi0'
        option 'ssid' 'OfficeAP'
        option 'mode' 'ap'
        option 'network' 'lan'
        option 'encryption' 'psk2'
        option 'key' '1234567890'


As simple as that! Now to enable the wifi, go to shell and

# wifi down; wifi up

2. Now to limit bandwidth, we'll be using wondershaper. To install:

# opkg update
# opkg install wshaper


3. Now find which interface is the FreeWifi assigned to

# iwconfig

On mine, it was on ath0

4. Modify /etc/config/wshaper and start wondershaper

config 'wshaper' 'settings'
    option 'network' 'ath0'
    option 'downlink' '256'
    option 'uplink' '128'


Now, start wondershaper.

# /etc/init.d/wshaper start

5. By default, wshaper isnt enabled at startup. so,

# ln -s /etc/init.d/wshaper /etc/rc.d/S99wshaper

Saturday, December 25, 2010

Load Balancing LTSP clients using Ethernet Bridging

Typical LTSP setup has the following configuration:


+-------------+
| Server |
+-------------+
| eth0 | eth1 |
+------+------+
/ |
/ |
Internet Switch
|
+---------+-------------+
| | |
Client-1 Client-2 ... Client-n

LTSP Clients

The problem with this is that the network card bottlenecks the performance. Once the number of clients increases (usually >5), even though the server is capable of handling the load, the network card (usually, 100BASE-TX) can't provide the throughput.

There are two solutions to this:
1. Use 1000BASE-T (gigabit) ethernet cards and switches
2. Use load balancing

Using gigabit ethernet cards solves the problem but they are expensive. The switches are expensive too. Plus there are flow control problems if the clients have 100Base-TX cards, which is usually the case.

Load balancing is an easier and cheaper approach. Although this can also go fairly complicated, here i'm going for the simplest one using ethernet bridging.

The trick is to use multiple NICs connected to multiple switches. Then bridge the cards to provide a common interface. Here's what it looks like:

+--------------------+
| Server |
+------------------- +
| eth0 | eth1 = eth2 |
+------+------+------+
/ | |
/ | |
Internet Switch Switch
| |
+----+-------+ +----+-------+
| | | | | |
C-1 C-2 ... C-n C-1 C-2 ... C-n

LTSP Clients LTSP Clients

Lets say, there are three NICs: eth0, eth1 and eth2. eth0 is connected to internet. eth1 (say, 192.168.0.254) is connected to LTSP clients. eth2 is unused and is supposed to be bridged with eth1.

First install bridge-utils
# apt-get install bridge-utils
Create a bridge (br0) and add eth1 and eth2 to it
# brctl addbr br0
# brctl stp br0 off
# brctl addif br0 eth1
# brctl addif br0 eth2
Now release the IP addresses of eth1 and eth2
# ifconfig eth1 down
# ifconfig eth2 down
# ifconfig eth1 0.0.0.0 up
# ifconfig eth2 0.0.0.0 up
Assign the LTSP IP address to bridge.
# ifconfig br0 192.168.0.254 up
Now connect eth1 and eth2 to separate switches, and each switch to (equal number of) LTSP clients.

Tuesday, April 07, 2009

Easy bandwidth shaping in Linux

There is an extensive and nicely written HOWTO on this topic but here I'm talking about some really easy to use bandwidth shaping tools -- wondershaper and trickle.

Wondershaper
This is the easiest tool I have found to limit bandwidth of a particular interface. All it takes is,


$ sudo wondershaper {interface} {down} {up}
the {down} and {up} are bandwidth in kilobits. So for example if you want to limit the bandwidth of interface eth1 to 256kbps uplink and 128kbps downlink,

$ sudo wondershaper eth1 256 128
To clear the limit,

$ sudo wondershaper clear eth1
Easy, eh?

Trickle
Unlike wondershaper, which limits the bandwidth to an entire interface, trickle is user-space bandwidth limiting tool. The syntax is,

$ trickle -u {up} -d {down} {program}
Both {up} and {down} and bandwidth in KB/s. Now if you invoke it as,

$ trickle -u 8 -d 8 firefox
It will fire up Firefox, limiting the bandwidth to 8KB/s. This is very useful specially if you are a web developer and want to test your application under various bandwidth conditions.

Furthermore, you can also run trickle as daemon (trickled) which can limit the bandwidth to several programs.