Skip to content

[sonic-bgpcfgd] Add ability to wait on rehydration for additional Loopback IPs during reloads#26349

Merged
StormLiangMS merged 3 commits into
sonic-net:masterfrom
anish-n:additional_los
Apr 1, 2026
Merged

[sonic-bgpcfgd] Add ability to wait on rehydration for additional Loopback IPs during reloads#26349
StormLiangMS merged 3 commits into
sonic-net:masterfrom
anish-n:additional_los

Conversation

@anish-n

@anish-n anish-n commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Why I did it

If there are additional Loopback IPs defined in config db that are being advertised out via frr template files(using bgp network statements) and their config has not replayed in sonic-bgpcfgd, then these loopback ips transiently fail to be advertised out by the templates.

Work item tracking
  • Microsoft ADO (number only):

How I did it

We introduce the ability to check for and fail peer addition requests if a additional loopbacks, as specified via a per-peer J2 file(additional_loopbacks.j2), are not replayed to bgpcfgd yet.

How to verify it

bgpcfgd unit test, and real device test in lab

Which release branch to backport (provide reason below if selected)

  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511

Tested branch (Please provide the tested image version)

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

anish-n added 2 commits March 21, 2026 01:05
Signed-off-by: anish-n <annarsia@microsoft.com>
Signed-off-by: anish-n <annarsia@microsoft.com>
Copilot AI review requested due to automatic review settings March 24, 2026 01:32
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a mechanism in sonic-bgpcfgd to block BGP peer programming during reload/rehydration until required Loopback IPv4 addresses are available, with required loopbacks optionally driven by a per-peer-type Jinja template.

Changes:

  • Extend BGPPeerMgrBase to discover additional required loopbacks from additional_loopbacks.conf.j2 and gate add_peer() until their IPv4 addresses (or bgp_router_id) are present.
  • Add/adjust unit tests to validate the new gating behavior and expected log messages.
  • Introduce an internal peer template listing Loopback4096 as an additional required loopback.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/sonic-bgpcfgd/bgpcfgd/managers_bgp.py Adds template-driven loopback dependency initialization and enforces loopback IPv4 availability before adding peers.
src/sonic-bgpcfgd/tests/test_bgp.py Updates tests to patch and assert new log_info / log_warn calls related to loopback dependency handling.
dockers/docker-fpm-frr/frr/bgpd/templates/internal/additional_loopbacks.conf.j2 Adds internal peer template declaring Loopback4096 as an additional required loopback.

Comment thread src/sonic-bgpcfgd/bgpcfgd/managers_bgp.py
Comment thread src/sonic-bgpcfgd/bgpcfgd/managers_bgp.py Outdated
@yxieca

yxieca commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

Signed-off-by: anish-n <annarsia@microsoft.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@yxieca

yxieca commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

@prsunny

prsunny commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

@anish-n , looks like no impact if lo0 is only present. @StormLiangMS , @deepak-singhal0408 could you review/signoff

@StormLiangMS StormLiangMS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — clean, extensible design. Approve with minor nits.

Summary

This PR gates BGP peer addition in bgpcfgd on additional Loopback IPs (beyond Loopback0) being replayed during reload/rehydration. Instead of hardcoding Loopback4096 for internal peers, it introduces a template-driven approach (additional_loopbacks.conf.j2) that makes the mechanism extensible per peer type.

What I Liked

  • Template-driven approach — new loopback dependencies can be added per peer type without code changes
  • Lazy init (post_dependencies_init) — avoids startup ordering issues by deferring template resolution to first add_peer()
  • Defensive fail-open — setting post_dependencies_init_complete = True before rendering means a broken template won't block all peer programming. This is the right trade-off for production stability
  • Generalized loop replaces the old separate Loopback0 / Loopback4096 checks — cleaner code

