Skip to content

Make the BGP multipath limits of the SONiC default VRF configurable - #2947

Merged
ideaship merged 3 commits into
mainfrom
implement/issue-2559-bgp-multipath-limits
Dec 1, 2026
Merged

ideaship merged 3 commits into
mainfrom
implement/issue-2559-bgp-multipath-limits

Conversation

@berendt

@berendt berendt commented Nov 28, 2026

Copy link
Copy Markdown
Member

Closes #2559

The SONiC config generator no longer pins max_ebgp_paths and max_ibgp_paths of default|ipv4_unicast and default|ipv6_unicast to "2". Each field resolves per device and on its own, first valid value wins:

  1. sonic_parameters.max_ebgp_paths / max_ibgp_paths in the device's custom fields
  2. _segment_bgp_max_ebgp_paths / _segment_bgp_max_ibgp_paths in its config context
  3. SONIC_BGP_MAX_PATHS in the conductor environment (new, shared by both fields)
  4. the built-in DEFAULT_BGP_MAX_PATHS = 2

A valid value is an int (not a bool) or a digit string from 1 to 256, the range sonic-bgp-global.yang gives both fields. An invalid value is skipped with a warning naming its source and the device. A missing or null one is skipped silently. A device that sets nothing generates the same config as before. default|l2vpn_evpn and the per-VRF address families are unchanged.

Commits

  1. Add the SONIC_BGP_MAX_PATHS setting: a string setting in osism/settings.py, deliberately not wrapped in int(), so a typo cannot fail the import for every osism process. Tests: test_sonic_bgp_max_paths_default, test_sonic_bgp_max_paths_override.
  2. Resolve the BGP multipath limits of the SONiC default VRF per device: removes the four literals from DEFAULT_VRF_BGP_GLOBALS_AF, and adds the BGP_MAX_PATHS_* / DEFAULT_VRF_MULTIPATH_AFS constants and _parse_bgp_max_paths / _get_bgp_max_paths. _add_default_vrf_configuration merges the resolved pair into both unicast families, still assigning per key. Tests: the new test_config_generator_multipath.py (53 cases), test_vrf_ipv4_unicast_limits_ignore_conductor_setting, and a subset assertion in test_generate_sonic_config_default_vrf_entries_match_policy_constants.
  3. Cover the BGP multipath limits in the SONiC E2E scenario: e2e-segment sets _segment_bgp_max_ebgp_paths: 4, and e2e-leaf-2 sets max_ebgp_paths: 8 / max_ibgp_paths: 4. The goldens were regenerated from a fresh stack (make sonic-e2e-down && make sonic-e2e-regen). They change in exactly the 20 lines the issue lists (9 files, max_ebgp_paths "4", and on leaf-2 "8" / "4"). VrfStorage|ipv4_unicast is untouched.

Notes for review

  • The one assertion this PR changes is in test_generate_sonic_config_default_vrf_entries_match_policy_constants. It goes from equality to af_attributes.items() <= ...items(), as the issue prescribes: the unicast constants no longer carry the two fields, so equality cannot hold. test_generate_sonic_config_emits_default_vrf_entries_without_vni_vrfs still pins the literal "2" values and is unedited.
  • Deviations from the approved plan:
    • test_get_bgp_max_paths_logs_source_at_debug is parametrized over the device and the segment source. The issue lists only the device case, but its criterion names both.
    • test_get_bgp_max_paths_falls_back_to_builtin_default also asserts that no WARNING is logged, since the "absent inputs" criterion cites it.
    • Local environment only (no effect on the diff): the tool venvs were built with uv because the machine's python3 lacks ensurepip, and the E2E runs used their own pipenv venv, so the unit-test venv stayed as CI builds it (no ansible-core).
  • Declined questions: none.

Verification

