Skip to content

[action] [PR:4354] Add CLI commands for bgp aggregate feature#295

Merged
mssonicbld merged 1 commit into
Azure:202603from
mssonicbld:cherry/msft-202603/4354
Mar 24, 2026
Merged

[action] [PR:4354] Add CLI commands for bgp aggregate feature#295
mssonicbld merged 1 commit into
Azure:202603from
mssonicbld:cherry/msft-202603/4354

Conversation

@mssonicbld

Copy link
Copy Markdown
Collaborator

What I did

Add CLI commands for bgp aggregate feature
The HLD design is at https://github.com/sonic-net/SONiC/blob/master/doc/BGP/BGP-route-aggregation-with-bbr-awareness.md#cli-design
image

How I did it

Files Modified
1. utilities_common/bgp.py — Added CFG_BGP_AGGREGATE_ADDRESS = "BGP_AGGREGATE_ADDRESS" constant
2. config/bgp_cli.py — Added:
• validate_ip_prefix() callback for IP prefix validation
• AGGREGATE_ADDRESS click group (config bgp aggregate-address)
• add command with options: --bbr-required, --summary-only, --as-set, --aggregate-address-prefix-list, --contributing-address-prefix-list
• remove command taking an address argument
• Both commands check for duplicate/missing entries before modifying Config DB
3. config/main.py — Registered bgp_cli.AGGREGATE_ADDRESS under the bgp group
4. show/bgp_cli.py — Added show_aggregate_address(db, af) helper that:
• Reads BGP_AGGREGATE_ADDRESS from Config DB
• Reads state from State DB when available
• Filters entries by address family (ipv4/ipv6)
• Displays flags: A=As Set, B=BBR Required, S=Summary Only
5. show/bgp_frr_v4.py — Added aggregate-address subcommand under show ip bgp
6. show/bgp_frr_v6.py — Added aggregate-address subcommand under show ipv6 bgp

Files Created
1. tests/bgp_aggregate_address_test.py — Unit tests for add/remove/show commands (10 test cases)
2. tests/bgp_input/mock_config/aggregate_address.json — Mock Config DB with v4+v6 entries
3. tests/bgp_input/mock_config/aggregate_address_empty.json — Empty mock Config DB
4. tests/bgp_input/assert_show_output.py — Expected show output strings for v4, v6, and empty cases

How to verify it

  1. Add UT
  2. Verified on DUT devices:
admin@sonic:~$ show ip bgp aggregate-address
Flags: A - As Set, B - BBR Required, S - Summary Only

Prefix          State    Option Flags    Aggregate Address Prefix List    Contributing Address Prefix List
--------------  -------  --------------  -------------------------------  ----------------------------------
192.168.0.0/24  Active   B
admin@sonic:~$ sudo config bgp aggregate-address add 192.168.0.0/24 --summary-only --as-set
Usage: config bgp aggregate-address add [OPTIONS] ADDRESS
Try 'config bgp aggregate-address add -h' for help.

Error: Aggregate address '192.168.0.0/24' already exists

admin@sonic:~$ sudo config bgp aggregate-address remove 192.168.0.0/24
admin@sonic:~$ sudo config bgp aggregate-address add 192.168.0.0/24 --summary-only --as-set
admin@sonic:~$ show ip bgp aggregate-address
Flags: A - As Set, B - BBR Required, S - Summary Only

Prefix          State    Option Flags    Aggregate Address Prefix List    Contributing Address Prefix List
--------------  -------  --------------  -------------------------------  ----------------------------------
192.168.0.0/24  Active   A,S

admin@sonic:~$ sudo config bgp aggregate-address add fc00:1::/64 --bbr-required --aggregate-address-prefix-list AGG_ROUTE_V4 --contributing-address-prefix-list CONTRIBUTING_ROUTE_V4
admin@sonic:~$ show ip bgp aggregate-address
Flags: A - As Set, B - BBR Required, S - Summary Only

