Skip to content

Commit

Permalink
show vnet routes all. (#2341) (#2472)
Browse files Browse the repository at this point in the history
orignal PR #2341 
The status information is retrieved using the status of the prefix from Application DB.
The status field can have 3 values.
Empty : Configured but not in Application DB.
Active : Configured and active in ASIC.
Inacive : Configured but not in ASIC due to lack of BFD session with endpoint

How to verify it
Add a vxlan tunnel route with single Endpoint monitoring. run the command to see active/ inactive based on BFD session state.
if multiple Endpoints are present then atleast one has to be Up for status to show up as active.
if endpoint monitoring is not enabled then status would show up as active.

Previous command output (if the output of a command-line utility has changed)
vnet name prefix endpoint mac address vni

Vnet1 10.2.1.0/24 200.3.152.32
Vnet_v4_in_v4-0 150.62.191.1/32 100.251.99.1,100.251.99.2,100.251.99.3
Vnet_v6_in_v6-0 fddd:a150:a251::a6:1/128 fddd:a100:a251::a10:1,fddd:a101:a251::a10:1
test_v4_in_v4-0 160.62.191.1/32 100.251.7.1
test_v4_in_v4-0 160.63.191.1/32 100.251.7.2
test_v4_in_v4-0 160.64.191.1/32 100.251.7.3

New command output (if the output of a command-line utility has changed)
vnet name prefix endpoint mac address vni status

Vnet1 10.2.1.0/24 200.3.152.32 active
Vnet_v4_in_v4-0 150.62.191.1/32 100.251.99.1,100.251.99.2,100.251.99.3
Vnet_v6_in_v6-0 fddd:a150:a251::a6:1/128 fddd:a100:a251::a10:1,fddd:a101:a251::a10:1 inactive
test_v4_in_v4-0 160.62.191.1/32 100.251.7.1 inactive
test_v4_in_v4-0 160.63.191.1/32 100.251.7.2 inactive
test_v4_in_v4-0 160.64.191.1/32 100.251.7.3 inactive
  • Loading branch information
siqbal1986 authored Nov 3, 2022
1 parent 936f1b1 commit b1b3661
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 7 deletions.
11 changes: 6 additions & 5 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -9482,7 +9482,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:
Expand All @@ -9499,10 +9499,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**
Expand Down
9 changes: 7 additions & 2 deletions show/vnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:*")
Expand All @@ -237,10 +238,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))
Expand Down
12 changes: 12 additions & 0 deletions tests/mock_tables/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,5 +313,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"
}
}
12 changes: 12 additions & 0 deletions tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -875,5 +875,17 @@
},
"LINK_TRAINING|Ethernet112": {
"status": "off"
},
"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"
}
}
29 changes: 29 additions & 0 deletions tests/show_vnet_test.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b1b3661

Please sign in to comment.