Mini-FAQ: QoS setup on the RouterTech firmware

All about firmwares for routers. Support for RouterTech firmwares is here too.
christi
Novice
Novice
Posts: 34
Joined: Fri May 04, 2007 7:56 pm

Mini-FAQ: QoS setup on the RouterTech firmware

Post by christi » Mon May 07, 2007 2:28 pm

This is a guide to setting up QoS (Quality of Service) on the RouterTech custom firmware. It may apply to some other AR7 firmwares too, but details will vary if so. It's not intended to be comprehensive, just to get you started with traffic shaping to improve your surfing experience.

Consider this a work in progress. The information here is gleaned from experimentation and guesswork, and could be wrong. Updates welcome.

Why QoS?

How often have you had a big download going on, but wanted to quickly check your mail, and found the download made everything way too slow? QoS is a way to solve this kind of problem by telling your router about the kind of traffic that's going through your network, and which is more important.

How does it work?

AR7 based routers use a proprietory traffic shaping algorithm called priowrr. What this does is divides all Internet traffic into three classes* called high, medium and low. High priority packets are always processed first, and then the remaining bandwidth is divided between medium and low packets. The default ratio is 60/40, but this can be changed. If you do not assign a priority to a particular type of traffic, it is treated as low priority.

*Actually there are four classes, but the second high priority queue doesn't seem to be used.

So what are we aiming for?

This will vary depending on your individual requirements. However, here's some suggestions.

High priority:

Use this queue for things that are being done which the users of the network will be waiting on. This is for interactive processes that require a fast response.

Use this for interactive logins (ssh), VoIP, and email (POP, IMAP, SMTP), Online gaming.

Warning: If this class gets full, packets from the lower classes may get lost. I would advise using it sparingly and not for high traffic applications like video streaming unless you have a lot of bandwidth.

Medium priority:

Use this queue for tasks that are important, but not hugely time critical. For example web, video streaming and ftp traffic.

Low priority:

Use this for background tasks that are non-interactive. File sharing applications are the most obvious candidate for the low queue, since this allows them to take up spare bandwidth when available without negatively impacting interactive tasks like web browsing.

How do we sort out which packets are which?

There are varying levels of sophistication with which this can be done. Here we'll opt for a simplistic approach that gets the job done, but could possibly be a lot more refined. Internet traffic is directed to and from ports, which are a way of telling the machine that is being communicated which program to pass the information to. These are standardised, so for example, web servers are almost always on port 80. Therefore we can say that almost all (unencryted) web traffic (including web downloads) will be either coming to or from port 80.

There are several types of packet that can be sent. The important ones for our purposes are TCP and UDP. Whether a packet is TCP or UDP depends on the kind of information being sent. In the case of web traffic the protocol is TCP.

Once we know the protocol and the ports it uses we have enough information to start setting up QoS.

Getting started

First we need to turn on QoS. We do this from the "IP QoS" submenu of the "Advanced" router configuration screen as follows:

1) Make sure the connection box indicates your Internet connection

2) Tick the box marked "Enable IPQoS".

3) (Optional) Adjust the weighting. The default is 60% medium, 40% low. Since we're proposing to have some interactive processes in the medium class, we might want to alter this to 70/30 or even 80/20. Change the value of either "medium priority weight" or "low priority weight" and the other will change automatically. Be aware that traffic that is not matched by our rules (such as traffic to webservers on non-standard ports) will go to the low queue.

4) Click Apply to turn QoS on.

Adding rules

Now we start to add our rules. As an example we'll look at the SSH protocol. This is a TCP protocol going to and from port 22. It's used for interactive logins to remote machines, and thus needs a good response, and will be added to the "High" queue. We need to create two rules as follows:

Rule Name: ssh-out
Destination Start Port: 22
Destination End Port: 22
Traffic Priority: High
Protocol: TCP

Rule Name: ssh-in
Source Start Port: 22
Source End Port: 22
Traffic Priority: High
Protocol: TCP

