Skip to content

PCQ Example

PCQ (Per Connection Queue) is a queuing discipline that dynamically equalizes or shapes traffic for multiple users using minimal administration. Unlike traditional static queue configurations that require individual rules for each user, PCQ automatically manages bandwidth distribution across all connections that match defined classifiers.

The power of PCQ lies in its ability to create dynamic sub-queues based on traffic characteristics. When traffic matches a PCQ queue type, the router creates separate queues for each unique value of the configured classifier (such as destination address, source address, or both), then distributes available bandwidth equally among these sub-queues. This approach eliminates the need to create individual queue rules for each user or subnet.

PCQ is particularly valuable in environments where multiple users share a limited bandwidth pool. Instead of manually configuring queues for each IP address, a single PCQ configuration automatically ensures fair bandwidth distribution. When one user is inactive, their allocated bandwidth becomes available to active users, maximizing utilization without requiring complex dynamic reconfiguration.

PCQ scenarios generally fall into three major categories, each addressing different bandwidth distribution requirements. Understanding these categories helps you select the appropriate configuration for your specific use case.

The first category involves providing equal bandwidth to a defined number of users with a maximum limit. This scenario is common in shared internet access scenarios where you want to ensure no single user monopolizes available bandwidth while allowing fair sharing among all users. The second category addresses situations where you need to distribute a known bandwidth equally between users, useful for guaranteeing minimum service levels to each client. The third category handles scenarios where the total bandwidth is unknown or variable, such as asymmetric DSL connections where actual throughput fluctuates based on line conditions.

PCQ operates at Layer 3 and above, classifying traffic based on IP addresses, ports, or other packet attributes visible to the firewall. The classifier determines how traffic gets grouped into dynamic sub-queues. For typical user bandwidth sharing, dst-address classifies traffic by destination (user’s IP), ensuring each user receives equal share of download bandwidth. Similarly, src-address classifies by source IP for upload traffic distribution.

Before deploying PCQ queues, you must define the queue types that specify the classification method and rate limits. These types serve as templates that the router applies when traffic matches queue rules.

Create queue types for download and upload traffic. The classifier determines how traffic gets divided among users:

/queue type add name="PCQ_download" kind=pcq pcq-rate=5M pcq-classifier=dst-address
/queue type add name="PCQ_upload" kind=pcq pcq-rate=1M pcq-classifier=src-address
ParameterDescriptionTypical Values
nameUnique identifier for the queue typeDescriptive name like PCQ_download
kindQueue type kind, must be pcqpcq
pcq-rateMaximum total bandwidth in bits per second5M, 10M, 0 (unlimited)
pcq-classifierTraffic classifier for sub-queue creationdst-address, src-address, src-port, dst-port

The pcq-rate parameter sets the maximum aggregate bandwidth for all sub-queues combined. When set to a specific value (such as 5M), no sub-queue can exceed this total. Setting pcq-rate=0 removes the aggregate limit, allowing sub-queues to consume all available bandwidth while still distributing it equally among users.

The classifier determines how traffic gets grouped. Using dst-address for download queues creates separate sub-queues for each destination IP address, ensuring each user receives equal bandwidth. The src-address classifier for upload queues creates sub-queues based on source IP, distributing upload bandwidth equally.

For more complex scenarios, you can combine multiple classifiers:

/queue type add name="PCQ_both" kind=pcq pcq-rate=5M pcq-classifier=src-address,dst-address

This configuration creates sub-queues for each unique source-destination address pair, useful when you need per-connection rather than per-user fairness.

Queue Tree provides a hierarchical approach to traffic management, allowing you to apply PCQ as part of a larger queuing structure. This method requires packet marking in the firewall mangle chain before referencing marked packets in queue tree rules.

For proper QoS with Queue Tree, use a two-step marking process: first mark connections, then mark packets based on connection marks. This ensures both directions of a connection get the same packet mark, which is essential for bidirectional traffic handling.

First, mark connections for upload and download traffic:

/ip firewall mangle add chain=prerouting action=mark-connection \
in-interface=ether2-LAN new-connection-mark=client_upload_conn
/ip firewall mangle add chain=prerouting action=mark-connection \
in-interface=ether1-WAN new-connection-mark=client_download_conn

