int changed = 0;
if (new && old)
/* count of exported routes stays the same */
- log(L_INFO "nothing happen - no change of counter");
else if (!old)
{
- log(L_INFO "increasing _counter");
ch->_counter++;
changed = 1;
- if (ch->_counter > 100)
- log(L_INFO "underflow?");
}
else if (!new)
{
- log(L_INFO "decreasing _counter");
ch->_counter--;
changed = 1;
- if (ch->_counter > 100)
- log(L_INFO "underflow? - ");
}
else /* shouldn't happen */
{
- log(L_INFO "BUG is here !!!");
bug("Both pointers *new and *old in rt_notify are NULL");
}
- log(L_INFO "stats channel %s: preparing to kick the timer %d", src_ch->name,
-changed);
if (changed)
{
- settle_timer_changed(ch->settle_timer);
- kick_settle_timer(ch->settle_timer);
+ settle_timer_changed(&ch->settle_timer);
+ kick_settle_timer(&ch->settle_timer);
}
}
static struct proto *
stats_init(struct proto_config *CF)
{
- log(L_INFO "stats_init() ");
struct proto *P = proto_new(CF);
struct stats_proto *p = (void *) P;
return P;
}
-static struct settle_timer_class stats_settle_class = {
- .action = stats_settle_timer,
- .kick = NULL,
-};
-
static void
stats_configure_channels(struct proto *P, struct proto_config *CF)
{
- log(L_INFO "stats_configure_channels()");
struct channel_config *cc;
WALK_LIST(cc, CF->channels)
{
static int
stats_start(struct proto *P)
{
- log(L_INFO "stats_start() ");
stats_configure_channels(P, P->cf);
+ /* evaluate terms on protocol start */
struct stats_term_config *tc;
WALK_LIST(tc, ((struct stats_config *) P->cf)->terms)
{
- log(L_INFO "term %s", tc->name);
- f_eval(tc->code, &tc->val);
- log(L_INFO "content: %s, matches %s", val_dump(&tc->val),
- tc->type == tc->val.type ? "yes" : "no");
+ stats_eval_term(tc);
}
return PS_UP;
struct stats_channel *sc = (void *) c;
struct stats_channel_config *scc = (void *) cc;
- sc->settle_timer->min_settle_time = &(scc->min_settle_time);
- sc->settle_timer->max_settle_time = &(scc->max_settle_time);
+ sc->settle_timer.min_settle_time = scc->min_settle_time;
+ sc->settle_timer.max_settle_time = scc->max_settle_time;
if (sc->counter != sc->_counter)
{
sc->_counter);
if (!P->disabled)
{
- cli_msg(-1006, " Settle time: %4u s", (*(sc->settle_timer->min_settle_time)) TO_S);
- cli_msg(-1006, " Settle time: %4u s", (*(sc->settle_timer->max_settle_time)) TO_S);
+ cli_msg(-1006, " Settle time: %4u s", sc->settle_timer.min_settle_time TO_S);
+ cli_msg(-1006, " Settle time: %4u s", sc->settle_timer.max_settle_time TO_S);
}
}
cli_msg(-1006, " Terms:");
- cli_msg(-1006, "terms list: %p", ((struct stats_config *) p->c)->terms);
+
+ struct stats_term_config *tc;
+ WALK_LIST(tc, ((struct stats_config *) P->cf)->terms)
+ {
+ stats_eval_term(tc);
+ cli_msg(-1006, " %s = %s", tc->name, val_dump(tc->val));
+ }
}
void
static void
stats_settle_timer(struct settle_timer *st)
{
- timer *t = (void *) st;
- struct stats_channel *c = t->data;
- log(L_INFO "stats_settle_timer() _counter: %u, counter: %u",
- c->_counter, c->counter);
+ struct stats_channel *c = st->settle_data;
/* update only if real change happen */
if (c->counter != c->_counter)
c->pool = p->p.pool;
- if (!c->settle_timer)
- c->settle_timer = stm_new_timer(
- c->pool, (void *) c, &stats_settle_class);
+ stm_init(&c->settle_timer, c->pool, (void *)c, stats_settle_timer);
- c->settle_timer->min_settle_time = &(cc->min_settle_time);
- c->settle_timer->max_settle_time = &(cc->max_settle_time);
+ c->settle_timer.min_settle_time = cc->min_settle_time;
+ c->settle_timer.max_settle_time = cc->max_settle_time;
c->_counter = 0;
c->counter = 0;
static void
stats_channel_shutdown(struct channel *C)
{
- log(L_INFO "stats_channel_shutdown()");
struct stats_channel *c = (void *) C;
- tm_stop((timer *) c->settle_timer);
-
- c->settle_timer->min_settle_time = NULL;
- c->settle_timer->max_settle_time = NULL;
-
- mb_free(c->settle_timer);
- c->settle_timer = NULL;
+ tm_stop(c->settle_timer.t);
c->_counter = 0;
c->counter = 0;
return 0;
}
-struct f_val
-stats_eval_term(struct stats_term_config *tc)
+void stats_eval_term(struct stats_term_config *tc)
{
- log(L_INFO "stats_eval_term() evaluating value of %s",
- tc->name);
- enum filter_return fret = f_eval(tc->code, &tc->val);
-
- if (fret > F_RETURN)
- tc->val.type = T_VOID;
-
- if (tc->type != tc->val.type)
- tc->val.type = T_VOID;
-
- log(L_INFO " stats_eval_term() returning %s", val_dump(&tc->val));
- return tc->val;
-}
-
-int
-stats_get_type(struct stats_term_config *tc)
-{
- log(L_INFO "stats_get_type()");
- return tc->type;
+ f_eval(tc->code, tc->val);
}
-
struct channel_class channel_stats = {
.channel_size = sizeof(struct stats_channel),
.config_size = sizeof(struct stats_channel_config),
struct stats_term_config {
node n;
const struct f_line *code;
- struct f_val val;
+ struct f_val *val;
int type; /* type declared in configuration */
const char *name;
};
pool *pool; /* copy of procotol pool */
u32 _counter; /* internal counter */
u32 counter; /* publicly accessible counter */
- struct settle_timer *settle_timer;
+ struct settle_timer settle_timer;
};
struct stats_channel_config {
};
int stats_get_counter(struct symbol *sym);
-struct f_val stats_eval_term(struct stats_term_config *tc);
-int stats_get_type(struct stats_term_config *tc);
-
-#if 0
-/*
- * get_stats_counter() - extract last notified counter
- * for specific stats channel if it runs
- *
- */
-inline int
-stats_get_counter(struct symbol *sym)
-{
- if (sym->ch_config->channel)
- return (int) ((struct stats_channel *) sym->ch_config->channel)->counter;
- else
- return 0;
-}
-
-/*
- * stats_eval_term() - evaluate stats term
- *
- */
-inline struct f_val
-stats_eval_term(struct stats_term_config *tc)
-{
- enum filter_return fret = f_eval(tc->code, &tc->val);
-
- if (fret > F_RETURN)
- tc->val.type = T_VOID;
-
- if (tc->type != tc->val.type)
- tc->val.type = T_VOID;
-
- return tc->val;
-}
-
-int
-stats_get_type(struct stats_term_config *tc)
-{
- return tc->type;
-}
-
-#endif // if 0
+void stats_eval_term(struct stats_term_config *tc);
#endif