If you ever hosted any internet service at home and/or had some network application using your Internet connection upload and disturbing your other activities, one very common example (but not actually my situation) is when running torrent traffic making your Internet games lag because uncontrolled torrents take away the upload bandwidth. Then you should consider making the applications you want to have priority (games, voice, video) against the other not so sensitive stuff (torrent, http, etc… ).
In theory, you need to prioritize different packets leaving from your router for the Internet to solve this situation. So lets do this on an example home network I created very simply for the sake of this article. On the next picture below, you see a typical home network. With example 100Mbit LAN and 3Mbits Internet upload.
Also with no other traffic, when someone tries to download a file from any LAN system, he can use the full speed. As visible below:
Ok, now what happens when both the internal users and the networkgeekstuff.com server starts to send packets at full speed to the internet? Well, there is no priority to any of the traffic streams, therefore the router will make both share the upload equally.
From a practical example test again downloading files from both networkgeekstuff.com and a random LAN system:
Creating priority for upload traffic on Mikrotik RB450
Ok, now I have showed you the problem, now for the solution. From the 3128kbps upload traffic, I would like to make these statements implemented:
- Networkgeekstuff.com server can make full use of the upload when no other traffic is using it
- Networkgeekstuff.com server has a reservation of 320kbps, this is exclusive for it.
- Other LAN systems have priority over Networkgeekstuff.com and can fully use whole upload bandwidth.
Configuration is three step process, classify->mark->prioritize:
1) We have to classify the two types of traffic we want to manipulate
/ip firewall mangle add chain=postrouting action=mark-connection \ new-connection-mark=networkgeekstuff.com_upload_packet \ passthrough=yes protocol=tcp \ out-interface=ether1 src-port=80 add chain=postrouting action=mark-connection \ new-connection-mark=LAN_upload_packet \ passthrough=yes src-address=192.168.10.128/26 \ out-interface=ether1
2) Then we have to mark the packets in each connection
/ip firewall mangle add chain=postrouting action=mark-packet \ new-packet-mark=networkgeekstuff.com_upload_packet_mark passthrough=no out-interface=ether1 \ connection-mark=networkgeekstuff.com_upload_packet add chain=postrouting action=mark-packet \ new-packet-mark=LAN_upload_packet_mark passthrough=no \ connection-mark=LAN_upload_packet
3) Now we create a priority tree
/queue tree add max-limit=3128k name=QoS_OVERALL parent=ether1
add name=QoS_LAN parent=QoS_OVERALL priority=1 packet-mark=LAN_upload_packet_mark
add name=QoS_NetworkGeekStuff parent=QoS_OVERALL priority=8 \ packet-mark=networkgeekstuff.com_upload_packet_mark limit-at=320k max-limit=3128k
Explanation is definitely needed on the 3rd part. As you see we give priority=1 (best) to the LAN marked packets and priority=8 (worst) to the networkgeekstuff.com upload traffic. Additionally you can notice that I have given the networkgeekstuff.com a reservation by using limit-at=320k, this means that there is no limit applied to the traffic if the traffic only uses less than 320kbps of bandwith. But also the max-limit=3128k tells the router to limit this traffic for maximum bandwidth (yes, it doesn’t make sense, but this parameter has to be set otherwise the configuration line is not actually working).
Results of the implementation
If you didn’t made a mistake, right now the traffic should behave a little like this:
Also the practical tests I managed to get and I hope they are self-explanatory, just notice how networkgeekstuff.com upload only gets around 40kbps and the other upload gets almost all remaining bandwidth.
More reading on Mikrotik QoS
I must say that I admit to not providing much explanation on why the configuration is the way I made it, the point is that Mikrotik guys made a very nice explanations on how to do QoS on their router themselves that is available behind these links:
- Mikrotik Bandwith Control – Older, but the best explanation with examples on queuing (the /queue tree I used in example)
- NetworkPro Quality of Service – Not all parts are relevant, but provides very good introduction on internal data flows inside MirkotikOS
Again, I hope this helps anyone a little. I didn’t wanted this to become an extensive explanation into Mikrotik QoS as there are better sources on this purpose available (as mentioned on the above section). But it can serve as a quick reference to solve one very common situation on small networks sharing both users and hosted services.