Traffic Shaping & Policing — Architecture & Algorithms
Overview
Traffic shaping and policing are mechanisms that control the rate, burstiness, and temporal distribution of packets entering or traversing a network. They ensure that traffic conforms to bandwidth contracts, prevent congestion, and enforce Quality of Service (QoS) guarantees. Although often discussed together, shaping and policing serve different purposes:
- Traffic shaping delays packets to smooth traffic and enforce a desired rate.
- Traffic policing drops or marks packets that exceed a rate or burst threshold.
These mechanisms are essential in routers, switches, data centers, wireless systems, and high‑speed interconnects where predictable performance and fairness are required.
Goals of Shaping and Policing
Traffic shaping and policing are designed to achieve several objectives:
- Rate enforcement — ensure flows do not exceed allocated bandwidth.
- Burst control — limit sudden traffic spikes that cause congestion.
- Fairness — prevent aggressive flows from starving others.
- QoS compliance — enforce service-level agreements (SLAs).
- Congestion avoidance — reduce queue buildup and packet loss.
- Latency control — smooth traffic to reduce jitter.
Different systems emphasize different goals depending on latency sensitivity, link capacity, and traffic patterns.
Architectural Principles
Token‑Based Rate Control
Most shaping and policing algorithms use token buckets or leaky buckets to regulate traffic. Tokens accumulate at a configured rate, and packets consume tokens when transmitted.
Burst Tolerance
Burst size determines how much traffic can be sent at once before rate limiting applies. Larger bursts improve efficiency but may increase jitter or congestion.
Queue Interaction
Shapers rely on queues to delay packets, while policers typically do not buffer traffic. This distinction is fundamental to their behavior.
Marking vs Dropping
Policers may:
- drop non‑conforming packets
- mark them (e.g., ECN, DSCP remarking) for downstream handling
Shapers never drop packets; they only delay them.
Traffic Shaping
Concept
Traffic shaping smooths traffic by delaying packets so that the output conforms to a desired rate profile. It is inherently buffer‑based.
How Shaping Works
A shaper:
- stores packets in a queue
- releases them according to a rate algorithm
- enforces long‑term rate and short‑term burst constraints
Shaping reduces jitter and prevents downstream congestion.
Common Shaping Algorithms
Token Bucket Shaping
Tokens accumulate at rate r. A packet of size s can be sent only if s\leq available tokens.
Pros: simple, flexible
Cons: allows bursts up to bucket size
Leaky Bucket Shaping
Packets are released at a fixed rate, regardless of input burstiness.
Pros: smooth output, low jitter
Cons: less flexible; may delay traffic excessively
Hierarchical Shaping
Multiple shapers arranged in a tree structure enforce:
- per‑class shaping
- per‑flow shaping
- aggregate shaping
Used in data centers and carrier networks.
Traffic Policing
Concept
Traffic policing enforces rate limits by dropping or marking packets that exceed configured thresholds. It is stateless in terms of buffering and does not delay traffic.
How Policing Works
A policer:
- checks packet size against available tokens
- consumes tokens for conforming packets
- drops or marks non‑conforming packets
Policing enforces strict compliance but may introduce loss and jitter.
Common Policing Algorithms
Single‑Rate Three‑Color Marker (srTCM)
Classifies packets as:
- green (conforming)
- yellow (exceeding committed burst)
- red (exceeding peak rate)
Used in DiffServ networks.
Two‑Rate Three‑Color Marker (trTCM)
Uses committed and peak rates to classify traffic more precisely.
Simple Token Bucket Policing
Drops packets when tokens are insufficient.
Pros: simple
Cons: harsh under bursty traffic
Shaping vs Policing
| Property | Shaping | Policing |
|---|---|---|
| Behavior | Delays packets | Drops or marks packets |
| Buffers | Required | Not required |
| Jitter | Reduced | Increased |
| Burst handling | Smooths bursts | Penalizes bursts |
| Use cases | QoS, real‑time, congestion avoidance | SLA enforcement, ingress control |
Shaping is gentler and improves quality; policing is stricter and enforces compliance.
Use Cases in Real Systems
Data Center Networks
Shaping is used to:
- smooth elephant flows
- reduce queue buildup
- integrate with ECN and DCTCP
Policing is used at ingress to enforce tenant bandwidth limits.
Carrier and ISP Networks
Hierarchical shaping enforces:
- per‑subscriber bandwidth
- per‑service class guarantees
- traffic engineering policies
Policing ensures SLA compliance and prevents abuse.
Wireless Networks
Wireless MACs use shaping and rate control to:
- adapt to channel quality
- reduce collisions
- manage airtime fairness
Policing is used less frequently due to the cost of packet loss.
High‑Speed Interconnects
PCIe, CXL, and NoCs use shaping‑like mechanisms to:
- regulate flit injection
- avoid congestion
- maintain deterministic latency
Policing is rare because lossless operation is required.
Performance Considerations
Latency and Jitter
Shaping reduces jitter but may increase latency.
Policing increases jitter and may cause retransmissions.
Throughput
Shaping maintains high throughput by smoothing bursts.
Policing may reduce throughput if many packets are dropped.
Fairness
Weighted shaping ensures fair bandwidth allocation.
Policing enforces fairness by penalizing aggressive flows.
Complexity
Shaping requires queues and timers.
Policing requires only counters and token logic.
Design Tradeoffs
- Latency vs smoothness — shaping improves smoothness but adds delay.
- Strictness vs friendliness — policing enforces rules but harms user experience.
- Hardware cost vs precision — shaping requires more memory and logic.
- Burst tolerance vs congestion — larger bursts improve efficiency but risk queue buildup.
- QoS guarantees vs scalability — hierarchical shaping improves QoS but increases complexity.
Related Pages
- Packet Scheduling — Architecture & Algorithms
- Protocol Flow Control — Architecture & Mechanisms
- Credit‑Based Flow Control — Architecture & Use Cases
- Sliding Window Protocols — Architecture & Dynamics
- Packet Fragmentation & Reassembly — Architecture & Design Considerations
Summary
Traffic shaping and policing regulate how traffic enters and traverses a network. Shaping smooths traffic by delaying packets, while policing enforces strict rate limits by dropping or marking non‑conforming packets. Together with scheduling and flow control, they form the foundation of bandwidth management and QoS in modern communication systems.