## Example Dual Rate Token Bucket as a Piggy Bank

Using a dual-rate token bucket is like using two piggy banks, each with a different savings rate. However, you can only take out money from one of the piggy banks at a time.

For example, you can save ten dollars per day into the first piggy bank (PIR = peak spending rate = \$10 per day) and then at the same time, you can save five dollars per day into the second piggy bank (CIR = normal average spending rate = \$5 per day). However, the maximum amount you can spend is \$10 per day, not \$15 per day, because you can only take out money from one piggy bank at a time.

In this example, after one day of savings, your first piggy bank (PIR bucket) will contain \$10 and your second piggy bank (CIR bucket) will contain \$5. The three different spending cases are examined here to show how dual-rate metering operates, using the piggy bank example:

■ Case 1: If you try to spend \$11 at once, then you are violating (Tp < B) your peak-spending rate of \$10 per day. In this case, you will not be allowed to spend the \$11 because \$11 is greater than the \$10 you have in the first piggy bank (PIR bucket). Remember, you can only take out money from one of the piggy banks at a time.

■ Case 2: If you try to spend \$9 at once, then you are exceeding (Tp > B > Tc) your normal average spending rate of \$5 per day. In this case, you will be allowed to spend the \$9 and just the first piggy bank (PIR bucket) will be decremented to \$10 - \$9, or \$1.

After spending \$9, the maximum amount you can continue to spend on that day is decremented to \$1.

■ Case 3: If you try to spend \$4, then you are conforming (Tp > B and Tc > B) to your normal average spending rate of \$5 per day. In this case, you will be allowed to spend the \$4, and both piggy banks (PIR and CIR bucket) will be updated.

The first piggy bank (PIR bucket) will be updated to \$10 - \$4 = \$6, and the second piggy bank (CIR bucket) will be updated to \$5 - \$4 = \$1.

Both piggy banks are updated because after spending \$4, the maximum amount you can continue to spend on that day is decremented to \$6, and the normal spending rate for that same day is decremented to \$1.

Therefore, after spending \$4, the following will occur:

■ If you continue to spend \$7 on that same day, then you will be violating your peak-spending rate for that day. In this case, you will not be allowed to spend the \$7 because \$7 is greater than the \$6 you have in the first piggy bank (PIR bucket).

■ If you continue to spend \$5 on that same day, then you will be exceeding your normal average spending rate for that day. In this case, you will be allowed to spend the \$5 and just the first piggy bank (PIR bucket) will be decremented to \$6 - \$5, or \$1.

■ If you continue to spend 50 cents on that same day, then you will be conforming to your normal average spending rate for that day. In this case, you will be allowed to spend the 50 cents, and both piggy banks (PIR and CIR bucket) will be updated. The first piggy bank (PIR bucket) will be updated to \$6 - \$0.50 = \$5.50, and the second piggy bank (CIR bucket) will be updated to \$1 - \$0.50 = \$0.50.

This topic describes how traffic can be shaped using a single token bucket scheme.

Class-Based Traffic Shaping

Cisco class-based traffic shaping only applies for outbound traffic.

Class-based traffic shaping uses the basic token bucket mechanism, in which Bc of tokens are added at every Tc time interval. The maximum size of the token bucket is Bc + Be. You can think of the traffic shaper operation like opening and closing of a transmit gate at every Tc interval. If the shaper gate is opened, the shaper checks to see if there are enough tokens in the token bucket to send the packet. If there are enough tokens, the packet is immediately forwarded. If there are not enough tokens, the packet is queued in the shaping queue until the next Tc interval. If the gate is closed, the packet is queued behind other packets in the shaping queue.

For example, on a 128-kbps link, if the CIR is 96 kbps, the Bc is 12 kbps, the Be is 0, and the Tc = 0.125 seconds, then during each Tc (125 ms) interval, the traffic shaper gate opens and up to 12 KB can be sent. To send 12 KB over a 128-kbps line will only take 91.25 ms. Therefore the router will, on the average, be sending at three-quarters of the line rate (128 kbps * 3/4 = 96 kbps).

Traffic shaping also includes the ability to send more than Bc of traffic in some time intervals after a period of inactivity. This extra number of bits in excess to the Bc is called Be.