From a7f223636f046be7c5a2b99d719e60bdee50b037 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 15 Mar 2024 20:42:39 -0400 Subject: [PATCH 1/3] bgpd: Optimize the usage of jhash There are a bunch of jhash_1word uses. Let's convert to jhash_3word and get rid of some calls. Signed-off-by: Donald Sharp --- bgpd/bgp_attr.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index b62319b211..209dcd2288 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -697,14 +697,9 @@ static uint32_t srv6_l3vpn_hash_key_make(const void *p) uint32_t key = 0; key = jhash(&l3vpn->sid, 16, key); - key = jhash_1word(l3vpn->sid_flags, key); - key = jhash_1word(l3vpn->endpoint_behavior, key); - key = jhash_1word(l3vpn->loc_block_len, key); - key = jhash_1word(l3vpn->loc_node_len, key); - key = jhash_1word(l3vpn->func_len, key); - key = jhash_1word(l3vpn->arg_len, key); - key = jhash_1word(l3vpn->transposition_len, key); - key = jhash_1word(l3vpn->transposition_offset, key); + key = jhash_3words(l3vpn->sid_flags, l3vpn->endpoint_behavior, l3vpn->loc_block_len, key); + key = jhash_3words(l3vpn->loc_node_len, l3vpn->func_len, l3vpn->arg_len, key); + key = jhash_2words(l3vpn->transposition_len, l3vpn->transposition_offset, key); return key; } @@ -863,15 +858,11 @@ unsigned int attrhash_key_make(const void *p) if (vnc_subtlvs) MIX(encap_hash_key_make(vnc_subtlvs)); #endif - MIX(attr->mp_nexthop_len); + MIX3(attr->mp_nexthop_len, attr->rmap_table_id, attr->nh_type); key = jhash(attr->mp_nexthop_global.s6_addr, IPV6_MAX_BYTELEN, key); key = jhash(attr->mp_nexthop_local.s6_addr, IPV6_MAX_BYTELEN, key); MIX3(attr->nh_ifindex, attr->nh_lla_ifindex, attr->distance); - MIX(attr->rmap_table_id); - MIX(attr->nh_type); - MIX(attr->bh_type); - MIX(attr->otc); - MIX(bgp_attr_get_aigp_metric(attr)); + MIX3(attr->bh_type, attr->otc, bgp_attr_get_aigp_metric(attr)); return key; } From e2090bf4c6a60e98ee6a3e17a35a82848c517239 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 15 Mar 2024 21:08:43 -0400 Subject: [PATCH 2/3] bgpd: Further extend `show bgp attribute-info` Fill out a bit more data about what is being held. Signed-off-by: Donald Sharp --- bgpd/bgp_attr.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 209dcd2288..2280aa9097 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -967,8 +967,11 @@ static void attr_show_all_iterator(struct hash_bucket *bucket, struct vty *vty) "\n", attr->flag, attr->distance, attr->med, attr->local_pref, attr->origin, attr->weight, attr->label, sid, attr->aigp_metric); - vty_out(vty, "\taspath: %s Community: %s Large Community: %s\n", - aspath_print(attr->aspath), + vty_out(vty, + "\tnh_ifindex: %u nh_flags: %u distance: %u nexthop_global: %pI6 nexthop_local: %pI6 nexthop_local_ifindex: %u\n", + attr->nh_ifindex, attr->nh_flags, attr->distance, &attr->mp_nexthop_global, + &attr->mp_nexthop_local, attr->nh_lla_ifindex); + vty_out(vty, "\taspath: %s Community: %s Large Community: %s\n", aspath_print(attr->aspath), community_str(attr->community, false, false), lcommunity_str(attr->lcommunity, false, false)); vty_out(vty, "\tExtended Community: %s Extended IPv6 Community: %s\n", From 1115feedc3f878853e2e67df9efdd0f5e5e1f997 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 3 Nov 2023 23:26:56 -0400 Subject: [PATCH 3/3] bgpd: add some counters not displayed yet Add some counters to keep track how often stuff is done. This is mainly for us developers. Signed-off-by: Donald Sharp --- bgpd/bgp_route.c | 10 +++++++++- bgpd/bgpd.h | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index ea6b288e2f..baeb96a9c8 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -745,6 +745,8 @@ int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, struct bgp_path_info *bpi_ultimate; struct peer *peer_new, *peer_exist; + bgp->bestpath_runs++; + *paths_eq = 0; /* 0. Null check. */ @@ -4119,8 +4121,10 @@ static void bgp_process_internal(struct bgp *bgp, struct bgp_dest *dest, } /* already scheduled for processing? */ - if (CHECK_FLAG(dest->flags, BGP_NODE_PROCESS_SCHEDULED)) + if (CHECK_FLAG(dest->flags, BGP_NODE_PROCESS_SCHEDULED)) { + bgp->node_already_on_queue++; return; + } /* If the flag BGP_NODE_SELECT_DEFER is set, do not add route to * the workqueue @@ -4129,6 +4133,7 @@ static void bgp_process_internal(struct bgp *bgp, struct bgp_dest *dest, if (BGP_DEBUG(update, UPDATE_OUT)) zlog_debug("BGP_NODE_SELECT_DEFER set for route %p", dest); + bgp->node_deferred_on_queue++; return; } @@ -13095,6 +13100,9 @@ DEFUN(show_ip_bgp_afi_safi_statistics, show_ip_bgp_afi_safi_statistics_cmd, json = json_object_new_object(); json_object_object_add(json, get_afi_safi_str(afi, safi, true), json_afi_safi); + json_object_int_add(json, "bgpBestPathCalls", bgp->bestpath_runs); + json_object_int_add(json, "bgpNodeOnQueue", bgp->node_already_on_queue); + json_object_int_add(json, "bgpNodeDeferredOnQueue", bgp->node_deferred_on_queue); vty_json(vty, json); } return ret; diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index eef5bab333..f37a722f0c 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -864,6 +864,10 @@ struct bgp { /* BGP route flap dampening configuration */ struct bgp_damp_config damp[AFI_MAX][SAFI_MAX]; + uint64_t bestpath_runs; + uint64_t node_already_on_queue; + uint64_t node_deferred_on_queue; + QOBJ_FIELDS; }; DECLARE_QOBJ_TYPE(bgp);