Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4e7609a
working prototype
NavdhaJindal Apr 12, 2025
5c1b9f5
pass vrf as context
NavdhaJindal Apr 24, 2025
fc07a60
test changes for ipv6
NavdhaJindal Apr 24, 2025
406cc9e
edit summary def
NavdhaJindal Apr 24, 2025
bd019bd
remove path join from test
NavdhaJindal Apr 26, 2025
c465866
remove code duplication in ipv4
NavdhaJindal Apr 29, 2025
32ac469
remove code duplication in ipv6
NavdhaJindal Apr 29, 2025
fdc8c1f
remove new test file, merge per vrf tests
NavdhaJindal May 1, 2025
47fad2f
refactor by adding helper functions
NavdhaJindal May 3, 2025
ecd9365
refactor into helper functions
NavdhaJindal May 3, 2025
f6ab27b
refactor neighbor and network tests
NavdhaJindal May 3, 2025
d52930c
add vrf param to network_test
NavdhaJindal May 3, 2025
158d58b
add bgp summary uts
NavdhaJindal May 5, 2025
d98f2b3
change expected error message
NavdhaJindal May 5, 2025
e6175a1
fix summary UTs
NavdhaJindal May 5, 2025
822baef
rename as 'all_bgp_instances'
NavdhaJindal May 5, 2025
29affd4
update command-reference
NavdhaJindal May 6, 2025
d485d86
remove extra whitespaces
NavdhaJindal May 8, 2025
488e2a9
add test with different vnet name
NavdhaJindal May 9, 2025
85d49c4
add tests for specific vrf
NavdhaJindal May 12, 2025
06d3ae0
add vrf tests to summary
NavdhaJindal May 12, 2025
7eeb8f2
correct nits
NavdhaJindal May 12, 2025
3bc10a2
revert command-reference changes
NavdhaJindal May 12, 2025
658c036
remove spacing
NavdhaJindal May 12, 2025
f0b084a
resolve static checks
NavdhaJindal May 13, 2025
60c1eec
fix typo
NavdhaJindal May 13, 2025
1da98b1
correct docstring and bgp function usecase
NavdhaJindal Jun 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2376,15 +2376,17 @@ Detailed show commands examples for Quagga are provided at the end of this docum

This command displays the summary of all IPv4 & IPv6 bgp neighbors that are configured and the corresponding states.

Optionally, you can specify a vrf-name in order to display summary only for that particular vrf.

- Usage:

*Versions >= 201904 using default FRR routing stack*
```
show bgp summary
show bgp [vrf <vrf-name>] summary
```
*Versions <= 201811 using Quagga routing stack*
```
show ip bgp summary
show ip bgp [vrf <vrf-name>] summary
```

- Example:
Expand Down Expand Up @@ -2462,11 +2464,11 @@ In order to get details for an IPv6 neigbor, use "show bgp ipv6 neighbor <ipv6_a

*Versions >= 201904 using default FRR routing stack*
```
show bgp neighbors [<ipv4-address> [advertised-routes | received-routes | routes]]
show bgp [vrf <vrf-name>] neighbors [<ipv4-address> [advertised-routes | received-routes | routes]]
```
*Versions <= 201811 using Quagga routing stack*
```
show ip bgp neighbors [<ipv4-address> [advertised-routes | received-routes | routes]]
show ip bgp [vrf <vrf-name>] neighbors [<ipv4-address> [advertised-routes | received-routes | routes]]
```

- Example:
Expand Down Expand Up @@ -2540,16 +2542,22 @@ Optionally, you can specify an IP address in order to display only that particul