Add these by pressing the "Add button" towards the bottom of the web page, then setting the appropriate fields in the form. Leave the other settings empty or at their default values. Press apply to add the rule. When this is complete, you should have two rules added to the table on the main page.

Suggested rules

Feel free to add any of the rules below, which will work for the default setup.

Note that since "low" seems to be the default, you probably do not explicitly need to add rules for protocols you would like to be low priority. It doesn't hurt to be explicit however, and they're included here for completeness.

You can of course add all of these as rules, but it's probably easier just to pick the ones you use yourself.

There's a large list of ports for IM, multimedia etc. at http://www.practicallynetworked.com/sha ... t_list.htm. Pick the ones you need from here.

Code: Select all

High priority

Service     Protocol Ports   Description
ssh         TCP      22      Interactive remote login via ssh
pop3        TCP      110     POP3 email (unencrypted)
pop3s       TCP      995     POP3 email (encrypted)
imap        TCP      143     IMAP email (unencrypted)
imaps       TCP      993     IMAP email (encrypted)
smtp        TCP      25      Outgoing SMTP email (unencrypted)
smtps       TCP      465     STMP email (encrypted)
smtpsgmail  TCP      587     Google's encrypted STMP email
dns         ANY      53      Name server traffic
bbciplayer  TCP      1947    BBC iPlayer
bbciplayer  UDP      1948    BBC iPlayer

Medium / Normal Priority

Service     Protocol Ports   Description
http        TCP      80      Web traffic (unencrypted)
https       TCP      443     Web traffic (encrypted)
ftp         TCP      20-21   FTP traffic (control and data)
nntp        TCP      119     Usenet news (unencrypted)
nntps       TCP      563     Usenet news (encrypted)

Low / Unimportant Priority

Service     Protocol Ports     Description
gnutella    ANY     6346       Gnutella P2P file sharing (inc. Shareaza)
limewire    ANY     6346-6347  Limewire P2P file sharing
azureus     ANY     6881-6889  Azureus and bittorrent P2P file sharing
Good luck. Don't forget to use the "Apply" button once all of the rules have been added, and to save your configuration when you're done.

Alternative/advanced configuration

The fact that the router assigns traffic to the low priority queue by default is less than ideal. In general it would be preferable for traffic we don't classify to be treated as normal priority, and be able to say "these protocols are important" or "these protocols should get minimal bandwidth when we're busy" about several protocols. It is actually possible to do this with the RouterTech firmware, although it's a bit confusing to set up.

There's essentially no difference between the "medium" and "low" priority levels in terms of what happens to them inside the router. If we set the priority rate for "medium" to 20% and "low" to 80%, then the "low" priority class will actually get more bandwidth than the "medium" class. This will effectively swap the meaning of "low" and "medium". Think of "low" as "normal" instead, and "medium" as "unimportant".

Set the priority rate for "medium" class packets to 20% then assign rules for "high" priority protocols as above. Put filesharing protocols in the "unimportant" ("medium") class, and then leave the "normal" ("low") class for web traffic etc. In this setup, we don't need to assign rules for any protocols in the "normal" class, since this is the default class and packets for which no rule exists will be directed here automatically.
Last edited by christi on Sat Nov 08, 2008 12:28 pm, edited 5 times in total.
User avatar
Shotokan101
RouterTech Team
RouterTech Team
Posts: 4779
Joined: Thu Jan 26, 2006 3:17 pm
Location: Glasgow, Scotland

Post by Shotokan101 » Mon May 07, 2007 4:41 pm

Great work christi :thumb: :cheers:

.....if that's your idea of "rough'n'ready" then I swoon when thinking what a "polished" effort might look like :shock:

Many thanks - I'm sure that this will be of benefit to many users in the future (including myself) :wink:

I'll see if we can get this "stickied" or otherwise publicised to make it easily spotted by the forum members. 8)

......so what are you working on at the moment then ? :twisted:
Jim

