Quality of Service

From DD-WRT Wiki

Revision as of 17:54, 25 July 2009 by Pbix (Talk | contribs)
Jump to: navigation, search

Quality of Service (QoS) is a method to guarantee a bandwidth relationship between individual applications or protocols. This is very handy when you max out your connection so that you can allow for each application to have some bandwidth and so that no single application can take down the internet connection. This allows, for example, a full speed download via FTP without causing jittering on a VOIP chat. The FTP will slow down slightly as bandwidth is needed for the VOIP, provided VOIP was given greater priority.

If you would like to set hard coded bandwidth limits (throttling), this can be done using the tc command

NOTE: Ethernet Port Priority only works on older, ADM based, chipsets. That is, the Linksys WRT54G v1.0, 1.1, 2.0 and the WRT54GS v1.0.


Initial Setup

  • Log into the Web Interface
  • Click on the Applications and Gaming Category (NAT / QoS in newer versions)
  • Click on the QoS sub category
  • Tick "Enabled" and save the settings
  • Set "Port" to WAN if you tend to max your pipes. Set it to LAN & WLAN if you want to avoid Intranet congestion.
  • Use the HTB Packet Scheduler if your traffic is primarily P2P, otherwise use HFSC (Especially if you do VOIP)
  • Enter 85 percent of your up and down bandwidth in the boxes (eg: if you have a 1.5 Mbit (1536 kbps) cable modem with 256 kbps upload, enter 218 for uplink and 1306 for downlink. Be careful not to mistakenly swap the uplink and downlink speeds -- a common error that will greatly slow down your WAN connection! You can have a free speed test done on your internet connection at DSL Reports. If your internet is routinely congested and you want to lower your ping, you should keep dropping these lower and lower until you find a sweet spot. Personally, I prefer an 85% cap on my upstream and a 95% cap on my downstream.
  • If you do not wish to apply QoS to downlink or uplink traffic, leave the corresponding value at 0. For example, if you entered 1000kbps for uplink and 0kbps for downlink, QoS traffic shaping will only be applied for uplink traffic.

These steps will enable Quality of Service (QoS) and cap your maximum connection speed to 85 percent of what your cable/DSL service is capable of providing. This decrease in speed is required to maintain a low latency. ISPs tend to use large buffers that add lots of latency if you fill them up. Traffic Shaping causes some 'lost' bandwidth, by moving traffic shaping to your router, instead of the ISP.

Optimize for Gaming

The Optimize for Gaming option found under the QoS administration page enables QoS on some tcp/udp ports found in some games.

Here is the complete list from the source code:

  • DirectX 8 and above (Age of Empires I and many others): 6073/tcp&udp, 2302-2400/tcp&udp
  • Counter Strike: 1200/udp, 27000-27015/udp, 27030-27039/tcp
  • Diablo I & II, Warcraft 3: 4000/tcp, 6112-6119/tcp&udp
  • Everquest: 7000/tcp, 1024-6000/udp
  • Half Life & Half Life 2: 6003/tcp, 7002/tcp, 27005/udp, 27010/udp, 27011/udp, 27015/udp
  • Quake2: 27910/tcp&udp
  • Quake3/RTCW: 27660/tcp&udp, 27950/udp, 27960/udp, 27965/udp, 27952/udp
  • Return to Castle Wolfenstein: 27950/udp, 27960/udp, 27965/udp, 27952/udp
  • Unreal Tournament (NOT 2004): 8080/tcp&udp, 27900/tcp&udp, 7777-7783/tcp&udp

If you do not play any of the above game, you should keep this option disabled.


  • DirectX 7 and previous are not supported (require 2300-2400).

Prioritizing by Application (Skype, Http) or Port Range (P2P)

  • Choose an available Service or Port Range from the list, or create one.
  • For P2P Applications, due to evolving protocols, encryption and obfuscation, it can be much better to define a Port Range [such as TCP/UDP, 60000-61000]. Set your P2P applications to operate within this range. This can significantly reduce the load on the router, avoid mis-identifying packets, and more efficiently shape your network traffic.
  • For Service definitions see here.
  • Add all your other selected Services and Port Ranges here
  • Prioritize to Express or Premium, or de-prioritize to Bulk. "Bulk" gives no guaranteed bandwidth, "Standard" ensures 10%, "Express" 15%, "Premium" 75% and "Exempt" 100% (values according to this post).
  • Services not configured are always Standard priority.
  • Choosing a Service (L7 Protocol) can work better than choosing a port range; though the router works harder.
  • Tip: If you have trouble modifying the drop-down list, suggest using Opera 9.x and the BrainSlayer router GUI style (worked for me, firefox, safari, and IE don't)

Prioritizing by IP Address (Netmask Priority)

These are entered in CIDR notation including the network prefix.

For example, to specify a single IP address enter xxx.xxx.xxx.xxx / 32. Be careful to enter netmask prefix as "32" because leaving it zero means something entirely different.

The network prefix is the number of bits of the IP address to use. For example, the entry results in a match against all address on your 192.168.1.xx subnet. An entry of results in all subnets beginning with 192.168.x.x being matched. So now you can see that results in every IP address (x.x.x.x) being matched which is probably not what you want.

After entering the IP address must press "Add" to get it appended to the list.

Prioritizing by MAC Address

In the case you want to prioritize traffic from a particular device without a static IP address on your LAN, you can prioritize by MAC Address.

  • Under 'MAC Priority', enter the MAC Address of the device
  • Click 'add'
  • click 'Save changes'

This method works via the source MAC address only so traffic is only properly prioritized if the connection was initiated from this address. Traffic initiated from somewhere else will not be properly marked even if it is destined for one of the listed MAC addresses.

Default Bandwidth Level

  • Bandwidth in Kbits is set to 5000 on DD-WRT v23 SP2 (09/13/06) special. This entry is as yet unexplained and even googleing it does not enlighten.
  • Default values are 0 in v24 SP2 and QoS is not applied when the particular interface is set to 0

Priorities explained

Bandwidth classification based on the four categories will be enabled first on the hardware ports, then on MAC addresses, then netmasks and finally services. If prioritizing by MAC addresses, highest priority should be express (exempt is NOT a priority) - up-prioritize programs via the ports (sidenote: regular internet activities are already top prioritized via inherent software). *A higher class does not necessarily mean better performance - match the priority to the needs of the MAC address.

  • Exempt - This class tries to keep the bandwith and packet flow untouched. Use for gaming.
  • Premium - The top bandwidth class. By default handshaking and icmp packets fall into this class. This class should be used sparingly. Occasionally VoIP service may be placed in this class so that voice receives top priority. Use per program requirement only.
  • Express - The Express class is for interactive applications that require bandwidth above standard services so that interactive apps run smoothly. Use for computers who have interactive data.
  • Standard - All services that are not specifically classed will fall under the standard class.
  • Bulk - The bulk class is only allocated bandwidth when the remaining classes are idle. Use this class for P2P services and downloading services like FTP.

Detailed breakdown of traffic

If you'll like to know the specifics, traffic are allocated based on the following percentages of uplink and downlink values on each class:

  • Exempt: untouched
  • Premium: 75% - 100%
  • Express: 15% - 100%
  • Standard: 10% - 100%
  • Bulk: 1.5% - 100%

What this really means is that if you have 10,000kbit of uplink traffic, "Standard" class traffic can be reduced and de-prioritized to 10% or 1,000kbit when a concurrent Express service requires the uplink pipe at the same time.

You can run the following tc command to check breakdown of traffic applied to each interface. Uplink limits are applied on the WAN interface while Downlink limits are applied on the LAN interface. The interface names are device specific so you might have to check by running "ifconfig" to list all interfaces on your router. The following command will check QoS uplink limits applied on a Broadcom device's WAN interface (vlan2):

tc class show dev vlan2

How Do You Check What QoS Priorities Were Applied

The DDWRT web UI doesn't display any live traffic. Short of doing a practical test, you can get your hands dirty by checking the conntrack entries via telnet or ssh access in the router. When you're logged in run:

cat /proc/net/ip_conntrack

It will list out all currently open connection and protocol that is currently being routed by the router. This is what it would look like:

tcp      6 113 ESTABLISHED src= dst= sport=48959 dport=21 src= dst= sport=21 dport=48959 [ASSURED] use=1 rate=73 l7proto=ftp mark=40
udp      17 29 src= dst= sport=56105 dport=53 src= dst= sport=53 dport=56105 use=1 rate=157 l7proto=dns mark=10

What you'll be interested to look at will be the first set of source and destination IP, including the port numbers. Next the presence of l7proto and the "mark" field. The entries indicate the current live connection QoS priority applied on them based on the "mark" field. The "mark" values corresponds to the following:

  • Exempt: 100
  • Premium: 10
  • Express: 20
  • Standard: 30
  • Bulk: 40
  • (no QoS matched): 0

I have "ftp" set to bulk, and "dns" set to premium priority. Thus the conntrack output confirmed that the right QoS rules were applied. Using this method requires that you know the destination IP, and port number of the service, and this must be checked while the connection is active. You may see "mark=0" for some l7proto service even though they are in configured in the list of QoS rules. This may mean that the layer 7 pattern matching system didn't match a new or changed header for that protocol. Custom service on port matches will usually take care of these.

Alternatively, you can also check applied QoS on active connections using the following command (pipe to more if output is huge):

cat /proc/net/ip_conntrack | awk '{print $1 " " $5 ":" $7 " " $6 ":" $8 " " $16}' | sed -e 's/sport=//' -e 's/dport=//' -e 's/mark=100/Exempt/' -e 's/mark=10/Premium/' -e 's/mark=20/Express/' -e 's/mark=30/Standard/' -e 's/mark=40/Bulk/' -e 's/mark=0/Default-Standard/'


With all these ways of marking traffic its easy to get confused about how seemingly contradictory requirements are resolved. For example, what happens if you have an IP rule setting IP to priority "exempt" and have a MAC rule setting MAC AA:BB:CC:DD:EE:FF to priority "bulk"?

The order the precendence is as follows:

MAC - If you have specified a MAC address priority then it takes precedence over all others

Netmask - The IP address entries are applied in the order that they appear in your netmask table. Interestingly only the first match applies. For example if you have an entry marking as bulk followed by an entry marking (all 192.168.1 addresses) as premium the traffic from would be marked bulk because it was the first match. Also if a match is found in this table it does not matter what you put in the services table.

Services - The services entries are applied in the order that they appear in your services tables. Again, only the first match will apply.

Ports - Be careful with port priorities. On many routers these have no effect at all. This is the case on my router (WRT54G-TM) so I cannot tell you how to verify that yours works or not. The note at the top of this page indicates specific models and versions.

Note for PPTP Users:

There seems to be a problem by using PPTP and QoS at the same time. If you use DD-WRT with enabled PPTP server and want to activate QoS for the WAN interface then you are no longer able to connect to the PPTP server from your LAN. PPTP, L2TP and IPSec Passthrough also doesn't work.

The problem is reproducible on a WRT54GL 1.1 with DD-WRT v24-sp1.


Xipeng Xiao, "Technical, Commercial and Regulatory Challenges of QoS: An Internet Service Model Perspective", Morgan Kaufmann/Elsevier, 2008

Tim Szigeti and Christina Hattingh, "End-to-End QoS Network Design: Quality of Service in LANs, WANs, and VPNs", Cisco Press, 2004

External Links