Click [here](#Quagga-BGP-Show-Commands) to see the example for "show ip bgp neighbors" for Quagga.

Optionally, you can specify a vrf-name in order to display only neighbors for that particular vrf.

- Example:
```
admin@sonic:~$ show bgp vrf Vnet_90 neighbors
```

**show ip bgp network [[<ipv4-address>|<ipv4-prefix>] [(bestpath | multipath | longer-prefixes | json)]]
**show ip bgp [vrf <vrf-name>] network [[<ipv4-address>|<ipv4-prefix>] [(bestpath | multipath | longer-prefixes | json)]]**

This command displays all the details of IPv4 Border Gateway Protocol (BGP) prefixes.

- Usage:


```
show ip bgp network [[<ipv4-address>|<ipv4-prefix>] [(bestpath | multipath | longer-prefixes | json)]]
show ip bgp [vrf <vrf-name>] network [[<ipv4-address>|<ipv4-prefix>] [(bestpath | multipath | longer-prefixes | json)]]
```

- Example:
Expand All @@ -2572,23 +2580,25 @@ This command displays all the details of IPv4 Border Gateway Protocol (BGP) pref
admin@sonic:~$ show ip bgp network 10.1.0.32/32 json

admin@sonic:~$ show ip bgp network 10.1.0.32/32 longer-prefixes

admin@sonic:~$ show ip bgp vrf Vnet_90 network
```

**show bgp ipv6 summary (Versions >= 201904 using default FRR routing stack)**
**show bgp [vrf <vrf-name>] ipv6 summary (Versions >= 201904 using default FRR routing stack)**

**show ipv6 bgp summary (Versions <= 201811 using Quagga routing stack)**
**show ipv6 bgp [vrf <vrf-name>] summary (Versions <= 201811 using Quagga routing stack)**

This command displays the summary of all IPv6 bgp neighbors that are configured and the corresponding states.

- Usage:

*Versions >= 201904 using default FRR routing stack*
```
show bgp ipv6 summary
show bgp [vrf <vrf-name>] ipv6 summary
```
*Versions <= 201811 using Quagga routing stack*
```
show ipv6 bgp summary
show ipv6 bgp [vrf <vrf-name>] summary
```

- Example:
Expand Down Expand Up @@ -2623,11 +2633,11 @@ This command displays all the details of one particular IPv6 Border Gateway Prot

*Versions >= 201904 using default FRR routing stack*
```
show bgp ipv6 neighbors [<ipv6-address> [(advertised-routes | received-routes | routes)]]
show bgp [vrf <vrf-name>] ipv6 neighbors [<ipv6-address> [(advertised-routes | received-routes | routes)]]
```
*Versions <= 201811 using Quagga routing stack*
```
show ipv6 bgp neighbors [<ipv6-address> [(advertised-routes | received-routes | routes)]]
show ipv6 bgp [vrf <vrf-name>] neighbors [<ipv6-address> [(advertised-routes | received-routes | routes)]]
```

- Example:
Expand All @@ -2637,19 +2647,21 @@ This command displays all the details of one particular IPv6 Border Gateway Prot
admin@sonic:~$ show bgp ipv6 neighbors fc00::72 received-routes

admin@sonic:~$ show bgp ipv6 neighbors fc00::72 routes

admin@sonic:~$ show bgp vrf Vnet_90 ipv6 neighbors
```
Click [here](#Quagga-BGP-Show-Commands) to see the example for "show ip bgp summary" for Quagga.


**show ipv6 bgp network [[<ipv6-address>|<ipv6-prefix>] [(bestpath | multipath | longer-prefixes | json)]]
**show ipv6 bgp [vrf <vrf-name>] network [[<ipv6-address>|<ipv6-prefix>] [(bestpath | multipath | longer-prefixes | json)]]

This command displays all the details of IPv6 Border Gateway Protocol (BGP) prefixes.

- Usage:


```
show ipv6 bgp network [[<ipv6-address>|<ipv6-prefix>] [(bestpath | multipath | longer-prefixes | json)]]
show ipv6 bgp [vrf <vrf-name>] network [[<ipv6-address>|<ipv6-prefix>] [(bestpath | multipath | longer-prefixes | json)]]
```

- Example:
Expand All @@ -2672,7 +2684,8 @@ This command displays all the details of IPv6 Border Gateway Protocol (BGP) pref
admin@sonic:~$ show ipv6 bgp network fc00::72/64 json

admin@sonic:~$ show ipv6 bgp network fc00::72/64 longer-prefixes
```

admin@sonic:~$ show ipv6 bgp vrf Vnet_90 network



Expand Down
139 changes: 108 additions & 31 deletions show/bgp_frr_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
def bgp():
"""Show IPv4 BGP (Border Gateway Protocol) information"""
if device_info.is_supervisor():
subcommand = sys.argv[3]
if sys.argv[3] in "vrf":
subcommand = sys.argv[5]
else:
subcommand = sys.argv[3]
if subcommand not in "network":
# the command will be executed directly by rexec if it is not "show ip bgp network"
click.echo("Since the current device is a chassis supervisor, " +
Expand All @@ -33,10 +36,7 @@ def bgp():
@bgp.command()
@multi_asic_util.multi_asic_click_options
def summary(namespace, display):
bgp_summary = bgp_util.get_bgp_summary_from_all_bgp_instances(
constants.IPV4, namespace, display)
bgp_util.display_bgp_summary(bgp_summary=bgp_summary, af=constants.IPV4)

summary_helper(namespace, display)

# 'neighbors' subcommand ("show ip bgp neighbors")
@bgp.command()
Expand All @@ -55,8 +55,104 @@ def summary(namespace, display):
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def neighbors(ipaddress, info_type, namespace):
"""Show IP (IPv4) BGP neighbors"""
neighbors_helper(ipaddress, info_type, namespace)

# 'network' subcommand ("show ip bgp network")
@bgp.command()
@click.argument('ipaddress',
metavar='[<ipv4-address>|<ipv4-prefix>]',
required=True if device_info.is_supervisor() else False)
@click.argument('info_type',
metavar='[bestpath|json|longer-prefixes|multipath]',
type=click.Choice(
['bestpath', 'json', 'longer-prefixes', 'multipath']),
required=False)
@click.option('--namespace',
'-n',
'namespace',
type=str,
show_default=True,
required=False,
help='Namespace name or all',
default="all",
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def network(ipaddress, info_type, namespace):
"""Show IP (IPv4) BGP network"""
network_helper(ipaddress, info_type, namespace)

@bgp.group(cls=clicommon.AliasedGroup)
@click.argument('vrf', required=True)
@click.pass_context
def vrf(ctx, vrf):
"""Show IPv4 BGP information for a given VRF"""
pass

# 'summary' subcommand ("show ip bgp vrf <vrf/vnet name> summary")
@vrf.command('summary')
@multi_asic_util.multi_asic_click_options
@click.pass_context
def vrf_summary(ctx, namespace, display):
vrf = ctx.parent.params['vrf']
summary_helper(namespace, display, vrf)

# 'neighbors' subcommand ("show ip bgp vrf neighbors")
@vrf.command('neighbors')
@click.argument('ipaddress', required=False)
@click.argument('info_type',
type=click.Choice(
['routes', 'advertised-routes', 'received-routes']),
required=False)
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
@click.pass_context
def vrf_neighbors(ctx, ipaddress, info_type, namespace):
"""Show IP (IPv4) BGP neighbors"""
vrf = ctx.parent.params['vrf']
neighbors_helper(ipaddress, info_type, namespace, vrf)

# 'network' subcommand ("show ip bgp vrf network")
@vrf.command('network')
@click.argument('ipaddress',
metavar='[<ipv4-address>|<ipv4-prefix>]',
required=True if device_info.is_supervisor() else False)
@click.argument('info_type',
metavar='[bestpath|json|longer-prefixes|multipath]',
type=click.Choice(
['bestpath', 'json', 'longer-prefixes', 'multipath']),
required=False)
@click.option('--namespace',
'-n',
'namespace',
type=str,
show_default=True,
required=False,
help='Namespace name or all',
default="all",
callback=multi_asic_util.multi_asic_namespace_validation_callback)
@click.pass_context
def vrf_network(ctx, ipaddress, info_type, namespace):
"""Show IP (IPv4) BGP network"""
vrf = ctx.parent.params['vrf']
network_helper(ipaddress, info_type, namespace, vrf)

def summary_helper(namespace, display, vrf=None):
bgp_summary = bgp_util.get_bgp_summary_from_all_bgp_instances(
constants.IPV4, namespace, display, vrf)
bgp_util.display_bgp_summary(bgp_summary=bgp_summary, af=constants.IPV4)


def neighbors_helper(ipaddress, info_type, namespace, vrf=None):
command = 'show ip bgp'
if vrf is not None:
command += ' vrf {}'.format(vrf)
command += ' neighbor'

command = 'show ip bgp neighbor'
if ipaddress is not None:
if not bgp_util.is_ipv4_address(ipaddress):
ctx = click.get_current_context()
Expand Down Expand Up @@ -87,29 +183,11 @@ def neighbors(ipaddress, info_type, namespace):
output += bgp_util.run_bgp_show_command(command, ns)

click.echo(output.rstrip('\n'))


# 'network' subcommand ("show ip bgp network")
@bgp.command()
@click.argument('ipaddress',
metavar='[<ipv4-address>|<ipv4-prefix>]',
required=True if device_info.is_supervisor() else False)
@click.argument('info_type',
metavar='[bestpath|json|longer-prefixes|multipath]',
type=click.Choice(
['bestpath', 'json', 'longer-prefixes', 'multipath']),
required=False)
@click.option('--namespace',
'-n',
'namespace',
type=str,
show_default=True,
required=False,
help='Namespace name or all',
default="all",
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def network(ipaddress, info_type, namespace):
"""Show IP (IPv4) BGP network"""

def network_helper(ipaddress, info_type, namespace, vrf=None):
command = 'show ip bgp'
if vrf is not None:
command += ' vrf {}'.format(vrf)

if device_info.is_supervisor():
# the command will be executed by rexec
Expand All @@ -125,7 +203,6 @@ def network(ipaddress, info_type, namespace):
ctx.fail('invalid namespace {}. provide namespace from list {}'
.format(namespace, multi_asic.get_namespace_list()))

command = 'show ip bgp'
if ipaddress is not None:
if '/' in ipaddress:
# For network prefixes then this all info_type(s) are available
Expand Down Expand Up @@ -154,4 +231,4 @@ def network(ipaddress, info_type, namespace):
click.echo(output.rstrip('\n'))
else:
output = bgp_util.run_bgp_show_command(command, namespace)
click.echo(output.rstrip('\n'))
click.echo(output.rstrip('\n'))
Loading
Loading