Skip to content

[action] [PR:26937] [PrefixListMgr]: Refactor PrefixListMgr to support multiple prefix types via config registry#2280

Merged
lizhijianrd merged 1 commit into
Azure:202603from
mssonicbld:cherry/msft-202603/26937
May 11, 2026
Merged

[action] [PR:26937] [PrefixListMgr]: Refactor PrefixListMgr to support multiple prefix types via config registry#2280
lizhijianrd merged 1 commit into
Azure:202603from
mssonicbld:cherry/msft-202603/26937

Conversation

@mssonicbld
Copy link
Copy Markdown
Collaborator

Why I did it

Currently PrefixListMgr only supports ANCHOR_PREFIX with hardcoded device-type checks and template references. This refactor makes PrefixListMgr data-driven and extensible, and adds a generic SUPPRESS_PREFIX type for route suppression use cases.

Work item tracking
  • Microsoft ADO (number only): 37638053

How I did it

Registry refactor (ANCHOR_PREFIX behavior unchanged):

  • Added PREFIX_TYPE_CONFIG registry mapping each prefix type to its templates, allowed device types, prefix-list naming lambda, and log labels
  • Added _is_device_allowed() helper using (type, subtype) tuple matching, with None = unrestricted
  • Refactored generate_prefix_list_config to use registry lookup instead of hardcoded checks
  • Renamed handler local prefix_list_nameprefix_type to avoid confusion with data["prefix_list_name"]
  • Used metadata.get("subtype", "") to handle devices without subtype

SUPPRESS_PREFIX type (new):

  • Added SUPPRESS_PREFIX registry entry with allowed_devices: None (any device)
  • Added add_suppress_prefix.conf.j2 / del_suppress_prefix.conf.j2 templates
  • In CLI: replaced global check_spine_router with per-type validate_device_for_type

constants.yml-driven prefix-list name resolution:

  • Prefix-list names resolved from constants.yml (bgp.prefix_list.<type>.ipv4_name / ipv6_name) with registry lambda as fallback
  • Enables downstream repos to override names via constants.yml alone

Backward-compatibility:

  • All 5 existing ANCHOR_PREFIX unit tests pass unchanged
  • PrefixListMgr registered on all devices — ANCHOR_PREFIX on non-spine devices logs a warning (no FRR state change; doesn't occur in practice)
  • CLI status now allowed on any device (read-only)

How to verify it

  • All 15 unit tests pass (5 existing ANCHOR_PREFIX + 2 registry validation + 5 SUPPRESS_PREFIX + 3 constants override/fallback)
  • ANCHOR_PREFIX behavior identical before and after

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

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

Tested branch (Please provide the tested image version)

  • SONiC.20251110.19

Description for the changelog

Refactor PrefixListMgr to use a data-driven config registry with constants.yml-driven prefix-list name resolution, and add generic SUPPRESS_PREFIX type.

Link to config_db schema for YANG module changes

No YANG model changes. Uses existing PREFIX_LIST table:
Prefix list

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

枣

Signed-off-by: Sonic Build Admin sonicbld@microsoft.com

…pes via config registry

#### Why I did it

Currently PrefixListMgr only supports ANCHOR_PREFIX with hardcoded device-type checks and template references. This refactor makes PrefixListMgr data-driven and extensible, and adds a generic SUPPRESS_PREFIX type for route suppression use cases.

##### Work item tracking
- Microsoft ADO **(number only)**: 37638053

#### How I did it

**Registry refactor (ANCHOR_PREFIX behavior unchanged):**
- Added `PREFIX_TYPE_CONFIG` registry mapping each prefix type to its templates, allowed device types, prefix-list naming lambda, and log labels
- Added `_is_device_allowed()` helper using `(type, subtype)` tuple matching, with `None` = unrestricted
- Refactored `generate_prefix_list_config` to use registry lookup instead of hardcoded checks
- Renamed handler local `prefix_list_name` → `prefix_type` to avoid confusion with `data["prefix_list_name"]`
- Used `metadata.get("subtype", "")` to handle devices without subtype

**SUPPRESS_PREFIX type (new):**
- Added `SUPPRESS_PREFIX` registry entry with `allowed_devices: None` (any device)
- Added `add_suppress_prefix.conf.j2` / `del_suppress_prefix.conf.j2` templates
- In CLI: replaced global `check_spine_router` with per-type `validate_device_for_type`

**constants.yml-driven prefix-list name resolution:**
- Prefix-list names resolved from `constants.yml` (`bgp.prefix_list.<type>.ipv4_name` / `ipv6_name`) with registry lambda as fallback
- Enables downstream repos to override names via `constants.yml` alone

**Backward-compatibility:**
- All 5 existing ANCHOR_PREFIX unit tests pass unchanged
- PrefixListMgr registered on all devices — ANCHOR_PREFIX on non-spine devices logs a warning (no FRR state change; doesn't occur in practice)
- CLI `status` now allowed on any device (read-only)

#### How to verify it

- All 15 unit tests pass (5 existing ANCHOR_PREFIX + 2 registry validation + 5 SUPPRESS_PREFIX + 3 constants override/fallback)
- ANCHOR_PREFIX behavior identical before and after

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

- [ ] 202305
- [ ] 202311
- [ ] 202405
- [ ] 202411
- [ ] 202505
- [ ] 202511
- [x] 202603

#### Tested branch (Please provide the tested image version)

- [x]  SONiC.20251110.19

#### Description for the changelog

Refactor PrefixListMgr to use a data-driven config registry with constants.yml-driven prefix-list name resolution, and add generic SUPPRESS_PREFIX type.

#### Link to config_db schema for YANG module changes
No YANG model changes. Uses existing PREFIX_LIST table:
[Prefix list](https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md#prefix-list)

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

<img width="491" height="526" alt="枣" src="https://github.com/user-attachments/assets/244cb96f-1b7d-4110-8ba4-92a5a4abcee0" />

Signed-off-by: Sonic Build Admin <sonicbld@microsoft.com>
@mssonicbld
Copy link
Copy Markdown
Collaborator Author

Original PR: sonic-net/sonic-buildimage#26937

@mssonicbld
Copy link
Copy Markdown
Collaborator Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@lizhijianrd lizhijianrd merged commit b23e478 into Azure:202603 May 11, 2026
4 of 11 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.

2 participants