Policing and shaping
Policers and shapers both hold traffic to a rate; they differ in what they do with the excess. A policer drops or re-marks traffic beyond the rate, incoming or outgoing, cutting it off flat. A shaper buffers outgoing traffic that briefly peaks above the rate and sends it later, smoothing it at the cost of delay. Token buckets measure both.
By Arif, founder of Daveth · Updated
The full 10 min walkthrough is in Daveth Pro (Network). See what the plan opens
What this page answers
What is the difference between traffic policing and shaping?
A policer drops or re-marks traffic beyond the rate, incoming or outgoing: quick, but dropped TCP segments must be sent again. A shaper buffers outgoing traffic that peaks above the rate and sends it when the rate drops back: nothing lost, but delayed. Read it in “4.1 Two ways to hold traffic to a rate”
What is traffic policing?
Holding traffic to a contracted rate by dropping or marking down whatever exceeds it. A single-rate two-colour policer lets conforming traffic through and drops or re-marks the rest. Read it in “4.1 Two ways to hold traffic to a rate”
4.1 Two ways to hold traffic to a rate
Policers and shapers both hold traffic to a rate, and they classify it the same way; they differ in what they do with the excess.
- A policer drops or re-marks traffic, incoming or outgoing, that goes beyond the rate.
- A shaper buffers and delays outgoing traffic that briefly peaks above the rate, and sends it once the rate drops back below; traffic already under the rate goes straight out.
It's like the difference between a bouncer and a queue at the door. The bouncer turns away whoever arrives faster than the door allows: quick, and the people turned away have to come back later. The queue lets everyone in eventually, just not at once. In the guide's Figure 14-9, the policed stream is cut off flat at the line, and the shaped stream is smoothed up to it.
Take the provider case: if they police you at 10 Mbps and you send 15 Mbps for half a second, whatever exceeds their Bc is theirs to drop, and your TCP sessions pay for it, like a courier who bins whatever doesn't fit in the van and leaves you to post it again. D1 shows the same bursts both ways.
D1

A policer drops a packet; TCP sends it again; the policer may well drop that too. It's the most expensive way to say no.
Policers for incoming traffic belong at the edge of the network, so traffic that's going to be dropped doesn't waste bandwidth in the core. Policers for outgoing traffic belong at the edge too, or on the core-facing interfaces of edge devices. The downside of policing: it causes TCP retransmissions when it drops traffic. Placing it there works like a ticket check at the station entrance instead of on the train: you stop the fare dodgers before they take up a seat.
Shapers are for egress traffic, typically on an enterprise's service provider-facing interfaces. They're useful when the provider polices incoming traffic, or when it doesn't police but has a maximum-rate SLA with penalties for going over. Because a shaper delays rather than drops, it causes fewer TCP retransmissions than policing. Picture yourself posting parcels to a depot that refuses anything over its daily limit: you don't send the whole pile and watch half come back; you hold some back for tomorrow.
The pattern: police what you receive (or what you must cap inside), shape what you send to someone who polices you. Both meter IP packets of either version, and markdown rewrites the DSCP in the IPv4 ToS byte or the IPv6 Traffic Class field alike (05-2). RFC 2697 counts the IP header in the rate, so an IPv6 packet, with its larger header, spends a few more tokens for the same payload.
Shaping your traffic before the provider polices it is like tidying before the inspection. Same mess, fewer fines.
A policer that sees traffic over its rate has two choices: drop it, or mark it down with a lower priority. Marking down means re-marking to a lower-priority class value: excess traffic marked AFx1 should be marked down to AFx2, or to AFx3 with a two-rate policer. Then a congestion-avoidance tool, such as DSCP-based WRED (05-4), configured throughout the network, drops AFx3 more aggressively than AFx2, and AFx2 more aggressively than AFx1. Think of the markdown like a yellow sticker on a supermarket item near its date: still on the shelf, and the first thing cleared when space runs out.
That's the AF drop probability from 05-2 put to work: the policer doesn't throw the packet away, it writes "drop me first" on it, and a congested hop further on decides. RFC 2698 says the same thing in its own terms: for AF, the colour can be coded as the drop precedence. It's like the standby list at an airport gate: you're still going if there's room, but you're the first one bumped when there isn't.
Markdown is the policer's way of saying "you can come in, but you're sitting by the toilets."
Cisco IOS policers and shapers are built on token buckets. The terms:
| Term | Meaning |
|---|---|
| CIR, Committed Information Rate | the contracted rate, in bits per second |
| Tc, Committed Time Interval | the interval, in ms, over which the Bc is sent: Tc = (Bc [bits] / CIR [bps]) × 1000 |
| Bc, Committed Burst Size | the bucket's maximum size, and the most traffic that can go in one Tc: Bc = CIR × (Tc / 1000) |
| Token | 1 byte, or 8 bits |
| Token bucket | fills with tokens at the CIR up to its maximum; each packet takes tokens equal to its size (1500 bytes takes 12,000 bits' worth) |
(The guide calls Bc "measured in bytes" and then works in bits, 12 Mb; RFC 2697 measures its buckets in bytes. On this page every number says which unit it's in.)
If there aren't enough tokens for a packet, the tool can buffer it until there are (shaping), drop it (policing), or mark it down (policing). Size the Bc at least as big as the largest IP packet in the stream, or bigger packets can never collect enough tokens and always exceed. When the bucket is full, new tokens are discarded, and discarded tokens can't be used later. With one bucket, traffic either conforms (enough tokens) or exceeds (not enough).
It works behind the scenes just like a pocket-money jar: a fixed amount goes in every week, you can't spend what isn't in the jar, and once the jar's full, the extra coins don't fit, so a quiet month doesn't buy you an enormous spree.
Now the guide's worked example. A 1 Gbps interface is policed at a CIR of 120 Mbps with a Bc of 12 Mb. You can't set the Tc in IOS; you work it out:
- Tc = 12,000,000 / 120,000,000 × 1000 = 100 ms, so 10 Tcs a second.
- Offered a continuous stream of 1500-byte (12,000-bit) packets, 12,000,000 / 12,000 = 1000 packets (rounded down) conform in each Tc; beyond that they're dropped or marked down.
- 1000 × 10 = 10,000 packets a second, and 10,000 × 12,000 bits = 120 Mbps: the CIR.
- The 1000 packets go out at line rate: 12,000,000 / 1,000,000,000 × 1000 = 12 ms.
This is the guide's interval model: a Bc's worth of tokens per Tc. Predict before you open D2: in each 100 ms Tc, for how long does conforming traffic get through, and what happens to the rest?
D2

12 ms, then 88 ms of nothing conforming. The guide prints "113 ms (125 ms minus 12 ms)", and its Figure 14-11 labels the Tc 125 ms, but its own arithmetic two paragraphs earlier gives a 100 ms Tc, and the figure itself draws its bursts every 100 ms. 100 − 12 = 88. Be careful what the gap means. A policer doesn't hold anything back: every packet that arrives in those 88 ms finds no tokens and is dropped or marked down on the spot. The receiver sees 12 ms of traffic, then 88 ms of none (or of marked-down traffic). The guide calls the gap "interpacket delay"; for a policer, nothing is delayed, it's lost or demoted. That's why the recommended Tc is 8 to 125 ms, with 8 to 10 ms for real-time traffic such as voice: a shorter Tc means shorter gaps in what gets through; a Tc over 125 ms makes them too large for most networks. (The RFC meters in D3 refill their buckets continuously instead, byte by byte, so they don't carve traffic into Tc-sized slices; the interval model is how the guide explains Bc and Tc.) The interval model makes a policer behave like a canteen that serves a minute's worth of trays at the start of every ten minutes and turns everyone else away: the right number of meals per hour, and a long, hungry gap for anyone who arrives late.
For 88 ms out of every 100, the guide's policer has one answer for every packet: "not this Tc."
The policing algorithms are the single-rate two-colour marker/policer, the single-rate three-colour (srTCM) and the two-rate three-colour (trTCM). The three line up like the models of one car: the second adds a spare tank, the third swaps it for a second fuel line.
The first policers were single-rate two-colour, using one token bucket: traffic conforms to the CIR or exceeds it, and each state can be transmitted, marked down or dropped. The guide's Figure 14-12 shows both versions: the excess marked down and still sent, or dropped, leaving the stream flat at the line. Two colours make it work like a turnstile with a single ticket check: you have a valid ticket or you don't, and there's no "almost".
The two-colour policer has exactly two moods, and neither of them is "maybe".
The srTCM is based on RFC 2697 and uses two buckets, so traffic can conform, exceed or violate. The first bucket works like the single-rate two-colour one. The difference: tokens left over after a quiet period, instead of being discarded, go into a second bucket, for later bursts over the CIR. That second bucket's size is the excess burst, Be. RFC 2697 is precise about it: tokens arrive at the CIR, fill bucket C up to CBS, and only when C is full do they go to bucket E, up to EBS. Bucket E sits beside bucket C like a savings pot next to the pocket-money jar: whatever doesn't fit in the jar goes into the pot, and a big weekend can dip into it.
The three colours:
- Conform (green): within Bc; usually transmitted, optionally re-marked.
- Exceed (yellow): over Bc, within Be; dropped, or marked down and transmitted.
- Violate (red): over Be; usually dropped, optionally marked down and transmitted.
Its parameters: CIR; Bc, the committed bucket, called CBS in RFC 2697; Be, the excess bucket, called EBS; Tc and Te, the token counts in the two buckets; and B, the incoming packet's length. Careful with that Tc: here it's a token count, "Not to be confused with the committed time interval Tc". (The guide mixes its units here: it gives B "in bits", calls both buckets "measured in bytes", and on p382 calls Be bits. RFC 2697 measures all of them in bytes.)
The logic in Figure 14-14: a packet that fits in the Bc bucket conforms; if not, one that fits in the Be bucket exceeds; otherwise it violates. (The figure writes "B < Tc"; RFC 2697 lets a packet exactly the size of the remaining tokens conform, Tc − B ≥ 0.)
Why use it? Its two buckets cause fewer TCP retransmissions and use bandwidth more efficiently, and it suits AF classes (AFx1, AFx2, AFx3). But a three-colour policer only makes sense if the colours get different actions; if two colours are treated the same, use the single-rate two-colour policer and keep it simple. A three-colour policer there is like a three-way switch bought for a lamp you only ever turn fully on or off. And note what its yellow depends on: tokens left over. The exceeding and violating rates vary because they rely on tokens spilling from the Bc bucket into the Be. That's why the guide's Figure 14-13 draws the line between exceed and violate as a wavy dotted line, where Figure 14-15 for the trTCM has a straight PIR line.
srTCM is generous with bursts right up until you use it all the time. Then it remembers it's a policer.
The trTCM is based on RFC 2698. The srTCM's reliance on leftover tokens makes its excess unpredictable; the trTCM fixes that with two rates, the CIR and the PIR (Peak Information Rate), and so allows a sustained excess rate. For example, violating traffic can be dropped at a defined rate, which the srTCM can't do. It's like a phone plan with a fixed allowance plus a clearly priced top-up, instead of "whatever you didn't use last month".
Continue the lesson
The whole lesson, with its drawings and its questions. The rest of this section and 9 more after it.



