0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-23 02:01:55 +00:00

Add new global counter for stats channel

New symbol is added for each stats protocol channel, the symbol is accessed by
same name as the underlying channel. Symbols evaluate to the sum of all routes
exported from connected table with generation less than max generation of
particular channel. Default max generation is 16.

Beware you shouldn't make cyclic references as the behavior of such
configuration is not defined!
This commit is contained in:
Vojtech Vilimek 2022-07-20 17:04:49 +02:00
parent 3c8e00c688
commit 727a8f32c4
6 changed files with 23 additions and 1 deletions

View File

@ -124,6 +124,7 @@ struct symbol {
struct ea_class *attribute; /* For SYM_ATTRIBUTE */ struct ea_class *attribute; /* For SYM_ATTRIBUTE */
struct f_val *val; /* For SYM_CONSTANT */ struct f_val *val; /* For SYM_CONSTANT */
uint offset; /* For SYM_VARIABLE */ uint offset; /* For SYM_VARIABLE */
struct channel_config *ch_config; /* For SYM_COUNTER */
}; };
char name[0]; char name[0];
@ -156,6 +157,7 @@ struct bytestring {
#define SYM_FILTER 4 #define SYM_FILTER 4
#define SYM_TABLE 5 #define SYM_TABLE 5
#define SYM_ATTRIBUTE 6 #define SYM_ATTRIBUTE 6
#define SYM_COUNTER 7
#define SYM_VARIABLE 0x100 /* 0x100-0x1ff are variable types */ #define SYM_VARIABLE 0x100 /* 0x100-0x1ff are variable types */
#define SYM_VARIABLE_RANGE SYM_VARIABLE ... (SYM_VARIABLE | 0xff) #define SYM_VARIABLE_RANGE SYM_VARIABLE ... (SYM_VARIABLE | 0xff)

View File

@ -758,6 +758,9 @@ symbol_value: symbol_known
case SYM_ATTRIBUTE: case SYM_ATTRIBUTE:
$$ = f_new_inst(FI_EA_GET, $1->attribute); $$ = f_new_inst(FI_EA_GET, $1->attribute);
break; break;
case SYM_COUNTER:
$$ = f_new_inst(FI_COUNTER, $1);
break;
default: default:
cf_error("Can't get value of symbol %s", $1->name); cf_error("Can't get value of symbol %s", $1->name);
} }

View File

@ -473,6 +473,12 @@
RESULT_VAL(fstk->vstk[curline.vbase + sym->offset]); RESULT_VAL(fstk->vstk[curline.vbase + sym->offset]);
} }
INST(FI_COUNTER, 0, 1) {
SYMBOL;
NEVER_CONSTANT;
RESULT(T_INT, i, get_stats_sum(sym));
}
INST(FI_CONSTANT, 0, 1) { INST(FI_CONSTANT, 0, 1) {
FID_MEMBER( FID_MEMBER(
struct f_val, struct f_val,

View File

@ -43,6 +43,7 @@
#include "filter/filter.h" #include "filter/filter.h"
#include "filter/f-inst.h" #include "filter/f-inst.h"
#include "filter/data.h" #include "filter/data.h"
#include "proto/stats/stats.h" /* provides function get_stats_sum used in f-inst.c */
/* Exception bits */ /* Exception bits */

View File

@ -61,6 +61,9 @@ stats_channel_start: net_type symbol
{ {
this_channel = channel_config_get(&channel_stats, $2->name, $1, this_proto); this_channel = channel_config_get(&channel_stats, $2->name, $1, this_proto);
STATS_CC->max_generation = 16; STATS_CC->max_generation = 16;
/* from filter/config.Y:
cf_define_symbol($3, SYM_VARIABLE | $2, offset, $3->scope->slots++) */
$2 = cf_define_symbol($2, SYM_COUNTER, ch_config, this_channel);
} }
stats_proto: stats_proto:

View File

@ -35,6 +35,13 @@ struct stats_channel_config {
u8 max_generation; u8 max_generation;
}; };
static inline int
get_stats_sum(struct symbol *sym)
{
if (sym->ch_config->channel)
return (int) ((struct stats_channel *) sym->ch_config->channel)->sum;
else
return 0;
}
#endif #endif