Commit f5f55d5
authored
Add CLI commands for bgp aggregate feature (#295)
<!--
Please make sure you've read and understood our contributing guidelines:
https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md
failure_prs.log skip_prs.log 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)1 parent fd161e5 commit f5f55d5
11 files changed
Lines changed: 847 additions & 0 deletions
File tree
- config
- doc
- show
- tests
- bgp_input
- mock_config
- utilities_common
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
| 3 | + | |
2 | 4 | | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
| |||
190 | 193 | | |
191 | 194 | | |
192 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4750 | 4750 | | |
4751 | 4751 | | |
4752 | 4752 | | |
| 4753 | + | |
4753 | 4754 | | |
4754 | 4755 | | |
4755 | 4756 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2786 | 2786 | | |
2787 | 2787 | | |
2788 | 2788 | | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
| 2794 | + | |
| 2795 | + | |
| 2796 | + | |
| 2797 | + | |
| 2798 | + | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
| 2807 | + | |
| 2808 | + | |
| 2809 | + | |
| 2810 | + | |
| 2811 | + | |
| 2812 | + | |
| 2813 | + | |
| 2814 | + | |
| 2815 | + | |
| 2816 | + | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
| 2822 | + | |
| 2823 | + | |
| 2824 | + | |
| 2825 | + | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
2789 | 2829 | | |
2790 | 2830 | | |
2791 | 2831 | | |
| |||
2916 | 2956 | | |
2917 | 2957 | | |
2918 | 2958 | | |
| 2959 | + | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
| 2991 | + | |
| 2992 | + | |
| 2993 | + | |
| 2994 | + | |
| 2995 | + | |
| 2996 | + | |
| 2997 | + | |
2919 | 2998 | | |
2920 | 2999 | | |
2921 | 3000 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
126 | 128 | | |
127 | 129 | | |
128 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
86 | 95 | | |
87 | 96 | | |
88 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
75 | 84 | | |
76 | 85 | | |
77 | 86 | | |
| |||
0 commit comments