Minor Observations (non-blocking)

  1. Double get_lo_ipv4("Loopback0|") call — The loop at line ~185 calls get_lo_ipv4(loopback + "|") for every loopback (including Loopback0), then line ~215 calls lo0_ipv4 = self.get_lo_ipv4("Loopback0|") again for kwargs['loopback0_ipv4']. Could cache the result from the loop to avoid the redundant directory lookup.

  2. get_lo_ipv4 local var still named loopback0_ipv4 — The function is now generalized (docstring updated to LoopbackX), but the local variable on line ~515 is still loopback0_ipv4. A rename to loopback_ipv4 would be consistent.

  3. Path constructionself.fabric.env.loader.searchpath[0] + "/" + base_template + ... — consider os.path.join() for robustness.

  4. No loopback name validation — Template output is parsed as free-form text. A malformed template could inject unexpected names into self.loopbacks. Low risk since templates are controlled, but a regex check (re.match(r'Loopback\d+', name)) would add a safety net.

CI Status

All builds and KVM tests (t0, t1-lag, t2) pass ✅. DCO/Semgrep clean.

@StormLiangMS

Copy link
Copy Markdown
Contributor

@deepak-singhal0408 could you review?

@yijingyan2

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

1 similar comment
@yijingyan2

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

@deepak-singhal0408 deepak-singhal0408 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good. thanks,

@mssonicbld

Copy link
Copy Markdown
Collaborator

Cherry-pick PR to msft-202506: Azure/sonic-buildimage-msft#2147

@prsunny

prsunny commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

@StormLiangMS , @deepak-singhal0408 , please check the labels for cherry-pick.

@mssonicbld

Copy link
Copy Markdown
Collaborator

Cherry-pick PR to 202511: #26615

mhchann pushed a commit to mhchann/sonic-buildimage that referenced this pull request May 7, 2026
…pback IPs during reloads (sonic-net#26349)

Why I did it
If there are additional Loopback IPs defined in config db that are being advertised out via frr template files(using bgp network statements) and their config has not replayed in sonic-bgpcfgd, then these loopback ips transiently fail to be advertised out by the templates.

Work item tracking
Microsoft ADO (number only):
How I did it
We introduce the ability to check for and fail peer addition requests if a additional loopbacks, as specified via a per-peer J2 file(additional_loopbacks.j2), are not replayed to bgpcfgd yet.

How to verify it
bgpcfgd unit test, and real device test in lab

Signed-off-by: anish-n <annarsia@microsoft.com>
Signed-off-by: mhchann <mhchann082@gmail.com>
roger530-ho pushed a commit to roger530-ho/sonic-buildimage that referenced this pull request Jun 23, 2026
…pback IPs during reloads (sonic-net#26349)

Why I did it
If there are additional Loopback IPs defined in config db that are being advertised out via frr template files(using bgp network statements) and their config has not replayed in sonic-bgpcfgd, then these loopback ips transiently fail to be advertised out by the templates.

Work item tracking
Microsoft ADO (number only):
How I did it
We introduce the ability to check for and fail peer addition requests if a additional loopbacks, as specified via a per-peer J2 file(additional_loopbacks.j2), are not replayed to bgpcfgd yet.

How to verify it
bgpcfgd unit test, and real device test in lab

Signed-off-by: anish-n <annarsia@microsoft.com>
xdqi pushed a commit to canonical/sonic-buildimage that referenced this pull request Jul 6, 2026
…pback IPs during reloads (sonic-net#26349)

Why I did it
If there are additional Loopback IPs defined in config db that are being advertised out via frr template files(using bgp network statements) and their config has not replayed in sonic-bgpcfgd, then these loopback ips transiently fail to be advertised out by the templates.

Work item tracking
Microsoft ADO (number only):
How I did it
We introduce the ability to check for and fail peer addition requests if a additional loopbacks, as specified via a per-peer J2 file(additional_loopbacks.j2), are not replayed to bgpcfgd yet.

How to verify it
bgpcfgd unit test, and real device test in lab

Signed-off-by: anish-n <annarsia@microsoft.com>
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.

8 participants