1
0
mirror of https://gitlab.labs.nic.cz/labs/bird.git synced 2024-05-11 16:54:54 +00:00

Timers: Fix TBF and some last remains

This commit is contained in:
Ondrej Zajicek (work)
2017-11-28 17:06:10 +01:00
parent 3b3b0910ff
commit 574b232427
11 changed files with 45 additions and 50 deletions

View File

@@ -69,7 +69,7 @@ static inline int u64_cmp(u64 i1, u64 i2)
/* Microsecond time */
typedef s64 btime;
typedef s64 bird_clock_t;
//typedef s64 bird_clock_t;
#define S_ * (btime) 1000000
#define MS_ * (btime) 1000
@@ -85,37 +85,23 @@ typedef s64 bird_clock_t;
#define NS /1000
#endif
#define TIME_INFINITY ((s64) 0x7fffffffffffffff)
/* Rate limiting */
struct tbf {
bird_clock_t timestamp; /* Last update */
u16 count; /* Available tokens */
btime timestamp; /* Last update */
u64 count; /* Available micro-tokens */
u16 burst; /* Max number of tokens */
u16 rate; /* Rate of replenishment */
u16 mark; /* Whether last op was limited */
u16 rate; /* Rate of replenishment (tokens / sec) */
u32 drop; /* Number of failed request since last successful */
};
/* Default TBF values for rate limiting log messages */
#define TBF_DEFAULT_LOG_LIMITS { .rate = 1, .burst = 5 }
void tbf_update(struct tbf *f);
static inline int
tbf_limit(struct tbf *f)
{
tbf_update(f);
if (!f->count)
{
f->mark = 1;
return 1;
}
f->count--;
f->mark = 0;
return 0;
}
int tbf_limit(struct tbf *f);
/* Logging and dying */