mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-11-08 12:18:42 +00:00
Settle timer revised version
Settle timer now doesn't inherit from timer and is meant to be embeded in other structures.
This commit is contained in:
parent
cbaf6bd630
commit
c4fdf63482
40
lib/timer.c
40
lib/timer.c
@ -386,11 +386,9 @@ static inline btime
|
||||
settled_time(struct settle_timer *st)
|
||||
{
|
||||
ASSUME(st->base_settle_time != 0);
|
||||
if (st->base_settle_time + *(st->max_settle_time) <
|
||||
st->last_change + *(st->min_settle_time))
|
||||
log(L_INFO "settle_timer will be triggered by MAX SETTLE TIME");
|
||||
return MIN_(st->last_change + *(st->min_settle_time),
|
||||
st->base_settle_time + *(st->max_settle_time));
|
||||
|
||||
return MIN_(st->last_change + st->min_settle_time,
|
||||
st->base_settle_time + st->max_settle_time);
|
||||
}
|
||||
|
||||
inline void
|
||||
@ -402,7 +400,7 @@ settle_timer_changed(struct settle_timer *st)
|
||||
void
|
||||
settle_timer(timer *t)
|
||||
{
|
||||
struct settle_timer *st = (void *) t;
|
||||
struct settle_timer *st = t->data;
|
||||
|
||||
if (!st->base_settle_time)
|
||||
return;
|
||||
@ -410,31 +408,29 @@ settle_timer(timer *t)
|
||||
btime settled_t = settled_time(st);
|
||||
if (current_time() < settled_t)
|
||||
{
|
||||
tm_set((timer *) st, settled_t);
|
||||
tm_set(t, settled_t);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Settled */
|
||||
st->base_settle_time = 0;
|
||||
|
||||
if (st->class->action)
|
||||
st->class->action(st);
|
||||
/* t->hook already occupied by settle_timer() */
|
||||
if (st->settle_hook)
|
||||
st->settle_hook(st);
|
||||
}
|
||||
|
||||
struct settle_timer *
|
||||
stm_new_timer(pool *p, void *data, struct settle_timer_class *class)
|
||||
void
|
||||
stm_init(struct settle_timer *st, pool *p, void *data,
|
||||
void (*settle_hook)(struct settle_timer *st))
|
||||
{
|
||||
struct settle_timer *st;
|
||||
st = mb_allocz(p, sizeof(struct settle_timer));
|
||||
st->class = class;
|
||||
st->t = tm_new_init(p, (void *) st, settle_timer, 0, 0);
|
||||
st->t->hook = settle_timer;
|
||||
st->t->data = (void *) st;
|
||||
|
||||
/* timer option randomize and recurrent are set to zero */
|
||||
timer *t = (void *) st;
|
||||
t->index = -1;
|
||||
t->hook = settle_timer;
|
||||
t->data = data;
|
||||
|
||||
return st;
|
||||
st->settle_data = data;
|
||||
st->settle_hook = settle_hook;
|
||||
}
|
||||
|
||||
void
|
||||
@ -444,7 +440,7 @@ kick_settle_timer(struct settle_timer *st)
|
||||
|
||||
st->base_settle_time = current_time();
|
||||
|
||||
timer *t = (void *) st;
|
||||
timer *t = st->t;
|
||||
if (!tm_active(t))
|
||||
tm_set(t, settled_time(st));
|
||||
}
|
||||
|
17
lib/timer.h
17
lib/timer.h
@ -129,21 +129,16 @@ int tm_format_real_time(char *x, size_t max, const char *fmt, btime t);
|
||||
*/
|
||||
|
||||
struct settle_timer {
|
||||
timer tm;
|
||||
btime *min_settle_time;
|
||||
btime *max_settle_time;
|
||||
btime min_settle_time;
|
||||
btime max_settle_time;
|
||||
btime base_settle_time;
|
||||
btime last_change;
|
||||
const struct settle_timer_class *class;
|
||||
timer *t;
|
||||
void (*settle_hook)(struct settle_timer *t);
|
||||
void *settle_data;
|
||||
};
|
||||
|
||||
struct settle_timer_class {
|
||||
void (*action)(struct settle_timer *st);
|
||||
void (*changed)(struct settle_timer *st);
|
||||
void (*kick)(struct settle_timer *st);
|
||||
};
|
||||
|
||||
struct settle_timer *stm_new_timer(pool *p, void *data, struct settle_timer_class *class);
|
||||
void stm_init(struct settle_timer *st, pool *p, void *data, void (*settle_hook)(struct settle_timer *st));
|
||||
void kick_settle_timer(struct settle_timer *st);
|
||||
void settle_timer_changed(struct settle_timer *st);
|
||||
|
||||
|
@ -1365,7 +1365,7 @@ rte_recalculate(struct rt_import_hook *c, net *net, rte *new, struct rte_src *sr
|
||||
stats->withdraws_ignored++;
|
||||
|
||||
if (old_ok || new_ok)
|
||||
settle_timer_changed(table->settle_timer);
|
||||
settle_timer_changed(&table->settle_timer);
|
||||
|
||||
if (table->config->sorted)
|
||||
{
|
||||
@ -2019,7 +2019,7 @@ rt_dump_hooks(rtable *tab)
|
||||
debug(" nhu_state=%u hcu_scheduled=%u use_count=%d rt_count=%u\n",
|
||||
tab->nhu_state, tab->hcu_scheduled, tab->use_count, tab->rt_count);
|
||||
debug(" last_rt_change=%t gc_time=%t gc_counter=%d prune_state=%u\n",
|
||||
tab->settle_timer->last_change, tab->gc_time, tab->gc_counter, tab->prune_state);
|
||||
tab->settle_timer.last_change, tab->gc_time, tab->gc_counter, tab->prune_state);
|
||||
|
||||
struct rt_import_hook *ih;
|
||||
WALK_LIST(ih, tab->imports)
|
||||
@ -2136,29 +2136,23 @@ rt_kick_prune_timer(rtable *tab)
|
||||
static void
|
||||
rt_settle_timer(struct settle_timer *st)
|
||||
{
|
||||
timer *t = (void *) st;
|
||||
rtable *tab = t->data;
|
||||
rtable *tab = st->settle_data;
|
||||
|
||||
struct rt_subscription *s;
|
||||
WALK_LIST(s, tab->subscribers)
|
||||
s->hook(s);
|
||||
}
|
||||
|
||||
static struct settle_timer_class rt_settle_class = {
|
||||
.action = rt_settle_timer,
|
||||
.kick = NULL,
|
||||
};
|
||||
|
||||
static inline void
|
||||
rt_schedule_notify(rtable *tab)
|
||||
{
|
||||
if (EMPTY_LIST(tab->subscribers))
|
||||
return;
|
||||
|
||||
if (tab->settle_timer->base_settle_time)
|
||||
if (tab->settle_timer.base_settle_time)
|
||||
return;
|
||||
|
||||
kick_settle_timer(tab->settle_timer);
|
||||
kick_settle_timer(&tab->settle_timer);
|
||||
}
|
||||
|
||||
void
|
||||
@ -2344,9 +2338,9 @@ rt_setup(pool *pp, struct rtable_config *cf)
|
||||
|
||||
t->rt_event = ev_new_init(p, rt_event, t);
|
||||
t->prune_timer = tm_new_init(p, rt_prune_timer, t, 0, 0);
|
||||
t->settle_timer = stm_new_timer(p, t, &rt_settle_class);
|
||||
stm_init(&t->settle_timer, p, t, rt_settle_timer);
|
||||
|
||||
settle_timer_changed(t->settle_timer);
|
||||
settle_timer_changed(&t->settle_timer);
|
||||
t->gc_time = current_time();
|
||||
|
||||
t->rl_pipe = (struct tbf) TBF_DEFAULT_LOG_LIMITS;
|
||||
|
@ -106,7 +106,7 @@ typedef struct rtable {
|
||||
struct tbf rl_pipe; /* Rate limiting token buffer for pipe collisions */
|
||||
|
||||
list subscribers; /* Subscribers for notifications */
|
||||
struct settle_timer *settle_timer; /* Settle time for notifications */
|
||||
struct settle_timer settle_timer; /* Settle time for notifications */
|
||||
list flowspec_links; /* List of flowspec links, src for NET_IPx and dst for NET_FLOWx */
|
||||
struct f_trie *flowspec_trie; /* Trie for evaluation of flowspec notifications */
|
||||
} rtable;
|
||||
|
Loading…
Reference in New Issue
Block a user