QoS Policing vs. Shaping

Compare and configure traffic policing and traffic shaping.

1. Executive Summary & Objective

In the realm of Quality of Service (QoS), managing and restricting the flow of traffic is essential to maintaining network stability and adhering to Service Level Agreements (SLAs). While queuing dictates the order in which packets are sent, Traffic Policing and Traffic Shaping dictate the rate at which packets are sent or received. Although they share the common goal of limiting bandwidth utilization to a defined threshold, their internal mechanisms, impact on traffic flows, and operational use cases are fundamentally opposed.

The primary objective of this module is to provide a rigorous comparative analysis of Traffic Policing versus Traffic Shaping. By the end of this lesson, you will understand the deep technical distinctions regarding how each mechanism handles excess traffic, their impact on TCP windowing and latency, and the specific topological scenarios where one is favored over the other. You will also gain hands-on proficiency in deploying, monitoring, and troubleshooting both policing and shaping configurations using the Cisco Modular QoS CLI (MQC), empowering you to design resilient WAN edge boundaries and control ingress traffic rates effectively.

2. Core Concept & Theory

Both Policing and Shaping measure the instantaneous flow of traffic against a configured bandwidth threshold, known as the Committed Information Rate (CIR). The critical difference lies entirely in how the router handles packets that arrive faster than the CIR allows.

Traffic Policing

Policing acts as a strict, unyielding enforcer. It continuously monitors the traffic rate, and the moment the flow exceeds the CIR, it takes immediate, punitive action.

  • Action on Excess: Excess packets are either immediately dropped (hard policing) or re-marked to a lower priority (e.g., modifying DSCP EF to DSCP 0) and transmitted, hoping downstream devices will drop them if congestion occurs.
  • Buffering: Policer implementations do not buffer excess traffic. They use a mathematical β€œtoken bucket” algorithm strictly for measurement.
  • Impact on Traffic: Dropping packets causes TCP to drastically reduce its window size (TCP slow start), leading to a jagged, sawtooth-patterned traffic flow. It introduces zero latency or jitter.
  • Direction: Can be applied both inbound (ingress) and outbound (egress).

Traffic Shaping

Shaping acts as a shock absorber. It monitors the traffic rate, and when the flow exceeds the CIR, it attempts to retain the excess packets in memory and transmit them later at a steady, controlled rate.

  • Action on Excess: Excess packets are queued in a dedicated buffer (memory) and scheduled for transmission in subsequent time intervals, smoothing out traffic bursts. Drops only occur if the buffer completely fills up (tail drop).
  • Buffering: Relies heavily on memory buffers and internal queuing structures (like CBWFQ) to hold and organize delayed packets.
  • Impact on Traffic: Creates a smooth, consistent output rate, preventing TCP window collapse. However, holding packets in buffers fundamentally introduces delay (latency) and variable delay (jitter).
  • Direction: Typically applied only outbound (egress), as you cannot effectively buffer and delay traffic that you have already received on an ingress interface.

The Token Bucket Algorithm

Both mechanisms rely on the Token Bucket algorithm to calculate rates:

  • Tokens are replenished into a bucket at a rate proportional to the CIR.
  • Every transmitted packet removes tokens from the bucket based on its byte size.
  • If the bucket has enough tokens, the packet conforms (is sent).
  • If the bucket is empty (traffic rate > CIR), the packet exceeds. Policer drops it; Shaper buffers it and waits for more tokens.

3. Architecture & Topology

To illustrate when to use which mechanism, consider a Service Provider (ISP) and an Enterprise Customer connected via a 1 Gbps Metro Ethernet fiber link.

The ISP’s Perspective: Policing (Ingress Enforcement) The customer has only paid for a 200 Mbps SLA. The ISP must protect its core network from the customer bursting at 1 Gbps. The ISP configures an Inbound Policer at 200 Mbps on the PE (Provider Edge) router facing the customer. If the customer sends traffic at 300 Mbps, the PE router immediately drops the excess 100 Mbps, enforcing the contract without consuming ISP memory buffers.

The Customer’s Perspective: Shaping (Egress Optimization) The enterprise CE (Customer Edge) router is physically capable of sending traffic to the ISP at 1 Gbps. If it does, the ISP’s strict policer will drop massive amounts of packets, destroying TCP throughput. To prevent this, the enterprise configures an Outbound Shaper at 200 Mbps on their CE router. When local users burst file transfers, the CE router buffers the 1 Gbps burst and slowly meters it out to the ISP at a smooth 200 Mbps. The traffic never hits the ISP’s policer, zero drops occur on the WAN link, and TCP throughput remains highly optimized.

Summary Rule of Thumb: Police inbound to enforce limits on untrusted sources; Shape outbound to adapt high-speed LANs to sub-rate WAN circuits.

4. Command Execution & Deployment

