QoS

Traffic Shaping

Traffic Shaping is a proactive QoS mechanism designed to regulate the flow of network traffic.

1. Traffic bursts and congestion

Network traffic often arrives in short, high-volume bursts. A user may browse a web page, causing a brief increase in activity followed by several minutes of inactivity. The user may then start a large file download that generates a sustained, high-speed packet flow. Applications therefore have different activity patterns, while an output interface may provide a fixed capacity.

When bursts from different sources converge on one device and use the same output link, the instantaneous arrival rate can exceed the link's capacity. This leads to . The router's buffers begin to fill, so packets wait longer. Once a buffer overflows, the router drops packets. The result can include queueing delay, packet loss, and retransmissions. Administrators then need tools to control the rate and timing of traffic.

2. Traffic shaping principle

regulates packet flow. Its primary goal is to match the rate at which packets leave an interface to a configured traffic profile or a service-provider contract. Outgoing traffic is then spread over time according to that profile. The mechanism needs space for waiting packets, so it is commonly applied on an outbound interface before a bottleneck.

The main operation of traffic shaping is delaying. When a burst exceeds the configured rate, packets are placed in a buffer or queue and can be transmitted during a later lull. The long-term average rate then remains within the limit. A buffer has finite capacity, so excess packets can be dropped after it fills. Delaying packets that fit in the buffer can reduce loss that triggers TCP retransmissions and smooth the output stream. The added latency is the cost of retaining the burst and must be considered when selecting the buffer size.

3. Traffic Shaping vs. Traffic Policing

Traffic shaping and traffic policing respond differently to packets that exceed a defined rate limit. Shaping retains packets in a queue and changes when they are sent, while a policer applies the action specified by its profile without waiting for a later transmission. Both mechanisms can use a token-bucket model, but an excess packet has a different outcome. A shaper therefore needs buffer space, whereas a policer can make its decision at the measurement point.

AspectTraffic ShapingTraffic Policing
Primary ActionDelays packets in a buffer; may drop excess after it fillsDrops, forwards, or re-marks excess packets
MechanismUses a buffer and queue to delay excess trafficMeasures the traffic profile and applies a configured action
Effect on Traffic FlowSmoothes bursts according to the configured rate profileLimits bursts; a simple model can produce a sawtooth-like flow
Impact on TCPIncreases latency; retained packets can avoid lossPacket loss can trigger TCP retransmissions
Typical Use CaseOften on outbound interfaces to control sent trafficOn ingress or egress to enforce a traffic limit

4. Traffic shaping algorithms

Network devices model shaping with parameters such as rate, burst size, and buffer capacity. Two classic models are the Leaky Bucket and the Token Bucket. These parameters determine how much traffic can wait and how quickly it is released at the output.

The Leaky Bucket Algorithm

  • Concept: The model describes a queue that can receive packets at any rate and an output served at a fixed rate. The output rate remains the same at different queue occupancies until the buffer becomes empty.
  • Operation: When a packet arrives, the system checks the buffer space. A packet that fits is placed in the queue, while a packet arriving at a full buffer is dropped. Packets leave the queue at a steady rate.
  • Effect: In the Leaky Bucket model, a bursty input becomes an output stream with a constant rate. When the queue is empty, the shaper does not create artificial traffic. Packetization still affects the exact transmission pattern.
  • Limitation: The model is rigid. The output rate cannot exceed the configured leak rate even when the link has spare capacity. A later burst sent over an idle link is still transmitted at the fixed rate, which can reduce use of the available capacity.

The Token Bucket Algorithm

The Token Bucket algorithm is a flexible alternative. It allows bursts up to a configured limit while controlling the long-term average rate.

  • Concept: This model uses a bucket filled with tokens at a constant rate. Each token represents permission to send a certain amount of data, such as one byte or one packet. The bucket has a maximum capacity, and stored tokens represent an allowed burst.
  • Operation:When a packet is ready to be transmitted, the shaper checks the token bucket. The packet's cost is based on bytes or another unit chosen by the configuration.
    • If there are enough tokens in the bucket to "pay for" the packet, the required number of tokens is removed, and the packet is sent immediately.
    • If there are not enough tokens, the packet must wait in a queue until sufficient tokens have been generated.
    Tokens are generated at a fixed rate rr. If the bucket's capacity is bb, the system allows bursts. In this simplified example, a full bucket lets an application send bb bytes at interface speed when the downstream path permits it. After the tokens are spent, the average rate returns to rr as tokens are replenished. A larger bb permits a larger burst after an idle period, while a smaller bb limits its size.
  • Effect: The Token Bucket algorithm controls the long-term average transmission rate (rr) and allows short-term bursts up to the bucket size (bb). This matches traffic with idle periods followed by short bursts. After tokens are exhausted, later packets wait or receive the policing action.
  • Flexibility: The bucket size sets the maximum short-term burst, while the token-generation rate sets the upper bound on average throughput. Burst frequency also depends on the source demand. Token Bucket is often used for both shaping and policing.

5. Traffic shaping use cases

Traffic shaping is usually applied at the output of a device or administrative domain to control traffic according to a rate and burst profile. Its parameters should match the downstream link and service agreement.

  • Service-provider contract: At an enterprise edge, an ISP may police customer traffic according to a contract, such as a 100100 Mbps connection. The enterprise can shape traffic on its outbound interface to at most 100100Mbps, reducing packets dropped by the provider's policer. The configured profile should remain within the service contract, including any burst allowance.
  • Slow WAN links: In a network with a central office and remote branches connected by slower WAN links, shaping on the central router limits the share of a single high-bandwidth application. This leaves part of the link for latency-sensitive applications at the branch and limits sudden queue growth during bursts.
  • Hierarchical QoS policies: Shaping can limit a main link to 1010 Mbps, while queues for voice, video, and data operate within that limit. The aggregate output remains within the configured profile, while classes can still receive different shares.

Related articles