Skip to content

bgpd: backpressure generic framework - #21192

Merged
ton31337 merged 4 commits into
FRRouting:masterfrom
chiragshah6:bgp_bp_gen
Mar 19, 2026
Merged

bgpd: backpressure generic framework#21192
ton31337 merged 4 commits into
FRRouting:masterfrom
chiragshah6:bgp_bp_gen

Conversation

@chiragshah6

Copy link
Copy Markdown
Member

This change decouples the backpressure logic from being tied exclusively to bgp_dest.
It introduces a generic structure that can hold a void pointer to any BGP-related object that needs to send to zebra using the the backpressure framework. The associated enum identifies the object type so the correct ZAPI handler can be invoked.

Signed-off-by: Chirag Shah chirag@nvidia.com
Signed-off-by: Donald Sharp sharpd@nvidia.com

@donaldsharp

Copy link
Copy Markdown
Member

I've added to the bgp architecture slide deck what I am thinking here

https://docs.google.com/presentation/d/15Uxdo0Ln6frATYZcQPJb8_N5vkIUk8y2gtoYu8go-Uw/edit?slide=id.g3cf86f010fe_0_0#slide=id.g3cf86f010fe_0_0

Slide 4 is what we currently have. Slide 5 is where I want to go. Currently we only apply backpressure to routes being installed into zebra. BGP on the other hand sends a bunch of different data down to zebra some of which is ignoring backpressure which is not good and also we get different orderings than originally intended. Chirag has implemented the abstraction of having a installation list instead of a dest list for what to install into zebra. We can now easily come back through and add other types to this setup.

@chiragshah6
chiragshah6 marked this pull request as ready for review March 16, 2026 23:04
@greptile-apps

greptile-apps Bot commented Mar 16, 2026

Copy link
Copy Markdown

Greptile Summary

This PR decouples the zebra announce backpressure FIFO from being directly tied to bgp_dest by introducing a generic bgp_bp_install_node wrapper struct. The wrapper holds a void *ptr and an enum bgp_bp_install_type to identify the object type, enabling future extension of the backpressure framework to non-route BGP objects. A back-pointer (za_inode) from bgp_dest to the wrapper node is added for integrity assertions. The show bgp router command is also enhanced to display the current zebra announce queue count.

  • Introduces struct bgp_bp_install_node with type discriminator and void pointer in bgpd.h, replacing the embedded zai list item in bgp_dest
  • Updates all FIFO iteration sites (bgp_zebra.c, bgpd.c, bgp_evpn.c) to allocate/free wrapper nodes and filter by type
  • Adds dest->za_inode back-pointer with assertion guards to catch double-enqueue or missing-enqueue bugs
  • Adds zebra announce queue count to show bgp router output (both JSON and text)

Confidence Score: 4/5

  • This PR is a well-structured refactoring with proper memory management and assertion guards; safe to merge with minor considerations.
  • The changes are clean and consistent. All allocation/free paths are properly paired. The FIFO iteration patterns using saved-next-before-delete are safe for the underlying singly-linked list. The back-pointer assertions add good safety nets. The only consideration is the additional heap allocation per queued route, but this is a reasonable trade-off for the generic framework. No logical bugs were found.
  • bgpd/bgp_zebra.c is the core file where the install/announce logic lives and has the most nuanced changes to review carefully.

Important Files Changed

Filename Overview
bgpd/bgpd.h Introduces bgp_bp_install_node struct and bgp_bp_install_type enum to decouple the zebra announce list from bgp_dest. Clean, well-structured addition.
bgpd/bgp_table.h Replaces embedded zai list item in bgp_dest with za_inode pointer to the new bgp_bp_install_node, and updates DECLARE_LIST to use the new node type. Consistent with the generic framework design.
bgpd/bgp_zebra.c Core changes: allocates/frees bgp_bp_install_node wrappers in route install/announce paths. Adds type-based dispatch and proper cleanup of za_inode. All cleanup paths correctly free the inode and null the back-pointer.
bgpd/bgpd.c Updates bgp_delete to iterate over bgp_bp_install_node items, filtering by type and freeing the wrapper node. Correctly handles the new indirection layer.
bgpd/bgp_evpn.c Updates EVPN VPN cleanup to iterate bgp_bp_install_node items, filter by route type, and free inode wrappers. Cleanup pattern is consistent with other call sites.
bgpd/bgp_vty.c Adds zebra announce queue count to the show bgp router output in both JSON and text formats. Simple, correct addition using %zu for size_t.
bgpd/bgp_memory.h Declares MTYPE_BGP_BP_INSTALL_NODE memory type for the new node allocations.
bgpd/bgp_memory.c Defines MTYPE_BGP_BP_INSTALL_NODE memory type. Standard boilerplate addition.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[bgp_zebra_route_install] -->|New dest on list| B{Schedule flags?}
    B -->|Neither INSTALL nor DELETE set| C[Allocate bgp_bp_install_node]
    C --> D[Set type = BGP_BP_INSTALL_ROUTE]
    D --> E[Set ptr = dest]
    E --> F[Add to zebra_announce FIFO tail]
    F --> G[Set dest->za_inode = inode]
    B -->|INSTALL or DELETE already set| H[Update za_bgp_pi in-place]

    I[bgp_handle_route_announcements_to_zebra] -->|Pop from FIFO| J{inode->type?}
    J -->|BGP_BP_INSTALL_ROUTE| K[Extract dest from inode->ptr]
    K --> L[Install/Withdraw to Zebra]
    L --> M[Cleanup: unlock, null pointers, XFREE inode]
    J -->|Other type future| N[XFREE inode, continue]

    O[bgp_delete / evpn_pop] -->|Iterate FIFO| P{inode->type == ROUTE?}
    P -->|Yes| Q[Match BGP instance or VPN]
    Q -->|Match| R[Del from FIFO, cleanup, XFREE inode]
    P -->|No| S[Skip - continue]
