Skip to content

[yang] Extended sonic-bmp.yang YANG model to include BMP collector(s) and policies #24965

Open
kalash-nexthop wants to merge 17 commits into
sonic-net:masterfrom
kalash-nexthop:bmp-configurable
Open

[yang] Extended sonic-bmp.yang YANG model to include BMP collector(s) and policies #24965
kalash-nexthop wants to merge 17 commits into
sonic-net:masterfrom
kalash-nexthop:bmp-configurable

Conversation

@kalash-nexthop

@kalash-nexthop kalash-nexthop commented Jan 2, 2026

Copy link
Copy Markdown
Contributor

Currently SONiC doesn't allow configuring external BMP collector, and instead relies on hard-coded local BMP collector config with only pre-policy support. Making this generic so that a user can set potentially multiple external collectors with multiple policies, as FRR already supports this.

Instead of just creating a PR with yang model, I added the vtysh cmd conversion stuff to this PR, so that I can demonstrate the model and corresponding vtysh config that's already supported in FRR.

fixes #24962
Link to HLD: sonic-net/SONiC#2366

Why I did it

Currently SONiC doesn't allow configuring external BMP collector, and instead relies on hard-coded local BMP collector config with only pre-policy support. But some customers want to use external collectors with both pre and post policy config.

Work item tracking
  • Microsoft ADO (number only):

How I did it

1- Extended sonic-bmp.yang YANG model to include BMP collector (potentially multiple collectors) configuration parameters: IP, port, stats interval, retry intervals, monitor policies.
2- The new yang model is similar to FRR's bmp yang model, but instead of using nested lists, it does below (3) so that SONiC's yang parser doesn't complain.
3- The model to allow multiple targets and collectors is similar to how BGP_NEIGHBOR container block is used for defining the neighbors, and then another BGP_NEIGHBOR_AF container to define afi-safis on those neighbors. I've verified that yang validation works for this.
4- Updated unified/separated mode templates (bgpd.conf.db.j2 and bgpd.main.conf.j2) to use BMP configuration from CONFIG_DB with fallback to default values
5- Added BMP handler in frrcfgd.py to dynamically convert CONFIG_DB BMP changes to vtysh commands for runtime configuration updates
6- Supports multiple configurable monitor policies per target: pre-policy, post-policy, loc-rib
7- Default collector IP is 127.0.0.1 when not specified to maintain backward compatibility

A sample yang model based on the new changes, showing multiple targets, multiple collectors per target, multiple afi-safis per target and multiple policies per afi-safi:

{
    "BMP_TARGET": {
        "production": {
            "mirror": "true",
            "stats-interval": "5000"
        },
        "monitoring": {
            "mirror": "false",
            "stats-interval": "10000"
        },
        "backup": {
            "mirror": "true",
            "stats-interval": "3000"
        }
    },
    "BMP_TARGET_COLLECTOR": {
        "production|192.168.1.100|5000": {
            "min-retry": "30000",
            "max-retry": "720000"
        },
        "production|192.168.1.101|5001": {
            "min-retry": "20000",
            "max-retry": "600000"
        },
        "monitoring|10.0.0.50|6000": {
            "min-retry": "15000",
            "max-retry": "300000"
        },
        "monitoring|10.0.0.51|6001": {
            "min-retry": "15000",
            "max-retry": "300000"
        },
        "backup|172.16.0.10|7000": {
            "min-retry": "10000",
            "max-retry": "180000"
        }
    },
    "BMP_TARGET_AFI_SAFI": {
        "production|ipv4_unicast": {
            "adj-rib-in-pre": "true",
            "adj-rib-in-post": "true",
            "loc-rib": "true"
        },
        "production|ipv6_unicast": {
            "adj-rib-in-pre": "true",
            "adj-rib-in-post": "false",
            "loc-rib": "true"
        },
        "production|l2vpn_evpn": {
            "adj-rib-in-pre": "false",
            "adj-rib-in-post": "true",
            "loc-rib": "false"
        },
        "monitoring|ipv4_unicast": {
            "adj-rib-in-pre": "true",
            "adj-rib-in-post": "false",
            "loc-rib": "false"
        },
        "monitoring|ipv6_unicast": {
            "adj-rib-in-pre": "true",
            "adj-rib-in-post": "false",
            "loc-rib": "false"
        },
        "backup|ipv4_unicast": {
            "adj-rib-in-pre": "true",
            "adj-rib-in-post": "true",
            "loc-rib": "true"
        }
    }
}

And corresponding vtysh commands in vtysh -c "show running-config"

router bgp 65100
 !
 bmp targets production
  bmp stats interval 5000
  bmp mirror
  bmp monitor ipv4 unicast pre-policy
  bmp monitor ipv4 unicast post-policy
  bmp monitor ipv4 unicast loc-rib
  bmp monitor ipv6 unicast pre-policy
  bmp monitor ipv6 unicast loc-rib
  bmp monitor l2vpn evpn post-policy
  bmp connect 192.168.1.100 port 5000 min-retry 30000 max-retry 720000
  bmp connect 192.168.1.101 port 5001 min-retry 20000 max-retry 600000
 exit
 !
 bmp targets monitoring
  bmp stats interval 10000
  bmp monitor ipv4 unicast pre-policy
  bmp monitor ipv6 unicast pre-policy
  bmp connect 10.0.0.50 port 6000 min-retry 15000 max-retry 300000
  bmp connect 10.0.0.51 port 6001 min-retry 15000 max-retry 300000
 exit
 !
 bmp targets backup
  bmp stats interval 3000
  bmp mirror
  bmp monitor ipv4 unicast pre-policy
  bmp monitor ipv4 unicast post-policy
  bmp monitor ipv4 unicast loc-rib
  bmp connect 172.16.0.10 port 7000 min-retry 10000 max-retry 180000
 exit
 !
