Mikrotik MTCNA Version 20.
0 1
Module 7:
RouterOS Quality
of Service (QoS)
Mikrotik MTCNA Version 20.0 276
Quality of Service ( QoS )
Bandwidth management is an essential part of every day operation for typical ISP's,
business, and even everyday home users. There are many different types of
management tools available to RouterOS users, QoS, rate-limiting, packet-limiting, to
name few
Mikrotik MTCNA Version 20.0 277
Quality of Service ( QoS )
Quality of Service (QoS) means that the router
should prioritize and shape network traffic.
QoS is not so much about limiting, it is more
about providing quality.
Mikrotik MTCNA Version 20.0 278
Quality of Service ( QoS )
Some features of MikroTik RouterOS Bandwidth
Control mechanism:
limit data rate for certain IP adresses, subnets,
protocols, ports, and other parameters
limit peer-to-peer traffic
prioritize some packet flows over others
use queue bursts for faster WEB browsing
apply queues on fixed time intervals
share available traffic among users equally, or
depending on the load of the channel
Note: Queue implementation in MikroTik RouterOS is based on Hierarchical Token Bucket (HTB).
HTB allows to create hierarchical queue structure and determine relations between queues.
Mikrotik MTCNA Version 20.0 279
Quality of Service ( QoS )
The main terms used to describe the level of QoS for network applications:
queuing discipline (qdisc) - an algorithm that holds and maintains a queue of
packets. It specifies the order of the outgoing packets (it means that queuing
discipline can reorder packets) and which packets to drop if there is no space
for them
CIR (Committed Information Rate) - the guaranteed data rate. It means that
traffic rate, not exceeding this value should always be delivered
MIR (Maximal Information Rate) - the maximal data rate router will provide
Priority - the order of importance in what traffic will be processed. You can
give priority to some traffic in order it to be handeled before some other
traffic
Contention Ratio - the ratio to which the defined data rate is shared among
users (when data rate is allocated to a number of subscribers). It is the
number of subscribers that have a single speed limitation, applied to all of
them together. For example, the contention ratio of 1:4 means that the
allocated data rate may be shared between no more than 4 users
Mikrotik MTCNA Version 20.0 280
Quality of Service ( QoS )
Two different ways to configure queues in
RouterOS:
/queue simple menu - designed to ease
configuration of simple, everyday queuing tasks
(such as single client upload/download
limitation, p2p traffic limitation, etc.).
/queue tree menu - for implementing advanced
queuing tasks (such as global prioritization policy,
user group limitations). Requires marked packet
flows from /ip firewall mangle facility.
Mikrotik MTCNA Version 20.0 281
Rate Limitation Principles
Rate limiting is used to control the rate of traffic flow
sent or received on a network interface.
Traffic which rate that is less than or equal to the
specified rate is sent, whereas traffic that exceeds the
rate is dropped or delayed.
Mikrotik MTCNA Version 20.0 282
Rate Limitation Principles
Rate limiting can be performed in two ways:
discard all packets that exceed rate limit
– rate limiting (SHAPER QUEUES) (100%
rate limiter when queue-size=0)
delay packets that exceed specific rate
limit in queue and transmit its when it is
possible – rate equalizing (SCHEDULER
QUEUES) ''(100% rate equalizing when
queue-size=unlimited)
Mikrotik MTCNA Version 20.0 283
Queue Kinds
RouterOS supports several queuing algorithms:
SCHEDULER QUEUES
PFIFO - Packets Packet First-In First-Out
BFIFO - Bytes First-In First-Out
RED - Random Early Detection
SFQ - Stochastic Fair Queuing
SHAPER QUEUES
PCQ – Per Connection Queue
HTB – Hierarchical Token Bucket
Mikrotik MTCNA Version 20.0 284
Queue Kinds
We can set the type of queue in the “/ queue type"
Mikrotik MTCNA Version 20.0 285
Simple Queue
The simpliest way to limit data rate for specific IP
addresses and/or subnets, is to use simple queues.
You can also use simple queues to build advanced QoS
applications. They have useful integrated features:
Peer-to-peer traffic queuing
Applying queue rules on chosen time intervals
Priorities
Using multiple packet marks from /ip
firewall mangle
Shaping of bidirectional traffic (one limit for the
total of upload + download)
Mikrotik MTCNA Version 20.0 286
Simple Queue Example
The Queue limits host 192.168.1.2 an upload of 2M data rates
Note: Target Address / Max Limit is necessary to set bandwidth limit in
Simple Queue
Mikrotik MTCNA Version 20.0 287
Simple Queue Sample Configuration
Limit your PC Tx-rate (upload) to 512 Kbps
Limit your PC Rx-rate (download) to 512 Kbps
Mikrotik MTCNA Version 20.0 288
Simple Queue Sample Configuration
Mikrotik MTCNA Version 20.0 289
QoS Feature “Burst”
Burst is one of the best ways to increase
HTTP performance
Bursts are used to allow higher data rates for
a short period of time
If an average data rate is less than burst-
threshold, burst could be used( actual data
rate can reach burst-limit)
Average data rate is calculated from the last
burst-time seconds
Mikrotik MTCNA Version 20.0 290
Burst - Average Data Rate
Burst Formula:
=burst threshold ( burst time ) / burst limit
Note, that the actual burst period is not equal to
the burst-time. It can be several times shorter
than the burst-time depending on the max-limit,
burst-limit, burst-threshold, and actual data rate
history.
Mikrotik MTCNA Version 20.0 291
Burst - Average Data Rate
Burst Formula:
=burst threshold ( burst time ) / burst limit
Example: If a client has a download queue
limit of 2 Mbps, max-limit of 4 Mbps, burst
limit of 16 Mbps and burst threshold of 3
Mbps then a burst time of 32 seconds,
What is the maximum possible time the
client can have 16 Mbps download speed?
Mikrotik MTCNA Version 20.0 292
Burst Sample Computation
Mikrotik MTCNA Version 20.0 293
Lab 7-1: Simple Queue Configuration
Make a Simple Queue for your laptop with the following:
Download : 1 Mbps
Upload : 1 Mbps
Burst : 4 Mbps
Mikrotik MTCNA Version 20.0 294
Queue Tree
Queue implementation on Mikrotik ROS is
based on HTB
Queue Tree is only one directional in one of the
HTB ( Simple Queue are two directional – direct
and reverse )
Queue Tree filters are applied on specified
interface
Queue Tree is not ordered ( Simple Queue have
strict order.
Queue Tree has 8 different priorities, 1 is the
highest.
Mikrotik MTCNA Version 20.0 295
Queue Tree (Equal Bandwidth Sharing)
This example shows how to
equally share 10Mbps
download and 2Mbps upload
among active users in the
network 192.168.X.0/24.
If Host A is downloading 2
Mbps, Host B gets 8 Mbps
and vice versa. There might
be situations when both
hosts want to use maximum
bandwidth (10 Mbps), then
they will receive 5 Mbps
each, the same goes for
upload.
Mikrotik MTCNA Version 20.0 296
Queue Tree (Equal Bandwidth Sharing)
Mark all traffic, coming from local network 192.168.X.0/24 with a
Connection mark ( LAN USERS-CON )
Mikrotik MTCNA Version 20.0 297
Queue Tree (Equal Bandwidth Sharing)
Mark all traffic, coming from local network 192.168.X.0/24 with a Packet
mark ( LAN USERS )
Mikrotik MTCNA Version 20.0 298
Queue Tree (Equal Bandwidth Sharing)
Now we will add 2 new PCQ types. The first, called pcq-download will
group all traffic by destination address. As we will attach this queue type
to the Local interface, it will create a dynamic queue for each destination
address (user) which is downloading to the network 192.168.X.0/24.
Mikrotik MTCNA Version 20.0 299
Queue Tree (Equal Bandwidth Sharing)
The second type, called pcq-upload will group the traffic by source
address. We will attach this queue to the Public interface so it will make
one dynamic queue for each user who is uploading to Internet from the
local network 192.168.X.0/24.
Mikrotik MTCNA Version 20.0 300
Queue Tree (Equal Bandwidth Sharing)
Make a queue tree for download traffic
Mikrotik MTCNA Version 20.0 301
Queue Tree (Equal Bandwidth Sharing)
Make a queue tree for upload traffic
Mikrotik MTCNA Version 20.0 302
Queue Tree (Equal Bandwidth Sharing)
QUEUE TREE LIST
Mikrotik MTCNA Version 20.0 303
Queue Tree (Equal Bandwidth Sharing)
Note: If your ISP cannot guarantee you a fixed amount of traffic, you can use
just one queue for upload and one for download, attached directly to the
interface.
Mikrotik MTCNA Version 20.0 304
Lab 7-2: Queue Tree Configuration
Create Queue Tree in your network using Equal Bandwidth Sharing:
Upstream = 2Mbps , Downstream = 2Mbps
Mikrotik MTCNA Version 20.0 305
PCQ ( Per Connection Queue )
To solve some SFQ imperfectness, Per
Connection Queuing (PCQ) was created.
PCQ is the only classless queuing type that can
do limitation. It is an improved version of SFQ
without its stohastic nature.
PCQ also creates subqueues, regarding the pcq-
classifier parameter. Each subqueue has a data
rate limit of pcq-rate and size of pcq-limit packets.
PCQ can be used to dynamically equalize or
shape traffic for multiple users, using little
administration.
Mikrotik MTCNA Version 20.0 306
PCQ Algorithm
If you classify the packets by src-address then all packets
with different source IP addresses will be grouped into
different subqueues. Now you can do the limitation or
equalization for each subqueue with the pcq-rate
parameter.
To equalize rate among subqueues, classified by the
pcq- classifier, set the pcq-rate to 0.
Mikrotik MTCNA Version 20.0 307
PCQ Algorithm
PCQ-RATE=128000
Mikrotik MTCNA Version 20.0 308
PCQ Algorithm
PCQ-RATE=0
Mikrotik MTCNA Version 20.0 309
Setting PCQ
Create Mangle Rules
Mikrotik MTCNA Version 20.0 310
Setting PCQ
Add Queue Types
Mikrotik MTCNA Version 20.0 311
Setting PCQ
Add Queue Tree
Mikrotik MTCNA Version 20.0 312
Lab 7-3: PCQ Configuration
Create PCQ with a Bandwidth of : 2Mbps
Mikrotik MTCNA Version 20.0 313