Then, mark packets based on the connection marks:

/ip firewall mangle add chain=prerouting action=mark-packet \
connection-mark=client_upload_conn new-packet-mark=client_upload passthrough=no
/ip firewall mangle add chain=prerouting action=mark-packet \
connection-mark=client_download_conn new-packet-mark=client_download passthrough=no

:::tip Why Two-Step Marking? Using mark-connection first then mark-packet with connection-mark ensures that:

  • All packets in a connection (both directions) receive the same packet mark
  • The QoS policy applies consistently to the entire traffic flow
  • Connection-level classification (like connection-rate) can be used :::

The first two mangle rules mark connections entering through ether2-LAN (local network) and ether1-WAN (from the internet) with connection marks. The next two rules use those connection marks to assign packet marks to all packets in those connections. This two-step approach ensures consistent marking across both directions of each connection.

After marking packets, create queue tree rules that reference the PCQ types and packet marks:

/queue tree add parent=global queue=PCQ_download packet-mark=client_download
/queue tree add parent=global queue=PCQ_upload packet-mark=client_upload
ParameterDescription
parentParent queue, global applies to all interfaces
queueQueue type to use for this traffic
packet-markFirewall packet mark to match

The parent=global setting applies the queue to all interfaces collectively, which is appropriate for most edge router configurations. If you need per-interface queuing, specify the interface name as the parent.

/ip firewall mangle
add chain=prerouting in-interface=ether2-LAN action=mark-connection new-connection-mark=client_upload_conn
add chain=prerouting in-interface=ether1-WAN action=mark-connection new-connection-mark=client_download_conn
add chain=prerouting connection-mark=client_upload_conn action=mark-packet new-packet-mark=client_upload passthrough=no
add chain=prerouting connection-mark=client_download_conn action=mark-packet new-packet-mark=client_download passthrough=no
/queue type
add name=PCQ_download kind=pcq pcq-rate=5M pcq-classifier=dst-address
add name=PCQ_upload kind=pcq pcq-rate=1M pcq-classifier=src-address
/queue tree
add parent=global queue=PCQ_download packet-mark=client_download
add parent=global queue=PCQ_upload packet-mark=client_upload

Simple Queues provide a simpler alternative to Queue Tree, combining packet marking and queuing into a single command. This approach is recommended for straightforward bandwidth sharing scenarios.

Create a simple queue that applies PCQ to an entire subnet:

/queue simple add target=192.168.0.0/24 queue=PCQ_upload/PCQ_download

The syntax queue=PCQ_upload/PCQ_download specifies separate queues for upload and download traffic within a single rule.

Apply total bandwidth limits while using PCQ for distribution:

/queue simple add name=Shared_Bandwidth target=192.168.0.0/24 \
max-limit=5M/1M queue=PCQ_upload/PCQ_download

The max-limit parameter sets the overall bandwidth ceiling for the entire subnet, while PCQ distributes this bandwidth among users.

Configure different PCQ settings for separate subnets:

/queue simple add name=Office target=10.0.0.0/24 queue=PCQ_upload/PCQ_download
/queue simple add name=Guests target=172.16.0.0/24 queue=PCQ_upload_Guest/PCQ_download_Guest
ParameterDescription
nameDescriptive name for the queue
targetTarget IP address or network
max-limitMaximum upload/download bandwidth (format: upload/download)
queueQueue type for upload/download (format: upload/download)
burst-limitBurst parameters for temporary speed increases
disabledEnable or disable the queue rule

Provide fair bandwidth distribution for all users on your local network:

/queue type add name=Download kind=pcq pcq-rate=10M pcq-classifier=dst-address
/queue type add name=Upload kind=pcq pcq-rate=2M pcq-classifier=src-address
/queue simple add target=192.168.1.0/24 queue=Upload/Download

With a 10Mbps download and 2Mbps upload link, this configuration ensures that 10 users each get approximately 1Mbps download and 200Kbps upload when all are active. If only 5 users are active, each gets 2Mbps download and 400Kbps upload.

Combine PCQ with priority queues to give preference to important users:

