Click
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
TokenRateX< P > Class Template Reference

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.
 

Detailed Description

template<typename P>
class TokenRateX< P >

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> >.

See also
TokenCounterX, TokenBucketX

Member Typedef Documentation

◆ parameter_type

template<typename P >
typedef P TokenRateX< P >::parameter_type

The template parameter type.

◆ token_type

template<typename P >
typedef P::token_type TokenRateX< P >::token_type

Unsigned type of token counts.

◆ time_point_type

template<typename P >
typedef P::time_point_type TokenRateX< P >::time_point_type

Type of time points.

◆ ticks_type

template<typename P >
typedef make_unsigned<typenameP::duration_type>::type TokenRateX< P >::ticks_type

Unsigned type of tick counts (differences between time points).

Constructor & Destructor Documentation

◆ TokenRateX() [1/3]

template<typename P >
TokenRateX< P >::TokenRateX ( )
inline

Construct an idle token rate.

◆ TokenRateX() [2/3]

template<typename P >
TokenRateX< P >::TokenRateX ( bool  unlimited)
inlineexplicit

Construct an idle or unlimited token rate.

Parameters
unlimitedidle if false, unlimited if true

◆ TokenRateX() [3/3]

template<typename P >
TokenRateX< P >::TokenRateX ( token_type  rate,
token_type  capacity 
)
inline

Construct a token rate representing rate.

Parameters
raterefill rate in tokens per period
capacitymaximum token accumulation

The rate is idle if either rate or capacity is 0.

See also
assign(rate, capacity)

Member Function Documentation

◆ assign() [1/2]

template<typename P >
void TokenRateX< P >::assign ( bool  unlimited = false)
inline

Set the token rate to idle or unlimited.

Parameters
unlimitedidle if false, unlimited if true

◆ assign() [2/2]

template<typename P >
void TokenRateX< P >::assign ( token_type  rate,
token_type  capacity 
)
inline

Set the token rate and capacity.

Parameters
raterefill rate in tokens per period
capacitymaximum 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.

◆ unlimited()

template<typename P >
bool TokenRateX< P >::unlimited ( ) const
inline

Return true iff the token rate is unlimited.

◆ idle()

template<typename P >
bool TokenRateX< P >::idle ( ) const
inline

Return true iff the token rate is idle.

◆ rate()

template<typename P >
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.

◆ capacity()

template<typename P >
token_type TokenRateX< P >::capacity ( ) const
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.

◆ tokens_per_tick()

template<typename P >
token_type TokenRateX< P >::tokens_per_tick ( ) const
inline

Return the number of tokens per tick.

◆ token_scale()

template<typename P >
token_type TokenRateX< P >::token_scale ( ) const
inline

Return the ratio of fractional tokens to real tokens.

◆ time_until_full()

template<typename P >
ticks_type TokenRateX< P >::time_until_full ( ) const
inline

Return the number of ticks required to refill a counter to capacity.

Returns (ticks_type) -1 for idle rates.

◆ now()

template<typename P >
time_point_type TokenRateX< P >::now ( ) const
inline

Return the current time point.

Implemented as P::now().

◆ time_point()

template<typename P >
template<typename U >
time_point_type TokenRateX< P >::time_point ( U  time) const
inline

Return the time point corresponding to the time parameter.

May not be available for all U types. Implemented as P::time_point(time).

◆ time_monotonic_difference()

template<typename P >
ticks_type TokenRateX< P >::time_monotonic_difference ( time_point_type  a,
time_point_type  b 
) const
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).


The documentation for this class was generated from the following file: