From 781806fb26a923dacf85b15074566bb60e82668a Mon Sep 17 00:00:00 2001 From: siqbal1486 Date: Mon, 29 Aug 2022 13:38:56 -0700 Subject: [PATCH 1/4] Added support for tunnel route status in show vnet routes all. The status may be active, inactive or not present at all. The status field cna have 3 values. Empty : Configured but not in ASIC Active : Configured and active in ASIC. Inacive : Configured but not in ASIC due to lack ofr BFD session. --- show/vnet.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/show/vnet.py b/show/vnet.py index 21d46af7fa..1aeb4ce355 100644 --- a/show/vnet.py +++ b/show/vnet.py @@ -207,7 +207,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 @@ -227,7 +228,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:*") @@ -237,10 +238,13 @@ 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')) + r.append(val_state.get('state')) table.append(r) click.echo(tabulate(table, header)) From a26f0642f41262093361f3b609d900380bb01aaa Mon Sep 17 00:00:00 2001 From: siqbal1486 Date: Mon, 29 Aug 2022 15:46:44 -0700 Subject: [PATCH 2/4] typo fix. --- show/vnet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/vnet.py b/show/vnet.py index 1aeb4ce355..af9d699bea 100644 --- a/show/vnet.py +++ b/show/vnet.py @@ -228,7 +228,7 @@ def all(): click.echo() - header = ['vnet name', 'prefix', 'endpoint', 'mac address', 'vni', status'] + 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:*") From ac7549dffaeab0a8b3d6c6fa1a7d6d4a5948afbf Mon Sep 17 00:00:00 2001 From: siqbal1486 Date: Wed, 14 Sep 2022 15:52:46 -0700 Subject: [PATCH 3/4] Added a test for the CLI. Fixed a bug. --- show/vnet.py | 3 ++- tests/mock_tables/appl_db.json | 12 ++++++++++++ tests/mock_tables/state_db.json | 12 ++++++++++++ tests/show_vnet_test.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/show_vnet_test.py diff --git a/show/vnet.py b/show/vnet.py index af9d699bea..4b5674cb62 100644 --- a/show/vnet.py +++ b/show/vnet.py @@ -244,7 +244,8 @@ def all(): r.append(val.get('endpoint')) r.append(val.get('mac_address')) r.append(val.get('vni')) - r.append(val_state.get('state')) + 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 29e161c9ca..cff7ff64a5 100644 --- a/tests/mock_tables/appl_db.json +++ b/tests/mock_tables/appl_db.json @@ -287,5 +287,17 @@ }, "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 06eba551c1..f249b1e88c 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -876,5 +876,17 @@ }, "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 From bec449c059b760590c15c91546c698317d2e0a7c Mon Sep 17 00:00:00 2001 From: siqbal1486 Date: Thu, 15 Sep 2022 11:30:33 -0700 Subject: [PATCH 4/4] Updated command reference. --- doc/Command-Reference.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 670049fe56..5799e110ce 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -9507,7 +9507,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 show the vnet routes which are configured but may or may not be active based on endpoint BFD status. - Usage: @@ -9524,10 +9524,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**