Testwiki/Quality of Service

From MikroTik Wiki
Jump to navigation Jump to search

Quality of Service

Queuing disciplines

Before we start to speak about queue and queuing disciplines (algorithms) we need to understand where queue is allocated, what is queuing and how it is implemented.

Buffer memory are typically used for queue allocation and it is used when there is a difference between the rate at which data is received and the rate at which it can be sent.

Queuing is the process of sequencing packets before they leave a router interface and it decides the order that packets leave any given interface. Normally, packets leave the router in the order they arrived. The queuing is only useful for packets in the outbound direction because packet arrives on an interface in the inbound direction it's already too late to queue it - it's already consumed network bandwidth. Which of queuing strategy to implement in your network is absolute your decision.

When we speak about queues we need understand two basic classes that related to traffic flows control algorithms in buffer memory on router interface:

  1. Queue management – control buffer availability and length of queue as well as leads packet rejection (drops packet) when it is necessary.
  2. Queuing (scheduling) algorithms – its describes which packet will be transmitted next in line

Simple Queue

The simplest 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 (scheduling) of bidirectional traffic (one limit for the total of upload + download)

Assume we have network topology like Figure 8.6 and we want to limited download and upload for private network (upload - 256kbps, and download – 512kbps).

File:Image8006.gif

Add a simple queue rule, which will limit the download traffic to 512kbps and upload to 256kbps for the network 10.1.1.0/24, served by the interface Ether2:

[admin@MikroTik] /queue simple> add name=private target-addresses=10.1.1.0/24 max-limit=256K/512K \
interface=ether2
In this case statement works right also if we indicate only one of parameters: "target-addresses=" or "interface=", because both of these define where and for which traffic this queue will be implemented.


Check your configuration:

[admin@Augsha] /queue simple> print 

Flags: X - disabled, I - invalid, D - dynamic 
 0    name="private" target-addresses=10.1.1.0/24 dst-address=0.0.0.0/0 
      interface=ether2 parent=none direction=both priority=8 
      queue=default-small/default-small limit-at=0/0 max-limit=256k/512k 
      burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s 
      total-queue=default-small


The max-limit parameter cuts down the maximum available bandwidth. The value max-limit=256k/512k means that clients from private network will get maximum of 512kbps for download and 256kbps for upload. The target-addresses allows to define the source IP addresses to which the queue rule will be applied.


Probably, you want to exclude the server from being limited, if so, add a queue for it without any limitation (max-limit=0/0 which means no limitation). Move this rule to the beginning of the list, because items in /queue simple are executed in order one by one if router finds rule that satisfy certain packet next rules aren’t compared:


[admin@MikroTik] /queue simple> add name=server target-addresses=10.1.1.1/32 max-limit=0/0 \
interface=ether2

All simple queue command references are available here.


Configuring PCQ

Per Connection Queue (PCQ) was introduced to optimize massive QoS systems, where most of the queues are exactly the same for different sub-streams. PCQ allows dynamically and equally share download and upload traffic (called also as “bandwidth equal distribution between users”). It means that if you have subnet with 3 hosts and maximum bandwidth for subnet is 6 Mbps, we can share it equally using PCQ. If one of host is downloading 1Mbps, all others share 5 Mbps and vice versa. There might be situation when all of the three hosts want to use maximum bandwidth (4 Mbps), then each of them receive 2 Mbps.

Look at previously example (see Figure 8.9) where we were limited download traffic equally among server and all workstation (see Figure 8.6) applying specific queue tree structure. We can perform it easy using PCQ rate limiting. In the same as configuring HTB also here is needed packet marking, it can be the similar as previously, but in this case we need to mark all packets that related to the network 10.1.1.0/24 with one common mark.


/ip firewall mangle> add chain=prerouting src-address=10.1.1.0/24
 action=mark-connection new-connection-mark=private_con

/ip firewall mangle> add chain=forward connection-mark=private_con 
action=mark-packet new-packet-mark='''private'''


Next think that we need to do is to define new PCQ type which will group all traffic by destination address. As I mentioned previous about PCQ then it allows to classify traffic flows (streams) by four parameters:

  • Source address
  • Destination address
  • Source port
  • Destination port

In this case we classify download traffic only by one parameter – destination address (dst-address), it will create a dynamic queue for each destination address.


 /queue type add name=pcq-download kind=pcq pcq-classifier=dst-address


Finally, make a queue tree for download traffic:


 /queue tree add name=Download parent=ether2 max-limit=2048
 /queue tree add parent=Download queue=pcq-download packet-mark='''private'''

It means, that PCQ can to perform equal bandwidth sharing on interface ether2, it will make one dynamic queue for each separate destination address. If we have network with four hosts (figure 8.6.) where maximum download is limited to 2Mbps and each of them want to use more than 512kbps, then all of them will receive data rate – 512Kbps.

In the same manner you can also equal distribute upload traffic from your LAN, but this case you create new queue tree and attach this queue to the public interface.