Skip to content

Conversation

@mike-dubrovsky
Copy link

Description

This PR adds a new info_count field to struct route_table that tracks only nodes with actual data (info != NULL), excluding auxiliary/glue nodes that exist solely for the Patricia trie structure.

Problem

BGP stores prefix destinations using the Patricia trie in lib/table.[ch].
This data structure requires auxiliary glue nodes to preserve tree structure invariants.

The show ip bgp summary command displays "RIB entries" using route_table_count(),
which counts all nodes in the Patricia trie, including internal glue nodes.
This is misleading because glue nodes don't represent actual routes.

Example - Before (incorrect):

sonic# show ip bgp summary

IPv4 Unicast Summary:
BGP router identifier 192.168.123.118, local AS number 1 VRF default vrf-id 0
BGP table version 12
RIB entries 7, using 896 bytes of memory   <-- includes glue nodes
Peers 1, using 24 KiB of memory

Neighbor        V         AS   MsgRcvd   MsgSent   TblVer  InQ OutQ  Up/Down State/PfxRcd   PfxSnt Desc
10.0.0.1        4          1       724       759       12    0    0 11:34:42            0        4 FRRouting/10.3

Total number of neighbors 1

In this example, there are only 4 actual prefixes (PfxSnt 4), but "RIB entries" shows 7 because it includes 3 auxiliary glue nodes created by the Patricia trie structure.

Example - After (correct):

RIB entries 4, using 896 bytes of memory   <-- only real prefixes

Solution

Add info_count field to struct route_table to track nodes with info != NULL
Add route_node_set_info() helper function that automatically maintains info_count when setting/clearing a node's info pointer
Update BGP to use route_node_set_info()

@donaldsharp
Copy link
Member

Let's get the frrbot problems cleaned up. This seems reasonable.

* Helper to update a node's ->info pointer while keeping the table's
* info_count in sync.
*/
static inline void route_node_set_info(struct route_node *node, void *info)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so ... the problem with introducing this api in this way is that it will only work if used consistently, everywhere. and ... there are lots of places in the code that touch route_node->info. what do you expect to have happen there? doing something in the library seems like something that should work everywhere. doing something just for bgp should maybe just be done in bgp code?

BGP stores prefix destinations using the Patricia trie in lib/table.[ch].
This data structure creates auxiliary (glue) nodes to preserve tree
structure invariants. These glue nodes have info == NULL and don't
represent actual routes.

Previously, `show ip bgp summary` reported "RIB entries" using the total
node count, which incorrectly included glue nodes. For example, 4 actual
prefixes might show as "RIB entries 7" due to 3 glue nodes.

- Add `info_count` field to `struct route_table` that tracks only nodes
  with info != NULL.
- Add route_node_set_info() helper to automatically
  maintain this counter when setting/clearing a node's info pointer.
- Update BGP to use the new counter for accurate RIB entry reporting.

Signed-off-by: Mike Dubrovsky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants