From dcf0038fd00d0f17c1e9c3e5046a8ce38747196d Mon Sep 17 00:00:00 2001 From: Igor Putovny Date: Fri, 5 Jan 2024 13:48:02 +0100 Subject: [PATCH] Run correct aggregation (by nets or by attributes) according to configuration --- proto/aggregator/aggregator.c | 20 +++++++++++++------- proto/aggregator/aggregator.h | 2 ++ proto/aggregator/config.Y | 5 +++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/proto/aggregator/aggregator.c b/proto/aggregator/aggregator.c index 41afa0ff0..461fb9082 100644 --- a/proto/aggregator/aggregator.c +++ b/proto/aggregator/aggregator.c @@ -65,6 +65,8 @@ extern linpool *rte_update_pool; +static void aggregator_bucket_update(struct aggregator_proto *p, struct aggregator_bucket *bucket, struct network *net); + static inline int is_leaf(const struct trie_node *node) { @@ -1332,14 +1334,17 @@ aggregator_rt_notify(struct proto *P, struct channel *src_ch, net *net, rte *new } HASH_WALK_END; - ev_schedule(&p->reload_trie); - - /* Announce changes */ - if (old_bucket) - aggregator_bucket_update(p, old_bucket, net); + if (p->net_present == 0) + ev_schedule(&p->reload_trie); + else + { + /* Announce changes */ + if (old_bucket) + aggregator_bucket_update(p, old_bucket, net); - if (new_bucket && (new_bucket != old_bucket)) - aggregator_bucket_update(p, new_bucket, net); + if (new_bucket && (new_bucket != old_bucket)) + aggregator_bucket_update(p, new_bucket, net); + } /* Cleanup the old bucket if empty */ if (old_bucket && (!old_bucket->rte || !old_bucket->count)) @@ -1403,6 +1408,7 @@ aggregator_init(struct proto_config *CF) p->aggr_on_count = cf->aggr_on_count; p->aggr_on_da_count = cf->aggr_on_da_count; p->aggr_on = cf->aggr_on; + p->net_present = cf->net_present; p->merge_by = cf->merge_by; P->rt_notify = aggregator_rt_notify; diff --git a/proto/aggregator/aggregator.h b/proto/aggregator/aggregator.h index 22638ac21..b2fd01551 100644 --- a/proto/aggregator/aggregator.h +++ b/proto/aggregator/aggregator.h @@ -25,6 +25,7 @@ struct aggregator_config { uint aggr_on_count; uint aggr_on_da_count; struct aggr_item *aggr_on; + int net_present; const struct f_line *merge_by; }; @@ -59,6 +60,7 @@ struct aggregator_proto { uint aggr_on_count; uint aggr_on_da_count; struct aggr_item *aggr_on; + int net_present; /* Merge filter */ const struct f_line *merge_by; diff --git a/proto/aggregator/config.Y b/proto/aggregator/config.Y index ad5b1e279..cec24c60f 100644 --- a/proto/aggregator/config.Y +++ b/proto/aggregator/config.Y @@ -47,10 +47,15 @@ aggregator_proto_item: if (AGGREGATOR_CFG->aggr_on) cf_error("Only one aggregate on clause allowed"); + AGGREGATOR_CFG->net_present = 0; int count = 0; for (const struct aggr_item_node *item = $3; item; item = item->next) { log(L_WARN "type %d sacode %d", item->i.type, item->i.sa.sa_code); + + if (item->i.type == AGGR_ITEM_STATIC_ATTR && item->i.sa.sa_code == SA_NET) + AGGREGATOR_CFG->net_present = 1; + count++; } -- 2.47.2