|
Click
|
Token bucket rate template. More...
#include <click/tokenbucket.hh>
Inherits P.
Public Types | |
| enum | { max_tokens = (token_type) -1 } |
| typedef P | parameter_type |
| The template parameter type. | |
| typedef P::token_type | token_type |
| Unsigned type of token counts. | |
| typedef P::time_point_type | time_point_type |
| Type of time points. | |
| typedef make_unsigned< typenameP::duration_type >::type | ticks_type |
| Unsigned type of tick counts (differences between time points). | |
Public Member Functions | |
| TokenRateX () | |
| Construct an idle token rate. | |
| TokenRateX (bool unlimited) | |
| Construct an idle or unlimited token rate. | |
| TokenRateX (token_type rate, token_type capacity) | |
| Construct a token rate representing rate. | |
| void | assign (bool unlimited=false) |
| Set the token rate to idle or unlimited. | |
| void | assign (token_type rate, token_type capacity) |
| Set the token rate and capacity. | |
| bool | unlimited () const |
| Return true iff the token rate is unlimited. | |
| bool | idle () const |
| Return true iff the token rate is idle. | |
| token_type | rate () const |
| Return the rate in tokens per period. | |
| token_type | capacity () const |
| Return the capacity in tokens. | |
| token_type | tokens_per_tick () const |
| Return the number of tokens per tick. | |
| token_type | token_scale () const |
| Return the ratio of fractional tokens to real tokens. | |
| ticks_type | time_until_full () const |
| Return the number of ticks required to refill a counter to capacity. | |
| time_point_type | now () const |
| Return the current time point. | |
| template<typename U > | |
| time_point_type | time_point (U time) const |
| Return the time point corresponding to the time parameter. | |
| ticks_type | time_monotonic_difference (time_point_type a, time_point_type b) const |
| Return b - a, assuming that b was measured after a. | |
Token bucket rate template.
The TokenRateX class implements a token bucket rate. TokenBucketX is initialized with a rate, in tokens per second, and a capacity in tokens. Associated token buckets fill up with tokens at the given rate, to a maximum of the capacity.
Two special types of rate are supported. An unlimited TokenRateX always refills associated counters to full capacity. Its capacity() equals token_max. An idle TokenRateX never refills.
Most users will be satisfied with the TokenRate type, which is equal to TokenRateX<TokenBucketUsecParameters<unsigned long long> >.
| typedef P TokenRateX< P >::parameter_type |
The template parameter type.
| typedef P::token_type TokenRateX< P >::token_type |
Unsigned type of token counts.
| typedef P::time_point_type TokenRateX< P >::time_point_type |
Type of time points.
| typedef make_unsigned<typenameP::duration_type>::type TokenRateX< P >::ticks_type |
Unsigned type of tick counts (differences between time points).
|
inline |
Construct an idle token rate.
|
inlineexplicit |
Construct an idle or unlimited token rate.
| unlimited | idle if false, unlimited if true |
|
inline |
|
inline |
Set the token rate to idle or unlimited.
| unlimited | idle if false, unlimited if true |
|
inline |
Set the token rate and capacity.
| rate | refill rate in tokens per period |
| capacity | maximum token accumulation |
Sets the token bucket's rate to rate and capacity to capacity. If either rate or capacity is 0, the rate becomes idle.
|
inline |
Return true iff the token rate is unlimited.
|
inline |
Return true iff the token rate is idle.
| P::token_type TokenRateX< P >::rate | ( | ) | const |
Return the rate in tokens per period.
Returns max_tokens for unlimited rates. Imprecise computer arithmetic may cause the result to differ from the configured rate.
|
inline |
Return the capacity in tokens.
Returns max_tokens for unlimited rates. Imprecise computer arithmetic may cause the result to differ from the configured capacity.
|
inline |
Return the number of tokens per tick.
|
inline |
Return the ratio of fractional tokens to real tokens.
|
inline |
Return the number of ticks required to refill a counter to capacity.
Returns (ticks_type) -1 for idle rates.
|
inline |
Return the current time point.
Implemented as P::now().
|
inline |
Return the time point corresponding to the time parameter.
May not be available for all U types. Implemented as P::time_point(time).
|
inline |
Return b - a, assuming that b was measured after a.
Some time measurements can, in rare cases, appear to jump backwards, as timestamps do when the user changes the current time. If this happens (b < a), time_monotonic_difference returns 0. Implemented as P::time_monotonic_difference(a, b).