/queue type add name=Priority_Download kind=pcq pcq-rate=0 pcq-classifier=dst-address
/queue type add name=Standard_Download kind=pcq pcq-rate=5M pcq-classifier=dst-address
/queue simple add target=192.168.1.10 priority=1 queue=Priority_Download/Priority_Upload
/queue simple add target=192.168.1.0/24 priority=8 queue=Standard_Download/Standard_Upload

Priority values range from 1 (highest) to 8 (lowest). Higher priority queues receive bandwidth before lower priority queues.

Ensure each user receives a minimum bandwidth allocation while allowing unused bandwidth to be shared:

/queue type add name=Shaped_Download kind=pcq pcq-rate=10M pcq-classifier=dst-address \
pcq-limit=50 pcq-burst-rate=2M pcq-burst-threshold=1M pcq-burst-time=10s

The pcq-limit parameter controls the maximum number of sub-queues (50 users in this example). The burst parameters allow temporary speed increases during brief high-demand periods.

Apply stricter PCQ limits to guest networks while maintaining quality for main network:

/queue type add name=Guest_Download kind=pcq pcq-rate=3M pcq-classifier=dst-address
/queue type add name=Guest_Upload kind=pcq pcq-rate=512k pcq-classifier=src-address
/queue simple add target=172.16.0.0/24 name=Guest_Queue queue=Guest_Upload/Guest_Download \
max-limit=512k/3M

Check current queue usage and statistics:

/queue simple print stats
/queue tree print stats

Monitor individual sub-queues created by PCQ:

/queue simple print detail

The output shows packet and byte counts for each sub-queue, helping identify bandwidth consumers.

Clear queue statistics for fresh monitoring:

/queue simple reset-counters
/queue tree reset-counters
  1. Verify the classifier matches your traffic direction
  2. Check for overlapping queue rules that might conflict
  3. Ensure pcq-rate is set appropriately for your link speed
  4. Review packet marking rules for accuracy
/queue type print
/ip firewall mangle print
  1. Confirm packet marks exist and match traffic
  2. Verify queue rules are enabled (not disabled)
  3. Check interface names in packet marking rules
  4. Ensure traffic actually passes through the router
/queue tree print stats
/ip firewall mangle print stats
  1. Reduce pcq-rate to create adequate headroom
  2. Check for interface errors or drops
  3. Verify duplex settings match on both ends
  4. Consider upgrading to hardware queuing on faster interfaces

If PCQ creates too many or too few sub-queues:

/queue type set [find name=PCQ_download] pcq-limit=100

The pcq-limit parameter controls the maximum number of sub-queues. Default is typically 2000, which suits most scenarios.

ParameterDescriptionRangeDefault
kindQueue type kindpcq, bfifo, sfq, etc.-
pcq-rateMaximum total bandwidth0-1000000000000
pcq-classifierTraffic classifierdst-address, src-address, ports-
pcq-limitMax sub-queues per PCQ1-1000002000
pcq-burst-rateBurst data rate0-1000000000000
pcq-burst-thresholdBurst activation threshold0-1000000000000
pcq-burst-timeBurst time window1s-60s15s
pcq-total-maxTotal queue size0-10000000000
ClassifierUse CaseCreates Sub-queue For
dst-addressDownload queuesEach destination IP
src-addressUpload queuesEach source IP
dst-portPort-based distributionEach destination port
src-portPort-based distributionEach source port
src-and-dst-addressCombined addressingEach unique IP pair

Start with conservative pcq-rate values that are slightly below your actual link capacity. This approach provides headroom for overhead and burst traffic. Monitor actual utilization over time and adjust rates accordingly.

Use Simple Queues for straightforward bandwidth sharing scenarios. Reserve Queue Tree for complex configurations requiring hierarchical queuing or integration with other traffic management features.

Document your PCQ configuration including the rationale for classifier choices and rate limits. This documentation helps with future troubleshooting and modifications.

Test new PCQ configurations during low-traffic periods. Use bandwidth testing tools to verify fair distribution across multiple simultaneous connections before deploying to production.

  • /queue type - Configure queue types including PCQ
  • /queue tree - Configure hierarchical queue trees
  • /queue simple - Configure simple queues
  • /ip firewall mangle - Mark packets for queue processing
  • /interface print - View interface statistics
  • /tool bandwidth-test - Test bandwidth distribution