Run locally on 1323a3a0:

  • pipenv run pytest tests/unit: 4285 passed, 3 xfailed (main baseline: 4229 passed, same 3 xfailed)
  • pipenv run pytest tests/unit/tasks/conductor/sonic/test_validator_artifacts.py: 11 passed, every golden validates
  • grep -c '"max_[ei]bgp_paths": "' osism/tasks/conductor/sonic/config_generator.py: 2 (the per-VRF literals only)
  • git diff --stat origin/main -- tests/e2e/golden/: 9 files changed, 20 insertions(+), 20 deletions(-)
  • make sonic-e2e, cold, against the committed goldens: >>> SONiC E2E golden test passed.
  • At the CI jobs' pinned versions: black==26.10.1 --check . (252 files unchanged), flake8==7.5.0 on every changed .py file (clean), mypy==1.20.2 --ignore-missing-imports --install-types --non-interactive . (no issues in 251 files)

Not exercised here: the Zuul check jobs flake8, python-black, mypy, and python-osism-sonic-e2e themselves. They run on this pull request. Locally, the seeding tool came from a netbox-manager checkout on its bump-dependencies branch, while the job uses netbox-manager's main.

Noticed but not touching

🤖 Generated with Claude Code

@berendt
berendt force-pushed the implement/issue-2559-bgp-multipath-limits branch from 1323a3a to 6c31be2 Compare November 29, 2026 09:11
@berendt
berendt marked this pull request as ready for review November 29, 2026 09:12
@berendt berendt moved this from New to Ready for review in Human Board Nov 29, 2026
@berendt
berendt requested a review from ideaship November 29, 2026 09:12
@berendt berendt self-assigned this Nov 29, 2026
return None
if isinstance(value, int):
limit = value
elif isinstance(value, str) and re.fullmatch(r"[0-9]+", value.strip()):

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.

[0-9]+ has no length bound, so int(value) raises ValueError for strings longer than 4300 digits (the integer string conversion limit in Python 3.11 and later). The exception escapes before the warning-and-fallback path runs. SONIC_BGP_MAX_PATHS is read for every device that has no NetBox override, so one bad conductor value would fail generation for all of those devices. It would not degrade with a warning, as the comment in settings.py promises.

Unrealistic input, but cheap to close:

Suggested change
elif isinstance(value, str) and re.fullmatch(r"[0-9]+", value.strip()):
elif isinstance(value, str) and re.fullmatch(r"0*[0-9]{1,3}", value.strip()):

This bounds the length and still accepts zero-padded values like "0004". Could you also add "9" * 4301 to test_parse_bgp_max_paths_rejects, plus a _get_bgp_max_paths test that checks the warning and the fallback for it?

