PCQ Example
PCQ Example
Section titled “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.
Overview
Section titled “Overview”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.
PCQ Queue Type Configuration
Section titled “PCQ Queue Type Configuration”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.
Creating PCQ Types
Section titled “Creating PCQ Types”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-addressUnderstanding PCQ Type Parameters
Section titled “Understanding PCQ Type Parameters”| Parameter | Description | Typical Values |
|---|---|---|
| name | Unique identifier for the queue type | Descriptive name like PCQ_download |
| kind | Queue type kind, must be pcq | pcq |
| pcq-rate | Maximum total bandwidth in bits per second | 5M, 10M, 0 (unlimited) |
| pcq-classifier | Traffic classifier for sub-queue creation | dst-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.
Advanced PCQ Configuration
Section titled “Advanced PCQ Configuration”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-addressThis configuration creates sub-queues for each unique source-destination address pair, useful when you need per-connection rather than per-user fairness.
Queue Tree Deployment
Section titled “Queue Tree Deployment”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.
Packet Marking Configuration
Section titled “Packet Marking Configuration”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_connThen, 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 :::
Understanding Packet Marking
Section titled “Understanding Packet Marking”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.
Queue Tree Rules
Section titled “Queue Tree Rules”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_uploadQueue Tree Parameters Explained
Section titled “Queue Tree Parameters Explained”| Parameter | Description |
|---|---|
| parent | Parent queue, global applies to all interfaces |
| queue | Queue type to use for this traffic |
| packet-mark | Firewall 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.
Complete Queue Tree Configuration
Section titled “Complete Queue Tree Configuration”/ip firewall mangleadd chain=prerouting in-interface=ether2-LAN action=mark-connection new-connection-mark=client_upload_connadd chain=prerouting in-interface=ether1-WAN action=mark-connection new-connection-mark=client_download_connadd chain=prerouting connection-mark=client_upload_conn action=mark-packet new-packet-mark=client_upload passthrough=noadd chain=prerouting connection-mark=client_download_conn action=mark-packet new-packet-mark=client_download passthrough=no
/queue typeadd name=PCQ_download kind=pcq pcq-rate=5M pcq-classifier=dst-addressadd name=PCQ_upload kind=pcq pcq-rate=1M pcq-classifier=src-address
/queue treeadd parent=global queue=PCQ_download packet-mark=client_downloadadd parent=global queue=PCQ_upload packet-mark=client_uploadSimple Queues Deployment
Section titled “Simple Queues Deployment”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.
Basic Simple Queue Configuration
Section titled “Basic Simple Queue Configuration”Create a simple queue that applies PCQ to an entire subnet:
/queue simple add target=192.168.0.0/24 queue=PCQ_upload/PCQ_downloadThe syntax queue=PCQ_upload/PCQ_download specifies separate queues for upload and download traffic within a single rule.
Simple Queue with Bandwidth Limits
Section titled “Simple Queue with Bandwidth Limits”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_downloadThe max-limit parameter sets the overall bandwidth ceiling for the entire subnet, while PCQ distributes this bandwidth among users.
Multiple Subnet Configuration
Section titled “Multiple Subnet Configuration”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_GuestSimple Queue Parameters
Section titled “Simple Queue Parameters”| Parameter | Description |
|---|---|
| name | Descriptive name for the queue |
| target | Target IP address or network |
| max-limit | Maximum upload/download bandwidth (format: upload/download) |
| queue | Queue type for upload/download (format: upload/download) |
| burst-limit | Burst parameters for temporary speed increases |
| disabled | Enable or disable the queue rule |
Common Use Cases
Section titled “Common Use Cases”Equal Bandwidth Sharing for LAN Users
Section titled “Equal Bandwidth Sharing for LAN Users”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/DownloadWith 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.
Prioritizing Specific Users
Section titled “Prioritizing Specific Users”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_UploadPriority values range from 1 (highest) to 8 (lowest). Higher priority queues receive bandwidth before lower priority queues.
Per-IP Bandwidth Guarantees
Section titled “Per-IP Bandwidth Guarantees”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=10sThe 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.
Guest Network Isolation
Section titled “Guest Network Isolation”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/3MMonitoring PCQ Performance
Section titled “Monitoring PCQ Performance”Viewing Queue Statistics
Section titled “Viewing Queue Statistics”Check current queue usage and statistics:
/queue simple print stats/queue tree print statsViewing PCQ Sub-queues
Section titled “Viewing PCQ Sub-queues”Monitor individual sub-queues created by PCQ:
/queue simple print detailThe output shows packet and byte counts for each sub-queue, helping identify bandwidth consumers.
Resetting Statistics
Section titled “Resetting Statistics”Clear queue statistics for fresh monitoring:
/queue simple reset-counters/queue tree reset-countersTroubleshooting PCQ
Section titled “Troubleshooting PCQ”Users Getting Unequal Bandwidth
Section titled “Users Getting Unequal Bandwidth”- Verify the classifier matches your traffic direction
- Check for overlapping queue rules that might conflict
- Ensure
pcq-rateis set appropriately for your link speed - Review packet marking rules for accuracy
/queue type print/ip firewall mangle printNo Traffic in PCQ Queues
Section titled “No Traffic in PCQ Queues”- Confirm packet marks exist and match traffic
- Verify queue rules are enabled (not disabled)
- Check interface names in packet marking rules
- Ensure traffic actually passes through the router
/queue tree print stats/ip firewall mangle print statsHigh Latency Despite PCQ
Section titled “High Latency Despite PCQ”- Reduce
pcq-rateto create adequate headroom - Check for interface errors or drops
- Verify duplex settings match on both ends
- Consider upgrading to hardware queuing on faster interfaces
PCQ Sub-queue Count Issues
Section titled “PCQ Sub-queue Count Issues”If PCQ creates too many or too few sub-queues:
/queue type set [find name=PCQ_download] pcq-limit=100The pcq-limit parameter controls the maximum number of sub-queues. Default is typically 2000, which suits most scenarios.
PCQ Parameters Reference
Section titled “PCQ Parameters Reference”Queue Type Parameters
Section titled “Queue Type Parameters”| Parameter | Description | Range | Default |
|---|---|---|---|
| kind | Queue type kind | pcq, bfifo, sfq, etc. | - |
| pcq-rate | Maximum total bandwidth | 0-100000000000 | 0 |
| pcq-classifier | Traffic classifier | dst-address, src-address, ports | - |
| pcq-limit | Max sub-queues per PCQ | 1-100000 | 2000 |
| pcq-burst-rate | Burst data rate | 0-100000000000 | 0 |
| pcq-burst-threshold | Burst activation threshold | 0-100000000000 | 0 |
| pcq-burst-time | Burst time window | 1s-60s | 15s |
| pcq-total-max | Total queue size | 0-1000000000 | 0 |
Classifier Options
Section titled “Classifier Options”| Classifier | Use Case | Creates Sub-queue For |
|---|---|---|
| dst-address | Download queues | Each destination IP |
| src-address | Upload queues | Each source IP |
| dst-port | Port-based distribution | Each destination port |
| src-port | Port-based distribution | Each source port |
| src-and-dst-address | Combined addressing | Each unique IP pair |
Best Practices
Section titled “Best Practices”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.
Related Commands
Section titled “Related Commands”/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