QoS on the WRT54GS with OpenWRT

From Docupedia

Date: 25/05/2006

Contents

Overview

So you've purchased yourself a WRT54G or WRT54GS and you've gone to the trouble of installing OpenWRT on it. Now your having problems when you wife is trying to keep up too date on her tv downloads and always seems to have the latest OC Episode downloading well you want to sit at home and play Counter-Strike without her download obsession bothering your gaming one. This is where the traffic conditioning skillz need to come to life. Hope this helps you.

Pre Install

Module Install

  • Make sure you have all the following modules installed:
ipkg install tc
ipkg install ip
ipkg install kmod-sched
ipkg install kmod-iptables-extra

Module Testing

  • Then make sure all the modules can be loaded
insmod ip_queue
insmod sch_htb
insmod sch_sfq
insmod cls_u32
insmod sch_ingress

Conditioner Install

Traffic Conditioner Script

#!/bin/bash  

# Setup modules on boot
insmod ip_queue 
insmod sch_htb
insmod sch_sfq
insmod cls_u32
insmod sch_ingress
                                                                    
# Setup iptables                                                                               
iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS  --clamp-mss-to-pmtu
iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 128       
                                                                                
# The Ultimate Setup For Your Internet Connection At Home                        
#                                                                                
#                                                                                
# Set the following values to somewhat less than your actual download            
# and uplink speed. In kilobits                                                  
DOWNLINK=2000                                                                    
UPLINK=625                                                                       
DEV=vlan1                                                                        
                                                                                
# clean existing down- and uplink qdiscs, hide errors                            
tc qdisc del dev $DEV root    2> /dev/null > /dev/null                           
tc qdisc del dev $DEV ingress 2> /dev/null > /dev/null                           
                                                                                
###### uplink                                                                    
                                                                                
# install root HTB, point default traffic to 1:20:                               
                                                                                
tc qdisc add dev $DEV root handle 1: htb default 20                              
                                                                                
# shape everything at $UPLINK speed - this prevents huge queues in your          
# DSL modem which destroy latency:                                               
                                                                                
tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit burst 6k      
                                                                                
# high prio class 1:10:                                                          
                                                                                
tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit burst 6k prio 1                                                               
                                                                                
# bulk & default class 1:20 - gets slightly less traffic,                        
# and a lower priority:                                                          

# This line has issues on the wrt b/c busybox doesn't implement full math abilities
# To get it to work just do the substitution manually for hte $UPLINK variable                                                                                
#tc class add dev $DEV parent 1:1 classid 1:20 htb rate $[9*$UPLINK/10]kbit burst 6k prio 2
tc class add dev $DEV parent 1:1 classid 1:20 htb rate 563kbit burst 6k prio 2

Script Placement

  • Then you need to have the following bash script I put it in place in /etc/init.d/S46pktsched
  • Make sure it has been chmod'd so that its executable (755)