Prefix          State    Option Flags    Aggregate Address Prefix List    Contributing Address Prefix List
--------------  -------  --------------  -------------------------------  ----------------------------------
192.168.0.0/24  Active   A,S

admin@sonic:~$ show ipv6 bgp aggregate-address
Flags: A - As Set, B - BBR Required, S - Summary Only

Prefix       State    Option Flags    Aggregate Address Prefix List    Contributing Address Prefix List
-----------  -------  --------------  -------------------------------  ----------------------------------
fc00:1::/64  Active   B               AGG_ROUTE_V4                     CONTRIBUTING_ROUTE_V4
admin@sonic:~$ sudo config bgp aggregate-address remove fc00:1::/64
admin@sonic:~$ show ipv6 bgp aggregate-address
Flags: A - As Set, B - BBR Required, S - Summary Only

Prefix    State    Option Flags    Aggregate Address Prefix List    Contributing Address Prefix List
--------  -------  --------------  -------------------------------  ----------------------------------
admin@sonic:~$ sudo config bgp aggregate-address add fc00:1::/64 --bbr-required --aggregate-address-prefix-list AGG_ROUTE_V4 --contributing-address-prefix-list CONTRIBUTING_ROUTE_V4
admin@sonic:~$ sudo config bgp aggregate-address add fc00:2::/64 --bbr-required --aggregate-address-prefix-list AGG_ROUTE_V4 --contributing-address-prefix-list CONTRIBUTING_ROUTE_V4

admin@sonic:~$sudo config bgp aggregate-address add fc00:9::/64   --bbr-required   --aggregate-address-prefix-list AGG_ROUTE_V4   --contributing-address-prefix-list *$CONTRIBUTING_ROUTE_V4_#$#$#
Error: '*#00' is invalid for contributing-address-prefix-list: only alphanumeric characters, underscores and hyphens are allowed

admin@sonic:~$ show ipv6 bgp aggregate-address
Flags: A - As Set, B - BBR Required, S - Summary Only

Prefix       State    Option Flags    Aggregate Address Prefix List    Contributing Address Prefix List
-----------  -------  --------------  -------------------------------  ----------------------------------
fc00:1::/64  Active   B               AGG_ROUTE_V4                     CONTRIBUTING_ROUTE_V4
fc00:2::/64  Active   B               AGG_ROUTE_V4                     CONTRIBUTING_ROUTE_V4
admin@sonic:~$ show ipv6 bgp -h
Usage: show ipv6 bgp [OPTIONS] COMMAND [ARGS]...

  Show IPv6 BGP (Border Gateway Protocol) information

Options:
  -?, -h, --help  Show this message and exit.

Commands:
  aggregate-address  Show IPv6 BGP aggregate addresses
  neighbors          Show IPv6 BGP neighbors
  network            Show BGP ipv6 network
  summary            Show summarized information of IPv6 BGP state
  vrf                Show IPv6 BGP information for a given VRF
admin@sonic:~$ sudo config bgp -h
Usage: config bgp [OPTIONS] COMMAND [ARGS]...

  BGP-related configuration tasks

Options:
  -?, -h, --help  Show this message and exit.

Commands:
  aggregate-address  Configure BGP aggregate addresses
  device-global      Configure BGP device global state
  remove             Remove BGP neighbor configuration from the device
  shutdown           Shut down BGP session(s)
  startup            Start up BGP session(s)

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

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

<!--
    Please make sure you've read and understood our contributing guidelines:
    https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

    ** Make sure all your commits include a signature generated with `git commit -s` **

    If this is a bug fix, make sure your description includes "closes #xxxx",
    "fixes #xxxx" or "resolves #xxxx" so that GitHub automatically closes the related
    issue when the PR is merged.

    If you are adding/modifying/removing any command or utility script, please also
    make sure to add/modify/remove any unit tests from the tests
    directory as appropriate.

    If you are modifying or removing an existing 'show', 'config' or 'sonic-clear'
    subcommand, or you are adding a new subcommand, please make sure you also
    update the Command Line Reference Guide (doc/Command-Reference.md) to reflect
    your changes.

    Please provide the following information:
