]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Add new global counter for stats channel
authorVojtech Vilimek <vojtech.vilimek@nic.cz>
Wed, 20 Jul 2022 15:04:49 +0000 (17:04 +0200)
committerVojtech Vilimek <vojtech.vilimek@nic.cz>
Wed, 20 Jul 2022 15:04:49 +0000 (17:04 +0200)
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!

conf/conf.h
filter/config.Y
filter/f-inst.c
filter/filter.c
proto/stats/config.Y
proto/stats/stats.h

index 4ccaa54e923c8d34352bc6a78027b1089a92bae1..d193155bd890b0b2d14d79bf44f9b74ff352013b 100644 (file)
@@ -124,6 +124,7 @@ struct symbol {
     struct ea_class *attribute;                /* For SYM_ATTRIBUTE */
     struct f_val *val;                 /* For SYM_CONSTANT */
     uint offset;                       /* For SYM_VARIABLE */
+    struct channel_config *ch_config;  /* For SYM_COUNTER */
   };
 
   char name[0];
@@ -156,6 +157,7 @@ struct bytestring {
 #define SYM_FILTER 4
 #define SYM_TABLE 5
 #define SYM_ATTRIBUTE 6
+#define SYM_COUNTER 7
 
 #define SYM_VARIABLE 0x100     /* 0x100-0x1ff are variable types */
 #define SYM_VARIABLE_RANGE SYM_VARIABLE ... (SYM_VARIABLE | 0xff)
index 8cecf9361442be23b36ce5e5c1c5d9f7908553ed..23b258cd9e1fd66f01152b6374613fd799111661 100644 (file)
@@ -758,6 +758,9 @@ symbol_value: symbol_known
       case SYM_ATTRIBUTE:
        $$ = f_new_inst(FI_EA_GET, $1->attribute);
        break;
+      case SYM_COUNTER:
+       $$ = f_new_inst(FI_COUNTER, $1);
+       break;
       default:
        cf_error("Can't get value of symbol %s", $1->name);
     }
index e7b642abfff422fbaac59dbcfec6ad846851bd3f..4dfd276b0b39565f8518ac5f6804de1097ad6d26 100644 (file)
     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) {
     FID_MEMBER(
       struct f_val,
index ad2fafe215f71aaa1833921f80510f65bbab7bcf..bd65777f34820eb63431bcbffe05e86d29f54b43 100644 (file)
@@ -43,6 +43,7 @@
 #include "filter/filter.h"
 #include "filter/f-inst.h"
 #include "filter/data.h"
+#include "proto/stats/stats.h"  /* provides function get_stats_sum used in f-inst.c */
 
 
 /* Exception bits */
index b32ea773a2074b9fd13d990ad6d1cb38d1b654d9..087ac75ae4d330867f7b84ab1f386771e693da0b 100644 (file)
@@ -61,6 +61,9 @@ stats_channel_start: net_type symbol
 {
   this_channel = channel_config_get(&channel_stats, $2->name, $1, this_proto);
   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:
index 51802341cceed27c28282e8aeb80468e94cfe395..d061e4eaf459f2584bdd58423adc96cfdac82b07 100644 (file)
@@ -35,6 +35,13 @@ struct stats_channel_config {
   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