Skip to content

Commit aad1143

Browse files
committed
Added support for tunnel route status in show vnet routes all. (sonic-net#2341)
* Added support for tunnel route status in show vnet routes all. * Added a test for the CLI. Fixed a bug. * Updated command reference.
1 parent 936f1b1 commit aad1143

File tree

5 files changed

+66
-7
lines changed

5 files changed

+66
-7
lines changed

doc/Command-Reference.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9482,7 +9482,7 @@ This command displays vnet neighbor information about all the vnets configured i
94829482
94839483
**show vnet routes all**
94849484
9485-
This command displays all routes information about all the vnets configured in the device.
9485+
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.
94869486
94879487
- Usage:
94889488
@@ -9499,10 +9499,11 @@ This command displays all routes information about all the vnets configured in t
94999499
Vnet_2000 100.100.3.0/24 Ethernet52
95009500
Vnet_3000 100.100.4.0/24 Vlan2000
95019501
9502-
vnet name prefix endpoint mac address vni
9503-
----------- -------------- ---------- ----------------- -----
9504-
Vnet_2000 100.100.1.1/32 10.10.10.1
9505-
Vnet_3000 100.100.2.1/32 10.10.10.2 00:00:00:00:03:04
9502+
vnet name prefix endpoint mac address vni status
9503+
----------- -------------- ---------- ----------------- ----- -------
9504+
Vnet_2000 100.100.1.1/32 10.10.10.1 active
9505+
Vnet_3000 100.100.2.1/32 10.10.10.2 00:00:00:00:03:04 inactive
9506+
Vnet_3000 100.100.2.3/32 10.10.10.6 00:00:00:00:03:04
95069507
```
95079508
95089509
**show vnet routes tunnel**

show/vnet.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ def all():
207207
"""Show all vnet routes"""
208208
appl_db = SonicV2Connector()
209209
appl_db.connect(appl_db.APPL_DB)
210-
210+
state_db = SonicV2Connector()
211+
state_db.connect(state_db.STATE_DB)
211212
header = ['vnet name', 'prefix', 'nexthop', 'interface']
212213

213214
# Fetching data from appl_db for VNET ROUTES
@@ -227,7 +228,7 @@ def all():
227228

228229
click.echo()
229230

230-
header = ['vnet name', 'prefix', 'endpoint', 'mac address', 'vni']
231+
header = ['vnet name', 'prefix', 'endpoint', 'mac address', 'vni', 'status']
231232

232233
# Fetching data from appl_db for VNET TUNNEL ROUTES
233234
vnet_rt_keys = appl_db.keys(appl_db.APPL_DB, "VNET_ROUTE_TUNNEL_TABLE:*")
@@ -237,10 +238,14 @@ def all():
237238
for k in vnet_rt_keys:
238239
r = []
239240
r.extend(k.split(":", 2)[1:])
241+
state_db_key = '|'.join(k.split(":",2))
240242
val = appl_db.get_all(appl_db.APPL_DB, k)
243+
val_state = state_db.get_all(state_db.STATE_DB, state_db_key)
241244
r.append(val.get('endpoint'))
242245
r.append(val.get('mac_address'))
243246
r.append(val.get('vni'))
247+
if val_state:
248+
r.append(val_state.get('state'))
244249
table.append(r)
245250

246251
click.echo(tabulate(table, header))

tests/mock_tables/appl_db.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,17 @@
313313
},
314314
"TUNNEL_ROUTE_TABLE:10.3.1.1": {
315315
"alias": "Vlan1000"
316+
},
317+
"VNET_ROUTE_TUNNEL_TABLE:test_v4_in_v4-0:160.163.191.1/32": {
318+
"endpoint":"100.251.7.1"
319+
},
320+
"VNET_ROUTE_TUNNEL_TABLE:Vnet_v6_in_v6-0:fddd:a156:a251::a6:1/128": {
321+
"endpoint": "fddd:a100:a251::a10:1,fddd:a101:a251::a10:1"
322+
},
323+
"VNET_ROUTE_TUNNEL_TABLE:test_v4_in_v4-0:160.162.191.1/32": {
324+
"endpoint":"100.251.7.1"
325+
},
326+
"VNET_ROUTE_TUNNEL_TABLE:test_v4_in_v4-0:160.164.191.1/32": {
327+
"endpoint":"100.251.7.1"
316328
}
317329
}

tests/mock_tables/state_db.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,5 +875,17 @@
875875
},
876876
"LINK_TRAINING|Ethernet112": {
877877
"status": "off"
878+
},
879+
"VNET_ROUTE_TUNNEL_TABLE|test_v4_in_v4-0|160.162.191.1/32": {
880+
"active_endpoints":"100.251.7.1",
881+
"state":"active"
882+
},
883+
"VNET_ROUTE_TUNNEL_TABLE|test_v4_in_v4-0|160.163.191.1/32": {
884+
"active_endpoints":"100.251.7.1",
885+
"state":"active"
886+
},
887+
"VNET_ROUTE_TUNNEL_TABLE|Vnet_v6_in_v6-0|fddd:a156:a251::a6:1/128": {
888+
"active_endpoints":"fddd:a100:a251::a10:1,fddd:a101:a251::a10:1",
889+
"state":"active"
878890
}
879891
}

tests/show_vnet_test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
from click.testing import CliRunner
3+
from utilities_common.db import Db
4+
import show.main as show
5+
6+
class TestShowVnetRoutesAll(object):
7+
@classmethod
8+
def setup_class(cls):
9+
print("SETUP")
10+
os.environ["UTILITIES_UNIT_TESTING"] = "1"
11+
12+
def test_show_vnet_routes_all_basic(self):
13+
runner = CliRunner()
14+
db = Db()
15+
16+
result = runner.invoke(show.cli.commands['vnet'].commands['routes'].commands['all'], [], obj=db)
17+
assert result.exit_code == 0
18+
expected_output = """\
19+
vnet name prefix nexthop interface
20+
----------- -------- --------- -----------
21+
22+
vnet name prefix endpoint mac address vni status
23+
--------------- ------------------------ ------------------------------------------- ------------- ----- --------
24+
Vnet_v6_in_v6-0 fddd:a156:a251::a6:1/128 fddd:a100:a251::a10:1,fddd:a101:a251::a10:1 active
25+
test_v4_in_v4-0 160.162.191.1/32 100.251.7.1 active
26+
test_v4_in_v4-0 160.163.191.1/32 100.251.7.1 active
27+
test_v4_in_v4-0 160.164.191.1/32 100.251.7.1
28+
"""
29+
assert result.output == expected_output

0 commit comments

Comments
 (0)