-->

#### What I did
Add CLI commands for bgp aggregate feature
The HLD design is at https://github.com/sonic-net/SONiC/blob/master/doc/BGP/BGP-route-aggregation-with-bbr-awareness.md#cli-design
<img width="1117" height="685" alt="image" src="https://github.com/user-attachments/assets/f74fe2f9-5f30-4214-900a-b00260d20199" />

#### How I did it
Files Modified
	1. utilities_common/bgp.py — Added CFG_BGP_AGGREGATE_ADDRESS = "BGP_AGGREGATE_ADDRESS" constant
	2. config/bgp_cli.py — Added:
	• validate_ip_prefix() callback for IP prefix validation
	• AGGREGATE_ADDRESS click group (config bgp aggregate-address)
	• add command with options: --bbr-required, --summary-only, --as-set, --aggregate-address-prefix-list, --contributing-address-prefix-list
	• remove command taking an address argument
	• Both commands check for duplicate/missing entries before modifying Config DB
	3. config/main.py — Registered bgp_cli.AGGREGATE_ADDRESS under the bgp group
	4. show/bgp_cli.py — Added show_aggregate_address(db, af) helper that:
	  • Reads BGP_AGGREGATE_ADDRESS from Config DB
	  • Reads state from State DB when available
	  • Filters entries by address family (ipv4/ipv6)
	  • Displays flags: A=As Set, B=BBR Required, S=Summary Only
	5. show/bgp_frr_v4.py — Added aggregate-address subcommand under show ip bgp
	6. show/bgp_frr_v6.py — Added aggregate-address subcommand under show ipv6 bgp

Files Created
	1. tests/bgp_aggregate_address_test.py — Unit tests for add/remove/show commands (10 test cases)
	2. tests/bgp_input/mock_config/aggregate_address.json — Mock Config DB with v4+v6 entries
	3. tests/bgp_input/mock_config/aggregate_address_empty.json — Empty mock Config DB
	4. tests/bgp_input/assert_show_output.py — Expected show output strings for v4, v6, and empty cases

#### How to verify it

1. Add UT
2. Verified on DUT devices:
```
admin@sonic:~$ show ip bgp aggregate-address
Flags: A - As Set, B - BBR Required, S - Summary Only

Prefix          State    Option Flags    Aggregate Address Prefix List    Contributing Address Prefix List
--------------  -------  --------------  -------------------------------  ----------------------------------
192.168.0.0/24  Active   B
admin@sonic:~$ sudo config bgp aggregate-address add 192.168.0.0/24 --summary-only --as-set
Usage: config bgp aggregate-address add [OPTIONS] ADDRESS
Try 'config bgp aggregate-address add -h' for help.

Error: Aggregate address '192.168.0.0/24' already exists

admin@sonic:~$ sudo config bgp aggregate-address remove 192.168.0.0/24
admin@sonic:~$ sudo config bgp aggregate-address add 192.168.0.0/24 --summary-only --as-set
admin@sonic:~$ show ip bgp aggregate-address
Flags: A - As Set, B - BBR Required, S - Summary Only

Prefix          State    Option Flags    Aggregate Address Prefix List    Contributing Address Prefix List
--------------  -------  --------------  -------------------------------  ----------------------------------
192.168.0.0/24  Active   A,S

admin@sonic:~$ sudo config bgp aggregate-address add fc00:1::/64 --bbr-required --aggregate-address-prefix-list AGG_ROUTE_V4 --contributing-address-prefix-list CONTRIBUTING_ROUTE_V4
admin@sonic:~$ show ip bgp aggregate-address
Flags: A - As Set, B - BBR Required, S - Summary Only

Prefix          State    Option Flags    Aggregate Address Prefix List    Contributing Address Prefix List
--------------  -------  --------------  -------------------------------  ----------------------------------
192.168.0.0/24  Active   A,S

admin@sonic:~$ show ipv6 bgp aggregate-address
Flags: A - As Set, B - BBR Required, S - Summary Only

Prefix       State    Option Flags    Aggregate Address Prefix List    Contributing Address Prefix List
-----------  -------  --------------  -------------------------------  ----------------------------------
fc00:1::/64  Active   B               AGG_ROUTE_V4                     CONTRIBUTING_ROUTE_V4
admin@sonic:~$ sudo config bgp aggregate-address remove fc00:1::/64
admin@sonic:~$ show ipv6 bgp aggregate-address
Flags: A - As Set, B - BBR Required, S - Summary Only

Prefix    State    Option Flags    Aggregate Address Prefix List    Contributing Address Prefix List
--------  -------  --------------  -------------------------------  ----------------------------------
admin@sonic:~$ sudo config bgp aggregate-address add fc00:1::/64 --bbr-required --aggregate-address-prefix-list AGG_ROUTE_V4 --contributing-address-prefix-list CONTRIBUTING_ROUTE_V4
admin@sonic:~$ sudo config bgp aggregate-address add fc00:2::/64 --bbr-required --aggregate-address-prefix-list AGG_ROUTE_V4 --contributing-address-prefix-list CONTRIBUTING_ROUTE_V4

admin@sonic:~$sudo config bgp aggregate-address add fc00:9::/64   --bbr-required   --aggregate-address-prefix-list AGG_ROUTE_V4   --contributing-address-prefix-list *$CONTRIBUTING_ROUTE_V4_#$#$#
Error: '*#00' is invalid for contributing-address-prefix-list: only alphanumeric characters, underscores and hyphens are allowed

admin@sonic:~$ show ipv6 bgp aggregate-address
Flags: A - As Set, B - BBR Required, S - Summary Only

Prefix       State    Option Flags    Aggregate Address Prefix List    Contributing Address Prefix List
-----------  -------  --------------  -------------------------------  ----------------------------------
fc00:1::/64  Active   B               AGG_ROUTE_V4                     CONTRIBUTING_ROUTE_V4
fc00:2::/64  Active   B               AGG_ROUTE_V4                     CONTRIBUTING_ROUTE_V4
admin@sonic:~$ show ipv6 bgp -h
Usage: show ipv6 bgp [OPTIONS] COMMAND [ARGS]...

  Show IPv6 BGP (Border Gateway Protocol) information

Options:
  -?, -h, --help  Show this message and exit.

Commands:
  aggregate-address  Show IPv6 BGP aggregate addresses
  neighbors          Show IPv6 BGP neighbors
  network            Show BGP ipv6 network
  summary            Show summarized information of IPv6 BGP state
  vrf                Show IPv6 BGP information for a given VRF
admin@sonic:~$ sudo config bgp -h
Usage: config bgp [OPTIONS] COMMAND [ARGS]...

  BGP-related configuration tasks

Options:
  -?, -h, --help  Show this message and exit.

Commands:
  aggregate-address  Configure BGP aggregate addresses
  device-global      Configure BGP device global state
  remove             Remove BGP neighbor configuration from the device
  shutdown           Shut down BGP session(s)
  startup            Start up BGP session(s)
```

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

#### Previous command output (if the output of a command-line utility has changed)

#### New command output (if the output of a command-line utility has changed)
@mssonicbld

Copy link
Copy Markdown
Collaborator Author

Original PR: sonic-net/sonic-utilities#4354

@mssonicbld

Copy link
Copy Markdown
Collaborator Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

@mssonicbld mssonicbld merged commit f5f55d5 into Azure:202603 Mar 24, 2026
4 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.

1 participant