Course contents

Unit 5: QoS and AppQoELesson 5.4 (4 of 7 in this unit)25 of 63 in the Advanced Cisco SD-WAN course

Policing, shaping, buffer and WAN bandwidth

Policing versus shaping with token-bucket arithmetic, why a burst can pass a rate but not a provider policer, queue length as delay, and what framing overhead does to a contracted rate.

Advanced · 15 min read

You'll learn to tell policing from shaping, work out a shaper's interval and burst from its rate and bucket, check a burst against a provider policer, turn a queue length into delay, and say what framing overhead does to a contracted rate.

Technical definition

Shaping and policing both hold traffic to a rate. A policer measures against a token bucket and drops or re-marks what does not conform, so it adds no delay and loses packets. A shaper uses the same bucket but holds the excess in a queue and sends it later, so it adds delay and loses fewer packets. Providers commonly police the traffic a customer sends, and customers shape before the provider's policer.

A policer drops, a shaper waits

Both tools compare traffic with a token bucket that fills at the configured rate. Traffic that finds enough tokens is conforming. What happens to the rest is the difference. A policer drops it or re-marks it, at once, with no queue. A shaper puts it in a queue and sends it when tokens are available. The shaper therefore turns an excess into delay, and the policer turns it into loss.

Diagram
Same excess, two outcomes
Same excess, two outcomes

Traffic above the rate is dropped or re-marked by a policer, which adds no delay. A shaper holds it in a queue and sends it later, which adds delay and loses fewer packets.

PolicerExcess droppedNo added delay
ShaperExcess queuedAdded delay
Shape on your side of the circuit, so that your own queues decide what waits. A provider's policer decides by dropping.
Diagram
Policing and shaping compared
Policing and shaping compared
PropertyPolicerShaper
Excess trafficDropped, or re-markedHeld in a queue
Delay addedNoneUp to the queue depth
OutputBursts pass if tokens allowSmoothed toward the rate
Works onInput or outputOutput only
Typical useA provider enforcing a contractA customer holding to the contract
The two use the same token bucket. The difference is only what happens to the excess.

The bucket and the interval

A shaper is defined by its rate, called the committed rate, and its burst, the committed burst. The interval is the burst divided by the rate. In each interval the shaper may send up to one burst of bits, and it sends them at the speed of the port, not at the shaped rate, then waits for the rest of the interval. A circuit shaped to 95 Mbps on a 1 Gbps port therefore sends in short bursts at 1 Gbps with gaps between them.

Diagram
One burst, one interval, one gap
One burst, one interval, one gap

A burst of 475,000 bits at a shaped rate of 95 megabits gives an interval of 5 milliseconds. The burst leaves the port in 0.475 milliseconds at 1 gigabit, and the shaper then waits 4.525 milliseconds until the next interval.

  1. Burst475,000 bits
  2. Rate95 Mbps
  3. Intervalburst / rate= 5 ms
  4. On the wire0.475 msat 1 Gbps
  5. Gap4.525 msof silence
The shaper sends at port speed in short bursts. The average over the interval is the shaped rate.
Diagram
Two shaper settings for 95 Mbps on a 1 Gbps port (computed)
Two shaper settings for 95 Mbps on a 1 Gbps port (computed)
BurstIntervalBurst on the wireGap until the next
475,000 bits (59,375 bytes)5 ms0.475 ms at 1 Gbps4.525 ms
95,000 bits (11,875 bytes)1 ms0.095 ms at 1 Gbps0.905 ms
Both settings average 95 Mbps. The first sends a burst five times larger. The next section shows why that can matter.

Worked example: shaped to the rate, still dropped

The contract is 100 Mbps and the edge shapes to 95 Mbps, which is under the rate. A transfer that fills the shaper still sees heavy loss on the circuit. The reason is the shape of the traffic, not its average. Suppose the provider polices at 100 Mbps with a committed burst of 15,000 bytes, which is 120,000 bits. This value is an assumption for the example. Contracts vary widely, and the way to find yours is to ask.

