Mastering Cisco Router QoS: A Deep Dive into CBWFQ and Key Concepts
Quality of Service (QoS) on Cisco routers is all about managing network traffic to ensure critical applications get the bandwidth and performance they need, especially under congestion. One of the most powerful tools in the QoS toolbox is Class-Based Weighted Fair Queuing (CBWFQ). In this post, we’ll explore CBWFQ and break down its key components—policies, shape-average, bandwidth remaining percent, priority, queue-limit, and random-detect—to help you configure QoS like a pro.
What is CBWFQ?
CBWFQ is an advanced queuing mechanism that builds on Weighted Fair Queuing (WFQ). It lets you:
- Define traffic classes based on criteria like IP address, protocol, or Access Control Lists (ACLs).
- Assign each class a specific amount of bandwidth or priority.
- Ensure fair treatment while prioritizing critical traffic during congestion.
Unlike basic WFQ, CBWFQ gives you manual control over how bandwidth is allocated, making it ideal for enterprise networks with diverse traffic types (e.g., voice, video, data).
Step 1: Building QoS Policies
QoS in Cisco IOS revolves around the Modular QoS CLI (MQC), a three-step process:
- Classify: Group traffic into classes using class-map.
- Define Policy: Set rules for each class using policy-map.
- Apply: Attach the policy to an interface with service-policy.
Example: Basic Policy Setup
class-map match-all VOICE
match protocol rtp
class-map match-all VIDEO
match dscp af41
class-map match-all DATA
match access-group 101
policy-map MY-QOS-POLICY
class VOICE
class VIDEO
class DATA
class class-default
- class-map: Identifies traffic (e.g., RTP for voice, DSCP for video, ACL 101 for data).
- policy-map: Defines what happens to each class (we’ll add actions next).
- class-default: Catches all unclassified traffic.
Step 2: Shaping Traffic with shape average
Traffic shaping smooths out bursts by limiting the rate at which packets are sent. The shape average command sets a sustained average rate (in bits per second) and buffers excess traffic.
Why Use It?
- Prevents downstream congestion.
- Ensures compliance with service provider limits.
Example:
policy-map MY-QOS-POLICY
class VIDEO
shape average 5000000 # 5 Mbps
- This caps video traffic at 5 Mbps, buffering excess packets to avoid drops.
How It Works:
- Uses a token bucket algorithm.
- Tokens refill at the configured rate (e.g., 5 Mbps).
- Packets send only if enough tokens are available; otherwise, they’re queued.
Step 3: Allocating Bandwidth with bandwidth and bandwidth remaining percent
CBWFQ lets you guarantee bandwidth to classes during congestion.
bandwidth
- Sets a minimum bandwidth in kilobits per second (kbps).
- Example:
policy-map MY-QOS-POLICY class VOICE bandwidth 1000 # 1 Mbps guaranteed class VIDEO bandwidth 2000 # 2 Mbps guaranteed
bandwidth remaining percent
- Allocates a percentage of the remaining bandwidth after higher-priority traffic.
- Useful when total bandwidth varies (e.g., on subinterfaces).
- Example:
policy-map MY-QOS-POLICY class DATA bandwidth remaining percent 50 # 50% of leftover bandwidth class class-default bandwidth remaining percent 25 # 25% of leftover bandwidth
Key Difference:
- bandwidth: Fixed allocation.
- bandwidth remaining percent: Dynamic, based on what’s left.
Step 4: Prioritizing Traffic with priority
The priority command creates a Low Latency Queue (LLQ) for delay-sensitive traffic (e.g., voice). It gets served first, up to a specified limit.
Why Use It?
- Minimizes jitter and latency for real-time applications.
Example:
policy-map MY-QOS-POLICY
class VOICE
priority 512 # 512 kbps strict priority
- Voice gets 512 kbps with absolute priority, policed to prevent starvation of other queues.
Caution:
- Overuse can starve lower classes. Use only for critical traffic.
Step 5: Managing Queues with queue-limit
The queue-limit command sets the maximum number of packets a class queue can hold before dropping excess packets.
Why Adjust It?
- Too small: Drops packets prematurely.
- Too large: Increases latency.
Example:
policy-map MY-QOS-POLICY
class VIDEO
bandwidth 2000
queue-limit 100 # Holds up to 100 packets
- Default varies by platform (e.g., 64 packets). Adjust based on traffic needs.
Step 6: Congestion Avoidance with random-detect
random-detect enables Weighted Random Early Detection (WRED), which drops packets probabilistically before queues fill up. This prevents tail drop (where all new packets are discarded when the queue is full).
Why Use WRED?
- Avoids global TCP synchronization (massive slowdown when all flows back off at once).
- Prioritizes based on DSCP or IP precedence.
Example:
policy-map MY-QOS-POLICY
class DATA
bandwidth remaining percent 50
random-detect dscp-based # Drop based on DSCP values
- Drops lower-DSCP packets (e.g., AF11) before higher ones (e.g., AF31) as the queue fills.
Tuning WRED:
- Set thresholds:
random-detect dscp af11 20 40 # Min 20, Max 40 packets
- Min: Start dropping probabilistically.
- Max: Drop all packets beyond this.
Note:
- WRED is not “random tail drop” (tail drop is FIFO’s default behavior). WRED is smarter and proactive.
Putting It All Together
Here’s a complete example:
class-map match-all VOICE
match protocol rtp
class-map match-all VIDEO
match dscp af41
class-map match-all DATA
match access-group 101
policy-map MY-QOS-POLICY
class VOICE
priority 512
queue-limit 50
class VIDEO
bandwidth 2000
shape average 5000000
queue-limit 100
class DATA
bandwidth remaining percent 50
random-detect dscp-based
class class-default
bandwidth remaining percent 25
interface GigabitEthernet0/0
service-policy output MY-QOS-POLICY
What This Does:
- Voice: 512 kbps priority, 50-packet queue.
- Video: 2 Mbps guaranteed, shaped to 5 Mbps, 100-packet queue.
- Data: 50% of remaining bandwidth, WRED for congestion.
- Default: 25% of remaining bandwidth.
Testing and Verification
- Check policy application:
show policy-map interface GigabitEthernet0/0
- Look for packet drops, queue usage, and bandwidth allocation.
Final Tips
- Test in a lab first: QoS misconfigs can disrupt traffic.
- Monitor: Use tools like show queueing or NetFlow.
- Scale wisely: Too many classes can overwhelm the router.
With CBWFQ, you’ve got the power to shape, prioritize, and manage your network traffic like a Cisco ninja. Happy configuring!