Skip to content

Commit ddcfcf8

Browse files
gechianganand-kumar-subramanian
authored andcommitted
Added show ip/v6 route summary support for multi-asic platform (sonic-net#1320)
* 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.
1 parent c6fdf3a commit ddcfcf8

7 files changed

Lines changed: 78 additions & 29 deletions

File tree

show/bgp_common.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def show_routes(args, namespace, display, verbose, ipver):
330330
device = multi_asic_util.MultiAsic(display, namespace)
331331
arg_strg = ""
332332
found_json = 0
333-
found_tables = 0
333+
found_other_parms = 0
334334
ns_l = []
335335
print_ns_str = False
336336
filter_by_ip = False
@@ -353,26 +353,24 @@ def show_routes(args, namespace, display, verbose, ipver):
353353
else:
354354
back_end_intf_set = None
355355
# get all the other arguments except json that needs to be the last argument of the cmd if present
356+
# For Multi-ASIC platform the support for combining routes will be supported for "show ip/v6 route"
357+
# and optionally with specific IP address as parameter and the json option. If any other option is
358+
# specified, the handling will always be handled by the specific namespace FRR.
356359
for arg in args:
357360
arg_strg += str(arg) + " "
358361
if str(arg) == "json":
359362
found_json = 1
360-
elif str(arg) == "tables":
361-
found_tables = 1
362363
else:
363364
try:
364365
filter_by_ip = ipaddress.ip_network(arg)
365366
except ValueError:
366367
# Not ip address just ignore it
367-
pass
368-
# Due to options such as "summary" and "tables" are not yet supported in multi-asic platform
369-
# we will let FRR handle all the processing instead of handling it here for non multi-asic platform
368+
found_other_parms = 1
369+
370370
if multi_asic.is_multi_asic():
371-
if found_tables:
372-
print("% Unknown command: show {} route {}".format(ipver, arg_strg))
373-
return
374-
if not found_json:
371+
if not found_json and not found_other_parms:
375372
arg_strg += "json"
373+
376374
combined_route = {}
377375
for ns in ns_l:
378376
# Need to add "ns" to form bgpX so it is sent to the correct bgpX docker to handle the request
@@ -398,6 +396,13 @@ def show_routes(args, namespace, display, verbose, ipver):
398396
error_msg = output
399397
print(error_msg)
400398
return
399+
400+
# Multi-asic show ip route with additional parms are handled by going to FRR directly and get those outputs from each namespace
401+
if found_other_parms:
402+
print("{}:".format(ns))
403+
print(output)
404+
continue
405+
401406
route_info = json.loads(output)
402407
if filter_back_end or print_ns_str:
403408
# clean up the dictionary to remove all the nexthops that are back-end interface

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,10 @@ def setup_multi_asic_bgp_instance(request):
170170
m_asic_json_file = 'ip_empty_route.json'
171171
elif request.param == 'ip_specific_route_on_1_asic':
172172
m_asic_json_file = 'ip_special_route_asic0_only.json'
173+
elif request.param == 'ip_route_summary':
174+
m_asic_json_file = 'ip_route_summary.txt'
173175
else:
174-
bgp_mocked_json = os.path.join(
176+
m_asic_json_file = os.path.join(
175177
test_path, 'mock_tables', 'dummy.json')
176178

177179
def mock_run_bgp_command(vtysh_cmd, bgp_namespace):

tests/ip_show_routes_multi_asic_test.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,6 @@ def test_show_multi_asic_ipv6_route_specific(
9191
assert result.exit_code == 0
9292
assert result.output == show_ip_route_common.show_ipv6_route_multi_asic_specific_route_output
9393

94-
@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
95-
['ip_route'], indirect=['setup_multi_asic_bgp_instance'])
96-
def test_show_multi_asic_ip_route_tables_option_err(
97-
self,
98-
setup_ip_route_commands,
99-
setup_multi_asic_bgp_instance):
100-
show = setup_ip_route_commands
101-
runner = CliRunner()
102-
result = runner.invoke(
103-
show.cli.commands["ip"].commands["route"], ["tables"])
104-
print("{}".format(result.output))
105-
assert result.exit_code == 0
106-
assert result.output == show_ip_route_common.show_ip_route_multi_asic_invalid_tables_cmd_err_output
107-
10894
# note that we purposely use the single bgp instance setup to cause trigger a param error bad
10995
# just bail out while executing in multi-asic show ipv6 route handling.
11096
# This is to test out the error parm handling code path
@@ -220,6 +206,20 @@ def test_show_multi_asic_ip_route_empty_route(
220206
assert result.exit_code == 0
221207
assert result.output == ""
222208

209+
@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
210+
['ip_route_summary'], indirect=['setup_multi_asic_bgp_instance'])
211+
def test_show_multi_asic_ip_route_summay(
212+
self,
213+
setup_ip_route_commands,
214+
setup_multi_asic_bgp_instance):
215+
show = setup_ip_route_commands
216+
runner = CliRunner()
217+
result = runner.invoke(
218+
show.cli.commands["ip"].commands["route"], ["summary"])
219+
print("{}".format(result.output))
220+
assert result.exit_code == 0
221+
assert result.output == show_ip_route_common.show_ip_route_summary_expected_output
222+
223223
@classmethod
224224
def teardown_class(cls):
225225
print("TEARDOWN")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Route Source Routes FIB (vrf default)
2+
kernel 1 1
3+
connected 6 6
4+
static 1 0
5+
ebgp 6371 6371
6+
ibgp 88 88
7+
------
8+
Totals 6467 6466
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Route Source Routes FIB (vrf default)
2+
kernel 1 1
3+
connected 6 6
4+
static 1 0
5+
ebgp 6371 6371
6+
ibgp 88 88
7+
------
8+
Totals 6467 6466
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Route Source Routes FIB (vrf default)
2+
kernel 1 1
3+
connected 14 14
4+
static 1 0
5+
ebgp 42 42
6+
ibgp 6409 6409
7+
------
8+
Totals 6467 6466

tests/show_ip_route_common.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,10 +584,6 @@
584584
dislay option 'everything' is not a valid option.
585585
"""
586586

587-
show_ip_route_multi_asic_invalid_tables_cmd_err_output = """\
588-
% Unknown command: show ip route tables
589-
"""
590-
591587
show_ip_route_multi_asic_specific_route_output = """\
592588
Routing entry for 10.0.0.4/31
593589
Known via "connected", distance 0, metric 0, best
@@ -644,3 +640,25 @@
644640
}
645641
"""
646642

643+
show_ip_route_summary_expected_output = """\
644+
asic0:
645+
Route Source Routes FIB (vrf default)
646+
kernel 1 1
647+
connected 6 6
648+
static 1 0
649+
ebgp 6371 6371
650+
ibgp 88 88
651+
------
652+
Totals 6467 6466
653+
654+
asic2:
655+
Route Source Routes FIB (vrf default)
656+
kernel 1 1
657+
connected 14 14
658+
static 1 0
659+
ebgp 42 42
660+
ibgp 6409 6409
661+
------
662+
Totals 6467 6466
663+
664+
"""

0 commit comments

Comments
 (0)