Quality of Service

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 08:05, 7 March 2013 (edit)
Tatsuya46 (Talk | contribs)
(Priorities explained)
← Previous diff
Current revision (22:34, 23 March 2018) (edit) (undo)
Ian5142 (Talk | contribs)
(Re-adding Moved sections.)
 
(106 intermediate revisions not shown.)
Line 1: Line 1:
You are here: '''[[Main_Page|DD-WRT wiki mainpage]] / [[Web_Interface|Web-GUI]] / NAT/QoS / QoS ''' You are here: '''[[Main_Page|DD-WRT wiki mainpage]] / [[Web_Interface|Web-GUI]] / NAT/QoS / QoS '''
- +{{Languages|Quality of Service}}
==Introduction== ==Introduction==
-'''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.+<font color=red>Be using a build NO OLDER than r32170 before proceeding!</font>
-If you would like to set hard coded bandwidth limits (throttling), this can be done using the [[tc command]] 
-<font color="red">'''NOTE:''' Ethernet Port Priority only works on old models with ADMtek switch chips.+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.
-That is, the Linksys WRT54G v1.0, 1.1, 2.0, 2.1 and the WRT54GS v1.0. It appears that this Ethernet Port Priority option has been removed for many models that do not support it, but many Broadcom G spec models that do not support it still display it.</font>+ 
 +Please note, as of 336XX, if QoS is enabled, SFE (Shortcut Forwarding Engine) is disabled, even if it shows up as enabled in the GUI, it is disabled.
 + 
 +'''If you plan on using QoS, please read [[Quality_of_Service#Priorities_explained|Priorities explained]] and [[Quality_of_Service#Precedence|Precedence]] before going any farther.'''
 + 
 +==Priorities explained==
 +* Maximum - This class offers maximum priority and should be used sparingly.
 +* Premium - Second highest bandwidth class, by default handshaking and ICMP packets fall into this class. Most VoIP and video services will function good in this class if Express is insufficient.
 +* Express - The Express class is for interactive applications that require bandwidth above standard services so that interactive apps run smoothly.
 +* Standard - All services that are not specifically classed will fall under standard class.
 +* Bulk - The bulk class is only allocated remaining bandwidth when the remaining classes are idle. If the line is full of traffic from other classes, Bulk will only be allocated 1% of total set limit. Use this class for P2P and downloading services like FTP.
 + 
 + 
 +Bandwidth is allocated based on the following "minimum to maximum" percentages of downlink and uplink values for each class as of current builds:
 + 
 +* Maximum: 75% - 100%
 +* Premium: 50% - 100%
 +* Express: 25% - 100%
 +* Standard: 15% - 100%
 +* Bulk: 5% - 100%
 + 
 + 
 +What this means is that if you have 10,000kbit of uplink traffic, "Standard" class traffic can be reduced and de-prioritized to 15% or 1,500kbit when a concurrent express or higher priority service requires the down/uplink pipe at the same time.
 + 
 +Check which priorities are used with the command below:
 +<pre>
 +iptables -t mangle -vnL
 +</pre>
 +Then scroll down to the Chain SVQOS_SVCS section.
 + 
 + 
 +===TCP Packet Priority===
 + 
 +Builds before r21061 will not have this option. Update your build if you dont have it, stay up to date.
 + 
 +Prioritize small TCP-packets with the following flags: ACK/SYN/FIN/RST
 + 
 +For detailed info on what these packets do see: http://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_segment_structure
 + 
 +It is highly recommended to have at least, SYN, FIN & RST checked, OR, none at all. ACK can go both ways as P2P intensive applications such as uTorrent etc involve a lot of ACKs, so theoretically prioritizing ACKs means you "prioritized P2P" though that is not entirely' accurate. Read up & do your own testing to find out whats best for your network. If you do not do large amounts of P2P activity on your network or none at all, then enable ACK prioritization.
 + 
 + 
 +==Precedence==
 +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 192.168.1.2 to priority "maximum" and have a MAC rule setting AA:BB:CC:DD:EE:FF to priority "bulk"?
 + 
 +The order the precedence is as follows:
 + 
 +* (1st) MAC Priority
 +* (2nd) Netmask Priority
 +* (3rd) Interface Priority
 +* (4th) Services Priority
 +* (5th) Ethernet Port Priority
 + 
 + 
 +<font color="red">'''NOTE:''' Ethernet Port Priority only works on old 802.11g only models with ADMtek switch chips. If you don't have ethernet port priority listed, your router does not support it. Ethernet port priority is different than interface priority.</font>
 + 
 +<font color="red">'''NOTE:''' Services can be used at the same time as netmask or MAC, such as limiting 192.168.1.2 to 6 Mbps down & 512 Kbps up while having http set to express, that device will have http packets prioritized within it's allocated bandwidth limit. This only applies to builds r21061 & newer</font>
 + 
 + 
 +For netmask, the IP address entries are applied in the order that they appear in your netmask table. Only the first match applies. Example, if you have an entry marking 192.168.1.10/32 as bulk, followed by an entry ABOVE IT, marking 192.168.1.0/24 (all 192.168.1.X) as premium, the traffic from 192.168.1.10 would be marked bulk because it was the first match.
 + 
 +For services, The services entries are applied in the order that they appear in your services tables going from bottom to top. Again, only the first match will apply.
==Initial Setup== ==Initial Setup==
* Log into the [[Web Interface]] * Log into the [[Web Interface]]
 +
* Select the NAT/QoS tab and then the QoS sub-tab. * Select the NAT/QoS tab and then the QoS sub-tab.
-* Tick "Enable" 
-* Set Port to "WAN" or "LAN & WLAN". The term WAN here refers to the WAN connection on your router while the term "LAN & WLAN" refers to the combination of your local ports and Wifi connections. Selecting "WAN" will apply QoS only to traffic moving into or out of your network, while selecting "LAN & WLAN" will apply QoS to ALL traffic passing through the router on your network. Selecting "LAN & WLAN" will limit WLAN<->WLAN and LAN<->WLAN transfer speeds to the lowest of the uplink/downlink speeds that you set while also limiting the LAN&WLAN<->WAN rates, and thus will not be the preferred solution for most people. However, there is a [[#Known_Bugs|known bug]] related to using the "WAN" setting that can be fixed with a firewall script. 
-<font color=red>Note: If you set "LAN & WLAN" then ebtables will be loaded which will cause iptables to see bridged traffic that it normally wouldn't. This often causes severe trouble for people using additional interfaces such as VPN tunnels. It is best to avoid the "LAN & WLAN" setting unless you're absolutely sure it does what you want and nothing more. Do not select "LAN & WLAN" to work around the WAN bug!</font>+* Click "Enable"
-* Select HTB as your Packet Scheduler if using a build older than 14390 due to a [http://svn.dd-wrt.com:8000/ticket/1095 major bug] with HFSC that has been fixed in 14390. If your build is higher than 14390 then you may use either HTB or HFSC.+* Set Port to "WAN". This works for all QoS setups EXCEPT, when using QoS by interface on a BRIDGED interface under "interface priority", UNBRIDGED interfaces work fine with WAN port setting. If you want to use QoS on a BRIDGED interface you must select port as "LAN & WLAN", which also works for all other QoS setups, but with slightly more CPU usage.
-* Set your upload and download speeds. You can use a speed test like [http://www.dslreports.com/stest DSL Reports] or [http://www.speedtest.net Speedtest.net] to check your actual connection speed. Some ISPs also provide their own bandwidth testing service, which may be more reliable than the links provided. '''The uplink/downlink setting in DD-WRT are with respect to the port selected above. It's a common error to get confused. When WAN is selected these match the uplink/downlink measured. When you select "LAN & WLAN" these are reversed.''' It is required that you enter 80% of the values you measure into the proper field. After you have everything set run the speed test again. If you get 80% of your previous measurement in each direction then things are cool. If you get results which are way off then chances are that you have reversed these values. +* Select HTB as your packet scheduler if you have "queuing discipline" listed below it, if not then use HFSC.
-*Ignore Optimize for gaming. It does not do anything and hopefully will be deleted one day.+* Select FQ_CODEL as your queuing discipline.
-You must enter a value for the uplink field but if you want you can enter 0 for the downlink field in which case no QoS will occur in that direction. I do not recommend setting your downlink field to zero.+* Set your download and upload speeds. You can use a speed test like [http://www.speedtest.net Speedtest.net] or [http://www.dslreports.com/speedtest dslreports.com/speedtest] to check your actual connection speed. Some ISPs also provide their own bandwidth testing service, which may be more reliable than the links provided. Enter no higher than 95% of the values you measured into the proper fields. After you have everything set run the speed test again. If you get near 90% of your previous measurement in each direction then things are cool. If you get results which are way off then chances are that you have reversed these values. You must enter a value for the uplink field but if you want you can enter 0 for the downlink field in which case no QoS will occur in that direction, setting your downlink field to 0 isn't recommended.
-It probably bugs you to set less than 100% of your available bandwidth in these fields but this is required. There will be a bottleneck somewhere in the system and QoS can only work if the bottleneck is in your router where it has some control. The goal is to force the bottleneck to be in your router as opposed to some random location out on the wire over which you have no control.  
-The situation can become confusing because most ISP's offer only "Best effort" service which means they don't actually guarantee any level of service to you. Some ISP's even have bursting (Comcast "PowerBoost") which will temporarily give you extra bandwidth when you first start using your connection but will later throttle down to a sustained rate. Fortunately there is usually a minimum level that you receive on a consistent basis and you must set your QoS limits below this minimum. The problem is finding this minimum and you may have to repeat speed tests many times before determining it. For this reason start with 80% of your measured speed and try things for a couple of days. If the performance is acceptable you can start to inch your levels up. If you go even 5% higher than you should be, your QoS will totally stop working (just too high) or randomly stop working (high when your ISP is slow). This can lead to a lot of confusion on your part so get it working first by conservatively setting these speeds and then optimize later.+It probably bugs you to set less than 100% of your available bandwidth in these fields but this is required. There will be a bottleneck somewhere in the system and QoS can only work if the bottleneck is in your router where it has control. The goal is to force the bottleneck to be in your router as opposed to some random location out on the wire over which you have no control. Some ISP's even have bursting ("powerboost") which will temporarily give you extra bandwidth when you first start using your connection but will later throttle down to a sustained rate. Fortunately there is usually a minimum level that you receive on a consistent basis and you must set your QoS limits below this minimum. The problem is finding this minimum and you may have to repeat speed tests many times before determining it. For this reason start with 80% of your measured speed and try things for a couple of days. If the performance is acceptable you can start to inch your levels up. If you go even 2% higher than you should be, your QoS will totally stop working (just too high) or randomly stop working (when your ISP node/DSLAM is slow aka saturated). This can lead to a lot of confusion on your part so get it working first by conservatively setting these speeds and then optimize later.
==Prioritizing by Application (Skype, Http) or Port Range (P2P) == ==Prioritizing by Application (Skype, Http) or Port Range (P2P) ==
* Choose an available Service or Port Range from the list or create one, and then press "Add" next to it. * Choose an available Service or Port Range from the list or create one, and then press "Add" next to it.
-* 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 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 [http://protocolinfo.org/wiki/List_of_protocols see here].+
* Add all your other selected Services and Port Ranges here * Add all your other selected Services and Port Ranges here
-* Choosing a Service (L7 Protocol) can work better than choosing a port range; though the router works harder.+* Choosing a Layer7 service based entry can work better than choosing a port range; though the router works harder as it has to dig into the packets beyond the header, to look at the data they contain.
If you wish to add more than one priority then use the "Add" button to create more entries. If you wish to add more than one priority then use the "Add" button to create more entries.
-==Prioritizing by IP Address (Netmask Priority)==+ 
 +==Prioritizing by Interface==
 +Select your preferred interference, click add, then select the speed or priority you want. You can also limit ethernet ports this way as well (ethX or vlanX). Any limits or priorities set are shared for that interface regardless how many clients are connected to it. Excellent for running a guest network/hotspot on eg, ath1.1, applying QoS on the entire interface makes it impossible for a greedy user to bypass it by MAC cloning, changing IPs etc, short of connecting to a different interface. The same interface can also be entered multiple times with different speed limits or priorities for different services, example, ath0 512/512 with ssl & ath0 0/1024 with http would mean ssl traffic on ath0 is limited to 512kbps down & up, http is unlimited on down (up to global limits is used) & limited to 1024 (1mbps) on up, remaining entered services are not limited (up to global limits for both directions).
 + 
 +==Prioritizing by Netmask (IP address)==
These are entered in CIDR notation including the network prefix. 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 as "32" because leaving it zero means ALL IP ADDRESSES. +For example, to specify a single IP address enter xxx.xxx.xxx.xxx/32. Be careful to enter netmask as /32 because leaving it /0 means ALL IPs!.
The netmask is the number of bits of the IP address to match. For example, the entry 192.168.1.0/24 matches 192.168.1.x addresses. An entry of 192.168.0.0/16 matches 192.168.x.x addresses. If you're unsure of how to create CIDR subnet masks and what they mean, then use a [http://www.subnet-calculator.com subnet calculator]. The netmask is the number of bits of the IP address to match. For example, the entry 192.168.1.0/24 matches 192.168.1.x addresses. An entry of 192.168.0.0/16 matches 192.168.x.x addresses. If you're unsure of how to create CIDR subnet masks and what they mean, then use a [http://www.subnet-calculator.com subnet calculator].
-After you have filled it out, press "Add" next to it.+After you have filled it out, press "add" next to it. If you want to add multiple entries (make sure to have order correct!) click "save" before entering in another so any previous changes don't get deleted, only click "apply" when you want to start testing your current changes displayed.
 + 
==Prioritizing by MAC Address== ==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.+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. Enter the MAC Address of the device and press "Add" next to it.
-Enter the MAC Address of the device and press "Add" next to it. 
-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. 
-==Priorities explained== 
-Bandwidth classification based on the four categories will be enabled first on MAC addresses, then netmasks and finally services. 
- 
-* Exempt - Exempt no longer ignores global limits, instead it is now treated as "absolute max priority" higher than that of premium & is now the top bandwidth class guaranteeing 60% at minimum. 
-* Premium - By default handshaking and icmp packets fall into this class. This class should be used sparingly. Occasionally VoIP and gaming services may be placed in this class so that they receive top priority. 
-* Express - The Express class is for interactive applications (IRC, instant messaging, SSH, telnet, etc.) that require bandwidth above standard services so that interactive apps run smoothly. 
-* Standard - All traffic that is not specifically classed will fall under the standard class. You should not need to explicitly set anything to this 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'd like to know the specifics, bandwidth is allocated based on the following percentages of uplink and downlink values for each class: 
- 
-* Exempt: 60% - 100% 
-* Premium: 25% - 100% 
-* Express: 10% - 100% 
-* Standard: 5% - 100% 
-* Bulk: 1% - 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 5% or 500kbit when a concurrent express or higher priority service requires the down/uplink pipe at the same time.  
- 
-You can run the tc command to check breakdown of traffic applied to each interface. Uplink limits are applied to the WAN interface (nvram get wan_iface) or LAN&WLAN bridge interface (br0) depending on which port you selected, while Downlink limits are applied to the imq0 interface. 
- 
- tc class show dev `get_wanface` 
- tc class show dev br0 
- tc class show dev imq0 
==How Do You Check What QoS Priorities Were Applied== ==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: 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:
<pre> <pre>
-cat /proc/net/ip_conntrack+iptables -t mangle -vnL
</pre> </pre>
 +Then scroll down to the Chain SVQOS_SVCS section.
 +
 +With the above iptables mangle command you can see the inbound/outbound chains, entered IPs/MACs/services & whats being matched where.
 +
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: 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:
<pre> <pre>
Line 92: Line 131:
</pre> </pre>
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: 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+* Maximum: 100
* Premium: 10 * Premium: 10
* Express: 20 * Express: 20
Line 98: Line 137:
* Bulk: 40 * Bulk: 40
* (no QoS matched): 0 * (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 either of the following commands (pipe to more if output is huge): 
-Generally try this first command, if you find the output to consistently state "Exempt" as I noticed for dd-wrt build SVN revision 13401M NEWD-2 K2.6 Eko, then use the second command+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.
-<pre>+
-awk '{ gsub(/(src|dst|sport|dport|mark)=/, ""); printf "%s %-21s %-21s %s\n", $1, $1 == "tcp" ? $5 ":" $7 : $4 ":" $6, $1 == "tcp" ? $6 ":" $8 : $5 ":" $7, $NF == 0 ? "Default/Standard" : $NF == 10 ? "Premium" : $NF == 20 ? "Express" : $NF == 30 ? "Standard" : $NF == 40 ? "Bulk" : "Exempt" }' /proc/net/ip_conntrack+
-</pre>+
- +
-Second Command:+
-<pre>+
-awk '{ gsub(/(src|dst|sport|dport|mark)=/, ""); printf "%s %-21s %-21s %s\n", $1, $1 == "tcp" ? $5 ":" $7 : $4 ":" $6, $1 == "tcp" ? $6 ":" $8 : $5 ":" $7, $(NF-2) == 0 ? "Default/Standard" : $(NF-2) == 10 ? "Premium" : $(NF-2) == 20 ? "Express" : $(NF-2) == 30 ? "Standard" : $(NF-2) == 40 ? "Bulk" : "Exempt" }' /proc/net/ip_conntrack+
-</pre>+
==Time Based QoS== ==Time Based QoS==
-As described in [http://www.dd-wrt.com/phpBB2/viewtopic.php?p=438664#438664 this thread] you can use [[CRON]] jobs to enable/disable QoS. This is just a simplistic approach but more complex things could be done if you put your mind to it. These commands will enable HTB QoS on the WAN port from 5PM to 1AM but you will still need to configure everything else in the GUI. If you want to use LAN&WLAN then change "`get_wanface`" to "br0". To change the times, see the [[CRON]] page for information.+As described in [http://www.dd-wrt.com/phpBB2/viewtopic.php?p=438664#438664 this thread] you can use [[CRON]] jobs to enable/disable QoS. This is just a simplistic approach but more complex things could be done if you put your mind to it. These commands will enable HTB QoS on the WAN port from 5PM to 1AM but you will still need to configure everything else in the GUI. If you want to use LAN&WLAN then change "`get_wanface`" to "imq1". To change the times, see the [[CRON]] page for information.
1 17 * * * root /usr/sbin/svqos `nvram get wshaper_downlink` `nvram get wshaper_uplink` `get_wanface` `nvram get wan_mtu` 0 1 17 * * * root /usr/sbin/svqos `nvram get wshaper_downlink` `nvram get wshaper_uplink` `get_wanface` `nvram get wan_mtu` 0
Line 129: Line 158:
1 10 * * * root /usr/sbin/svqos '''[downlink rate]''' '''[uplink rate]''' `get_wanface` `nvram get wan_mtu` 0; nvram set wshaper_downlink='''[downlink rate]'''; nvram set wshaper_uplink='''[uplink rate]'''; 1 10 * * * root /usr/sbin/svqos '''[downlink rate]''' '''[uplink rate]''' `get_wanface` `nvram get wan_mtu` 0; nvram set wshaper_downlink='''[downlink rate]'''; nvram set wshaper_uplink='''[uplink rate]''';
-== Script Generator ==+<font color="red">Edit: This will cause trouble on current firmware releases greater than r21061. Use the predefined service handler to stop/start QoS instead. Even if needed, use imq1 instead of br0 for internal traffic shaping.
 +</font>
 +<pre>stopservice wshaper
 +startservice wshaper</pre>
-There is an old script generator available, which you may find useful to set up QoS. http://www.robsonn.user.icpnet.pl/generator.zip+<font color="red">If you need to alter down/up rates edit the nvram variables before restarting wshaper</font>
-It generates a script which you can copy/paste at Administration -> Commands -> Save Firewall.+<pre>
-Because of it's age, it often generates scripts that won't work properly. Sometimes this can be solved easily, for instance you will need to change any instances of "modprobe" to "insmod" to insert kernel modules. Other things are not easy, such as any iptables rule with iprange which is not included in most DD-WRT builds and so you should use netmasks as an alternative. There is also a fundamental flaw with the way it writes scripts that prevents any service rules from working properly so you must stick to IP/MAC/TCP/UDP/port based rules.+nvram set wshaper_downlink=20000
- +nvram set wshaper_uplink=800
-==Precedence==+startservice wshaper
-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 192.168.1.2 to priority "exempt" and have a MAC rule setting MAC AA:BB:CC:DD:EE:FF to priority "bulk"? +</pre>
- +
-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 192.168.1.10/32 as bulk followed by an entry marking 192.168.1.0/24 (all 192.168.1 addresses) as premium the traffic from 192.168.1.10 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.+
-* Ethernet Ports - See the note in the [[#Introduction|Introduction]]+
- +
-'''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.+
- +
-(update July 2009) tested DD-WRT v24-sp2 Build 12548M on my Asus rotuer- the problem seems to be fixed.+
- +
-==Known Bugs==+
-There are some bugs which can affect your success with QoS.+
- +
-* When the port is set to WAN and a downlink limit is set, uplink traffic also gets counted by the downlink queue. This also causes LAN traffic to the router (ie. if you're running a NAS on the router) to be put into the downlink queue. A solution that users can implement themselves is explained in [http://svn.dd-wrt.com:8000/ticket/1559 ticket 1559].+
-* Adding and deleting services, MAC address and netmasks is relatively simple with the web interface which is great, however, DD-WRT is not so good at actually updating its internal runtime data on the fly to reflect your selections. The result can be erroneous and conflicting iptables entries that can seriously hamper your performance. This can be especially confusing if you make a change then test, make another change the test, etc. Save your changes and reboot your router after you have completed your changes to avoid any problems. If you are able to reproduce this problem or want more information, please see [http://svn.dd-wrt.com:8000/ticket/1560 ticket 1560]. 
-==Books== 
-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= =External Links=
-* [http://www.sevana.fi/aqua-powered-asterisk-voice-quality-monitoring-solution.php AQuA Powered Asterisk Voice Quality Monitoring Solution] 
-* [http://www.sevana.fi/aqua_wiki.php AQuA - Audio Quallity Analyzer] 
* [http://luxik.cdi.cz/~devik/qos/htb/manual/userg.htm HTB Manual] * [http://luxik.cdi.cz/~devik/qos/htb/manual/userg.htm HTB Manual]
* [http://linux.die.net/man/8/iptables iptables man page] * [http://linux.die.net/man/8/iptables iptables man page]
-* [http://protocolinfo.org/wiki/List_of_protocols Look up the DD-WRT pre-defined QoS Service definitions] 
-* [http://www.solosoft.org/projects/qos A more detailed QoS Setup Page] 
-* [http://www.csc.fi/english/funet/calc/laskin2.html Netmask Calculator] 
* [http://l7-filter.sourceforge.net/ L7-Filter] * [http://l7-filter.sourceforge.net/ L7-Filter]
* [http://frottle.sourceforge.net/ Frottle sourceforge] * [http://frottle.sourceforge.net/ Frottle sourceforge]
-* [http://patraswireless.net/software.html Petra's wireless homepage]+* [http://www.gargoyle-router.com/wiki/doku.php?id=qos Lots of QoS myths explained, what QoS can & can't do & much more info.]
-* [http://www.dd-wrt.com/phpBB2/viewtopic.php?t=3100 Another way of doing it for experienced users]+
-* [http://www.linksysinfo.org/forums/showthread.php?t=60304 Using QoS - Tomato firmware (same guidelines will apply to DD-WRT)]+
[[Category:Traffic moderation]] [[Category:Traffic moderation]]
[[Category:Basic tutorials]] [[Category:Basic tutorials]]

Current revision

You are here: DD-WRT wiki mainpage / Web-GUI / NAT/QoS / QoS


Contents

[edit] Introduction

Be using a build NO OLDER than r32170 before proceeding!


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.

Please note, as of 336XX, if QoS is enabled, SFE (Shortcut Forwarding Engine) is disabled, even if it shows up as enabled in the GUI, it is disabled.

If you plan on using QoS, please read Priorities explained and Precedence before going any farther.

[edit] Priorities explained

  • Maximum - This class offers maximum priority and should be used sparingly.
  • Premium - Second highest bandwidth class, by default handshaking and ICMP packets fall into this class. Most VoIP and video services will function good in this class if Express is insufficient.
  • Express - The Express class is for interactive applications that require bandwidth above standard services so that interactive apps run smoothly.
  • Standard - All services that are not specifically classed will fall under standard class.
  • Bulk - The bulk class is only allocated remaining bandwidth when the remaining classes are idle. If the line is full of traffic from other classes, Bulk will only be allocated 1% of total set limit. Use this class for P2P and downloading services like FTP.


Bandwidth is allocated based on the following "minimum to maximum" percentages of downlink and uplink values for each class as of current builds:

  • Maximum: 75% - 100%
  • Premium: 50% - 100%
  • Express: 25% - 100%
  • Standard: 15% - 100%
  • Bulk: 5% - 100%


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

Check which priorities are used with the command below:

iptables -t mangle -vnL

Then scroll down to the Chain SVQOS_SVCS section.


[edit] TCP Packet Priority

Builds before r21061 will not have this option. Update your build if you dont have it, stay up to date.

Prioritize small TCP-packets with the following flags: ACK/SYN/FIN/RST

For detailed info on what these packets do see: http://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_segment_structure

It is highly recommended to have at least, SYN, FIN & RST checked, OR, none at all. ACK can go both ways as P2P intensive applications such as uTorrent etc involve a lot of ACKs, so theoretically prioritizing ACKs means you "prioritized P2P" though that is not entirely' accurate. Read up & do your own testing to find out whats best for your network. If you do not do large amounts of P2P activity on your network or none at all, then enable ACK prioritization.


[edit] Precedence

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 192.168.1.2 to priority "maximum" and have a MAC rule setting AA:BB:CC:DD:EE:FF to priority "bulk"?

The order the precedence is as follows:

  • (1st) MAC Priority
  • (2nd) Netmask Priority
  • (3rd) Interface Priority
  • (4th) Services Priority
  • (5th) Ethernet Port Priority


NOTE: Ethernet Port Priority only works on old 802.11g only models with ADMtek switch chips. If you don't have ethernet port priority listed, your router does not support it. Ethernet port priority is different than interface priority.

NOTE: Services can be used at the same time as netmask or MAC, such as limiting 192.168.1.2 to 6 Mbps down & 512 Kbps up while having http set to express, that device will have http packets prioritized within it's allocated bandwidth limit. This only applies to builds r21061 & newer


For netmask, the IP address entries are applied in the order that they appear in your netmask table. Only the first match applies. Example, if you have an entry marking 192.168.1.10/32 as bulk, followed by an entry ABOVE IT, marking 192.168.1.0/24 (all 192.168.1.X) as premium, the traffic from 192.168.1.10 would be marked bulk because it was the first match.

For services, The services entries are applied in the order that they appear in your services tables going from bottom to top. Again, only the first match will apply.

[edit] Initial Setup

  • Select the NAT/QoS tab and then the QoS sub-tab.
  • Click "Enable"
  • Set Port to "WAN". This works for all QoS setups EXCEPT, when using QoS by interface on a BRIDGED interface under "interface priority", UNBRIDGED interfaces work fine with WAN port setting. If you want to use QoS on a BRIDGED interface you must select port as "LAN & WLAN", which also works for all other QoS setups, but with slightly more CPU usage.
  • Select HTB as your packet scheduler if you have "queuing discipline" listed below it, if not then use HFSC.
  • Select FQ_CODEL as your queuing discipline.
  • Set your download and upload speeds. You can use a speed test like Speedtest.net or dslreports.com/speedtest to check your actual connection speed. Some ISPs also provide their own bandwidth testing service, which may be more reliable than the links provided. Enter no higher than 95% of the values you measured into the proper fields. After you have everything set run the speed test again. If you get near 90% of your previous measurement in each direction then things are cool. If you get results which are way off then chances are that you have reversed these values. You must enter a value for the uplink field but if you want you can enter 0 for the downlink field in which case no QoS will occur in that direction, setting your downlink field to 0 isn't recommended.


It probably bugs you to set less than 100% of your available bandwidth in these fields but this is required. There will be a bottleneck somewhere in the system and QoS can only work if the bottleneck is in your router where it has control. The goal is to force the bottleneck to be in your router as opposed to some random location out on the wire over which you have no control. Some ISP's even have bursting ("powerboost") which will temporarily give you extra bandwidth when you first start using your connection but will later throttle down to a sustained rate. Fortunately there is usually a minimum level that you receive on a consistent basis and you must set your QoS limits below this minimum. The problem is finding this minimum and you may have to repeat speed tests many times before determining it. For this reason start with 80% of your measured speed and try things for a couple of days. If the performance is acceptable you can start to inch your levels up. If you go even 2% higher than you should be, your QoS will totally stop working (just too high) or randomly stop working (when your ISP node/DSLAM is slow aka saturated). This can lead to a lot of confusion on your part so get it working first by conservatively setting these speeds and then optimize later.

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

  • Choose an available Service or Port Range from the list or create one, and then press "Add" next to it.
  • 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.
  • Add all your other selected Services and Port Ranges here
  • Choosing a Layer7 service based entry can work better than choosing a port range; though the router works harder as it has to dig into the packets beyond the header, to look at the data they contain.

If you wish to add more than one priority then use the "Add" button to create more entries.


[edit] Prioritizing by Interface

Select your preferred interference, click add, then select the speed or priority you want. You can also limit ethernet ports this way as well (ethX or vlanX). Any limits or priorities set are shared for that interface regardless how many clients are connected to it. Excellent for running a guest network/hotspot on eg, ath1.1, applying QoS on the entire interface makes it impossible for a greedy user to bypass it by MAC cloning, changing IPs etc, short of connecting to a different interface. The same interface can also be entered multiple times with different speed limits or priorities for different services, example, ath0 512/512 with ssl & ath0 0/1024 with http would mean ssl traffic on ath0 is limited to 512kbps down & up, http is unlimited on down (up to global limits is used) & limited to 1024 (1mbps) on up, remaining entered services are not limited (up to global limits for both directions).

[edit] Prioritizing by Netmask (IP address)

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 as /32 because leaving it /0 means ALL IPs!.

The netmask is the number of bits of the IP address to match. For example, the entry 192.168.1.0/24 matches 192.168.1.x addresses. An entry of 192.168.0.0/16 matches 192.168.x.x addresses. If you're unsure of how to create CIDR subnet masks and what they mean, then use a subnet calculator.

After you have filled it out, press "add" next to it. If you want to add multiple entries (make sure to have order correct!) click "save" before entering in another so any previous changes don't get deleted, only click "apply" when you want to start testing your current changes displayed.


[edit] 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. Enter the MAC Address of the device and press "Add" next to it.



[edit] 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:

iptables -t mangle -vnL

Then scroll down to the Chain SVQOS_SVCS section.

With the above iptables mangle command you can see the inbound/outbound chains, entered IPs/MACs/services & whats being matched where.

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=192.168.1.5 dst=83.141.4.210 sport=48959 dport=21 src=83.141.4.210 dst=216.239.61.104 sport=21 dport=48959 [ASSURED] use=1 rate=73 l7proto=ftp mark=40
udp      17 29 src=192.168.1.5 dst=128.63.2.53 sport=56105 dport=53 src=128.63.2.53 dst=216.239.61.104 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:

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


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.

[edit] Time Based QoS

As described in this thread you can use CRON jobs to enable/disable QoS. This is just a simplistic approach but more complex things could be done if you put your mind to it. These commands will enable HTB QoS on the WAN port from 5PM to 1AM but you will still need to configure everything else in the GUI. If you want to use LAN&WLAN then change "`get_wanface`" to "imq1". To change the times, see the CRON page for information.

1 17 * * * root /usr/sbin/svqos `nvram get wshaper_downlink` `nvram get wshaper_uplink` `get_wanface` `nvram get wan_mtu` 0
*/6 1-17 * * * root /usr/sbin/svqos stop 0 `get_wanface` 0 0

If you use HFSC then you would do something like this instead.

1 17 * * * root /usr/sbin/svqos2 `nvram get wshaper_uplink` `nvram get wshaper_downlink` `get_wanface` `nvram get wan_mtu` 0
*/6 1-17 * * * root /usr/sbin/svqos2 stop 0 `get_wanface` 0 0 

As described in this thread you can also set different rates at different times by doing something like this which changes the HTB rates.

1 23 * * * root /usr/sbin/svqos [downlink rate] [uplink rate] `get_wanface` `nvram get wan_mtu` 0; nvram set wshaper_downlink=[downlink rate]; nvram set wshaper_uplink=[uplink rate];
1 10 * * * root /usr/sbin/svqos [downlink rate] [uplink rate] `get_wanface` `nvram get wan_mtu` 0; nvram set wshaper_downlink=[downlink rate]; nvram set wshaper_uplink=[uplink rate];

Edit: This will cause trouble on current firmware releases greater than r21061. Use the predefined service handler to stop/start QoS instead. Even if needed, use imq1 instead of br0 for internal traffic shaping.

stopservice wshaper
startservice wshaper

If you need to alter down/up rates edit the nvram variables before restarting wshaper

nvram set wshaper_downlink=20000
nvram set wshaper_uplink=800
startservice wshaper



[edit] External Links