Loading

Last reviewed commit: a752fb9

Comment thread bgpd/bgpd.h
@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@chiragshah6
chiragshah6 requested a review from ton31337 March 17, 2026 14:55
@mjstapp
mjstapp self-requested a review March 17, 2026 15:38
This change decouples the backpressure logic
from being tied exclusively to bgp_dest.
It introduces a generic structure that can hold a void
pointer to any BGP-related object that needs to send to zebra
using the the backpressure framework. The associated enum identifies
the object type so the correct ZAPI handler can be invoked.

Signed-off-by: Chirag Shah <chirag@nvidia.com>
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
For generic backpressur logic, the dest carrying
the backpressure list node pointer.

Signed-off-by: Chirag Shah <chirag@nvidia.com>
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
BGP started at Mon Mar 16 19:27:16 2026
BGP GSHUT is disabled.
Number of BGP instances (including default): 1
BGP suppress-fib-pending is disabled.
BGP Input Queue Limit: 10000
BGP Output Queue Limit: 10000
Zebra Announce Count: 0 <<<
BGP Global Update Delay Timers:
  Update Delay Time: 0s
    Establish Wait Time: 0s

{
  "bgpStartedAt":"Mon Mar 16 19:27:16 2026\n",
  "bgpStartedGracefully":"No",
  "bgpGShutEnabled":false,
  "bgpInMaintenanceMode":"No",
  "bgpInstanceCount":1,
  "bgpWaitForFibSet":false,
  "bgpInputQueueLimit":10000,
  "bgpOutputQueueLimit":10000,
  "zebraAnnounceCount":0,
  "bgpUpdateDelayTime":0,
  "bgpEstablishWaitTime":0,
  "bgpRMapDelayTimer":5
}

Signed-off-by: Chirag Shah <chirag@nvidia.com>
node# show bgp statistics
BGP IPv6 Unicast RIB statistics (VRF default)
Total Advertisements          :           15
Total Prefixes                :           15
Average prefix length         :        98.13
Unaggregateable prefixes      :           15
Maximum aggregateable prefixes:            0
BGP Aggregate advertisements  :            0
Address space advertised      :  6.01295e+10
            /32 equivalent %s
:  7.58942e-19
            /48 equivalent %s
:   4.9738e-14

Advertisements with paths     :           15
Longest AS-Path (hops)        :            0
Average AS-Path length (hops) :         0.00
Largest AS-Path (bytes)       :            0
Average AS-Path size (bytes)  :         0.00
Highest public ASN            :            0
Zebra announce queue          :            0 <<<<<<<

node# show bgp statistics json
{
  "ipv6Unicast":[
    {
      "instance":"VRF default",
      "totalAdvertisements":171,
      "totalPrefixes":64,
      "averagePrefixLength":101.0,
      "unaggregateablePrefixes":64,
      "maximumAggregateablePrefixes":0,
      "bgpAggregateAdvertisements":0,
      "addressSpaceAdvertised":231928233994.0,
      "/32equivalent":2.9273458658370797e-18,
      "/48equivalent":1.9184653866349886e-13,
      "advertisementsWithPaths":171,
      "longestAsPath":4,
      "averageAsPathLengthHops":2.2807017543859649,
      "largestAsPath":18,
      "averageAsPathSizeBytes":10.947368421052632,
      "highestPublicAsn":0,
      "zebraAnnounceQueue":0, <<<<<
}

Signed-off-by: Chirag Shah <chirag@nvidia.com>

@riw777 riw777 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good

@ton31337
ton31337 merged commit 9a30938 into FRRouting:master Mar 19, 2026
28 of 29 checks passed
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.

4 participants