Parents aren’t supposed to have a favorite child, but if you grew up with any brothers or sisters, you know that usually isn’t true. (Yes, their favorite was you. Of course it was.) While it might be unfair to give one kid preferential treatment over another, it’s completely legit in the world of networking. (Also legit: bad segues.) In fact, discriminating for and against different kinds of network traffic can be a very good idea indeed.
Today’s broadband pipes are more crowded than ever. Stuffed full with file downloads, VoIP traffic, fast-twitch games, and IM sessions, there’s a lot of data squeezing its way through your Internetting. Quality of Service, or QoS, generally refers to strategies for creating priority queues, so that some data is given preference over other data.
The obvious and most common use for QoS is to give high priority to real-time traffic, like VoIP services such as Skype, and games which require the lowest latency so you have a chance to return fire. Less time-sensitive traffic, like large downloads and P2P transfers, can afford to slow down when urgent data is coming through.
You can setup relatively sophisticated, or very simple, QoS rules on a sub-$60 router like the Linksys WRT54G and similar compatible routers using the open-source firmware DD-WRT. Using the latest V23 firmware for DD-WRT, establishing QoS priorities is relatively straightforward, albeit with some quirks.
QoS Classifications
As we’ll soon see, DD-WRT lets you define QoS priorities for up to four general sources of traffic:
- Network services. This is the most common category for defining QoS rules. Priorities defined here apply to traffic originating from specific network applications, like Skype and Bittorrent.
- Netmask/IP address. In this category, you can promote or demote traffic originating from a particular machine or networked block of machines, regardless of which network application is creating the traffic.
- MAC address. Similar to Netmask/IP, except that you assign priority based on a machine’s unique MAC address rather than its IP address. This lets you target specific physical machines even if they receive dynamic IP addresses.
- Ethernet port. This special category lets you prioritize traffic originating from a particular switched router port. The “special” caveat is that Ethernet port priority only works on DD-WRT compatible routers using the ADM6996L chipset – this includes the Linksys WRT54G versions 1.0, 1.1, 2.0, and WRT54GS version 1.0.
Within any category, DD-WRT offers five priority classifications:
- Exempt. QoS rules do not apply to this classification.
- Premium. The elite class. Only traffic that requires the utmost priority should receive this classification, like VoIP traffic – ideally, only if the next lowest class proves insufficient.
- Express. Like business-class in air travel, express priority is a cut above the cattle class, but not quite the comfy seats with leg room to spare. Services which benefit from real-time activity should first try express classification before being bumped to premium.
- Standard. The default – any service without a QoS rule is assigned to standard class. Traffic in this class is treated normally except where traffic in higher classes requires bandwidth.
- Bulk. Low priority traffic, like P2P, can be classified as bulk. Only receives bandwidth when other classifications are idle.
Know Your Bandwidth
Before getting our hands dirty, you should be prepared with information about your broadband bandwidth. DD-WRT QoS requires that you set global values for your maximum upload and download speeds. It is strongly recommended that you set these values at between 85-90% of your “true” speeds, which leaves room for network overhead and minimizes your network latency by not saturating your connection.
Most broadband services are rated in Megabits per second (Mbps). You can multiply this value by 1024 to convert to Kilobits per second (Kbps). Suppose your cable modem service is rated at 3Mbps download/768Kbps upload:
Example download speed:
3Mbps * 1024 = 3072Kbps * 0.85 = 2611KbpsExample upload speed:
768Kbps * 0.85 = 653Kbps
We multiply by 0.85 to calculate 85% of the total. You can also determine your real-world bandwidth by visiting a speed test site such as testmy.net or Speedtest.net, which may indicate a lower speed than the advertised value that you’re paying good money for. Who are we kidding? Of course it will be lower.
Setting up QoS
Step 1. Open a browser on your PC and connect to the DD-WRT router – its default address ishttp://192.168.1.1 unless you’ve set it otherwise. The default login is root and password is admin. Of course, you should change these. If you don’t, you’ll have terrible dreams at night.
Step 2. Click to the Applications & Gaming/QoS menu. On this page you set most of the QoS settings. To start the QoS engine, check Enable beside “Start QoS”.
Assuming you want the QoS settings to apply to your Internet usage (you do), select WAN for “Port.”
The “Packet Scheduler” item is the source of some confusion among the DD-WRT community. Short answer: stick with HTB. The alternative, HFSC, is alleged to not yet work reliably. Both describe algorithms for implementing QoS, but word on the street is that more people have more success with HTB – so, like every good parent says, do it “because we said so.”
For the “Uplink” speed, enter the number you calculated earlier. Remember to enter the value in Kbps (not Mbps), and be sure to enter your upload speed here – not your download speed. Otherwise you’ll see some slow results indeed.
Of course, enter your calculated “Downlink” speed in the next box.
The “Optimize for Gaming” checkbox is basically a pre-configured setting only for use with a predefined set of games. You can find the reported list of games on the Internet, but really, you’re better off configuring QoS settings explicitly rather than rely on a checkbox that may or may not include the particular version of a particular game. In other words, we’re leaving this unchecked.
Setting up QoS, continued:
Step 3. To add a network application to the QoS rules, first click on the drop down list beside the “Add” button. Scroll through to see if your application is already listed. DD-WRT includes so-called L7 filters for a long list of applications. An L7 filter is used to determine what application is sending traffic, not by static means like port usage, but by analyzing the packets and matching a known fingerprint. L7 filters are the most reliable way to assign QoS, because they can identify a data stream more accurately than port usage.
For each relevant network application you find in the menu, click the Add button and let the page refresh. In this example we first added bittorrent from the list followed by skypetoskype.
For each network application you can assign a priority class. Select the priority you want for each service and then be sure to click the Save Settings button at the bottom of the page.
In the example above, we’ve assign P2P Bittorrent traffic to the lowest priority, “bulk,” and real-time VoIP Skype traffic to the highest priority, “premium.”
Step 4. Suppose you want to assign QoS for an application that isn’t listed – click the Add/Edit Service button to launch a pop-up window where you can define custom services.
We want to add a new definition for Radmin, a remote desktop application. Due to a bizarre quirk in DD-WRT V23 SP1, some users find that when they try to define a new service, it can’t later be added to the QoS rules. A workaround seems to be creating the new service two times, each with a different name. So, we create the radmin service twice, with the names “radmin1” and “radmin2”.
Because there is no L7 filter for Radmin, we define this application the old-fashioned way. Above we’ve told DD-WRT to identify Radmin traffic as any TCP packets on port 4899.
Click the “Add” button to add the new service to the list, and then be sure to click “Apply” for the new list to actually be saved. The pop-up window now closes.
Returning to the services settings, we now see the newly created radmin1 (and radmin2) in the drop down list. Chose “radmin1” and clicked the “Add” button, and then assign “Express” priority to this application.
Step 5. You can also define priorities based on originating IP address rather than network protocol.
To simply add a single IP address, type it into the fields and click “Add.” Here we added a single IP address, 192.168.0.10, and then assigned it “Exempt” priority. Because it is defined as exempt, traffic from this machine will not be subject to any of the QoS rules regardless of which application is creating the traffic.
To add a block of IP addresses, calculate the NetMask by visiting an online IP address calculator. For example, if we enter the range 192.168.0.1-192.168.0.15 into this calculator, the resulting NetMask in NetAddr notation is 192.168.0.0/28. Enter this value into the IP/Mask fields and click “Add”. You can then assign a priority level for all traffic originating from any machines within the 192.168.0.1-192.160.0.15 block.
Step 6. Similarly, you can also assign QoS to an individual machine identified by its MAC, rather than IP, address. This makes sense when, for instance, the machine in question might be assigned a dynamic IP. (Technically, a MAC address identifies a network adapter rather than a machine. A single machine could have multiple network adapters, and you can assign a given QoS priority to one adapter but not the other.)
Enter the six hex segments of your machine/network adapter’s MAC address and then click “Add.” When the page refreshes, you can select a QoS priority level and then be sure to click “Save Settings” at the bottom of the page.
Step 7. Users of certain router models can optionally set QoS levels per switched Ethernet port. As stated earlier, the Ethernet Port Priority settings only work with Linksys models WRT54G versions 1.0, 1.1, 2.0, and WRT54GS version 1.0, or other DD-WRT compatible routers with the ADM6996L chipset.
On supported routers you can set both a QoS priority level as well as a maximum throughput threshold, as low as 256Kbps, or even disable that port entirely.
In and Out
The nature of network traffic is such that QoS levels are better controlled for outgoing traffic than incoming. The router has great control over the rate it sends out packets – it has less control over the rate they come in. To achieve incoming QoS priorities, the router may try to “stall” incoming traffic. Users reports indicate mixed success applying QoS levels to incoming traffic compared to outgoing.
Users also report mixed success with QoS levels in general, particularly with the current version of DD-WRT (V23). Some users get exactly the results they expect while others do not.
Troubleshooting
If your QoS settings don’t seem to behave the way you expect, you may need to try several approaches. You can change a service priority from an L7 filter to a port-based definition, for example. You may find that QoS levels for a machine identified by its IP rather than its MAC are more reliable, or vice versa.
In preparing this tutorial, my DD-WRT administration interface exhibited odd behavior on several occasions. Sometimes, the interface would hang after applying or saving settings, such as adding a new service priority. Often, after creating a new service definition, the interface would revert to a blank page.
In most cases, reloading the main administration page and navigating back to the QoS page resolved the hiccups. One time, the router had to be power cycled. Despite the quirks with the interface, though, ultimately the QoS settings stuck. So stick with it.