Diagram
One burst against the provider's bucket (computed)
One burst against the provider's bucket (computed)
StepInterval 5 msInterval 1 ms
Burst sent by the shaper475,000 bits95,000 bits
Time on the wire at 1 Gbps0.475 ms0.095 ms
Tokens added by the policer meanwhile47,500 bits9,500 bits
Policer's bucket plus tokens added167,500 bits129,500 bits
Excess the policer drops307,500 bits0 bits
Share of the burst lost64.7 percent0 percent
A model with assumed values. The larger burst overruns the provider's bucket although the average is below the contracted rate.
Diagram
Evidence from the burst case
Evidence from the burst case

The edge shapes to 95 megabits on a 100 megabit contract and still loses packets. The average is under the rate, but each burst is 475,000 bits against a provider bucket of 120,000 bits plus the tokens added during the burst. The excess is dropped. A smaller burst fits inside the bucket.

  1. SymptomLoss on the circuit at busy timesthough the shaper is below the rate
  2. Average95 Mbps against a 100 Mbps contractthe average fits
  3. Burst475,000 bits sent in 0.475 msagainst 167,500 bits of allowance
  4. Loss307,500 bits dropped per burst64.7 percent of the burst
  5. FixA smaller burst, or more headroom,and ask the provider for its burst
A rate has two numbers: how much on average, and how much at once. Both have to fit the policer.

The repair has three parts. Ask the provider for the committed burst of the contract, in writing. Choose a shaper burst, or an interval, that fits inside it, which here means the 1 ms setting. And if the platform derives the burst by itself and does not let you set it, shape further below the contracted rate and test with a bulk transfer. A test at a quiet hour proves nothing, because a burst needs traffic to fill it.

The two settings above are only two points. The table sweeps the burst to find where the edge of what fits lies, using the same assumed bucket.

Diagram
Which shaper burst fits the assumed provider bucket (computed)
Which shaper burst fits the assumed provider bucket (computed)
Shaper burstInterval at 95 MbpsLost at the policerResult
95,000 bits1.0 ms0 bitsFits
120,000 bits1.3 ms0 bitsFits
133,333 bits1.4 ms0 bitsThe largest that fits
200,000 bits2.1 ms60,000 bits (30 percent)Drops
300,000 bits3.2 ms150,000 bits (50 percent)Drops
475,000 bits5.0 ms307,500 bits (64.7 percent)Drops
Assumed: a 100 Mbps policer with a 120,000-bit bucket on a 1 Gbps port, as above. The largest burst that fits is the bucket divided by one minus 100 over 1,000, which is 133,333 bits. Computed by script; the real bucket is in the provider's contract.

Buffers turn packets into delay

A queue's length in packets looks harmless until it is converted to time. The delay a full queue adds is its size in bits divided by the rate that drains it. For 1,200-byte packets at 95 Mbps the figures grow fast.

Diagram
Queue length as delay at 95 Mbps (computed)
Queue length as delay at 95 Mbps (computed)
Queue lengthBits queuedDelay when full
64 packets of 1,200 bytes614,4006.5 ms
1,000 packets of 1,200 bytes9,600,000101 ms
4,000 packets of 1,200 bytes38,400,000404 ms
Bulk TCP fills a queue however large it is. A large queue shared with voice would break the delay budget. A large queue in a class of its own only slows that class.
Diagram
From queue length to delay
From queue length to delay

Take the packets in the queue, multiply by the packet size in bits, and divide by the rate that drains the queue.

  1. Packetsin the queue
  2. Bitsx size x 8
  3. Divideby the rate
  4. Delaywhen full
Check the delay of every queue against the delay budget of the traffic that uses it.

What counts toward the contracted rate

A rate is counted over some number of bytes per packet, and the choice changes the answer for small packets. A provider may count the Ethernet frame only, or the frame plus the 8-byte preamble and the 12-byte gap that follows it. The edge's shaper may count another way again. Compute the difference for the packets you carry.

