Skip to content

Commit

Permalink
[201911]: add show bgp neigh/network support for multi asic (#1587)
Browse files Browse the repository at this point in the history
This is port of the PR #1574 in 201911 branch

This PR is to add support for the commands show ip bgp neighbor and show ip bgp network
Add unit tests for these commands
  • Loading branch information
arlakshm authored May 4, 2021
1 parent 9f695d0 commit 92aadfd
Show file tree
Hide file tree
Showing 11 changed files with 1,696 additions and 39 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
'mock_tables/asic0/*',
'mock_tables/asic1/*',
'mock_tables/asic2/*',
'bgp_commands_input/*',
'filter_fdb_input/*',
'pfcwd_input/*',
'sku_create_input/*',
Expand Down
91 changes: 69 additions & 22 deletions show/bgp_frr_v4.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import click

from sonic_py_common import multi_asic
from show.main import AliasedGroup, ip
import utilities_common.bgp_util as bgp_util
import utilities_common.constants as constants
import utilities_common.multi_asic as multi_asic_util
from show.main import AliasedGroup, ip, run_command



###############################################################################
Expand All @@ -30,36 +32,82 @@ def summary(namespace, display):
# 'neighbors' subcommand ("show ip bgp neighbors")
@bgp.command()
@click.argument('ipaddress', required=False)
@click.argument('info_type', type=click.Choice(['routes', 'advertised-routes', 'received-routes']), required=False)
def neighbors(ipaddress, info_type):
@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)
def neighbors(ipaddress, info_type, namespace):
"""Show IP (IPv4) BGP neighbors"""

command = 'sudo vtysh -c "show ip bgp neighbor'

command = 'show ip bgp neighbor'
if ipaddress is not None:
command += ' {}'.format(ipaddress)

# info_type is only valid if ipaddress is specified
if info_type is not None:
command += ' {}'.format(info_type)

command += '"'

run_command(command)
if not bgp_util.is_ipv4_address(ipaddress):
ctx = click.get_current_context()
ctx.fail("{} is not valid ipv4 address\n".format(ipaddress))
try:
actual_namespace = bgp_util.get_namespace_for_bgp_neighbor(
ipaddress)
if namespace is not None and namespace != actual_namespace:
click.echo(
"[WARNING]: bgp neighbor {} is present in namespace {} not in {}"
.format(ipaddress, actual_namespace, namespace))

# save the namespace in which the bgp neighbor is configured
namespace = actual_namespace

command += ' {}'.format(ipaddress)

# info_type is only valid if ipaddress is specified
if info_type is not None:
command += ' {}'.format(info_type)
except ValueError as err:
ctx = click.get_current_context()
ctx.fail("{}\n".format(err))

ns_list = multi_asic.get_namespace_list(namespace)
output = ""
for ns in ns_list:
output += bgp_util.run_bgp_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=False)
@click.argument('info_type', metavar='[bestpath|json|longer-prefixes|multipath]',
type=click.Choice(['bestpath', 'json', 'longer-prefixes', 'multipath']), required=False)
def network(ipaddress, info_type):
@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=True if multi_asic.is_multi_asic is True else False,
help='Namespace name or all',
default=None,
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def network(ipaddress, info_type, namespace):
"""Show IP (IPv4) BGP network"""

command = 'sudo vtysh -c "show ip bgp'
if multi_asic.is_multi_asic() and namespace not in multi_asic.get_namespace_list():
ctx = click.get_current_context()
ctx.fail('-n/--namespace option required. provide namespace from list {}'\
.format(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
# For network prefixes then this all info_type(s) are available
pass
else:
# For an ipaddress then check info_type, exit if specified option doesn't work.
Expand All @@ -74,6 +122,5 @@ def network(ipaddress, info_type):
if info_type is not None:
command += ' {}'.format(info_type)

command += '"'

run_command(command)
output = bgp_util.run_bgp_command(command, namespace)
click.echo(output.rstrip('\n'))
84 changes: 70 additions & 14 deletions show/bgp_frr_v6.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import click

from sonic_py_common import multi_asic
import utilities_common.bgp_util as bgp_util
import utilities_common.constants as constants
import utilities_common.multi_asic as multi_asic_util
from show.main import AliasedGroup, ipv6, run_command
from show.main import AliasedGroup, ipv6
###############################################################################
#
# 'show ipv6 bgp' cli stanza
Expand All @@ -28,27 +29,83 @@ def summary(namespace, display):
# 'neighbors' subcommand ("show ipv6 bgp neighbors")
@bgp.command()
@click.argument('ipaddress', required=False)
@click.argument('info_type', type=click.Choice(['routes', 'advertised-routes', 'received-routes']), required=False)
def neighbors(ipaddress, info_type):
@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)
def neighbors(ipaddress, info_type, namespace):
"""Show IPv6 BGP neighbors"""
ipaddress = "" if ipaddress is None else ipaddress

if ipaddress is not None:
if not bgp_util.is_ipv6_address(ipaddress):
ctx = click.get_current_context()
ctx.fail("{} is not valid ipv6 address\n".format(ipaddress))
try:
actual_namespace = bgp_util.get_namespace_for_bgp_neighbor(
ipaddress)
if namespace is not None and namespace != actual_namespace:
click.echo(
"bgp neighbor {} is present in namespace {} not in {}"
.format(ipaddress, actual_namespace, namespace))

# save the namespace in which the bgp neighbor is configured
namespace = actual_namespace
except ValueError as err:
ctx = click.get_current_context()
ctx.fail("{}\n".format(err))
else:
ipaddress = ""

info_type = "" if info_type is None else info_type
command = 'sudo vtysh -c "show bgp ipv6 neighbor {} {}"'.format(ipaddress, info_type)
run_command(command)
command = 'show bgp ipv6 neighbor {} {}'.format(
ipaddress, info_type)

ns_list = multi_asic.get_namespace_list(namespace)
output = ""
for ns in ns_list:
output += bgp_util.run_bgp_command(command, ns)

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


# 'network' subcommand ("show ipv6 bgp network")
@bgp.command()
@click.argument('ipaddress', metavar='[<ipv6-address>|<ipv6-prefix>]', required=False)
@click.argument('info_type', metavar='[bestpath|json|longer-prefixes|multipath]',
type=click.Choice(['bestpath', 'json', 'longer-prefixes', 'multipath']), required=False)
def network(ipaddress, info_type):
@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=True if multi_asic.is_multi_asic is True else False,
help='Namespace name or all',
default=None,
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def network(ipaddress, info_type, namespace):
"""Show BGP ipv6 network"""

command = 'sudo vtysh -c "show bgp ipv6'
command = 'show bgp ipv6'

if multi_asic.is_multi_asic() and namespace not in multi_asic.get_namespace_list():
ctx = click.get_current_context()
ctx.fail('-n/--namespace option required. provide namespace from list {}'\
.format(multi_asic.get_namespace_list()))

if ipaddress is not None:
if '/' in ipaddress:
# For network prefixes then this all info_type(s) are available
# For network prefixes then this all info_type(s) are available
pass
else:
# For an ipaddress then check info_type, exit if specified option doesn't work.
Expand All @@ -63,6 +120,5 @@ def network(ipaddress, info_type):
if info_type is not None:
command += ' {}'.format(info_type)

command += '"'

run_command(command)
output = bgp_util.run_bgp_command(command, namespace)
click.echo(output.rstrip('\n'))
Empty file.
Loading

0 comments on commit 92aadfd

Please sign in to comment.