Token Bucket
Overview
A token bucket is a container that can store a certain number of tokens. The system places tokens into a token bucket at the configured rate. If the token bucket is full, excess tokens overflow and the number of tokens in the bucket can no longer increase.
The system determines whether there are enough tokens in the bucket for packet forwarding. If so, the traffic rate conforms to the rate limit. Otherwise, the traffic rate exceeds or violates the rate limit.
- The single rate three color marker (srTCM) algorithm determines traffic bursts based on packet lengths.
- The two rate three color marker (trTCM) algorithm determines traffic bursts based on packet rates.
The srTC and trTCM algorithms mark packets red, yellow, or green based on traffic metering results. Then the system processes packets based on their colors. The two algorithms can work in color-aware and color-blind modes. The color-blind mode is used as an example in the following descriptions.
Single-Rate-Two-Bucket Mechanism
The single-rate-two-bucket mechanism uses the srTCM algorithm to measure traffic and marks packets green, yellow, or red based on the metering result.
- CIR: indicates the rate at which tokens are put into bucket C, that is, the average traffic rate that bucket C allows.
- CBS: indicates the capacity of bucket C, that is, the maximum volume of burst traffic that bucket C allows.
- Excess burst size (EBS): indicates the capacity of bucket E, that is, the maximum volume of excess burst traffic that bucket E allows.
- If Tc is less than the CBS, Tc increases.
- If Tc is equal to the CBS and Te is smaller than the EBS, Te increases.
- If Tc is equal to the CBS and Te is equal to the EBS, Tc and Te do not increase.
- If B is less than or equal to Tc, the packet is colored green, and Tc decreases by B.
- If B is greater than Tc and less than or equal to Te, the packet is colored yellow and Te decreases by B.
- If B is greater than Tc and B is greater than Te, the packet is colored red, and Tc and Te remain unchanged.
Two-Rate-Two-Bucket Mechanism
The two-rate-two-bucket mechanism uses the trTCM algorithm to measure traffic and marks packets green, yellow, or red based on the metering result.
- Peak information rate (PIR): indicates the rate at which tokens are put into bucket P, that is, the maximum traffic rate that bucket P allows. The PIR is greater than the CIR.
- CIR: indicates the rate at which tokens are put into bucket C, that is, the average traffic rate that bucket C allows.
- Peak burst size (PBS): indicates the capacity of bucket P, that is, the maximum volume of burst traffic that bucket P allows.
- CBS: indicates the capacity of bucket C, that is, the maximum volume of burst traffic that bucket C allows.
- If Tp is less than the PBS, Tp increases. If Tp is greater than or equal to the PBS, Tp remains unchanged.
- If Tc is less than the CBS, Tc increases. If Tc is greater than or equal to the CBS, Tp remains unchanged.
- If B is greater than Tp, the packet is colored red.
- If B is greater than Tc and less than or equal to Tp, the packet is colored yellow and Tp decreases by B.
- If B is less than or equal to Tp and B is less than or equal to Tc, the packet is colored green, and Tp and Tc decrease by B.
Color-aware Mode
- If the packet has been colored green, the metering mechanism is the same as that in color-blind mode.
- If the packet has been colored yellow, the system marks the packet yellow if it conforms to the limit and marks the packet red if it violates the limit, depending on the packet length and the number of tokens.
- If the packet has been colored red, it is marked red in the token bucket.