X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Ftbf.h;h=7f0d09cf048f0490ffba098eb96cb53aa2c51c68;hb=8c23d507cbb0af5452d6d4e16b1750adfbb7d28d;hp=141547913f9cc2459f99bbd602caa55bb1ceab65;hpb=16f04029db50b765d952cf4cf053d34262a40db1;p=libucw.git diff --git a/ucw/tbf.h b/ucw/tbf.h index 14154791..7f0d09cf 100644 --- a/ucw/tbf.h +++ b/ucw/tbf.h @@ -10,14 +10,25 @@ #ifndef _UCW_TBF_H_ #define _UCW_TBF_H_ +/** A data structure describing a single TBF. **/ struct token_bucket_filter { - double rate; // Number of tokens per second + double rate; // Number of tokens received per second uns burst; // Capacity of the bucket timestamp_t last_hit; // Internal state... double bucket; + uns drop_count; }; +/** Initialize the bucket. **/ void tbf_init(struct token_bucket_filter *f); + +/** + * Ask the filter to process a single event. Returns a negative number + * if the event exceeds the rate (and should be dropped) and a non-negative + * number if the event passes the filter. + * The absolute value of the result is the number of dropped events + * since the last passed event. + **/ int tbf_limit(struct token_bucket_filter *f, timestamp_t now); #endif