exit
!

How to verify it

  • Manually verified the generated vtysh config for above yang model in config_db.json in both separated and unified mode by doing config reload.
  • Manually verified the dynamic vtysh config generation by frrcfgd.py for above
  • Manually verified that config reload as well as config replace don't complain of yang validation failure for above model.

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)

@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).

@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).

@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).

@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).

@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).

…ially multiple collectors) configuration parameters: IP, port, stats interval, retry intervals, monitor policies.

- Updated unified/separated mode templates (bgpd.conf.db.j2 and bgpd.main.conf.j2) to use BMP configuration from CONFIG_DB with fallback to default values
- Added BMP handler in frrcfgd.py to dynamically convert CONFIG_DB BMP changes to vtysh commands for runtime configuration updates
- Supports multiple configurable monitor policies per target: pre-policy, post-policy, loc-rib
- Default collector IP is 127.0.0.1 when not specified to maintain backward compatibility

Signed-off-by: Kalash Nainwal <kalash@nexthop.ai>
@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).

@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).

@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).

@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).

Brad's commit c833bde (sonic-net#26587) rephrased the BMP table-dump
descriptions into the "BGP Monitoring Protocol (BMP) ... configuration."
and "Enable or disable ..." voice. Keep the rest of the BMP YANG
consistent with that style:

- Replace "<CONTAINER> part of config_db.json" with proper
  "<purpose> configuration." descriptions for BMP_TARGET,
  BMP_TARGET_COLLECTOR, and BMP_TARGET_AFI_SAFI.
- Reword boolean leaves (mirror, adj-rib-in-pre/post, loc-rib) to the
  "Enable or disable ..." pattern.
- Tighten leafref / numeric leaves to describe purpose rather than
  just restating the field name.
- Add trailing periods to enum descriptions and the 2026-01-02
  revision note for consistency.
- Expand the afi-safi-type typedef description to spell out AFI/SAFI.

No functional/schema changes; descriptions only.

Signed-off-by: Kalash Nainwal <kalash@nexthop.ai>
@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).

@kalash-nexthop

Copy link
Copy Markdown
Contributor Author

Hi @kalash-nexthop, the pipeline cannot be triggered since the branch has conflicts with the master branch. Could you please resolve the conflicts first in order to trigger the pipelines? Thanks

Hi @yijingyan2 , Done.

@yxieca

yxieca commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

1 similar comment
@yxieca

yxieca commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

Replace the raw string type (length 1..64) with the canonical
sonic-types interface_name typedef (length 1..15, per IFNAMSIZ from
<net/if.h>). Matches the convention already used by
sonic-loopback-interface.yang, sonic-vrf.yang, and
sonic-smart-switch.yang.

No frrcfgd / template / test changes: the CONFIG_DB key is still
`source-interface` and any valid interface name that passed the old
1..64 bound also passes 1..15 (real interface names are at most 15
chars).

Signed-off-by: Kalash Nainwal <kalash@nexthop.ai>
@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 Apr 23, 2026

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

5 similar comments
@yxieca

yxieca commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

@yxieca

yxieca commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

@yxieca

yxieca commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

@yxieca

yxieca commented May 4, 2026

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

@yxieca

yxieca commented May 5, 2026

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

@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).

@kalash-nexthop

Copy link
Copy Markdown
Contributor Author

/azpw run

@mssonicbld

Copy link
Copy Markdown
Collaborator

⚠️ Notice: /azpw run only runs failed jobs now. If you want to trigger a whole pipline run, please rebase your branch or close and reopen the PR.
💡 Tip: You can also use /azpw retry to retry failed jobs directly.

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

No failed(or canceled) jobs found in completed stages. Only failed(or canceled) jobs in completed stages can be retried.

Stages in progress: Build, BuildVS. Please wait for the stages to complete and then retry again.

…ection

The merge from upstream/master pulled in test_bgp_neighbor_description_injection
but its two decorator lines

    @patch.dict('sys.modules', **mockmapping)
    @patch('frrcfgd.frrcfgd.g_run_command')

were lost in the conflict resolution, so pytest collection failed with
"fixture 'run_cmd' not found".  Add them back to match the master copy.

No functional change.

Signed-off-by: Kalash Nainwal <kalash@nexthop.ai>
@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).

@kalash-nexthop

Copy link
Copy Markdown
Contributor Author

/azpw run

@mssonicbld

Copy link
Copy Markdown
Collaborator

⚠️ Notice: /azpw run only runs failed jobs now. If you want to trigger a whole pipline run, please rebase your branch or close and reopen the PR.
💡 Tip: You can also use /azpw retry to retry failed jobs directly.

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) stages in build 1107866:

✅Stage Test:

  • Job Trivy vulnerability scan (docker-ptf): retried.
  • Job impacted-area-kvmtest-t2 by Elastictest: retried.

@yxieca

yxieca commented May 11, 2026

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

1 similar comment
@yxieca

yxieca commented May 13, 2026

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: Allow streaming BMP events to an external BMP collector

6 participants