limit = _parse_bgp_max_paths(value)
if limit is None:
logger.warning(
f"Ignoring invalid {label} value {value!r} for device {device.name}: "

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.

For the SONIC_BGP_MAX_PATHS source, this fires once per field for every device, on every sync. On a 40-switch fabric that is 80 identical warnings per run. Each one says "for device leaf-N", so a single global misconfiguration (including SONIC_BGP_MAX_PATHS= set to an empty string) looks like many device-specific problems.

Could the conductor setting be validated once, e.g. with a small functools.cached helper, and warned about once without a device name? The per-device warning still makes sense for sonic_parameters and _segment_bgp_*.

#
# _segment_bgp_max_ebgp_paths raises max_ebgp_paths of the default VRF to 4
# for every fixture device. _segment_bgp_max_ibgp_paths is deliberately left
# unset, so max_ibgp_paths shows the built-in fallback of 2.

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.

Two things here:

  1. Because max_ibgp_paths falls through to the conductor setting, the goldens now depend on the caller's environment. sonic_golden_test.sh exports the other SONIC_* variables but leaves SONIC_BGP_MAX_PATHS alone, so python -m tests.e2e.generate inherits it from the caller's shell. With SONIC_BGP_MAX_PATHS=8 exported, every device without a device override gets "8". A normal run then fails with golden mismatches, and --regenerate quietly writes "8" into the committed goldens. Could you add unset SONIC_BGP_MAX_PATHS (or export SONIC_BGP_MAX_PATHS=2) next to the other SONIC_* exports in the runner?

  2. Nit: the 2 here is not really the built-in fallback. settings.SONIC_BGP_MAX_PATHS defaults to "2", so the value comes from the conductor setting. DEFAULT_BGP_MAX_PATHS is only reached when that setting is invalid.

assert config["BGP_GLOBALS_AF"][f"default|{af_name}"] == af_attributes
assert (
af_attributes.items()
<= config["BGP_GLOBALS_AF"][f"default|{af_name}"].items()

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.

With the switch from == to a <= subset check, this test no longer catches unexpected extra keys in the default-VRF address families. For example, max_*_paths leaking into l2vpn_evpn would now pass. Could we keep exact equality instead? Compare the IPv4/IPv6 unicast entries against {**af_attributes, "max_ebgp_paths": "2", "max_ibgp_paths": "2"} and the remaining ones against af_attributes. If the subset check stays, please say in the commit message that the assertion was loosened.

# ---------------------------------------------------------------------------


def test_get_bgp_max_paths_falls_back_to_builtin_default(loguru_logs):

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.

The autouse fixture sets SONIC_BGP_MAX_PATHS to "2", so this test resolves from the conductor setting and never reaches DEFAULT_BGP_MAX_PATHS. The invalid-conductor tests do cover the real fallback, so nothing goes untested, but the name claims more than the test does. Either patch the setting to None here, which _get_bgp_max_paths skips, so the test really covers the no-sources case, or rename it to something like ..._uses_conductor_default.

@github-project-automation github-project-automation Bot moved this from Ready for review to In review in Human Board Nov 30, 2026
berendt and others added 3 commits November 30, 2026 17:50
Conductor-wide default for max_ebgp_paths and max_ibgp_paths in the IPv4
and IPv6 unicast address families of the SONiC default VRF. It is kept as
a string, not wrapped in int(), so a typo cannot fail the import of
osism.settings for every osism process; the SONiC config generator
validates it and falls back to 2.

Part of #2559.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Christian Berendt <berendt@osism.tech>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The generator pinned max_ebgp_paths and max_ibgp_paths of
default|ipv4_unicast and default|ipv6_unicast to 2, so a leaf with more
than two uplinks installed only two equal-cost paths.

Each field now resolves on its own, first valid value wins:
sonic_parameters.max_ebgp_paths / max_ibgp_paths on the device, then
_segment_bgp_max_ebgp_paths / _segment_bgp_max_ibgp_paths in its config
context, then SONIC_BGP_MAX_PATHS, then the built-in 2. A valid value is an
int (not a bool) or a digit string from 1 to 256, the range of
sonic-bgp-global.yang. An invalid value is skipped with a warning: per
device for the NetBox sources, once per sync run and without a device name
for SONIC_BGP_MAX_PATHS, which is the same for every device. A missing or
null value is skipped silently. A device that sets nothing generates the
same config as before. l2vpn_evpn and the per-VRF address families are
unchanged.

Part of #2559.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Christian Berendt <berendt@osism.tech>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The e2e-segment config context sets _segment_bgp_max_ebgp_paths to 4, so
every fixture device shows the segment default for max_ebgp_paths and the
default of SONIC_BGP_MAX_PATHS, 2, for max_ibgp_paths. e2e-leaf-2 sets
max_ebgp_paths 8 and max_ibgp_paths 4 in sonic_parameters, proving the
per-device override over the segment value and over the conductor
setting.

sonic_golden_test.sh unsets SONIC_BGP_MAX_PATHS before it generates, so a
value exported in the caller's shell can neither fail the comparison nor
end up in regenerated goldens.

The goldens were regenerated from a fresh stack with make sonic-e2e-down
and make sonic-e2e-regen; they change in the default-VRF unicast address
families only (9 files, 20 lines).

Part of #2559.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Christian Berendt <berendt@osism.tech>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@berendt
berendt force-pushed the implement/issue-2559-bgp-multipath-limits branch from 6c31be2 to 614cca1 Compare November 30, 2026 17:51
@berendt
berendt requested a review from ideaship November 30, 2026 18:10
@ideaship
ideaship merged commit 062cd0f into main Dec 1, 2026
2 checks passed
@ideaship
ideaship deleted the implement/issue-2559-bgp-multipath-limits branch December 1, 2026 06:56
@github-project-automation github-project-automation Bot moved this from In review to Done in Human Board Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Make the BGP multipath limits of the SONiC default VRF configurable

2 participants