QoS Traffic Shaping Basics
Learn the fundamental concepts of Quality of Service (QoS), specifically focusing on traffic shaping and queuing techniques.
1. Executive Summary & Objective
In modern converged network environments, managing bandwidth effectively is critical to ensuring that business-critical applications perform consistently and reliably. Quality of Service (QoS) serves as the foundation for controlling the flow of traffic, preventing congestion, and ensuring that delay-sensitive traffic, such as voice and video, receives the required priority. Traffic shaping is one of the foundational pillars of QoS, acting as a crucial traffic management mechanism that regulates the transmission rate of data across a network interface.
The primary objective of this module is to provide a comprehensive and deep technical understanding of QoS traffic shaping basics. By the end of this lesson, you will be able to articulate the necessity of traffic shaping, understand the intricate mechanics of how shaping interacts with underlying queuing mechanisms, and deploy robust shaping configurations on industry-standard networking equipment. Furthermore, you will gain the ability to troubleshoot shaping policies and validate their effectiveness in live network scenarios. This knowledge is indispensable for network engineers tasked with optimizing Wide Area Network (WAN) circuits, minimizing packet drops, and maximizing the overall efficiency of network infrastructure.
2. Core Concept & Theory
At its essence, traffic shaping is a mechanism used to control the rate at which traffic is sent out of an interface. Unlike policing, which simply drops or re-marks packets that exceed a specified rate limit, shaping attempts to retain excess packets in a buffer and schedule them for later transmission. This fundamental difference makes shaping ideal for scenarios where dropping packets is highly undesirable, such as when interfacing with a service providerβs strict policing policies.
To fully grasp traffic shaping, one must understand the underlying parameters that govern it:
- Committed Information Rate (CIR): The target bandwidth rate that the shaper attempts to achieve, usually expressed in bits per second (bps).
- Committed Burst (Bc): The maximum number of bits that the shaper allows to be transmitted in a single time interval.
- Time Interval (Tc): The period over which the CIR is measured. The relationship is defined by the formula:
Tc = Bc / CIR. - Excess Burst (Be): An optional parameter allowing the shaper to occasionally send more traffic than the Bc, assuming there is unused bandwidth from previous intervals.
When the traffic rate entering the shaper is below the CIR, packets are transmitted immediately. However, if a sudden burst of traffic exceeds the CIR, the shaper calculates how many packets can be sent within the current Tc based on the Bc. Any packets exceeding this amount are held in a shaping queue. In subsequent intervals, the shaper continuously drains this queue.
It is vital to understand that shaping introduces delay (latency) and jitter. Because packets are held in a queue rather than dropped, they take longer to traverse the network. Therefore, shaping is typically not recommended for real-time traffic like voice, which is highly sensitive to delay. Instead, shaping is best suited for TCP-based traffic that can tolerate minor delays but would suffer heavily from packet loss and the resulting TCP retransmissions.
Moreover, shaping relies heavily on queuing mechanisms. When packets are buffered by the shaper, they must be organized in memory. If multiple flows are being shaped, the device needs a way to determine which packet from the buffer should be transmitted next. This is where advanced queuing mechanisms like Class-Based Weighted Fair Queuing (CBWFQ) are often deployed in conjunction with shaping to ensure fairness among different traffic classes.
3. Architecture & Topology
Consider a classic enterprise WAN architecture where a central data center is connected to multiple remote branch offices via an MPLS or SD-WAN network provided by an Internet Service Provider (ISP).
- Headquarters Router (HQ-R1): Has a physical 1 Gbps connection to the ISP. However, the organization has only purchased a 100 Mbps sub-rate circuit for cost reasons.
- Service Provider Edge (SP-PE): The ISPβs router enforces a strict 100 Mbps policer on traffic received from HQ-R1. If HQ-R1 sends traffic faster than 100 Mbps, SP-PE will aggressively drop the excess packets.
- Branch Router (BR-R1): Connected via a 100 Mbps circuit, receiving traffic from HQ-R1.
If HQ-R1, unaware of the 100 Mbps contractual limit, bursts traffic at its physical line rate of 1 Gbps, the SP-PE policer will drop massive amounts of packets. This will cause TCP windows to collapse, resulting in retransmissions and severe performance degradation for applications.
To architect a solution, a Traffic Shaper must be implemented on the outbound interface of HQ-R1 facing the SP-PE. The shaper is configured with a CIR of 100 Mbps. When HQ-R1 attempts to burst data at 1 Gbps, the shaper buffers the excess traffic and smoothly meters it out at precisely 100 Mbps. This architectural design ensures that traffic never hits the ISPβs policer, preventing packet drops and maintaining optimal TCP throughput.
4. Command Execution & Deployment
Deploying traffic shaping on Cisco IOS involves utilizing the Modular QoS CLI (MQC). The deployment process is divided into three distinct steps: defining the class of traffic (if necessary), creating the policy map containing the shaping instructions, and applying the policy to the appropriate interface.
Step 1: Define Traffic Classes (Optional for generic shaping)
In many scenarios, you may want to shape all traffic leaving an interface. In this case, you can use the default class (class-default). For more granular shaping, you would define class maps.
Step 2: Create the Policy Map
Here, we configure the policy map to shape all outbound traffic to 100 Mbps. We will configure an average shaper, which is the most common implementation.
HQ-R1(config)# policy-map WAN-SHAPER
HQ-R1(config-pmap)# class class-default
HQ-R1(config-pmap-c)# shape average 100000000
(Note: 100,000,000 bps = 100 Mbps)
For advanced tuning, you can manually specify the Bc and Be parameters to optimize the time interval (Tc). For example, to ensure a 10ms interval (useful for minimizing jitter for any mixed traffic), you calculate Bc = CIR * Tc = 100,000,000 * 0.010 = 1,000,000 bits.
HQ-R1(config-pmap-c)# shape average 100000000 1000000 1000000
Step 3: Apply the Policy to the Interface
The shaping policy must be applied in the outbound direction on the interface connecting to the WAN.
HQ-R1(config)# interface GigabitEthernet0/0/0
HQ-R1(config-if)# description Connection to ISP
HQ-R1(config-if)# service-policy output WAN-SHAPER
Nested QoS (Hierarchical QoS)
Often, you need to shape the overall link to 100 Mbps and apply queuing (like CBWFQ) within that shaped rate. This is done using a hierarchical policy map.
! Define child policy for queuing
HQ-R1(config)# policy-map CHILD-QUEUING
HQ-R1(config-pmap)# class VOICE
HQ-R1(config-pmap-c)# priority percent 10
HQ-R1(config-pmap)# class DATA
HQ-R1(config-pmap-c)# bandwidth percent 50
! Define parent policy for shaping
HQ-R1(config)# policy-map PARENT-SHAPER
HQ-R1(config-pmap)# class class-default
HQ-R1(config-pmap-c)# shape average 100000000
HQ-R1(config-pmap-c)# service-policy CHILD-QUEUING
5. Verification & Troubleshooting
Once the shaping policy is deployed, continuous monitoring and verification are required to ensure it operates correctly and that the buffers are not being overrun.
Verification Commands
- Verify Policy Map Configuration:
HQ-R1# show policy-map WAN-SHAPER
This command displays the configured parameters, ensuring your CIR, Bc, and Be calculations are correctly applied.
- Check Real-Time Interface Statistics:
The most critical command for troubleshooting QoS is
show policy-map interface.
HQ-R1# show policy-map interface GigabitEthernet0/0/0
Key Metrics to Analyze:
- Target/Average Rate: Ensures the shaper is aiming for the correct bandwidth limit.
- Packets delayed (buffered): Indicates that shaping is actively working and holding packets.
- Packets dropped: If drops are incrementing within the shaper class, it indicates that the shaperβs buffer (queue limit) has been completely filled. This means the burst of traffic was too sustained for the shaper to handle. You may need to increase the queue depth or investigate the source of the sustained burst.
- Active Queue Depth: Shows how many packets are currently waiting in the buffer.
Common Troubleshooting Scenarios
- High Latency Reported by Users: If users complain about slow application response times, the shaping buffer might be constantly full. A constantly full buffer means continuous delay. Investigate whether the circuit bandwidth (CIR) is genuinely sufficient for the organizationβs needs.
- Voice Quality Issues: If voice traffic is traversing a shaped link without a nested priority queue, voice packets will be delayed in the shaping buffer, causing severe jitter. Always implement Hierarchical QoS (HQoS) with a priority queue inside the shaper when voice is present.
6. Sandbox / Interactive Lab Context
To solidify your understanding, deploy the following scenario in your lab environment (GNS3, CML, or EVE-NG).
Lab Setup:
- Connect two routers, R1 and R2, via Gigabit Ethernet links.
- Configure IP addresses on both interfaces to establish connectivity.
- Set up a basic routing protocol (e.g., OSPF) or static routes if using loopbacks to generate traffic.
Task 1: Baseline Testing
- Use the
iperf3tool (or extended pings with large packet sizes) to generate traffic from a host behind R1 to a host behind R2. - Observe that the traffic utilizes the full 1 Gbps link capacity.
Task 2: Implement Shaping
- On R1, configure a policy map to shape outbound traffic on the interface facing R2 to exactly 50 Mbps.
- Apply the policy map to the interface.
Task 3: Validation and Analysis
- Re-run the
iperf3test from the host behind R1. - Observe the bandwidth reported by iperf3; it should now strictly adhere to the 50 Mbps limit.
- Concurrently, execute
show policy-map interface GigabitEthernet0/0on R1. - Watch the output dynamically. You should see the
packets delayedcounter incrementing rapidly, proving that the router is actively buffering and shaping the traffic rather than dropping it. - Try bursting UDP traffic at 100 Mbps using iperf. Watch the shaperβs behavior. Eventually, if the queue depth limit is reached, you will begin to observe tail drops in the
show policy-map interfaceoutput, illustrating the limits of shaping buffers.
π§ͺ Want to practise this on your own computer? See how to set up your lab →