.....I'm Sorry But I Can't Do That Dave.....
User avatar
studioeng
Experienced
Experienced
Posts: 454
Joined: Mon Oct 23, 2006 11:59 pm
Location: Dorset, England
Contact:

Post by studioeng » Tue May 08, 2007 1:13 pm

Superb :D just what I was waiting for :D

Just one small thing tho, with each application do you need to add a rule for both in and out, or only add which direction it travels; for example SMTP would only need the source ports and POP3/IMAP would only need destination!?

Or am I completely missing the plot?
User avatar
Shotokan101
RouterTech Team
RouterTech Team
Posts: 4779
Joined: Thu Jan 26, 2006 3:17 pm
Location: Glasgow, Scotland

Post by Shotokan101 » Tue May 08, 2007 1:24 pm

studioeng wrote:Superb :D just what I was waiting for :D

Just one small thing tho, with each application do you need to add a rule for both in and out, or only add which direction it travels; for example SMTP would only need the source ports and POP3/IMAP would only need destination!?

Or am I completely missing the plot?
See this thread for some discussion on whether QoS should be applied incomin/outgoing - ingress/egress - lan/wan........
Jim

.....I'm Sorry But I Can't Do That Dave.....
christi
Novice
Novice
Posts: 34
Joined: Fri May 04, 2007 7:56 pm

Post by christi » Tue May 08, 2007 1:49 pm

studioeng wrote:Just one small thing tho, with each application do you need to add a rule for both in and out, or only add which direction it travels; for example SMTP would only need the source ports and POP3/IMAP would only need destination!?
As far as I can see, you don't really lose anything by shaping in both directions. Particularly since it's not impossible to saturate your downstream bandwidth as well. Generally speaking shaping in both directions should minimise latency on time critical packets in the high priority class.

The only argument I can think of against doing so would be tying up resource s with potentially little or no benefit. Most routers shouldn't be so resource constrained that a few extra QoS rules are a huge issue.
User avatar
studioeng
Experienced
Experienced
Posts: 454
Joined: Mon Oct 23, 2006 11:59 pm
Location: Dorset, England
Contact:

Post by studioeng » Tue May 08, 2007 1:57 pm

Shotokan101 wrote:See this thread for some discussion on whether QoS should be applied incomin/outgoing - ingress/egress - lan/wan........
I have read through that thread in the past, but it didn't seem to reach any real conclusion so I disregarded it. This thread actually seems to be getting somewhere regarding QoS.

Another small thing, would you need to reboot the router in order for the new rules to be applied, or does this happen on the fly??
User avatar
Shotokan101
RouterTech Team
RouterTech Team
Posts: 4779
Joined: Thu Jan 26, 2006 3:17 pm
Location: Glasgow, Scotland

Post by Shotokan101 » Tue May 08, 2007 1:58 pm

From examination of the iptables output on my router it seems to take effect (like most things) immediately - but needs to be saved for retention after reboot......
Jim

.....I'm Sorry But I Can't Do That Dave.....
christi
Novice
Novice
Posts: 34
Joined: Fri May 04, 2007 7:56 pm

Post by christi » Wed May 09, 2007 2:11 am

Shotokan101 wrote:Great work christi :thumb: :cheers:

.....if that's your idea of "rough'n'ready" then I swoon when thinking what a "polished" effort might look like :shock:
Glad you liked it. :smile:
......so what are you working on at the moment then ? :twisted:
Well, still tinkering. As you can see above, I've come up with a slight refinement to the QoS stuff that I think leads to a better experience. Also I've realised a nasty unintended consequence of the ruleset above. File transfers using scp (or any protocol assigned high, such as outgoing mail attachments) will prevent all web traffic. Sadly it's an inherent flaw in the way that the QoS algorithm on the AR7 works, and in general if you want three separate QoS classes, it's unavoidable. Temporarily disabling QoS is probably the way to go in these circumstances.