Diagram
Two ways to count a frame
Two ways to count a frame

One way counts only the frame bytes. The other counts the frame plus the 8-byte preamble and the 12-byte gap that follows it, which is what the line really carries.

Frame onlyHeader, payloadand check sequence
On the wireFrame plus 8-byte preambleand 12-byte gap
Ask the provider which way it counts, and check which way the edge's shaper counts.
Diagram
Preamble and gap against frame size (computed)
Preamble and gap against frame size (computed)
FrameSizeBytes on the wireExtra for preamble and gap
Smallest Ethernet frame64 bytes8431.3 percent
G.711 voice with encapsulation288 bytes3086.9 percent
Largest standard frame1,518 bytes1,5381.3 percent
The voice frame is the 270-byte packet from earlier lessons plus 18 bytes of Ethernet header and check sequence.

On a link full of small packets, the difference between the two ways of counting is large. On a link of large packets it is small. That is one more reason for shaping a few percent below the contracted rate and for confirming with the provider which bytes they count.

The difference bites hardest when the two sides count differently. Suppose the provider counts the preamble and gap against a 100 Mbps contract, and the edge's shaper counts frame bytes only, at 95 Mbps. The table shows the rate the provider sees for three frame sizes.

Diagram
Wire rate when the shaper counts frames only (computed)
Wire rate when the shaper counts frames only (computed)
Frame sizeRate the provider seesFits a 100 Mbps contract?Highest shaper rate that fits
64 bytes124.7 MbpsNo76.2 Mbps
288 bytes (G.711 voice)101.6 MbpsNo93.5 Mbps
1,518 bytes96.3 MbpsYes98.7 Mbps
Assumed: the shaper counts frame bytes only at 95 Mbps, and the provider counts the frame plus 20 bytes of preamble and gap against 100 Mbps. Computed by script. What each side counts varies, so confirm both.

Learn more: QoS Counters and Queue-Drop TroubleshootingQoS Concepts: Marking, Queueing and Shaping

Test yourself

Predict · scenario 1

What is the main difference between a policer and a shaper?

Predict · scenario 2

A shaper is set to 95 Mbps with a burst of 475,000 bits. What is its interval?

Predict · scenario 3

The edge is shaped to 95 Mbps on a 100 Mbps contract, yet bursts are dropped. Which cause fits?

Predict · scenario 4

A queue holds 1,000 packets of 1,200 bytes and drains at 95 Mbps. How much delay does a full queue add?

Predict · scenario 5

Why does counting preamble and gap matter more for voice than for bulk data?

Predict · scenario 6

The provider polices at 100 Mbps with an assumed bucket of 120,000 bits, on a 1 Gbps port. A shaper burst of 200,000 bits arrives at full port speed. What share of the burst is dropped?

Predict · scenario 7

A shaper counts frame bytes only and is set to 95 Mbps. The provider counts frame plus preamble and gap against a 100 Mbps contract. All the traffic is 288-byte voice frames. What rate does the provider see?

Predict · scenario 8

Which shaper burst fits an assumed provider bucket of 120,000 bits on a 100 Mbps policer, with the shaper's port at 1 Gbps?

FAQ

Why shape below the contracted rate?
A shaper that sends exactly at the contracted rate has no margin for the way the provider counts bytes or for the bursts it sends. A few percent of headroom keeps the edge's queue, not the provider's policer, in charge of what is lost.
Can a shaper be set to the physical port speed instead?
Not usefully. If the port is faster than the circuit, a shaper at the port speed holds nothing back, so no queue forms at the edge and the provider's policer decides what is lost.
Does the provider count Ethernet preamble and gaps?
It depends on the provider and the service, and so does what the edge's shaper counts. Ask both questions in writing and compute the overhead for your packet sizes, because small packets pay the most.
Are bigger buffers better?
Only up to a point. A bigger queue loses fewer packets but holds each one longer, so delay grows. Bulk TCP traffic fills whatever buffer it is given. Size queues by the delay they can add, and keep delay-sensitive traffic in its own queue.