From b53d8694056b87fb25a47bcca6b1952f95011a9c Mon Sep 17 00:00:00 2001 From: Vojtech Vilimek Date: Thu, 14 Jul 2022 17:08:03 +0200 Subject: [PATCH] Add statistics of export route (per protocol) --- proto/stats/stats.c | 52 +++++++++++++++++++++++++++++++++++++++------ proto/stats/stats.h | 3 ++- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/proto/stats/stats.c b/proto/stats/stats.c index 8f240710..e8b4e7a1 100644 --- a/proto/stats/stats.c +++ b/proto/stats/stats.c @@ -1,5 +1,5 @@ /* - * BIRD -- Table-to-Table Routing Protocol a.k.a Pipe + * BIRD -- Statistics Protocol * * (c) 2022 Vojtech Vilimek * (c) 2022 CZ.NIC z.s.p.o. @@ -33,12 +33,33 @@ static void stats_rt_notify(struct proto *P, struct channel *src_ch, const net_addr *n, rte *new, const rte *old) { struct stats_proto *p = (void *) P; + log(L_INFO "stats_rf_notify()"); + + if (new && old) + { + new->generation = old->generation + 1; + p->counters[old->generation]--; + p->counters[new->generation]++; + log(L_INFO "counter %u increased", new->generation); + } + else if (new && !old) + { + new->generation = 0; + p->counters[0]++; + log(L_INFO "counter 0 increased"); + } + else if (!new && old) + { + (p->counters[old->generation])--; + log(L_INFO "counter %u decreased", old->generation); + } } static int stats_preexport(struct channel *c, rte *e) { struct stats_proto *p = (void *) c->proto; + log(L_INFO "stats_preexport()"); return 0; } @@ -59,6 +80,7 @@ stats_init(struct proto_config *CF) struct proto *P = proto_new(CF); struct stats_proto *p = (void *) P; struct stats_config *cf = (void *) CF; + log(L_INFO "stats_init()"); P->rt_notify = stats_rt_notify; P->preexport = stats_preexport; @@ -76,6 +98,17 @@ stats_init(struct proto_config *CF) return P; } +static int +stats_start(struct proto *P) +{ + struct stats_proto *p = (struct stats_proto *) P; + log(L_INFO "stats_start() "); + + p->counters = (u32 *) mb_allocz(p->p.pool, 256 * sizeof(u32)); + + return PS_UP; +} + static int stats_reconfigure(struct proto *P, struct proto_config *CF) { @@ -98,17 +131,21 @@ stats_get_status(struct proto *P, byte *buf) struct stats_proto *p = (void *) P; } -static void -stats_show_stats(struct stats_proto *p) -{ - -} - static void stats_show_proto_info(struct proto *P) { struct stats_proto *p = (void *) P; + cli_msg(-1006, " Counters contents "); + for (int i = 0; i < 64; i++) + { + cli_msg(-1006, "%3u: %10u | %3u: %10u | %3u: %10u | %3u: %10u", + i , *(p->counters + i), + (i + 64 ), *(p->counters + i + 64), + (i + 128), *(p->counters + i + 128), + (i + 192), *(p->counters + i + 192) + ); + } } void @@ -127,6 +164,7 @@ struct protocol proto_stats = { .proto_size = sizeof(struct stats_proto), .config_size = sizeof(struct stats_config), .init = stats_init, + .start = stats_start, .reconfigure = stats_reconfigure, .copy_config = stats_copy_config, .get_status = stats_get_status, diff --git a/proto/stats/stats.h b/proto/stats/stats.h index 6d448d4b..a03c221f 100644 --- a/proto/stats/stats.h +++ b/proto/stats/stats.h @@ -1,5 +1,5 @@ /* - * BIRD -- Table-to-Table Routing Protocol a.k.a Pipe + * BIRD -- Statistics Protocol * * (c) 2022 Vojtech Vilimek * (c) 2022 CZ.NIC z.s.p.o. @@ -20,6 +20,7 @@ struct stats_proto { struct proto p; struct channel *c; struct tbf rl_gen; + u32 *counters; }; #endif