I do wonder why TI didn't just use the wonder shaper like everyone else.
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12067
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Post by thechief » Wed May 09, 2007 7:43 pm

Don't know about wonder shaper, but the next firmware release will have rshaper.
The Chief: :afro: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
User avatar
the_flames
Regular
Regular
Posts: 67
Joined: Wed Nov 01, 2006 10:25 pm
Location: UK

Post by the_flames » Wed May 09, 2007 10:49 pm

does enabling QOS increase the memory usage significantly?
or is it a low memory friendly thing to have running?
User avatar
Shotokan101
RouterTech Team
RouterTech Team
Posts: 4779
Joined: Thu Jan 26, 2006 3:17 pm
Location: Glasgow, Scotland

Post by Shotokan101 » Wed May 09, 2007 10:53 pm

the_flames wrote:does enabling QOS increase the memory usage significantly?
or is it a low memory friendly thing to have running?
As it's effectively just adding IPTABLES entries it shouldn't be very memory intensive - provided you don't add thousands of rules of course......

.....same applies to processor utilisation I would think......
Jim

.....I'm Sorry But I Can't Do That Dave.....
legume
Experienced
Experienced
Posts: 101
Joined: Fri Apr 13, 2007 11:57 pm

Post by legume » Wed May 09, 2007 11:26 pm

thechief wrote:Don't know about wonder shaper, but the next firmware release will have rshaper.
Do you know where it hooks WRT nat - I can't tell by the code, imq uses more than just those netfilter hooks to choose.

It looks like depending on where it hooks you may or may not end up with the same limit in both directions (assuming you are NATing).

Enabling sch_ingress and policer - both of which are small and don't need memory for packet queues, would let you set asymmetric rates or just police one way if you wanted. 2.4 policer sees packets after they have been de natted. Policing doesn't lag out the user either like real queueing will.

Whatever is chosen shaping from the wrong end of the bottleneck is not perfectly doable in some ways a policer is better than just one big buffer (though you can make the buffer smaller I suppose)

Andy.
legume
Experienced
Experienced
Posts: 101
Joined: Fri Apr 13, 2007 11:57 pm

Post by legume » Thu May 10, 2007 12:10 am

Shotokan101 wrote:
the_flames wrote:does enabling QOS increase the memory usage significantly?
or is it a low memory friendly thing to have running?
As it's effectively just adding IPTABLES entries it shouldn't be very memory intensive - provided you don't add thousands of rules of course......

.....same applies to processor utilisation I would think......
Hmm - maybe it's my setup (but I have looked when default), but I don't see any iptables rules added. It's all tc/u32 - horrible to read and displayed twice just to make it worse (they fixed that on 2.6s).

Andy.
User avatar
Shotokan101
RouterTech Team
RouterTech Team
Posts: 4779
Joined: Thu Jan 26, 2006 3:17 pm
Location: Glasgow, Scotland

Post by Shotokan101 » Thu May 10, 2007 12:26 am

legume wrote:
Shotokan101 wrote:
the_flames wrote:does enabling QOS increase the memory usage significantly?
or is it a low memory friendly thing to have running?
As it's effectively just adding IPTABLES entries it shouldn't be very memory intensive - provided you don't add thousands of rules of course......

.....same applies to processor utilisation I would think......
Hmm - maybe it's my setup (but I have looked when default), but I don't see any iptables rules added. It's all tc/u32 - horrible to read and displayed twice just to make it worse (they fixed that on 2.6s).

Andy.
You're probably right Andy - I'm getting confused with port forwarding.... :?

How do you display the "tc" info. ?
Jim

.....I'm Sorry But I Can't Do That Dave.....
legume
Experienced
Experienced
Posts: 101
Joined: Fri Apr 13, 2007 11:57 pm

Post by legume » Thu May 10, 2007 12:44 am

How do you display the "tc" info. ?
tc filter ls dev ppp0

It's horrible to read :-)

Andy.
Post Reply