Hi!
I have 3 PC-s at home, and i would like to share the bandwith. I want low latencies even if other computers are downloading. Unfortunately there is little or confusing documentation about this topic. Some of the documentation claims it is not possible to shape ingress (incoming) traffic, but (i think) that is not true.
I had to install the dd-wrt firmware and learned the qos concepts it uses.
I assign static IP addresses to the computers with dhcp (dnsmasq, /etc/ethers).
This picture helped me a lot: http://upload.wikimedia.org/wikipedia/c … ecture.png
http://openwrt.org/OpenWrtDocs/Configuration
I have a WRT54GS. Here is what i did:
Install Whiterussion RC2
ipkg update
ipkg install kmod-sched
ipkg install kmod-iptables-extra
ipkg install tc
ipkg install iptables-extra
My script is attached below.
TODO:
It would be nice to have IMQ - with that it is possible to shape incoming traffic for both WLAN and LAN. Shaping is a per device thing, so this script only shapes the wired ethernet.
Outgoing traffic should be shaped too (possibly on the ppp0 interface)
Please share your thoughts!
---------------------
#!/bin/sh
# to check the status of the qos stuff:
# iptables -t mangle -L
# tc -s qdisc show dev eth1
# tc -s class show dev eth1
. /etc/functions.sh
#It is ok for WRT54-G/GS, it may differ for other
#http://openwrt.org/OpenWrtDocs/Configuration
DOWN_IFACE=vlan0
# uplink bandwidth
# specified in kbits (about 90% of actual max uplink rate)
UP_RATE=100
DOWN_RATE=800
#Inserting various kernel modules
insmod ipt_TOS
insmod ipt_tos
insmod ipt_length
insmod sch_prio
insmod sch_red
insmod sch_htb
insmod sch_sfq
insmod sch_ingress
insmod cls_tcindex
insmod cls_fw
insmod cls_route
insmod cls_u32
echo alma0
# Clear all traffic control things to start from a clean state
tc qdisc del dev $DOWN_IFACE root
echo alma1
tc qdisc add dev $DOWN_IFACE root handle 1: htb default 1
#This is for the intra-LAN traffic
tc class add dev $DOWN_IFACE parent 1: classid 1:1 htb rate 10000kbit burst 6k cburst 2624b
tc class add dev $DOWN_IFACE parent 1:1 classid 1:2 htb rate ${DOWN_RATE}kbit ceil ${DOWN_RATE}kbit
#Class for the first computer minimum 250kbit maximum all
tc class add dev $DOWN_IFACE parent 1:2 classid 1:10 htb rate 250kbit ceil ${DOWN_RATE}kbit burst 6k cburst 2624b
#Class for the second computer
tc class add dev $DOWN_IFACE parent 1:2 classid 1:20 htb rate 250kbit ceil ${DOWN_RATE}kbit burst 6k cburst 2624b
#Class for the third computer
tc class add dev $DOWN_IFACE parent 1:2 classid 1:30 htb rate 250kbit ceil ${DOWN_RATE}kbit burst 6k cburst 2624b
#Class for any other computer
tc class add dev $DOWN_IFACE parent 1:2 classid 1:40 htb rate 50kbit ceil ${DOWN_RATE}kbit burst 6k cburst 2624b
echo alma2
#See this webpage for what these numbers mean:
#http://lartc.org/howto/lartc.adv-qdisc.red.html
#Maybe i should play with them later
tc qdisc add dev $DOWN_IFACE parent 1:10 handle 10: red limit 400000b min 10000b max 50000b avpkt 1000 burst 10 ecn
tc qdisc add dev $DOWN_IFACE parent 1:20 handle 20: red limit 400000b min 10000b max 50000b avpkt 1000 burst 10 ecn
tc qdisc add dev $DOWN_IFACE parent 1:30 handle 30: red limit 400000b min 10000b max 50000b avpkt 1000 burst 10 ecn
tc qdisc add dev $DOWN_IFACE parent 1:40 handle 40: red limit 400000b min 10000b max 50000b avpkt 1000 burst 10 ecn
# I could use SFQ, but RED seems to be better
#tc qdisc add dev $DOWN_IFACE parent 1:10 handle 10: sfq perturb 10
#tc qdisc add dev $DOWN_IFACE parent 1:20 handle 20: sfq perturb 10
#tc qdisc add dev $DOWN_IFACE parent 1:30 handle 30: sfq perturb 10
#tc qdisc add dev $DOWN_IFACE parent 1:40 handle 40: sfq perturb 10
echo alma3
#Flush the mangle table
iptables -t mangle -F
#Not really sure exactly what traffic comes to the POSTROUTING chain,
#but it works
#Mark all incoming, outgoing traffic (should separate later!)
#Default
iptables -t mangle -A POSTROUTING -s 192.168.1.0/24 -d ! 192.168.1.0/24 -j MARK --set-mark 0x40
iptables -t mangle -A POSTROUTING -d 192.168.1.0/24 -s ! 192.168.1.0/24 -j MARK --set-mark 0x40
#This is my first computer
iptables -t mangle -A POSTROUTING -d 192.168.1.50 -s ! 192.168.1.0/24 -j MARK --set-mark 0x10
iptables -t mangle -A POSTROUTING -s 192.168.1.50 -d ! 192.168.1.0/24 -j MARK --set-mark 0x10
#Second computer
iptables -t mangle -A POSTROUTING -d 192.168.1.51 -s ! 192.168.1.0/24 -j MARK --set-mark 0x20
iptables -t mangle -A POSTROUTING -s 192.168.1.51 -d ! 192.168.1.0/24 -j MARK --set-mark 0x20
#Third computer
iptables -t mangle -A POSTROUTING -d 192.168.1.52 -s ! 192.168.1.0/24 -j MARK --set-mark 0x30
iptables -t mangle -A POSTROUTING -s 192.168.1.52 -d ! 192.168.1.0/24 -j MARK --set-mark 0x30
echo alma4
#We assign the traffic to classes using the marks
tc filter add dev $DOWN_IFACE protocol ip parent 1: handle 0x10 fw classid 1:10
tc filter add dev $DOWN_IFACE protocol ip parent 1: handle 0x20 fw classid 1:20
tc filter add dev $DOWN_IFACE protocol ip parent 1: handle 0x30 fw classid 1:30
tc filter add dev $DOWN_IFACE protocol ip parent 1: handle 0x40 fw classid 1:40