Configurations utilize the Cisco MQC structure.

Scenario 1: Traffic Policing Configuration

We will configure an inbound policer to restrict a guest Wi-Fi subnet (VLAN 10) to 10 Mbps, dropping any excess.

enable
configure terminal

! Define the class
class-map match-all GUEST-TRAFFIC
 match vlan 10

! Create the policing policy
policy-map GUEST-POLICER
 class GUEST-TRAFFIC
  ! Police to 10 Mbps (10,000,000 bps)
  ! Allow a normal burst (Bc) of 1,500,000 bytes
  ! Action for conforming traffic is transmit, exceeding is drop
  police 10000000 1500000 conform-action transmit exceed-action drop

! Apply inbound on the interface connecting to the Guest AP switch
interface GigabitEthernet0/1
 service-policy input GUEST-POLICER
exit

Scenario 2: Traffic Shaping Configuration

We will configure an outbound shaper to smooth all egress traffic to 50 Mbps before it hits a provider’s sub-rate link.

configure terminal

! Create the shaping policy
policy-map WAN-SHAPER
 class class-default
  ! Shape average rate to 50 Mbps (50,000,000 bps)
  shape average 50000000

! Apply outbound on the WAN interface
interface GigabitEthernet0/0
 description Connection to ISP
 service-policy output WAN-SHAPER
exit

Note: For complex scenarios, you can combine them. You can Shape the overall interface to 50 Mbps, and then apply a hierarchical child policy to Police specific traffic (like non-business streaming video) to 5 Mbps inside that shaped pipe.

5. Verification & Troubleshooting

Monitoring the behavior of policers and shapers is crucial to ensure they are configured with the correct mathematical rates and are behaving as expected under load.

Verification Commands

  1. Verify MQC Interface Statistics:
Router# show policy-map interface GigabitEthernet0/0

Analyzing Policer Output:

  • Look at the conformed and exceeded counters (usually displayed in bytes and bps).
  • If exceeded is rapidly climbing and you see high drop rates, the traffic volume is significantly larger than your configured CIR. If this is unexpected, investigate the traffic source.

Analyzing Shaper Output:

  • Look at the Target/Average Rate to ensure your CIR calculation was correct (watch for extra zeros).
  • Monitor packets delayed. This confirms the buffering mechanism is working.
  • Monitor drops. Shapers should generally not drop packets unless the sustained rate heavily exceeds the CIR for a prolonged period, overflowing the shaping queue buffer limit.

Troubleshooting Scenarios

  • Severe VoIP Degradation on a Shaped Link: If voice traffic is traversing a shaped interface without an LLQ priority queue configured inside the shaper, the voice packets are being buffered. Buffering induces jitter, which destroys RTP streams. Solution: Implement Hierarchical QoS, placing voice in a strict priority queue inside the shaping policy.
  • TCP Throughput is Abysmally Low but Link isn’t Full: If a policer is configured with a Committed Burst (Bc) that is too small, TCP will perceive drops too early during its window scaling phase, causing it to back off drastically. Ensure your Bc parameters are tuned appropriately for TCP traffic (typically CIR * 1.5 / 8 as a baseline).

6. Sandbox / Interactive Lab Context

Deploy the following to witness the drastic difference between policing and shaping on TCP throughput.

Lab Setup:

  1. Connect two routers (R1 and R2) via a fast link (Gigabit).
  2. Connect PC-1 to R1 and PC-2 to R2.

Task 1: The Policer Test

  • On R1, configure an outbound Policer on the R2-facing interface set to 10 Mbps (Drop exceed).
  • From PC-1, initiate an iperf3 TCP bandwidth test to PC-2.
  • Observe the iperf3 output. The bandwidth will likely fluctuate wildly, averaging lower than 10 Mbps, and you will see massive amounts of TCP Retransmissions reported.
  • Run show policy-map interface on R1 to verify drops.

Task 2: The Shaper Test

  • Remove the policer policy from R1.
  • Configure an outbound Shaper on the same interface set to 10 Mbps.
  • Re-run the iperf3 TCP test.
  • Observe the iperf3 output. The bandwidth will plateau smoothly and consistently at exactly 9.5 - 10 Mbps, with near-zero TCP Retransmissions.
  • Run show policy-map interface on R1. You will see packets delayed incrementing heavily, but zero drops. This visually confirms the superiority of shaping for optimizing TCP file transfers over restricted links.

πŸ§ͺ Want to practise this on your own computer? See how to set up your lab →

πŸ€–

Need clarification? Ask GT

Hi, I'm GT β€” your AI tutor for QoS Policing vs. Shaping. What would you like to know?
πŸ“

Knowledge Check

1 of 3

What is the key behavioral difference between policing and shaping?

Report a problem

About: /lessons/qos-policing-vs-shaping