Skip to content

Lab 07-05 · PCQ: the same limit for every client, with one rule

MTCNA

Module 7 · QoS. Official course slides 302–308: Per Connection Queuing (PCQ), its rate and limit parameters, the PCQ example (two queue types, interface queues on WAN and LAN) and the LAB "PCQ example" (slide 308).

A café has 60 customers on its WiFi. The owner wants each one to get at most 2 Mbps, so nobody ruins it for the others. With what you know so far, that means 60 simple queues, one per address, and editing them every time the DHCP pool changes. Now imagine a hotel with 600 rooms.

There is a better way: one queue that automatically creates a separate, identical limit for every client it sees. That queue is PCQ. Today you build it the way the course does, and prove with two laptops that both get exactly the same speed.

What you will learn

  • Explain what PCQ does and why it replaces many simple queues
  • Create queue types of kind PCQ with a rate and a classifier (source or destination address)
  • Choose the right classifier: dst-address for downloads, src-address for uploads
  • Apply them as interface queues (WAN and LAN ports), as on slide 306
  • Prove with two simultaneous downloads that every client gets the same limit

One queue, many sub-queues

PCQ (Per Connection Queuing) is a queue type that splits traffic into sub-streams according to a classifier, and gives each sub-stream its own queue with the same rate.

The motorway again. Until now each toll gate had to be built by hand for one car. PCQ is a smart toll plaza: whenever a car with a new number plate arrives, a new booth opens just for it, with the same speed as all the others. When the car leaves, the booth disappears.

flowchart LR
    IN["<b>Download traffic</b><br>to the LAN"] --> C{"<b>Classifier</b><br>dst-address"}
    C -- "to .200" --> S1["sub-queue .200<br>rate 256k"]
    C -- "to .201" --> S2["sub-queue .201<br>rate 256k"]
    C -- "to .202 ..." --> S3["sub-queue ...<br>rate 256k"]
    S1 --> PC1["pc1"]
    S2 --> PC2["pc2"]
    S3 --> PCN["any new client"]

Its parameters (slide 303)

Parameter Meaning Lab value
Classifier What makes a sub-stream: source/destination address and/or port dst-address (download), src-address (upload)
Rate (pcq-rate) Maximum speed of each sub-stream 256k
Limit (pcq-limit) Queue size of one sub-stream, in KiB default 50
Total limit (pcq-total-limit) Maximum queued data of all sub-streams together, in KiB default 2000

Which classifier for which direction?

