Repository navigation
bgpd: answer a plain VPN route-refresh with a per-peer resync - #24602
fdumontet6WIND wants to merge 4 commits into
Conversation
A ROUTE-REFRESH makes bgp_announce_route() split the peer out of its update-subgroup: the adj-out and the packet queue are copied, then the table is walked again with one advertisement per route, until the new subgroup merges back. With hundreds of VPN peers refreshing (session wave, route-target change), the duplicated adj-outs exhaust memory. A plain ROUTE-REFRESH (no ORF) only asks for the routes already advertised, which are in the subgroup adj-out with the outbound policy applied. Introduce a per-peer resync: the peer stays in its subgroup and a cursor walks the VPN table, encoding each adj-out entry like the shared updates and adapting it to the peer by bpacket_reformat_for_peer(). Resync packets alternate with the shared ones, at the pace of the peer output queue, and EoRR is sent at the end. Entries with a pending advertisement or withdraw are left to the shared stream. When all the peers of a subgroup are resyncing, the resyncs are replaced by one forced walk of the subgroup, as the "all pending" combine of peer_af_announce_route(): encoded once, shared. The combine count also considers peers with a plain t_announce_route pending (ORF refresh, clear soft out), not just peers already in resync - mixed with resyncing peers, the threshold could otherwise never be reached even at 100%. The share of the subgroup needed to trigger the combine is configurable per AFI/SAFI. A plain ROUTE-REFRESH received from an enhanced-RR, graceful-restart peer before our own EoR is deferred and only answered once that EoR goes out. That deferred path is now also eligible for resync - the one case where a session wave (the scenario motivating resync in the first place) is most likely to hit this deferral, since the local EoR itself is the slowest to come out precisely when many peers converge at once. Eligibility is re-checked once the BoRR is sent, not cached, so resync never starts before it (bgp_resync_combine() can force a shared walk). Restricted to SAFI_MPLS_VPN, a subgroup of at least two peers, no addpath TX, no pending announce, coalesce or subgroup refresh, and EoR already sent to a graceful-restart peer; otherwise the split path is kept. Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
Add `bgp route-refresh resync [combine-threshold (0-100)]` under the ipv4-vpn/ipv6-vpn address-family nodes (same place as `bgp retain route-target all`), as a per-AFI/SAFI toggle with its own combine-threshold, so ipv4-vpn and ipv6-vpn can be enabled independently. Default combine-threshold is 100 (all the peers), 0 never combines. Also show the feature's state in operational commands: a "Peer refreshes resync" counter next to "Peer refreshes combined" in show bgp update-groups (subgroup and global stats, text and JSON), and a per-peer-AFI resync status line (prefixes/packets sent) in show bgp neighbor (text and JSON) when a resync is in progress. Previously only visible via debug bgp neighbor-events. Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
Port of the topotest from the bgp_route_refresh_resync branch: a VPNv4 route reflector with 20 eBGP VPE peers, exercising ROUTE-REFRESH from a VPE (vpe_refresh_one/burst/churn) against the per-peer resync path. Also fix an exabgp command-line compatibility issue in topogen.py (TopoExaBGP), needed for this topotest's older-exabgp-compatible command line: "-e" is not understood by all exabgp versions, only the long "--env" form is. Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
[Medium impact] The behavior is limited to configured plain route refreshes for VPN peers. Fix the shared force-flag clear before merging because it can prevent a peer from receiving its requested refresh. Findings
Fix with agent prompt### Issue 1
bgpd/bgp_packet.c:608-609
`bgp_announce_route(..., true)` sets `SUBGRP_STATUS_FORCE_UPDATES` before starting a 500 ms per-peer timer. During that delay, another peer in the subgroup can drain its queue and reach this block because its own `t_announce_route` is unset. It clears the shared flag before the requested refresh runs, so duplicate suppression can discard the unchanged routes that must be resent. The requesting peer can then remove those routes when the refresh ends.
This also affects refreshes with resync disabled. Leave the flag clearing in `subgroup_announce_route()`, which already clears it after the walk.
```suggestion
```
### Issue 2
bgpd/bgp_updgrp_packet.c:1800-1805
`bgp_resync_packet()` has no limit on how many destinations it visits before returning. Routes without an advertisement for this subgroup, or with `adj->adv` set, skip the packet-size checks. A peer allowed only a small part of a large VPN table can therefore scan almost the entire table in one call. The caller checks `event_should_yield()` only afterward.
Add a visited-destination or time limit and resume from the saved cursor so refreshes do not hold up other peers and CLI requests.
### Issue 3
tests/topotests/bgp_rr_vpe_updgrp/test_bgp_rr_vpe_updgrp.py:979-984
`refresh_converged()` checks that the router received the requests, then checks route counts that were already correct before the refresh. With resync, the peers also remain in one subgroup throughout, so the later subgroup check does not prove completion either. These tests can pass even if no routes are resent or the resync never finishes. The reported completion time and peak memory can also stop too early.
Wait for each requested refresh to finish, check that routes were resent, and assert that the expected resync path was used.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds an opt-in VPN route-refresh path that keeps peers in their shared subgroup and replays advertised routes with a per-peer cursor.
Acknowledged limitation: Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Plain VPN refresh] --> B{Eligible for resync?}
B -->|No| C[Existing announcement path]
B -->|Yes| D{Combine threshold reached?}
D -->|Yes| E[Stop per-peer replays]
E --> F[Force one shared table walk]
D -->|No| G[Start per-peer cursor]
G --> H[Alternate replay and shared packets]
H --> I[Cursor and shared work finish]
F --> I
C --> I
I --> J[Send end-of-refresh when required]
Reviews (1) · Last reviewed commit: "tests: add bgp_rr_vpe_updgrp (route-refr..." · Reviewed by Greptile |
| UNSET_FLAG(paf->subgroup->sflags, | ||
| SUBGRP_STATUS_FORCE_UPDATES); |
There was a problem hiding this comment.
Refresh replies can skip routes
bgp_announce_route(..., true) sets SUBGRP_STATUS_FORCE_UPDATES before starting a 500 ms per-peer timer. During that delay, another peer in the subgroup can drain its queue and reach this block because its own t_announce_route is unset. It clears the shared flag before the requested refresh runs, so duplicate suppression can discard the unchanged routes that must be resent. The requesting peer can then remove those routes when the refresh ends.
This also affects refreshes with resync disabled. Leave the flag clearing in subgroup_announce_route(), which already clears it after the walk.
| UNSET_FLAG(paf->subgroup->sflags, | |
| SUBGRP_STATUS_FORCE_UPDATES); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: bgpd/bgp_packet.c
Line: 608-609
Comment:
**Refresh replies can skip routes**
`bgp_announce_route(..., true)` sets `SUBGRP_STATUS_FORCE_UPDATES` before starting a 500 ms per-peer timer. During that delay, another peer in the subgroup can drain its queue and reach this block because its own `t_announce_route` is unset. It clears the shared flag before the requested refresh runs, so duplicate suppression can discard the unchanged routes that must be resent. The requesting peer can then remove those routes when the refresh ends.
This also affects refreshes with resync disabled. Leave the flag clearing in `subgroup_announce_route()`, which already clears it after the walk.
```suggestion
```
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| for (; r->dest; bgp_resync_advance(r)) { | ||
| const struct prefix *dest_p = bgp_dest_get_prefix(r->dest); | ||
|
|
||
| adj = adj_lookup(r->dest, subgrp, 0); | ||
| if (!adj || !adj->attr || adj->adv) | ||
| continue; |
There was a problem hiding this comment.
Filtered refreshes block other work
bgp_resync_packet() has no limit on how many destinations it visits before returning. Routes without an advertisement for this subgroup, or with adj->adv set, skip the packet-size checks. A peer allowed only a small part of a large VPN table can therefore scan almost the entire table in one call. The caller checks event_should_yield() only afterward.
Add a visited-destination or time limit and resume from the saved cursor so refreshes do not hold up other peers and CLI requests.
Prompt To Fix With AI
This is a comment left during a code review.
Path: bgpd/bgp_updgrp_packet.c
Line: 1800-1805
Comment:
**Filtered refreshes block other work**
`bgp_resync_packet()` has no limit on how many destinations it visits before returning. Routes without an advertisement for this subgroup, or with `adj->adv` set, skip the packet-size checks. A peer allowed only a small part of a large VPN table can therefore scan almost the entire table in one call. The caller checks `event_should_yield()` only afterward.
Add a visited-destination or time limit and resume from the saved cursor so refreshes do not hold up other peers and CLI requests.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| def refresh_converged(tgen, refresh_before, count): | ||
| """None once the rr got ``count`` more ROUTE-REFRESH and all converged.""" | ||
| got = rr_refresh_recv(tgen.gears["rr"]) - refresh_before | ||
| if got < count: | ||
| return "rr got {}/{} ROUTE-REFRESH".format(got, count) | ||
| return all_converged(tgen) |
There was a problem hiding this comment.
Tests pass before refresh finishes
refresh_converged() checks that the router received the requests, then checks route counts that were already correct before the refresh. With resync, the peers also remain in one subgroup throughout, so the later subgroup check does not prove completion either. These tests can pass even if no routes are resent or the resync never finishes. The reported completion time and peak memory can also stop too early.
Wait for each requested refresh to finish, check that routes were resent, and assert that the expected resync path was used.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/topotests/bgp_rr_vpe_updgrp/test_bgp_rr_vpe_updgrp.py
Line: 979-984
Comment:
**Tests pass before refresh finishes**
`refresh_converged()` checks that the router received the requests, then checks route counts that were already correct before the refresh. With resync, the peers also remain in one subgroup throughout, so the later subgroup check does not prove completion either. These tests can pass even if no routes are resent or the resync never finishes. The reported completion time and peak memory can also stop too early.
Wait for each requested refresh to finish, check that routes were resent, and assert that the expected resync path was used.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
A ROUTE-REFRESH makes bgp_announce_route() split the peer out of its
update-subgroup: the adj-out and the packet queue are copied, then the
table is walked again with one advertisement per route, until the new
subgroup merges back. With hundreds of VPN peers refreshing (session
wave, route-target change), the duplicated adj-outs exhaust memory.
A plain ROUTE-REFRESH (no ORF) only asks for the routes already
advertised, which are in the subgroup adj-out with the outbound policy
applied. Introduce a per-peer resync: the peer stays in its subgroup
and a cursor walks the VPN table, encoding each adj-out entry like the
shared updates and adapting it to the peer by
bpacket_reformat_for_peer(). Resync packets alternate with the shared
ones, at the pace of the peer output queue, and EoRR is sent at the
end. Entries with a pending advertisement or withdraw are left to the
shared stream.
When all the peers of a subgroup are resyncing, the resyncs are
replaced by one forced walk of the subgroup, as the "all pending"
combine of peer_af_announce_route(): encoded once, shared. The combine
count also considers peers with a plain t_announce_route pending (ORF
refresh, clear soft out), not just peers already in resync - mixed
with resyncing peers, the threshold could otherwise never be reached
even at 100%. The share of the subgroup needed to trigger the combine
is configurable per AFI/SAFI.
A plain ROUTE-REFRESH received from an enhanced-RR, graceful-restart
peer before our own EoR is deferred and only answered once that EoR
goes out. That deferred path is now also eligible for resync - the one
case where a session wave (the scenario motivating resync in the first
place) is most likely to hit this deferral, since the local EoR itself
is the slowest to come out precisely when many peers converge at once.
Eligibility is re-checked once the BoRR is sent, not cached, so resync
never starts before it (bgp_resync_combine() can force a shared walk).
Restricted to SAFI_MPLS_VPN, a subgroup of at least two peers, no
addpath TX, no pending announce, coalesce or subgroup refresh, and EoR
already sent to a graceful-restart peer; otherwise the split path is
kept.