diff --git a/show/bgp_common.py b/show/bgp_common.py index f439c97e65dd..50df00dcbbb8 100644 --- a/show/bgp_common.py +++ b/show/bgp_common.py @@ -52,12 +52,18 @@ def get_mpls_label_strgs(label_list): label_str_2_return += "/" + label_string return label_str_2_return -def get_nexthop_info_str(nxhp_info): +def get_nexthop_info_str(nxhp_info, filterByIp): str_2_return = "" if "ip" in nxhp_info: - str_2_return = " via {},".format(nxhp_info['ip']) + if filterByIp: + str_2_return = " * {}".format(nxhp_info['ip']) + else: + str_2_return = " via {},".format(nxhp_info['ip']) if "interfaceName" in nxhp_info: - str_2_return += " {},".format(nxhp_info['interfaceName']) + if filterByIp: + str_2_return += ", via {}".format(nxhp_info['interfaceName']) + else: + str_2_return += " {},".format(nxhp_info['interfaceName']) elif "directlyConnected" in nxhp_info: str_2_return = " is directly connected," if "interfaceName" in nxhp_info: @@ -152,13 +158,7 @@ def print_ip_routes(route_info, filter_by_ip): if "directlyConnected" in info[i]['nexthops'][j]: print(" * directly connected, {}\n".format(info[i]['nexthops'][j]['interfaceName'])) else: - if "ip" in info[i]['nexthops'][j]: - str_2_print = " * {}".format(info[i]['nexthops'][j]['ip']) - - if "active" in info[i]['nexthops'][j]: - str_2_print += ", via {}".format(info[i]['nexthops'][j]['interfaceName']) - else: - str_2_print += " inactive" + str_2_print = get_nexthop_info_str(info[i]['nexthops'][j], True) print(str_2_print) print("") else: @@ -183,7 +183,7 @@ def print_ip_routes(route_info, filter_by_ip): # For all subsequent nexthops skip the spacing to not repeat the prefix section str_2_print += " "*(str_length - 3) # Get the nexhop info portion of the string - str_2_print += get_nexthop_info_str(info[i]['nexthops'][j]) + str_2_print += get_nexthop_info_str(info[i]['nexthops'][j], False) # add uptime at the end of the string str_2_print += " {}".format(info[i]['uptime']) # print out this string diff --git a/tests/conftest.py b/tests/conftest.py index 9a2f30438ee3..16c018bb641c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -170,6 +170,8 @@ 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_specific_recursive_route': + m_asic_json_file = 'ip_special_recursive_route.json' elif request.param == 'ip_route_summary': m_asic_json_file = 'ip_route_summary.txt' else: diff --git a/tests/ip_show_routes_multi_asic_test.py b/tests/ip_show_routes_multi_asic_test.py index 19e9137df066..271467dae54a 100644 --- a/tests/ip_show_routes_multi_asic_test.py +++ b/tests/ip_show_routes_multi_asic_test.py @@ -77,6 +77,20 @@ def test_show_multi_asic_ip_route_specific_on_1_asic( assert result.exit_code == 0 assert result.output == show_ip_route_common.show_specific_ip_route_expected_output + @pytest.mark.parametrize('setup_multi_asic_bgp_instance', + ['ip_specific_recursive_route'], indirect=['setup_multi_asic_bgp_instance']) + def test_show_multi_asic_ip_route_specific_recursive_route( + 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"], ["193.11.208.0/25"]) + print("{}".format(result.output)) + assert result.exit_code == 0 + assert result.output == show_ip_route_common.show_specific_recursive_route_expected_output + @pytest.mark.parametrize('setup_multi_asic_bgp_instance', ['ipv6_specific_route'], indirect=['setup_multi_asic_bgp_instance']) def test_show_multi_asic_ipv6_route_specific( diff --git a/tests/mock_tables/asic0/ip_special_recursive_route.json b/tests/mock_tables/asic0/ip_special_recursive_route.json new file mode 100644 index 000000000000..0904495cebcf --- /dev/null +++ b/tests/mock_tables/asic0/ip_special_recursive_route.json @@ -0,0 +1,39 @@ +{ + "193.11.208.0/25": [ + { + "destSelected": true, + "distance": 20, + "installed": true, + "internalFlags": 8, + "internalNextHopActiveNum": 2, + "internalNextHopNum": 2, + "internalStatus": 16, + "metric": 0, + "nexthops": [ + { + "active": true, + "afi": "ipv4", + "fib": true, + "flags": 3, + "interfaceIndex": 728, + "interfaceName": "PortChannel0005", + "ip": "10.0.0.5" + }, + { + "active": true, + "afi": "ipv4", + "fib": true, + "flags": 3, + "interfaceIndex": 727, + "interfaceName": "PortChannel0002", + "ip": "10.0.0.1" + } + ], + "prefix": "193.11.208.0/25", + "protocol": "bgp", + "selected": true, + "table": 254, + "uptime": "00:14:32" + } + ] +} diff --git a/tests/mock_tables/asic1/ip_special_recursive_route.json b/tests/mock_tables/asic1/ip_special_recursive_route.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/tests/mock_tables/asic1/ip_special_recursive_route.json @@ -0,0 +1 @@ +{} diff --git a/tests/mock_tables/asic2/ip_special_recursive_route.json b/tests/mock_tables/asic2/ip_special_recursive_route.json new file mode 100644 index 000000000000..76f6de0ed58e --- /dev/null +++ b/tests/mock_tables/asic2/ip_special_recursive_route.json @@ -0,0 +1,35 @@ +{ + "193.11.208.0/25": [ + { + "destSelected": true, + "distance": 20, + "installed": true, + "internalFlags": 8, + "internalNextHopActiveNum": 0, + "internalNextHopNum": 0, + "internalStatus": 16, + "metric": 0, + "nexthops": [ + { + "active": true, + "afi": "ipv4", + "flags": 5, + "ip": "10.0.0.9", + "recursive": true + }, + { + "active": true, + "afi": "ipv4", + "flags": 5, + "ip": "10.0.0.1", + "recursive": true + } + ], + "prefix": "193.11.208.0/25", + "protocol": "bgp", + "selected": true, + "table": 254, + "uptime": "00:14:35" + } + ] +} diff --git a/tests/show_ip_route_common.py b/tests/show_ip_route_common.py index e18e8b0a5a15..386d32e55e39 100644 --- a/tests/show_ip_route_common.py +++ b/tests/show_ip_route_common.py @@ -93,6 +93,17 @@ """ +show_specific_recursive_route_expected_output = """\ +Routing entry for 193.11.208.0/25 + Known via "bgp", distance 20, metric 0, best + Last update 00:14:32 ago + * 10.0.0.1, via PortChannel0002 + * 10.0.0.5, via PortChannel0005 + * 10.0.0.9 (recursive) + * 10.0.0.1 (recursive) + +""" + show_special_ip_route_expected_output = """\ Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,