bgpd: Fix BGP-LS initial TED sync and cleanup on peer deactivation#163
Open
suphawitwanl wants to merge 3 commits intoaitestfrom
Open
bgpd: Fix BGP-LS initial TED sync and cleanup on peer deactivation#163suphawitwanl wants to merge 3 commits intoaitestfrom
suphawitwanl wants to merge 3 commits intoaitestfrom
Conversation
After registering with the LS database, no initial sync is requested, so the TED remains empty until the IGP sends unsolicited updates. Any topology changes that occurred before registration are permanently missed and never originated as BGP-LS NLRIs. Additionally, LS_MSG_EVENT_SYNC messages are not handled in the TED processors, so any sync response from zebra is silently dropped. Request a sync via ls_request_sync() immediately after registration, following the same pattern used by other TED consumers such as pathd. Handle LS_MSG_EVENT_SYNC alongside LS_MSG_EVENT_ADD in bgp_ls_process_vertex(), bgp_ls_process_edge(), and bgp_ls_process_subnet(). Signed-off-by: Carmine Scarpitta <[email protected]>
When the last BGP-LS peer is deactivated, locally originated BGP-LS routes are not withdrawn from the RIB, leaving stale routes on peers. The TED is also not cleared, so the next registration re-originates on top of stale state. Add bgp_ls_withdraw_ted() which removes all self-originated paths via bgp_clear_route() and clears all TED entries. Call it in peer_deactivate() when the last BGP-LS peer is being deactivated, before unregistering from the LS database. Signed-off-by: Carmine Scarpitta <[email protected]>
Add test_bgp_ls_peer_deactivate() to verify that deactivating the last BGP-LS peer on r2 withdraws all locally originated routes on r2 and clears all received routes on rr. Add test_bgp_ls_peer_reactivate() to verify that reactivating the peer triggers a fresh TED sync, re-originates all BGP-LS NLRIs on r2, and re-advertises them to rr. Signed-off-by: Carmine Scarpitta <[email protected]>
Greptile SummaryThis PR fixes two correctness bugs in the BGP-LS subsystem: (1) the TED was never populated on startup because
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Operator
participant bgpd
participant TED
participant RIB
participant Zebra/IGP
Note over Operator,Zebra/IGP: Initial registration (fixed)
Operator->>bgpd: neighbor X activate (link-state)
bgpd->>Zebra/IGP: ls_register()
bgpd->>Zebra/IGP: ls_request_sync()
Zebra/IGP-->>bgpd: LS_MSG_EVENT_SYNC messages
bgpd->>TED: add vertex/edge/subnet
bgpd->>RIB: originate BGP-LS NLRIs
Note over Operator,Zebra/IGP: Peer deactivation (fixed)
Operator->>bgpd: no neighbor X activate (last peer)
bgpd->>RIB: bgp_clear_route(peer_self) — async withdraw
bgpd->>TED: bgp_ls_ted_clear() — sync clear
bgpd->>Zebra/IGP: ls_unregister()
Note over Operator,Zebra/IGP: Peer reactivation
Operator->>bgpd: neighbor X activate
bgpd->>Zebra/IGP: ls_register()
bgpd->>Zebra/IGP: ls_request_sync()
Zebra/IGP-->>bgpd: LS_MSG_EVENT_SYNC messages
bgpd->>TED: repopulate
bgpd->>RIB: re-originate BGP-LS NLRIs
Prompt To Fix All With AIThis is a comment left during a code review.
Path: tests/topotests/bgp_link_state/test_bgp_link_state.py
Line: 932
Comment:
**File handle not closed**
`open(reffile).read()` opens the file without a `with` statement, leaving the file handle unclosed until garbage-collected. Use a context manager to ensure the file is closed promptly — this pattern appears in both `test_bgp_ls_peer_reactivate` blocks.
```suggestion
with open(reffile) as f:
expected = json.loads(f.read())
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "tests: Verify BGP-LS routes withdrawn on..." | Re-trigger Greptile |
| # Reactivate the BGP-LS peer. | ||
| r2.vtysh_cmd( | ||
| "configure terminal\n" | ||
| "router bgp 65000\n" |
There was a problem hiding this comment.
open(reffile).read() opens the file without a with statement, leaving the file handle unclosed until garbage-collected. Use a context manager to ensure the file is closed promptly — this pattern appears in both test_bgp_ls_peer_reactivate blocks.
Suggested change
| "router bgp 65000\n" | |
| with open(reffile) as f: | |
| expected = json.loads(f.read()) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/topotests/bgp_link_state/test_bgp_link_state.py
Line: 932
Comment:
**File handle not closed**
`open(reffile).read()` opens the file without a `with` statement, leaving the file handle unclosed until garbage-collected. Use a context manager to ensure the file is closed promptly — this pattern appears in both `test_bgp_ls_peer_reactivate` blocks.
```suggestion
with open(reffile) as f:
expected = json.loads(f.read())
```
How can I resolve this? If you propose a fix, please make it concise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes two issues in the BGP-LS code.
Initial sync: After registering with the LS database, BGP-LS never requests a sync, leaving the TED empty until the IGP sends unsolicited updates. Fix by calling
ls_request_sync()after registration.Peer deactivation: When the last BGP-LS peer is deactivated, self-originated routes are not withdrawn and the TED is not cleared, leaving stale state. Fix by adding
bgp_ls_withdraw_ted()and calling it frompeer_deactivate().