diff --git a/tests/bgp_commands_test.py b/tests/bgp_commands_test.py index 24b4fdeafb16..c8624687814c 100644 --- a/tests/bgp_commands_test.py +++ b/tests/bgp_commands_test.py @@ -4,6 +4,12 @@ from click.testing import CliRunner +from utilities_common import multi_asic +from utilities_common import constants + +from unittest.mock import patch + +from sonic_py_common import device_info show_bgp_summary_v4 = """\ IPv4 Unicast Summary: @@ -91,6 +97,117 @@ Error: bgp summary from bgp container not in json format """ +show_bgp_summary_v4_chassis = """\ + +IPv4 Unicast Summary: +BGP router identifier 10.3.147.15, local AS number 65100 vrf-id 0 +BGP table version 21464 +RIB entries 25783, using 4950336 bytes of memory +Peers 23, using 501768 KiB of memory +Peer groups 3, using 192 bytes of memory + + +Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName +----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- -------------- +10.0.0.1 4 65200 4632 11028 0 0 0 00:18:31 8514 ARISTA01T2 +10.0.0.9 4 65202 4632 11029 0 0 0 00:18:33 8514 ARISTA05T2 +10.0.0.13 4 65203 4632 11028 0 0 0 00:18:33 8514 ARISTA07T2 +10.0.0.17 4 65204 4631 11028 0 0 0 00:18:31 8514 ARISTA09T2 +10.0.0.21 4 65205 4632 11031 0 0 0 00:18:33 8514 ARISTA11T2 +10.0.0.25 4 65206 4632 11031 0 0 0 00:18:33 8514 ARISTA13T2 +10.0.0.29 4 65207 4632 11028 0 0 0 00:18:31 8514 ARISTA15T2 +10.0.0.33 4 65208 4633 11029 0 0 0 00:18:33 8514 ARISTA01T0 +10.0.0.37 4 65210 4632 11028 0 0 0 00:18:32 8514 ARISTA03T0 +10.0.0.39 4 65211 4629 6767 0 0 0 00:18:22 8514 ARISTA04T0 +10.0.0.41 4 65212 4632 11028 0 0 0 00:18:32 8514 ARISTA05T0 +10.0.0.43 4 65213 4629 6767 0 0 0 00:18:23 8514 ARISTA06T0 +10.0.0.45 4 65214 4633 11029 0 0 0 00:18:33 8514 ARISTA07T0 +10.0.0.47 4 65215 4629 6767 0 0 0 00:18:23 8514 ARISTA08T0 +10.0.0.49 4 65216 4633 11029 0 0 0 00:18:35 8514 ARISTA09T0 +10.0.0.51 4 65217 4633 11029 0 0 0 00:18:33 8514 ARISTA10T0 +10.0.0.53 4 65218 4632 11029 0 0 0 00:18:35 8514 ARISTA11T0 +10.0.0.55 4 65219 4632 11029 0 0 0 00:18:33 8514 ARISTA12T0 +10.0.0.57 4 65220 4632 11029 0 0 0 00:18:35 8514 ARISTA13T0 +10.0.0.59 4 65221 4632 11029 0 0 0 00:18:33 8514 ARISTA14T0 + +Total number of neighbors 20 +""" + +show_bgp_summary_v6_chassis = """\ + +IPv6 Unicast Summary: +BGP router identifier 10.3.147.15, local AS number 65100 vrf-id 0 +BGP table version 12971 +RIB entries 25783, using 4950336 bytes of memory +Peers 23, using 501768 KiB of memory +Peer groups 3, using 192 bytes of memory + + +Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName +----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- -------------- +fc00::1a 4 65203 4438 6578 0 0 0 00:08:57 8514 ARISTA07T2 +fc00::2 4 65200 4439 6578 0 0 0 00:08:56 8513 ARISTA01T2 +fc00::2a 4 65205 4439 6578 0 0 0 00:08:57 8514 ARISTA11T2 +fc00::3a 4 65207 4439 6578 0 0 0 00:08:57 8514 ARISTA15T2 +fc00::4a 4 65210 4439 6579 0 0 0 00:08:59 8514 ARISTA03T0 +fc00::4e 4 65211 4440 6579 0 0 0 00:09:00 8514 ARISTA04T0 +fc00::5a 4 65214 4440 6579 0 0 0 00:09:00 8514 ARISTA07T0 +fc00::5e 4 65215 4438 6576 0 0 0 00:08:50 8514 ARISTA08T0 +fc00::6a 4 65218 4441 6580 0 0 0 00:09:01 8514 ARISTA11T0 +fc00::6e 4 65219 4442 6580 0 0 0 00:09:01 8514 ARISTA12T0 +fc00::7a 4 65222 4441 6580 0 0 0 00:09:01 8514 ARISTA15T0 +fc00::12 4 65202 4438 6578 0 0 0 00:08:57 8514 ARISTA05T2 +fc00::22 4 65204 4438 6578 0 0 0 00:08:57 8514 ARISTA09T2 +fc00::32 4 65206 4438 6578 0 0 0 00:08:57 8514 ARISTA13T2 +fc00::42 4 65208 4442 6580 0 0 0 00:09:01 8514 ARISTA01T0 +fc00::52 4 65212 4439 6579 0 0 0 00:08:59 8514 ARISTA05T0 +fc00::56 4 65213 4439 6579 0 0 0 00:08:59 8514 ARISTA06T0 +fc00::62 4 65216 4438 6576 0 0 0 00:08:50 8514 ARISTA09T0 +fc00::66 4 65217 4442 6580 0 0 0 00:09:01 8514 ARISTA10T0 +fc00::72 4 65220 4441 6580 0 0 0 00:09:01 8514 ARISTA13T0 + +Total number of neighbors 20 +""" + +show_bgp_summary_v4_all_chassis = """\ + +IPv4 Unicast Summary: +BGP router identifier 10.3.147.15, local AS number 65100 vrf-id 0 +BGP table version 21464 +RIB entries 25783, using 4950336 bytes of memory +Peers 23, using 501768 KiB of memory +Peer groups 3, using 192 bytes of memory + + +Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName +----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- ------------------ +3.3.3.6 4 65100 0 0 0 0 0 never Connect str2-chassis-lc6-1 +3.3.3.7 4 65100 808 178891 0 0 0 00:17:47 1458 str2-chassis-lc7-1 +10.0.0.1 4 65200 4632 11028 0 0 0 00:18:31 8514 ARISTA01T2 +10.0.0.9 4 65202 4632 11029 0 0 0 00:18:33 8514 ARISTA05T2 +10.0.0.13 4 65203 4632 11028 0 0 0 00:18:33 8514 ARISTA07T2 +10.0.0.17 4 65204 4631 11028 0 0 0 00:18:31 8514 ARISTA09T2 +10.0.0.21 4 65205 4632 11031 0 0 0 00:18:33 8514 ARISTA11T2 +10.0.0.25 4 65206 4632 11031 0 0 0 00:18:33 8514 ARISTA13T2 +10.0.0.29 4 65207 4632 11028 0 0 0 00:18:31 8514 ARISTA15T2 +10.0.0.33 4 65208 4633 11029 0 0 0 00:18:33 8514 ARISTA01T0 +10.0.0.37 4 65210 4632 11028 0 0 0 00:18:32 8514 ARISTA03T0 +10.0.0.39 4 65211 4629 6767 0 0 0 00:18:22 8514 ARISTA04T0 +10.0.0.41 4 65212 4632 11028 0 0 0 00:18:32 8514 ARISTA05T0 +10.0.0.43 4 65213 4629 6767 0 0 0 00:18:23 8514 ARISTA06T0 +10.0.0.45 4 65214 4633 11029 0 0 0 00:18:33 8514 ARISTA07T0 +10.0.0.47 4 65215 4629 6767 0 0 0 00:18:23 8514 ARISTA08T0 +10.0.0.49 4 65216 4633 11029 0 0 0 00:18:35 8514 ARISTA09T0 +10.0.0.51 4 65217 4633 11029 0 0 0 00:18:33 8514 ARISTA10T0 +10.0.0.53 4 65218 4632 11029 0 0 0 00:18:35 8514 ARISTA11T0 +10.0.0.55 4 65219 4632 11029 0 0 0 00:18:33 8514 ARISTA12T0 +10.0.0.57 4 65220 4632 11029 0 0 0 00:18:35 8514 ARISTA13T0 +10.0.0.59 4 65221 4632 11029 0 0 0 00:18:33 8514 ARISTA14T0 +10.0.0.61 4 65222 4633 11029 0 0 0 00:18:33 8514 INT_NEIGH0 + +Total number of neighbors 23 +""" + class TestBgpCommands(object): @classmethod @@ -139,3 +256,66 @@ def test_bgp_summary_error( print("{}".format(result.output)) assert result.exit_code == 2 assert result.output == show_error_invalid_json + + def display_external(self): + return constants.DISPLAY_EXTERNAL + + def display_all(self): + return constants.DISPLAY_ALL + + @pytest.mark.parametrize( + 'setup_single_bgp_instance_chassis', ['v4'], + indirect=['setup_single_bgp_instance_chassis'] + ) + @patch.object(multi_asic.MultiAsic, 'get_display_option', display_external) + @patch('sonic_py_common.device_info.get_platform_info') + def test_bgp_summary_v4_chassis( + self, mock_is_chassis, setup_bgp_commands, + setup_single_bgp_instance_chassis + ): + mock_is_chassis.return_value = {'switch_type': 'voq'} + show = setup_bgp_commands + runner = CliRunner() + result = runner.invoke( + show.cli.commands["ip"].commands["bgp"].commands["summary"], []) + print("{}".format(result.output)) + assert result.exit_code == 0 + assert result.output == show_bgp_summary_v4_chassis + + @pytest.mark.parametrize( + 'setup_single_bgp_instance_chassis', ['v6'], + indirect=['setup_single_bgp_instance_chassis'] + ) + @patch.object(multi_asic.MultiAsic, 'get_display_option', display_external) + @patch('sonic_py_common.device_info.get_platform_info') + def test_bgp_summary_v6_chassis( + self, mock_is_chassis, setup_bgp_commands, + setup_single_bgp_instance_chassis + ): + mock_is_chassis.return_value = {'switch_type': 'voq'} + show = setup_bgp_commands + runner = CliRunner() + result = runner.invoke( + show.cli.commands["ipv6"].commands["bgp"].commands["summary"], []) + print("{}".format(result.output)) + assert result.exit_code == 0 + assert result.output == show_bgp_summary_v6_chassis + + @pytest.mark.parametrize( + 'setup_single_bgp_instance_chassis', ['v4'], + indirect=['setup_single_bgp_instance_chassis'] + ) + @patch.object(multi_asic.MultiAsic, 'get_display_option', display_all) + @patch('sonic_py_common.device_info.get_platform_info') + def test_bgp_summary_v4_all_chassis( + self, mock_is_chassis, setup_bgp_commands, + setup_single_bgp_instance_chassis + ): + mock_is_chassis.return_value = {'switch_type': 'voq'} + show = setup_bgp_commands + runner = CliRunner() + result = runner.invoke( + show.cli.commands["ip"].commands["bgp"].commands["summary"], []) + print("{}".format(result.output)) + assert result.exit_code == 0 + assert result.output == show_bgp_summary_v4_all_chassis diff --git a/tests/conftest.py b/tests/conftest.py index 68bf6cbc4395..ecf32ffa0534 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,7 +4,6 @@ import sys from unittest import mock - import pytest from sonic_py_common import device_info, multi_asic from swsscommon.swsscommon import ConfigDBConnector @@ -126,12 +125,37 @@ def setup_multi_broadcom_masic(): multi_asic.is_multi_asic= mock.MagicMock(return_value=False) +@pytest.fixture +def setup_single_bgp_instance_chassis(request): + import utilities_common.bgp_util as bgp_util + + def mock_show_bgp_summary( + vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND + ): + if os.path.isfile(bgp_mocked_json): + with open(bgp_mocked_json) as json_data: + mock_frr_data = json_data.read() + return mock_frr_data + return "" + + if request.param == 'v4': + bgp_mocked_json = os.path.join( + test_path, 'mock_tables', 'ipv4_bgp_summary_chassis.json') + elif request.param == 'v6': + bgp_mocked_json = os.path.join( + test_path, 'mock_tables', 'ipv6_bgp_summary_chassis.json') + + bgp_util.run_bgp_command = mock.MagicMock( + return_value=mock_show_bgp_summary("", "")) + + @pytest.fixture def setup_t1_topo(): dbconnector.topo = "t1" yield dbconnector.topo = None + @pytest.fixture def setup_single_bgp_instance(request): import utilities_common.bgp_util as bgp_util @@ -151,7 +175,7 @@ def mock_show_bgp_summary(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RV mock_frr_data = json_data.read() return mock_frr_data return "" - + def mock_run_bgp_command_for_static(vtysh_cmd, bgp_namespace="", vtysh_shell_cmd=constants.RVTYSH_COMMAND): if vtysh_cmd == "show ip route vrf all static": return config_int_ip_common.show_ip_route_with_static_expected_output @@ -176,7 +200,7 @@ def mock_run_show_ip_route_commands(request): else: return "" - + if any ([request.param == 'ipv6_route_err', request.param == 'ip_route',\ request.param == 'ip_specific_route', request.param == 'ip_special_route',\ request.param == 'ipv6_route', request.param == 'ipv6_specific_route']): @@ -248,7 +272,7 @@ def mock_run_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVT if m_asic_json_file.startswith('bgp_v4_network') or \ m_asic_json_file.startswith('bgp_v6_network'): return mock_show_bgp_network_multi_asic(m_asic_json_file) - + if m_asic_json_file.startswith('bgp_v4_neighbor') or \ m_asic_json_file.startswith('bgp_v6_neighbor'): return mock_show_bgp_neighbor_multi_asic(m_asic_json_file, bgp_namespace) diff --git a/tests/mock_tables/config_db.json b/tests/mock_tables/config_db.json index 94a684f90b68..59bd5880c699 100644 --- a/tests/mock_tables/config_db.json +++ b/tests/mock_tables/config_db.json @@ -1533,6 +1533,26 @@ "nhopself": "0", "rrclient": "0" }, + "BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.6": { + "admin_status": "up", + "asn": "65100", + "holdtime": "0", + "keepalive": "0", + "local_addr": "3.3.3.3", + "name": "str2-chassis-lc6-1", + "nhopself": "0", + "rrclient": "0" + }, + "BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.7": { + "admin_status": "up", + "asn": "65100", + "holdtime": "0", + "keepalive": "0", + "local_addr": "3.3.3.3", + "name": "str2-chassis-lc7-1", + "nhopself": "0", + "rrclient": "0" + }, "FLEX_COUNTER_TABLE|QUEUE": { "POLL_INTERVAL": "10000", "FLEX_COUNTER_STATUS": "enable" diff --git a/tests/mock_tables/ipv4_bgp_summary_chassis.json b/tests/mock_tables/ipv4_bgp_summary_chassis.json new file mode 100644 index 000000000000..d6c233877e17 --- /dev/null +++ b/tests/mock_tables/ipv4_bgp_summary_chassis.json @@ -0,0 +1,437 @@ +{ +"ipv4Unicast":{ + "routerId":"10.3.147.15", + "as":65100, + "vrfId":0, + "vrfName":"default", + "tableVersion":21464, + "ribCount":25783, + "ribMemory":4950336, + "peerCount":23, + "peerMemory":501768, + "peerGroupCount":3, + "peerGroupMemory":192, + "peers":{ + "10.0.0.1":{ + "remoteAs":65200, + "version":4, + "msgRcvd":4632, + "msgSent":11028, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:31", + "peerUptimeMsec":1111000, + "peerUptimeEstablishedEpoch":1637176411, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.9":{ + "remoteAs":65202, + "version":4, + "msgRcvd":4632, + "msgSent":11029, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:33", + "peerUptimeMsec":1113000, + "peerUptimeEstablishedEpoch":1637176409, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.13":{ + "remoteAs":65203, + "version":4, + "msgRcvd":4632, + "msgSent":11028, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:33", + "peerUptimeMsec":1113000, + "peerUptimeEstablishedEpoch":1637176409, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.17":{ + "remoteAs":65204, + "version":4, + "msgRcvd":4631, + "msgSent":11028, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:31", + "peerUptimeMsec":1111000, + "peerUptimeEstablishedEpoch":1637176411, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.21":{ + "remoteAs":65205, + "version":4, + "msgRcvd":4632, + "msgSent":11031, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:33", + "peerUptimeMsec":1113000, + "peerUptimeEstablishedEpoch":1637176409, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.25":{ + "remoteAs":65206, + "version":4, + "msgRcvd":4632, + "msgSent":11031, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:33", + "peerUptimeMsec":1113000, + "peerUptimeEstablishedEpoch":1637176409, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.29":{ + "remoteAs":65207, + "version":4, + "msgRcvd":4632, + "msgSent":11028, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:31", + "peerUptimeMsec":1111000, + "peerUptimeEstablishedEpoch":1637176411, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.33":{ + "remoteAs":65208, + "version":4, + "msgRcvd":4633, + "msgSent":11029, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:33", + "peerUptimeMsec":1113000, + "peerUptimeEstablishedEpoch":1637176409, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.37":{ + "remoteAs":65210, + "version":4, + "msgRcvd":4632, + "msgSent":11028, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:32", + "peerUptimeMsec":1112000, + "peerUptimeEstablishedEpoch":1637176410, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.39":{ + "remoteAs":65211, + "version":4, + "msgRcvd":4629, + "msgSent":6767, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:22", + "peerUptimeMsec":1102000, + "peerUptimeEstablishedEpoch":1637176420, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.41":{ + "remoteAs":65212, + "version":4, + "msgRcvd":4632, + "msgSent":11028, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:32", + "peerUptimeMsec":1112000, + "peerUptimeEstablishedEpoch":1637176410, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.43":{ + "remoteAs":65213, + "version":4, + "msgRcvd":4629, + "msgSent":6767, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:23", + "peerUptimeMsec":1103000, + "peerUptimeEstablishedEpoch":1637176419, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.45":{ + "remoteAs":65214, + "version":4, + "msgRcvd":4633, + "msgSent":11029, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:33", + "peerUptimeMsec":1113000, + "peerUptimeEstablishedEpoch":1637176409, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.47":{ + "remoteAs":65215, + "version":4, + "msgRcvd":4629, + "msgSent":6767, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:23", + "peerUptimeMsec":1103000, + "peerUptimeEstablishedEpoch":1637176419, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.49":{ + "remoteAs":65216, + "version":4, + "msgRcvd":4633, + "msgSent":11029, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:35", + "peerUptimeMsec":1115000, + "peerUptimeEstablishedEpoch":1637176407, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.51":{ + "remoteAs":65217, + "version":4, + "msgRcvd":4633, + "msgSent":11029, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:33", + "peerUptimeMsec":1113000, + "peerUptimeEstablishedEpoch":1637176409, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.53":{ + "remoteAs":65218, + "version":4, + "msgRcvd":4632, + "msgSent":11029, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:35", + "peerUptimeMsec":1115000, + "peerUptimeEstablishedEpoch":1637176407, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.55":{ + "remoteAs":65219, + "version":4, + "msgRcvd":4632, + "msgSent":11029, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:33", + "peerUptimeMsec":1113000, + "peerUptimeEstablishedEpoch":1637176409, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.57":{ + "remoteAs":65220, + "version":4, + "msgRcvd":4632, + "msgSent":11029, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:35", + "peerUptimeMsec":1115000, + "peerUptimeEstablishedEpoch":1637176407, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.59":{ + "remoteAs":65221, + "version":4, + "msgRcvd":4632, + "msgSent":11029, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:33", + "peerUptimeMsec":1113000, + "peerUptimeEstablishedEpoch":1637176409, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "10.0.0.61":{ + "remoteAs":65222, + "version":4, + "msgRcvd":4633, + "msgSent":11029, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:18:33", + "peerUptimeMsec":1113000, + "peerUptimeEstablishedEpoch":1637176409, + "pfxRcd":8514, + "pfxSnt":12847, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "3.3.3.6":{ + "remoteAs":65100, + "version":4, + "msgRcvd":0, + "msgSent":0, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"never", + "peerUptimeMsec":0, + "pfxRcd":0, + "state":"Connect", + "connectionsEstablished":0, + "connectionsDropped":0, + "idType":"ipv4" + }, + "3.3.3.7":{ + "hostname":"str2-7804-lc7-1", + "remoteAs":65100, + "version":4, + "msgRcvd":808, + "msgSent":178891, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:17:47", + "peerUptimeMsec":1067000, + "peerUptimeEstablishedEpoch":1637176455, + "pfxRcd":1458, + "pfxSnt":178819, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + } + }, + "failedPeers":1, + "totalPeers":23, + "dynamicPeers":0, + "bestPath":{ + "multiPathRelax":"true", + "peerTypeRelax":true + } +} +} diff --git a/tests/mock_tables/ipv6_bgp_summary_chassis.json b/tests/mock_tables/ipv6_bgp_summary_chassis.json new file mode 100644 index 000000000000..fd525ed88c72 --- /dev/null +++ b/tests/mock_tables/ipv6_bgp_summary_chassis.json @@ -0,0 +1,437 @@ +{ +"ipv6Unicast":{ + "routerId":"10.3.147.15", + "as":65100, + "vrfId":0, + "vrfName":"default", + "tableVersion":12971, + "ribCount":25783, + "ribMemory":4950336, + "peerCount":23, + "peerMemory":501768, + "peerGroupCount":3, + "peerGroupMemory":192, + "peers":{ + "fc00::2":{ + "remoteAs":65200, + "version":4, + "msgRcvd":4439, + "msgSent":6578, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:08:56", + "peerUptimeMsec":536000, + "peerUptimeEstablishedEpoch":1637278598, + "pfxRcd":8513, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::12":{ + "remoteAs":65202, + "version":4, + "msgRcvd":4438, + "msgSent":6578, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:08:57", + "peerUptimeMsec":537000, + "peerUptimeEstablishedEpoch":1637278597, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::1a":{ + "remoteAs":65203, + "version":4, + "msgRcvd":4438, + "msgSent":6578, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:08:57", + "peerUptimeMsec":537000, + "peerUptimeEstablishedEpoch":1637278597, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::22":{ + "remoteAs":65204, + "version":4, + "msgRcvd":4438, + "msgSent":6578, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:08:57", + "peerUptimeMsec":537000, + "peerUptimeEstablishedEpoch":1637278597, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::2a":{ + "remoteAs":65205, + "version":4, + "msgRcvd":4439, + "msgSent":6578, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:08:57", + "peerUptimeMsec":537000, + "peerUptimeEstablishedEpoch":1637278597, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::32":{ + "remoteAs":65206, + "version":4, + "msgRcvd":4438, + "msgSent":6578, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:08:57", + "peerUptimeMsec":537000, + "peerUptimeEstablishedEpoch":1637278597, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::3a":{ + "remoteAs":65207, + "version":4, + "msgRcvd":4439, + "msgSent":6578, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:08:57", + "peerUptimeMsec":537000, + "peerUptimeEstablishedEpoch":1637278597, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::42":{ + "remoteAs":65208, + "version":4, + "msgRcvd":4442, + "msgSent":6580, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:09:01", + "peerUptimeMsec":541000, + "peerUptimeEstablishedEpoch":1637278593, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::4a":{ + "remoteAs":65210, + "version":4, + "msgRcvd":4439, + "msgSent":6579, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:08:59", + "peerUptimeMsec":539000, + "peerUptimeEstablishedEpoch":1637278595, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::4e":{ + "remoteAs":65211, + "version":4, + "msgRcvd":4440, + "msgSent":6579, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:09:00", + "peerUptimeMsec":540000, + "peerUptimeEstablishedEpoch":1637278594, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::52":{ + "remoteAs":65212, + "version":4, + "msgRcvd":4439, + "msgSent":6579, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:08:59", + "peerUptimeMsec":539000, + "peerUptimeEstablishedEpoch":1637278595, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::56":{ + "remoteAs":65213, + "version":4, + "msgRcvd":4439, + "msgSent":6579, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:08:59", + "peerUptimeMsec":539000, + "peerUptimeEstablishedEpoch":1637278595, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::5a":{ + "remoteAs":65214, + "version":4, + "msgRcvd":4440, + "msgSent":6579, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:09:00", + "peerUptimeMsec":540000, + "peerUptimeEstablishedEpoch":1637278594, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::5e":{ + "remoteAs":65215, + "version":4, + "msgRcvd":4438, + "msgSent":6576, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:08:50", + "peerUptimeMsec":530000, + "peerUptimeEstablishedEpoch":1637278604, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::62":{ + "remoteAs":65216, + "version":4, + "msgRcvd":4438, + "msgSent":6576, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:08:50", + "peerUptimeMsec":530000, + "peerUptimeEstablishedEpoch":1637278604, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::66":{ + "remoteAs":65217, + "version":4, + "msgRcvd":4442, + "msgSent":6580, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:09:01", + "peerUptimeMsec":541000, + "peerUptimeEstablishedEpoch":1637278593, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::6a":{ + "remoteAs":65218, + "version":4, + "msgRcvd":4441, + "msgSent":6580, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:09:01", + "peerUptimeMsec":541000, + "peerUptimeEstablishedEpoch":1637278593, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::6e":{ + "remoteAs":65219, + "version":4, + "msgRcvd":4442, + "msgSent":6580, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:09:01", + "peerUptimeMsec":541000, + "peerUptimeEstablishedEpoch":1637278593, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::72":{ + "remoteAs":65220, + "version":4, + "msgRcvd":4441, + "msgSent":6580, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:09:01", + "peerUptimeMsec":541000, + "peerUptimeEstablishedEpoch":1637278593, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::76":{ + "remoteAs":65221, + "version":4, + "msgRcvd":4441, + "msgSent":6580, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:09:01", + "peerUptimeMsec":541000, + "peerUptimeEstablishedEpoch":1637278593, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "fc00::7a":{ + "remoteAs":65222, + "version":4, + "msgRcvd":4441, + "msgSent":6580, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:09:01", + "peerUptimeMsec":541000, + "peerUptimeEstablishedEpoch":1637278593, + "pfxRcd":8514, + "pfxSnt":12846, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv6" + }, + "3.3.3.6":{ + "remoteAs":65100, + "version":4, + "msgRcvd":0, + "msgSent":0, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"never", + "peerUptimeMsec":0, + "pfxRcd":0, + "state":"Active", + "connectionsEstablished":0, + "connectionsDropped":0, + "idType":"ipv4" + }, + "3.3.3.7":{ + "hostname":"str2-7804-lc7-1", + "remoteAs":65100, + "version":4, + "msgRcvd":808, + "msgSent":178891, + "tableVersion":0, + "outq":0, + "inq":0, + "peerUptime":"00:08:14", + "peerUptimeMsec":494000, + "peerUptimeEstablishedEpoch":1637278640, + "pfxRcd":1456, + "pfxSnt":178818, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + } + }, + "failedPeers":1, + "totalPeers":23, + "dynamicPeers":0, + "bestPath":{ + "multiPathRelax":"true", + "peerTypeRelax":true + } +} +} diff --git a/utilities_common/bgp_util.py b/utilities_common/bgp_util.py index c0262b3aeb9a..3b2ef99a11d7 100644 --- a/utilities_common/bgp_util.py +++ b/utilities_common/bgp_util.py @@ -97,6 +97,8 @@ def get_bgp_neighbors_dict(namespace=multi_asic.DEFAULT_NAMESPACE): static_neighbors = get_neighbor_dict_from_table(config_db, 'BGP_NEIGHBOR') static_internal_neighbors = get_neighbor_dict_from_table(config_db, 'BGP_INTERNAL_NEIGHBOR') static_neighbors.update(static_internal_neighbors) + static_internal_neighbors = get_neighbor_dict_from_table(config_db, 'BGP_VOQ_CHASSIS_NEIGHBOR') + static_neighbors.update(static_internal_neighbors) bgp_monitors = get_neighbor_dict_from_table(config_db, 'BGP_MONITORS') static_neighbors.update(bgp_monitors) dynamic_neighbors = get_dynamic_neighbor_subnet(config_db) diff --git a/utilities_common/multi_asic.py b/utilities_common/multi_asic.py index 2586d216bf65..7e704befe7d4 100644 --- a/utilities_common/multi_asic.py +++ b/utilities_common/multi_asic.py @@ -5,7 +5,7 @@ import netifaces import pyroute2 from natsort import natsorted -from sonic_py_common import multi_asic +from sonic_py_common import multi_asic, device_info from utilities_common import constants from utilities_common.general import load_db_config @@ -24,6 +24,9 @@ def __init__( self.is_multi_asic = multi_asic.is_multi_asic() self.db = db + def get_display_option(self): + return self.display_option + def is_object_internal(self, object_type, cli_object): ''' The function checks if a CLI object is internal and returns true or false. @@ -46,9 +49,9 @@ def skip_display(self, object_type, cli_object): returns false, if the cli option is all or if it the platform is single ASIC. ''' - if not self.is_multi_asic: + if not self.is_multi_asic and not device_info.is_chassis(): return False - if self.display_option == constants.DISPLAY_ALL: + if self.get_display_option() == constants.DISPLAY_ALL: return False return self.is_object_internal(object_type, cli_object) @@ -59,7 +62,7 @@ def get_ns_list_based_on_options(self): else: namespaces = multi_asic.get_all_namespaces() if self.namespace_option is None: - if self.display_option == constants.DISPLAY_ALL: + if self.get_display_option() == constants.DISPLAY_ALL: ns_list = namespaces['front_ns'] + namespaces['back_ns'] else: ns_list = namespaces['front_ns'] @@ -80,14 +83,14 @@ def multi_asic_ns_choices(): def multi_asic_display_choices(): - if not multi_asic.is_multi_asic(): + if not multi_asic.is_multi_asic() and not device_info.is_chassis(): return [constants.DISPLAY_ALL] else: return [constants.DISPLAY_ALL, constants.DISPLAY_EXTERNAL] def multi_asic_display_default_option(): - if not multi_asic.is_multi_asic(): + if not multi_asic.is_multi_asic() and not device_info.is_chassis(): return constants.DISPLAY_ALL else: return constants.DISPLAY_EXTERNAL