Skip to content

Commit

Permalink
Added show ip/v6 route summary support for multi-asic platform (#1320)
Browse files Browse the repository at this point in the history
* Added show ip/v6 route summary support for multi-asic platform by making any additional parameter handling other than specific route cases or json format to be handled by the corresponding namespace FRR directly.
  • Loading branch information
gechiang committed Dec 23, 2020
1 parent 6202a81 commit d63d11d
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 29 deletions.
25 changes: 15 additions & 10 deletions show/bgp_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def show_routes(args, namespace, display, verbose, ipver):
device = multi_asic_util.MultiAsic(display, namespace)
arg_strg = ""
found_json = 0
found_tables = 0
found_other_parms = 0
ns_l = []
print_ns_str = False
filter_by_ip = False
Expand All @@ -353,26 +353,24 @@ def show_routes(args, namespace, display, verbose, ipver):
else:
back_end_intf_set = None
# get all the other arguments except json that needs to be the last argument of the cmd if present
# For Multi-ASIC platform the support for combining routes will be supported for "show ip/v6 route"
# and optionally with specific IP address as parameter and the json option. If any other option is
# specified, the handling will always be handled by the specific namespace FRR.
for arg in args:
arg_strg += str(arg) + " "
if str(arg) == "json":
found_json = 1
elif str(arg) == "tables":
found_tables = 1
else:
try:
filter_by_ip = ipaddress.ip_network(arg)
except ValueError:
# Not ip address just ignore it
pass
# Due to options such as "summary" and "tables" are not yet supported in multi-asic platform
# we will let FRR handle all the processing instead of handling it here for non multi-asic platform
found_other_parms = 1

if multi_asic.is_multi_asic():
if found_tables:
print("% Unknown command: show {} route {}".format(ipver, arg_strg))
return
if not found_json:
if not found_json and not found_other_parms:
arg_strg += "json"

combined_route = {}
for ns in ns_l:
# Need to add "ns" to form bgpX so it is sent to the correct bgpX docker to handle the request
Expand All @@ -398,6 +396,13 @@ def show_routes(args, namespace, display, verbose, ipver):
error_msg = output
print(error_msg)
return

# Multi-asic show ip route with additional parms are handled by going to FRR directly and get those outputs from each namespace
if found_other_parms:
print("{}:".format(ns))
print(output)
continue

route_info = json.loads(output)
if filter_back_end or print_ns_str:
# clean up the dictionary to remove all the nexthops that are back-end interface
Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ def setup_multi_asic_bgp_instance(request):
m_asic_json_file = 'ip_empty_route.json'
elif request.param == 'ip_specific_route_on_1_asic':
m_asic_json_file = 'ip_special_route_asic0_only.json'
elif request.param == 'ip_route_summary':
m_asic_json_file = 'ip_route_summary.txt'
else:
bgp_mocked_json = os.path.join(
m_asic_json_file = os.path.join(
test_path, 'mock_tables', 'dummy.json')

def mock_run_bgp_command(vtysh_cmd, bgp_namespace):
Expand Down
28 changes: 14 additions & 14 deletions tests/ip_show_routes_multi_asic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,6 @@ def test_show_multi_asic_ipv6_route_specific(
assert result.exit_code == 0
assert result.output == show_ip_route_common.show_ipv6_route_multi_asic_specific_route_output

@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['ip_route'], indirect=['setup_multi_asic_bgp_instance'])
def test_show_multi_asic_ip_route_tables_option_err(
self,
setup_ip_route_commands,
setup_multi_asic_bgp_instance):
show = setup_ip_route_commands
runner = CliRunner()
result = runner.invoke(
show.cli.commands["ip"].commands["route"], ["tables"])
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ip_route_common.show_ip_route_multi_asic_invalid_tables_cmd_err_output

# note that we purposely use the single bgp instance setup to cause trigger a param error bad
# just bail out while executing in multi-asic show ipv6 route handling.
# This is to test out the error parm handling code path
Expand Down Expand Up @@ -220,6 +206,20 @@ def test_show_multi_asic_ip_route_empty_route(
assert result.exit_code == 0
assert result.output == ""

@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['ip_route_summary'], indirect=['setup_multi_asic_bgp_instance'])
def test_show_multi_asic_ip_route_summay(
self,
setup_ip_route_commands,
setup_multi_asic_bgp_instance):
show = setup_ip_route_commands
runner = CliRunner()
result = runner.invoke(
show.cli.commands["ip"].commands["route"], ["summary"])
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ip_route_common.show_ip_route_summary_expected_output

@classmethod
def teardown_class(cls):
print("TEARDOWN")
Expand Down
8 changes: 8 additions & 0 deletions tests/mock_tables/asic0/ip_route_summary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Route Source Routes FIB (vrf default)
kernel 1 1
connected 6 6
static 1 0
ebgp 6371 6371
ibgp 88 88
------
Totals 6467 6466
8 changes: 8 additions & 0 deletions tests/mock_tables/asic1/ip_route_summary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Route Source Routes FIB (vrf default)
kernel 1 1
connected 6 6
static 1 0
ebgp 6371 6371
ibgp 88 88
------
Totals 6467 6466
8 changes: 8 additions & 0 deletions tests/mock_tables/asic2/ip_route_summary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Route Source Routes FIB (vrf default)
kernel 1 1
connected 14 14
static 1 0
ebgp 42 42
ibgp 6409 6409
------
Totals 6467 6466
26 changes: 22 additions & 4 deletions tests/show_ip_route_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,6 @@
dislay option 'everything' is not a valid option.
"""

show_ip_route_multi_asic_invalid_tables_cmd_err_output = """\
% Unknown command: show ip route tables
"""

show_ip_route_multi_asic_specific_route_output = """\
Routing entry for 10.0.0.4/31
Known via "connected", distance 0, metric 0, best
Expand Down Expand Up @@ -644,3 +640,25 @@
}
"""

show_ip_route_summary_expected_output = """\
asic0:
Route Source Routes FIB (vrf default)
kernel 1 1
connected 6 6
static 1 0
ebgp 6371 6371
ibgp 88 88
------
Totals 6467 6466
asic2:
Route Source Routes FIB (vrf default)
kernel 1 1
connected 14 14
static 1 0
ebgp 42 42
ibgp 6409 6409
------
Totals 6467 6466
"""

0 comments on commit d63d11d

Please sign in to comment.