diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 12d6af86e8..a952a143b7 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -8200,7 +8200,7 @@ This command displays vnet neighbor information about all the vnets configured i **show vnet routes all** -This command displays all routes information about all the vnets configured in the device. +This command displays all routes information about all the vnets configured in the device. It also shows the status of the routes which may or may not be active. - Usage: @@ -8217,10 +8217,11 @@ This command displays all routes information about all the vnets configured in t Vnet_2000 100.100.3.0/24 Ethernet52 Vnet_3000 100.100.4.0/24 Vlan2000 - vnet name prefix endpoint mac address vni - ----------- -------------- ---------- ----------------- ----- - Vnet_2000 100.100.1.1/32 10.10.10.1 - Vnet_3000 100.100.2.1/32 10.10.10.2 00:00:00:00:03:04 + vnet name prefix endpoint mac address vni status + ----------- -------------- ---------- ----------------- ----- ------- + Vnet_2000 100.100.1.1/32 10.10.10.1 active + Vnet_3000 100.100.2.1/32 10.10.10.2 00:00:00:00:03:04 inactive + Vnet_3000 100.100.2.3/32 10.10.10.6 00:00:00:00:03:04 ``` **show vnet routes tunnel** diff --git a/show/vnet.py b/show/vnet.py index 4514a9afe4..d3e7e1ba46 100644 --- a/show/vnet.py +++ b/show/vnet.py @@ -208,7 +208,8 @@ def all(): """Show all vnet routes""" appl_db = SonicV2Connector() appl_db.connect(appl_db.APPL_DB) - + state_db = SonicV2Connector() + state_db.connect(state_db.STATE_DB) header = ['vnet name', 'prefix', 'nexthop', 'interface'] # Fetching data from appl_db for VNET ROUTES @@ -228,7 +229,7 @@ def all(): click.echo() - header = ['vnet name', 'prefix', 'endpoint', 'mac address', 'vni'] + header = ['vnet name', 'prefix', 'endpoint', 'mac address', 'vni', 'status'] # Fetching data from appl_db for VNET TUNNEL ROUTES vnet_rt_keys = appl_db.keys(appl_db.APPL_DB, "VNET_ROUTE_TUNNEL_TABLE:*") @@ -238,10 +239,14 @@ def all(): for k in vnet_rt_keys: r = [] r.extend(k.split(":", 2)[1:]) + state_db_key = '|'.join(k.split(":",2)) val = appl_db.get_all(appl_db.APPL_DB, k) + val_state = state_db.get_all(state_db.STATE_DB, state_db_key) r.append(val.get('endpoint')) r.append(val.get('mac_address')) r.append(val.get('vni')) + if val_state: + r.append(val_state.get('state')) table.append(r) click.echo(tabulate(table, header)) diff --git a/tests/mock_tables/appl_db.json b/tests/mock_tables/appl_db.json index 14a331930a..d93f84201e 100644 --- a/tests/mock_tables/appl_db.json +++ b/tests/mock_tables/appl_db.json @@ -180,5 +180,41 @@ }, "VXLAN_REMOTE_VNI_TABLE:Vlan200:25.25.25.27": { "vni": "200" + }, + "MUX_CABLE_TABLE:Ethernet32": { + "state": "active" + }, + "MUX_CABLE_TABLE:Ethernet0": { + "state": "active" + }, + "MUX_CABLE_TABLE:Ethernet4": { + "state": "standby" + }, + "MUX_CABLE_TABLE:Ethernet8": { + "state": "standby" + }, + "MUX_CABLE_TABLE:Ethernet16": { + "state": "standby" + }, + "MUX_CABLE_TABLE:Ethernet12": { + "state": "active" + }, + "TUNNEL_ROUTE_TABLE:10.2.1.1": { + "alias": "Vlan1000" + }, + "TUNNEL_ROUTE_TABLE:10.3.1.1": { + "alias": "Vlan1000" + }, + "VNET_ROUTE_TUNNEL_TABLE:test_v4_in_v4-0:160.163.191.1/32": { + "endpoint":"100.251.7.1" + }, + "VNET_ROUTE_TUNNEL_TABLE:Vnet_v6_in_v6-0:fddd:a156:a251::a6:1/128": { + "endpoint": "fddd:a100:a251::a10:1,fddd:a101:a251::a10:1" + }, + "VNET_ROUTE_TUNNEL_TABLE:test_v4_in_v4-0:160.162.191.1/32": { + "endpoint":"100.251.7.1" + }, + "VNET_ROUTE_TUNNEL_TABLE:test_v4_in_v4-0:160.164.191.1/32": { + "endpoint":"100.251.7.1" } } diff --git a/tests/mock_tables/state_db.json b/tests/mock_tables/state_db.json index 97fc394d5e..bba5900ec0 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -641,5 +641,74 @@ "pck_expected_count": "840", "link_prober_unknown_start": "2022-Jan-26 03:13:05.366900", "link_prober_unknown_end": "2022-Jan-26 03:17:35.446580" + }, + "PORT_TABLE|Ethernet16": { + "state": "ok", + "netdev_oper_status": "up", + "admin_status": "up", + "mtu": "9100", + "speed": "100" + }, + "PORT_TABLE|Ethernet36": { + "state": "ok", + "netdev_oper_status": "up", + "admin_status": "up", + "mtu": "9100", + "speed": "10" + }, + "PORT_TABLE|Ethernet24": { + "state": "ok", + "netdev_oper_status": "up", + "admin_status": "up", + "mtu": "9100", + "speed": "1000" + }, + "LINK_TRAINING|Ethernet0": { + "status": "not_trained" + }, + "LINK_TRAINING|Ethernet32": { + "status": "trained" + }, + "LINK_TRAINING|Ethernet112": { + "status": "off" + }, + "ALL_SERVICE_STATUS|mgmt-framework": { + "app_ready_status": "OK", + "fail_reason": "-", + "service_status": "OK", + "update_time": "-" + }, + "ALL_SERVICE_STATUS|swss": { + "app_ready_status": "OK", + "fail_reason": "-", + "service_status": "OK", + "update_time": "-" + }, + "ALL_SERVICE_STATUS|bgp": { + "app_ready_status": "Down", + "fail_reason": "Inactive", + "service_status": "Down", + "update_time": "-" + }, + "ALL_SERVICE_STATUS|pmon": { + "app_ready_status": "OK", + "fail_reason": "-", + "service_status": "OK", + "update_time": "-" + }, + "SYSTEM_READY|SYSTEM_STATE": { + "Status":"DOWN" + }, + "VNET_ROUTE_TUNNEL_TABLE|test_v4_in_v4-0|160.162.191.1/32": { + "active_endpoints":"100.251.7.1", + "state":"active" + }, + "VNET_ROUTE_TUNNEL_TABLE|test_v4_in_v4-0|160.163.191.1/32": { + "active_endpoints":"100.251.7.1", + "state":"active" + }, + "VNET_ROUTE_TUNNEL_TABLE|Vnet_v6_in_v6-0|fddd:a156:a251::a6:1/128": { + "active_endpoints":"fddd:a100:a251::a10:1,fddd:a101:a251::a10:1", + "state":"active" } } diff --git a/tests/show_vnet_test.py b/tests/show_vnet_test.py new file mode 100644 index 0000000000..dcb7486178 --- /dev/null +++ b/tests/show_vnet_test.py @@ -0,0 +1,29 @@ +import os +from click.testing import CliRunner +from utilities_common.db import Db +import show.main as show + +class TestShowVnetRoutesAll(object): + @classmethod + def setup_class(cls): + print("SETUP") + os.environ["UTILITIES_UNIT_TESTING"] = "1" + + def test_show_vnet_routes_all_basic(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(show.cli.commands['vnet'].commands['routes'].commands['all'], [], obj=db) + assert result.exit_code == 0 + expected_output = """\ +vnet name prefix nexthop interface +----------- -------- --------- ----------- + +vnet name prefix endpoint mac address vni status +--------------- ------------------------ ------------------------------------------- ------------- ----- -------- +Vnet_v6_in_v6-0 fddd:a156:a251::a6:1/128 fddd:a100:a251::a10:1,fddd:a101:a251::a10:1 active +test_v4_in_v4-0 160.162.191.1/32 100.251.7.1 active +test_v4_in_v4-0 160.163.191.1/32 100.251.7.1 active +test_v4_in_v4-0 160.164.191.1/32 100.251.7.1 +""" + assert result.output == expected_output