]> mj.ucw.cz Git - libucw.git/blob - ucw/tbf.h
tableprinter: return value of table_set_col_opt changed to int
[libucw.git] / ucw / tbf.h
1 /*
2  *      UCW Library -- Rate Limiting based on the Token Bucket Filter
3  *
4  *      (c) 2009 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #ifndef _UCW_TBF_H_
11 #define _UCW_TBF_H_
12
13 #ifdef CONFIG_UCW_CLEAN_ABI
14 #define tbf_init ucw_tbf_init
15 #define tbf_limit ucw_tbf_limit
16 #endif
17
18 /** A data structure describing a single TBF. **/
19 struct token_bucket_filter {
20   double rate;                          // Number of tokens received per second
21   uint burst;                           // Capacity of the bucket
22   timestamp_t last_hit;                 // Internal state...
23   double bucket;
24   uint drop_count;
25 };
26
27 /** Initialize the bucket. **/
28 void tbf_init(struct token_bucket_filter *f);
29
30 /**
31  * Ask the filter to process a single event. Returns a negative number
32  * if the event exceeds the rate (and should be dropped) and a non-negative
33  * number if the event passes the filter.
34  * The absolute value of the result is the number of dropped events
35  * since the last passed event.
36  **/
37 int tbf_limit(struct token_bucket_filter *f, timestamp_t now);
38
39 #endif