2022-07-13 13:39:14 +00:00
|
|
|
/*
|
2022-07-14 15:08:03 +00:00
|
|
|
* BIRD -- Statistics Protocol
|
2022-07-13 13:39:14 +00:00
|
|
|
*
|
2022-07-14 12:51:03 +00:00
|
|
|
* (c) 2022 Vojtech Vilimek <vojtech.vilimek@nic.cz>
|
|
|
|
* (c) 2022 CZ.NIC z.s.p.o.
|
2022-07-13 13:39:14 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BIRD_STATS_H_
|
|
|
|
#define _BIRD_STATS_H_
|
2022-07-26 12:54:22 +00:00
|
|
|
#include "lib/timer.h"
|
2022-07-27 11:21:47 +00:00
|
|
|
#include "filter/data.h"
|
2022-07-13 13:39:14 +00:00
|
|
|
|
2022-07-19 08:21:43 +00:00
|
|
|
struct stats_channel;
|
|
|
|
|
2022-07-27 11:21:47 +00:00
|
|
|
struct stats_term_config {
|
|
|
|
node n;
|
|
|
|
const struct f_line *code;
|
|
|
|
struct f_val val;
|
|
|
|
int type; /* type declared in configuration */
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
2022-07-13 13:39:14 +00:00
|
|
|
struct stats_config {
|
|
|
|
struct proto_config c;
|
2022-07-27 11:21:47 +00:00
|
|
|
list terms; /* list of counter terms */
|
2022-07-13 13:39:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct stats_proto {
|
|
|
|
struct proto p;
|
2022-07-19 08:21:43 +00:00
|
|
|
struct stats_channel *c;
|
2022-07-13 13:39:14 +00:00
|
|
|
struct tbf rl_gen;
|
2022-07-19 08:21:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct stats_channel {
|
|
|
|
struct channel c;
|
2022-07-26 12:54:22 +00:00
|
|
|
pool *pool; /* copy of procotol pool */
|
|
|
|
u32 _counter; /* internal counter */
|
|
|
|
u32 counter; /* publicly accessible counter */
|
|
|
|
struct settle_timer *settle_timer;
|
2022-07-13 13:39:14 +00:00
|
|
|
};
|
|
|
|
|
2022-07-19 08:21:43 +00:00
|
|
|
struct stats_channel_config {
|
|
|
|
struct channel_config c;
|
2022-07-26 12:54:22 +00:00
|
|
|
btime min_settle_time; /* wait before notifying filters */
|
|
|
|
btime max_settle_time;
|
2022-07-19 08:21:43 +00:00
|
|
|
};
|
|
|
|
|
2022-07-27 11:21:47 +00:00
|
|
|
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
|
2022-07-26 12:54:22 +00:00
|
|
|
/*
|
|
|
|
* get_stats_counter() - extract last notified counter
|
|
|
|
* for specific stats channel if it runs
|
|
|
|
*
|
|
|
|
*/
|
2022-07-27 11:21:47 +00:00
|
|
|
inline int
|
|
|
|
stats_get_counter(struct symbol *sym)
|
2022-07-20 15:04:49 +00:00
|
|
|
{
|
|
|
|
if (sym->ch_config->channel)
|
2022-07-26 12:54:22 +00:00
|
|
|
return (int) ((struct stats_channel *) sym->ch_config->channel)->counter;
|
2022-07-20 15:04:49 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
2022-07-20 13:01:41 +00:00
|
|
|
|
2022-07-27 11:21:47 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2022-07-13 13:39:14 +00:00
|
|
|
#endif
|