For downloads, the packets go to the client: the client is the destination, so the classifier is dst-address. For uploads, the client is the source: src-address. Swap them and all clients downloading from the same server end up in one sub-stream (named after the server's address), sharing a single 256k. We measured it with the simple-queue version of this lab (see Step 3): 105k each instead of 210k each.

Where the PCQ goes: interface queues

A queue type is just a recipe. It does nothing until you attach it somewhere. The course attaches it as an interface queue (Queues → Interface Queues): the queue every packet goes through when it leaves an interface.

Direction Leaves r1 through Queue type
Download (Internet → client) the LAN ports (ether3, ether4) pcq-download-256k (dst-address)
Upload (client → Internet) the WAN port (ether2) pcq-upload-256k (src-address)

Why 256k and not the slide's 512k?

The free CHR licence caps each virtual port at about 1 Mbps. Two clients at 512k would need about the whole cap, so you could not tell "the PCQ limits them" from "the licence limits them". At 256k each, the difference is clear.

The scenario

The router starts from the factory configuration with FastTrack already disabled (Lab 07-01) and no queues. In the course the trainer builds PCQ on the class router and the students are the clients; here you build it on r1, and pc1 and pc2 are the clients.

flowchart LR
    INET["<b>internet</b><br>198.51.100.10<br>iperf3 on 5201 and 5202"]
    CAP["<b>class-ap</b><br>10.0.0.1 · 198.51.100.1"]
    subgraph R1["r1 · your router"]
        WAN["ether2 (WAN)<br>upload PCQ"]
        BR["<b>bridge1</b> 192.168.88.1/24<br>ports ether3, ether4<br>download PCQ"]
    end
    PC1["<b>pc1</b><br>192.168.88.200"]
    PC2["<b>pc2</b><br>192.168.88.201"]
    INET ---|"198.51.100.0/24"| CAP
    CAP ---|"10.0.0.0/24"| WAN
    WAN --- BR
    BR ---|"ether3"| PC1
    BR ---|"ether4"| PC2
Node Role Address
internet Two iperf3 servers and the web server 198.51.100.10 ports 5201, 5202, 80
class-ap Class gateway, DNS, NAT 10.0.0.1/24, 198.51.100.1/24
r1 Your router, FastTrack disabled, no queues WAN by DHCP, LAN 192.168.88.1/24
pc1 Client 1 192.168.88.200
pc2 Client 2 192.168.88.201

Why ether2 and not ether1?

On a real hAP the Internet port is ether1. In the virtual lab ether1 is reserved for the lab itself (containerlab uses it to manage the router), so the Internet port is ether2 and the LAN ports start at ether3. Never touch ether1 in these labs.

Start the lab

Download the lab files and unzip them: 07-05-pcq.zip. Open a terminal inside the 07-05-pcq folder.

sudo containerlab deploy -t topology.clab.yml

Give RouterOS about two minutes to boot. You need three terminals:

ssh admin@clab-mtcna-07-05-r1            # password: admin
docker exec -it clab-mtcna-07-05-pc1 bash
docker exec -it clab-mtcna-07-05-pc2 bash

./check.sh (with CLAB_EXEC="docker exec") tells you at any moment what is already solved.

Step 1 · Measure two clients with no queue

Start both at the same moment (within a second):

iperf3 -c 198.51.100.10 -R -t 15 -p 5201      # on pc1
iperf3 -c 198.51.100.10 -R -t 15 -p 5202      # on pc2

Expected: together about 1 Mbps, often split unevenly (in our test 629k and 315k).

Done when you have both numbers in your report.

Step 2 · Create the two PCQ queue types

One type per direction, as on slide 305.

WinBox: Queues → Queue Types → +. Type Name pcq-download-256k, Kind pcq, Rate 256k, Classifier: tick Dst. Address only. OK. Again: pcq-upload-256k, Kind pcq, Rate 256k, Classifier Src. Address only.

/queue type add name=pcq-download-256k kind=pcq pcq-rate=256k pcq-classifier=dst-address
/queue type add name=pcq-upload-256k kind=pcq pcq-rate=256k pcq-classifier=src-address
/queue type print where kind=pcq

Expected: your two types plus RouterOS's own pcq-upload-default and pcq-download-default (rate 0 = unlimited per sub-stream).

Check yourself

  1. Why does the download type classify by destination address?

Done when both types show pcq-rate=256k and the right classifier.

Step 3 · Attach them as interface queues

Slide 306: the WAN interface gets the upload type and the LAN interface gets the download type.

WinBox: Queues → Interface Queues, double-click ether2, Queue Type pcq-upload-256k. Then ether3 and ether4, Queue Type pcq-download-256k.

/queue interface set ether2 queue=pcq-upload-256k
/queue interface set ether3 queue=pcq-download-256k
/queue interface set ether4 queue=pcq-download-256k
/queue interface print

Expected: ACTIVE-QUEUE shows your PCQ types on those three ports.

The LAN is a bridge: use its ports

On the slides the LAN is one interface. Here the LAN is bridge1, and RouterOS 7.23 refuses an interface queue on the bridge: failure: non rate limit queues are useless on this interface. Put the download PCQ on every physical LAN port of the bridge (ether3, ether4) instead. A new LAN port added to the bridge later needs it too.

Each port has its own PCQ

An interface queue belongs to one interface, so ether3 and ether4 each run their own PCQ. In this lab pc1 and pc2 sit on different ports, so they would be separated even with a wrong classifier. In a real office, dozens of clients sit behind one port (a switch or a WiFi access point): there the classifier is the only thing that tells them apart.

Another way: one simple queue with PCQ inside

The same result, in one line, with a simple queue whose target is the whole LAN interface: /queue simple add name=lan-clients target=bridge1 queue=pcq-upload-256k/pcq-download-256k. A simple queue can use any queue type, not only the default one. We tested it in this lab too: 210k and 210k for two simultaneous downloads.

Done when the three interfaces show the PCQ types.

Step 4 · Prove that everybody gets the same

Repeat Step 1 (both at the same moment). Then one alone, plus an upload:

iperf3 -c 198.51.100.10 -R -t 10 -p 5201      # pc1 alone, download
iperf3 -c 198.51.100.10 -t 10 -p 5201         # pc1 alone, upload

Expected: together, about 210k and 210k, the same for both; alone, still under 256k (each client has its own 256k, it does not get more because the other one is idle). Watch it like the course does, on r1 (Tools → Torch, Interface ether3):

/tool torch interface=ether3

And the course's download on pc1:

curl -o /dev/null http://www.mikrotik.com/routeros.npk

About 30 kB/s (256 ÷ 8 = 32 kB/s, minus headers), whoever downloads.

Check yourself

  1. Compare Step 1 and Step 4: what changed in fairness? What changed in total speed?
  2. If a third laptop joins the LAN on ether4's switch, what do you have to configure for it? Why?
  3. With PCQ, pc1 alone does not get the whole line. With the limit-at/max-limit queues of Lab 07-03 it did. When would you prefer each one?

Done when both clients get about the same speed, under 256k. Run ./check.sh: it must say lab mtcna-07-05 solved.

If something goes wrong

Symptom Likely cause Fix
non rate limit queues are useless on this interface You set the interface queue on bridge1 Use the bridge's ports: ether3, ether4
Clients downloading from the same server share one 256k Download type classifies by src-address /queue type set pcq-download-256k pcq-classifier=dst-address
Downloads are not limited at all The download type is on ether2 (where downloads arrive, not leave) Download PCQ on the LAN ports, upload PCQ on the WAN port
Only pc1 is limited Only ether3 got the PCQ Also /queue interface set ether4 queue=pcq-download-256k
iperf3: the server is busy Both PCs used the same port pc1 -p 5201, pc2 -p 5202

Clean up

sudo containerlab destroy -t topology.clab.yml --cleanup

Key takeaways

  • PCQ creates one sub-stream per client automatically, each with the same rate: one rule instead of hundreds.
  • The classifier decides what a client is: dst-address for downloads, src-address for uploads.
  • A queue type is a recipe; it works once attached to an interface queue or a simple queue.
  • Interface queues act on traffic leaving an interface: download on the LAN ports, upload on the WAN port.
  • In RouterOS 7.23 a bridge refuses an interface queue: put it on the bridge's ports.

Quick check

1. What does PCQ do?
  • It splits traffic into sub-streams by a classifier and limits each one to the same rate
  • It gives one client a guaranteed rate and the others what is left
  • It lets clients go faster than the limit for a few seconds
  • It blocks clients that use too much traffic

PCQ (Per Connection Queuing) creates a sub-stream for each value of the classifier (for example each destination address) and gives each the same pcq-rate. Guarantees are limit-at; short speed-ups are burst.

2. Which classifier does the download PCQ need?
  • dst-address
  • src-address
  • dst-port
  • src-port

Download packets travel to the client, so the client's address is the destination. Classifying by source would group all clients under the server's address.

3. On which interface is the download PCQ attached as an interface queue?
  • The LAN ports, where the download leaves the router towards the clients
  • The WAN port, where the download enters the router
  • The management port ether1
  • The loopback interface

An interface queue works on traffic leaving an interface. Downloads leave r1 through the LAN ports, uploads leave through the WAN port.

4. pcq-rate is 256k. pc1 and pc2 download at the same time from a 1 Mbps line. What does each get?
  • About the same for both, under 256k
  • 128k each, because they share 256k
  • About 500k each, half of the line
  • 256k for the first one and nothing for the second

Each client has its own sub-stream with its own 256k. They do not share it, and they cannot go above it. The lab measured about 210k each.

5. Why did RouterOS answer 'non rate limit queues are useless on this interface'?
  • An interface queue was set on the bridge, which refuses it
  • The PCQ type had no rate
  • FastTrack was still enabled
  • The queue type name contained numbers

In RouterOS 7.23 bridge1 refuses an interface queue with that message. The fix is to attach the PCQ to the physical ports of the bridge, or to use a simple queue with target=bridge1.

6. A hotel wants every guest limited to 10 Mbit down and 2 Mbit up, with 400 rooms. Pick the two pieces it needs.
  • A PCQ type with pcq-rate=10M and classifier dst-address
  • A PCQ type with pcq-rate=2M and classifier src-address
  • 400 simple queues, one per room
  • A simple queue with max-limit=2M/10M for the whole LAN

Two PCQ types, one per direction, create a sub-stream per guest automatically. 400 simple queues would work but are exactly what PCQ avoids; a single max-limit for the whole LAN would make all guests share 10M.

This closes Module 7: you can now cap, target, guarantee, burst and share bandwidth fairly. Next module: tunnels.