RouterOS - Queue (QoS)

最後更新: 2024-09-30

目錄

 


介紹

 

Queue implementation in MikroTik RouterOS is based on Hierarchical Token Bucket (HTB).

在 ROS 有兩個方式設定 Queue, 分別是

  • /queue simple
  • /queue tree

Queue 行完 TreeQueue 會再行 SimpleQueue, 亦即是會 Queue 兩次

simple 與 tree 的分別

# 一條規則接著一條規則運行

/queue simple

# 平行式處理

/queue tree

HTB Properties

  • parent
  • priority (1(highest)..8)   # Prioritize one child queue over other child queue (Does not work on parent queues)
                                        # Child queue with higher priority will have chance to reach its max-limit
                                       # before child with lower priority.
  • queue type                   # 在這裡設定限速會另靈活 (kind)

 


Simple Queue

 

Flow Identifiers

target (IP/Mask, NIC)    # multiple choice

list of IP address ranges that will be limited by this queue.

defining the Source IP addresses to which the queue rule will be applied.

dst (IP/Mask, NIC)

allows to select only specific stream (from target address to this destination address)

Example 1

# 針對 local subnet(192.168.8.0/24) 設定限速(upload: 5M, download: 10M)

/queue simple add name=Local_PC \
  target=192.168.8.0/24 max-limit=5M/10M

max-limit

Format: upload/download

Example 2

續 Exampe 1, 設定 Server Up/Down = 50M/100M

/queue simple 
add name=Server target=192.168.8.11 max-limit=50M/100M \
  queue=default/default
move Server Local_PC

 * 由於 Up/Down 較快, 所以使用了較長的 queue (queue=default)

 * Local_PC 要排先過 Server 才有作用

 


PCQ (Per Connection Queue)

 

功能: shape traffic for multiple users

PCQ parameters:

pcq-classifier (dst-address | dst-port | src-address | src-port; default: "")

設定如何分 sub-stream (user)

對於 DL 時, 可以在 Wan 的 prerouting mark package

之後以 dst-address/address-mask 去分辨 user

pcq-rate (number)

bandwidth 沒有用盡, 在有 burst 但已侯用盡的情況下,

它是每 sub-steam 的速度(最少有此速度)

limit-at (NUMBER)

normal data rate that is guaranteed to a target

burst(預設不超速)

pcq-burst-rate (number)

maximal data rate which can be reached while the burst for substream is allowed

pcq-burst-threshold (number)

This is value of burst on/off switch. 當平衡速度超過它時就會停止burst

長時間後它會趨近平衡速度

pcq-burst-time (Default: 10s)

多久計算一次 average data rate (This is NOT the time of actual burst)

為方便計算, 建設設定成 16s

average-rate (read-only)

每 1/16 burst-time 計算一次 burst-time 時段的速度.

查看

/queue tree> print rate

burst 的計算

pcq-burst-rate=10M, pcq-burst-threshold, 7M, pcq-burst-time=16s, pcq-rate=5M

address-mask

pcq-dst-address-mask (Default: 32 = 255.255.255.255):

the size of the IPv4 network that will be used as a dst-address sub-stream identifier

pcq-src-address-mask (Default: 32 = 255.255.255.255):

the size of the IPv4 network that will be used as an src-address sub-stream identifier

Queue Size

main option that decide should the package be dropped or scheduled for later time.

100% Shaper => Queue-size=0

100% Scheduler => Queue-size=unlimited

queue type (info: Upload Queued Packets)

  • Default-small (queue size of 10)
  • Default (queue size of 50)

會自動填的設定

pcq-limit (number)               # Default: 50KiB

queue size of single sub-stream (in KiB)

pcq-total-limit (number)       # Default: 2000KiB

maximum amount of queued data in all sub-streams (in KiB)

 

PCQ Example

Step 1: Mark packets

/ip firewall mangle add chain=prerouting action=mark-packet \
   in-interface=ether1-WAN new-packet-mark=client_download \
   passthrough=yes comment="QoS: Wan Download"

/ip firewall mangle add chain=prerouting action=mark-packet \
   in-interface=ether2-LAN new-packet-mark=client_upload \
   passthrough=yes comment="QoS: Wan Upload"

Step 2: Add queue types

# download: 5 mb/s
/queue type add name="PCQ_Download" kind=pcq pcq-rate=5000000 pcq-classifier=dst-address

# upload: 3 mb/s
/queue type add name="PCQ_Upload" kind=pcq pcq-rate=3000000 pcq-classifier=src-address

Notes

  • 必須填的 "Limit" 及 "Total Limit" 會填上 50KiB 及 2000KiB
  • Src. 及 Dst. Address Mask 都會填 32

Step 3: Add "queue rules" in Queue Tree

將有 client_download(packet-mark) 的包分到 PCQ_download(queue type)

/queue tree add parent=global queue=PCQ_Download packet-mark=client_download

/queue tree add parent=global queue=PCQ_Upload packet-mark=client_upload

Checking

/queue tree> print rate    

Flags: X - disabled, I - invalid
 #   NAME               PARENT              PACKET-MARK                    RATE
 0   queue1             global              client_download            10061872

RATE 是 UI 的 Avg. Rate
是指此 Queue 當前的速度(所有 Client 的 Rate 加總)

/queue tree> print stats

Flags: X - disabled, I - invalid
 0   name="queue1" parent=global packet-mark=client_download rate=10046128
     packet-rate=130 queued-bytes=84060 queued-packets=21 bytes=663806929
     packets=131431 dropped=1058 pcq-queues=3

/queue monitor

  queued-packets: 29
    queued-bytes: 88760

 


Interface Queues

 

only-hardware-queue

It leaves interface with only hw transmit descriptor ring buffer which acts as a queue in itself.

Usually at least 100 packets can be queued for transmit in transmit descriptor ring buffer.

Transmit descriptor ring buffer size and the amount of packets that can be queued in it varies for different types of ethernet MACs.

Having no software queue is especially beneficial on SMP systems
  because it removes the requirement to synchronize access to it from different cpus/cores which is expensive.

 


DSL 限速 Example

 

# 在 mangle table 的 forward chain 內 mark connection & packet

/ip firewall mangle add chain=forward action=mark-packet \
  new-packet-mark=users-pkt connection-mark=users-con \
  passthrough=yes comment="QoS Rule"

/ip firewall mangle add chain=forward action=mark-connection \
  new-connection-mark=users-con src-address=192.168.8.0/24 \
  passthrough=yes

 * 注意由於使用了 passthrough, 所以 mark rules 係有次序的

# 透過有 "users-pkg" 的 mark 去限速. pppoe-out1 係對街的 NIC, bridge 對內的 NIC

/queue tree

add name="Upload" parent=pppoe-out1 packet-mark="" max-limit=600k
add name="DSL-Upload" parent=Upload packet-mark=users-pkt max-limit=450k

add name="Download" parent=bridge packet-mark="" max-limit=6M
add name="DSL-Download" parent=Download packet-mark=users-pkt max-limit=5M

 * 這裡的 queue type 預設使用了 default-small (pfifo 10 pkts) # default: pfifo 50 pkts

 


Doc

 

 

Creative Commons license icon Creative Commons license icon