Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -12371,6 +12371,8 @@ This command displays vnet neighbor information about all the vnets configured i

This command displays either all routes information about all the vnets or a specified vnet configured in the device. It also shows the vnet routes which are configured but may or may not be active based on endpoint BFD status.

For ECMP tunnel routes with per-endpoint `mac_address` or `vni` lists, the endpoints, MAC addresses, and VNIs are wrapped together in aligned chunks (2 per row when any item exceeds 15 characters, 3 per row otherwise).

- Usage:

```
Expand All @@ -12386,11 +12388,12 @@ This command displays either all routes information about all the vnets or a spe
Vnet_2000 100.100.3.0/24 Ethernet52
Vnet_3000 100.100.4.0/24 Vlan2000

vnet name prefix endpoint mac address vni metric status
----------- -------------- ---------- ----------------- ----- -------- --------
Vnet_2000 100.100.1.1/32 10.10.10.1 0 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
vnet name prefix endpoint mac address vni metric status
---------------- --------------- ----------------------------------- ----------------------------------- ------- -------- --------
Vnet_2000 100.100.1.1/32 10.10.10.1,10.10.10.2 aa:bb:cc:00:00:01,aa:bb:cc:00:00:02 100,200 active
10.10.10.3,10.10.10.4 aa:bb:cc:00:00:03,aa:bb:cc:00:00:04 300,400
Vnet_3000 100.100.2.1/32 10.10.10.5 00:00:00:00:03:04 0 inactive
Vnet_3000 100.100.2.3/32 10.10.10.6 00:00:00:00:03:04
```

**show vnet routes local [<vnet_name>]**
Expand All @@ -12417,6 +12420,8 @@ This command displays either local routes information about all the vnets or a s

This command displays tunnel routes information about all the vnets or a specified vnet configured in the device.

For ECMP routes with per-endpoint `mac_address` or `vni` lists, the endpoints, MAC addresses, and VNIs are wrapped together in aligned chunks. An optional vnet name argument filters the output to a single vnet.

- Usage:

```
Expand All @@ -12427,11 +12432,17 @@ This command displays tunnel routes information about all the vnets or a specifi

```
admin@sonic:~$ show vnet routes tunnel
vnet name prefix endpoint mac address vni metric status
----------- -------------- ---------- ----------------- ----- -------- --------
Vnet_2000 100.100.1.1/32 10.10.10.1 0 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
vnet name prefix endpoint mac address vni metric status
---------------- --------------- ----------------------------------- ----------------------------------- ------- -------- --------
Vnet_2000 100.100.1.1/32 10.10.10.1,10.10.10.2 aa:bb:cc:00:00:01,aa:bb:cc:00:00:02 100,200 active
10.10.10.3,10.10.10.4 aa:bb:cc:00:00:03,aa:bb:cc:00:00:04 300,400
Vnet_3000 100.100.2.1/32 10.10.10.5 00:00:00:00:03:04 0 inactive

admin@sonic:~$ show vnet routes tunnel Vnet_2000
vnet name prefix endpoint mac address vni metric status
---------------- --------------- ----------------------------------- ----------------------------------- ------- -------- --------
Vnet_2000 100.100.1.1/32 10.10.10.1,10.10.10.2 aa:bb:cc:00:00:01,aa:bb:cc:00:00:02 100,200 active
10.10.10.3,10.10.10.4 aa:bb:cc:00:00:03,aa:bb:cc:00:00:04 300,400
```

#### Vnet config commands
Expand Down
67 changes: 38 additions & 29 deletions show/vnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ def endpoint(args):
have_status = False
for k in vnet_rt_keys:
val = appl_db.get_all(appl_db.APPL_DB, k)
endpoints = val.get('endpoint').split(',')
monitors = val.get('endpoint_monitor').split(',')
endpoints = val.get('endpoint').split(',') if val and 'endpoint' in val else []
monitors = val.get('endpoint_monitor').split(',') if val and 'endpoint_monitor' in val else []
for idx, endpoint in enumerate(endpoints):
if args == endpoint:
prefix.append(k.split(":", 2)[2])
Expand Down Expand Up @@ -444,28 +444,42 @@ def routes():

def pretty_print(table, r, epval, mac_addr, vni, metric, state):
endpoints = epval.split(',')
row_width = 3
max_len = 0
for ep in endpoints:
max_len = len(ep) if len(ep) > max_len else max_len
if max_len > 15:
row_width = 2
iter = 0
while iter < len(endpoints):
if iter +row_width > len(endpoints):
r.append(",".join(endpoints[iter:]))
# When mac_address or vni is a per-endpoint list, split so all three fields
# wrap in the same chunks, keeps rows aligned at any ECMP scale.
macs = mac_addr.split(',') if mac_addr and ',' in mac_addr else None
vnis = vni.split(',') if vni and ',' in vni else None

# Derive row_width from the longest single item across all three fields so
# that long MAC addresses or IPv6 endpoints don't overflow the terminal.
all_items = list(endpoints)
if macs:
all_items.extend(macs)
if vnis:
all_items.extend(vnis)
max_len = max((len(item) for item in all_items), default=0)
row_width = 2 if max_len > 15 else 3

i = 0
while i < len(endpoints):
r.append(",".join(endpoints[i:i + row_width]))
# Wrap mac and vni in sync with endpoints when they are lists
if macs:
r.append(",".join(macs[i:i + row_width]) if i < len(macs) else "")
else:
r.append(",".join(endpoints[iter:iter + row_width]))
if iter == 0:
r.append(mac_addr)
r.append(vni)
r.append(mac_addr if i == 0 else "")
if vnis:
r.append(",".join(vnis[i:i + row_width]) if i < len(vnis) else "")
else:
r.append(vni if i == 0 else "")
if i == 0:
r.append(metric)
r.append(state)
else:
r.extend(["", "", "", ""])
iter += row_width
r.extend(["", ""])
i += row_width
table.append(r)
r = ["",""]
r = ["", ""]


@routes.command()
@click.argument('vnet_name', required=False)
Expand Down Expand Up @@ -544,16 +558,11 @@ def _show_tunnel_helper(vnet_name=None, appl_db=None, state_db=None):
val = appl_db.get_all(appl_db.APPL_DB, k)
val_state = state_db.get_all(state_db.STATE_DB, state_db_key)
epval = val.get('endpoint')
if len(epval) < 40:
r.append(epval)
r.append(val.get('mac_address'))
r.append(val.get('vni'))
r.append(val.get('metric'))
if val_state:
r.append(val_state.get('state'))
table.append(r)
continue
state = val_state.get('state') if val_state else ""
pretty_print(table, r, epval, val.get('mac_address'), val.get('vni'), val.get('metric'), state)
raw_metric = val.get('metric')
metric = int(raw_metric) if raw_metric else ''
pretty_print(table, r, epval,
val.get('mac_address') or '', val.get('vni') or '',
metric, state)

click.echo(tabulate(table, tunnel_header))
11 changes: 11 additions & 0 deletions tests/mock_tables/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,17 @@
"endpoint":"100.251.7.1",
"endpoint_monitor":"100.251.7.1"
},
"VNET_ROUTE_TUNNEL_TABLE:Vnet_mac_vni_scale:10.0.0.0/24": {
"endpoint": "10.0.0.1,10.0.0.2,10.0.0.3,10.0.0.4,10.0.0.5,10.0.0.6",
"mac_address": "aa:bb:cc:00:00:01,aa:bb:cc:00:00:02,aa:bb:cc:00:00:03,aa:bb:cc:00:00:04,aa:bb:cc:00:00:05,aa:bb:cc:00:00:06",
"vni": "100,200,300,400,500,600"
},
"VNET_ROUTE_TUNNEL_TABLE:Vnet_7127926:30.0.21.0/24": {
"endpoint": "100.106.230.44,10.134.85.10,100.106.229.38,100.106.229.170,100.106.228.160,10.134.84.24,100.106.230.168,10.90.92.16,10.224.116.42,100.106.228.134,100.106.229.171,100.106.228.161",
"mac_address": "00:22:48:03:8c:f8,60:45:bd:a3:8d:ab,60:45:bd:a3:21:88,60:45:bd:a2:e4:39,7c:1e:52:06:89:0f,7c:1e:52:06:8b:cd,60:45:bd:a3:8f:ae,60:45:bd:a2:e8:f9,60:45:bd:a2:e5:ee,60:45:bd:a4:be:3e,60:45:bd:a3:8d:ac,7c:1e:52:06:89:10",
"vni": "7127926,7127926,7127926,7127926,7127926,7127926,7127926,7127926,7127926,7127926,7127926,7127926",
"metric": "5"
},
"BGP_PROFILE_TABLE:FROM_SDN_SLB_ROUTES": {
"community_id" : "1234:1235"
},
Expand Down
8 changes: 8 additions & 0 deletions tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,14 @@
"active_endpoints":"fddd:a100:a251::a10:1,fddd:a101:a251::a10:1,fddd:a102:a251::a10:1,fddd:a103:a251::a10:1",
"state":"active"
},
"VNET_ROUTE_TUNNEL_TABLE|Vnet_mac_vni_scale|10.0.0.0/24": {
"active_endpoints":"10.0.0.1,10.0.0.2,10.0.0.3,10.0.0.4,10.0.0.5,10.0.0.6",
"state":"active"
},
"VNET_ROUTE_TUNNEL_TABLE|Vnet_7127926|30.0.21.0/24": {
"active_endpoints":"100.106.230.44,10.134.85.10,100.106.229.38,100.106.229.170,100.106.228.160,10.134.84.24,100.106.230.168,10.90.92.16,10.224.116.42,100.106.228.134,100.106.229.171,100.106.228.161",
"state":"active"
},
"BFD_SESSION_TABLE|default|default|100.251.7.1": {
"state":"Up",
"type": "async_active",
Expand Down
14 changes: 14 additions & 0 deletions tests/mock_tables/vnet_ecmp/appl_db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"VNET_ROUTE_TUNNEL_TABLE:Vnet_7127926:30.0.21.0/24": {
"endpoint": "100.106.230.44,10.134.85.10,100.106.229.38,100.106.229.170,100.106.228.160,10.134.84.24,100.106.230.168,10.90.92.16,10.224.116.42,100.106.228.134,100.106.229.171,100.106.228.161",
"mac_address": "00:22:48:03:8c:f8,60:45:bd:a3:8d:ab,60:45:bd:a3:21:88,60:45:bd:a2:e4:39,7c:1e:52:06:89:0f,7c:1e:52:06:8b:cd,60:45:bd:a3:8f:ae,60:45:bd:a2:e8:f9,60:45:bd:a2:e5:ee,60:45:bd:a4:be:3e,60:45:bd:a3:8d:ac,7c:1e:52:06:89:10",
"vni": "7127926,7127926,7127926,7127926,7127926,7127926,7127926,7127926,7127926,7127926,7127926,7127926",
"metric": "5"
},
"VNET_ROUTE_TUNNEL_TABLE:Vnet_7127926:30.0.20.0/24": {
"endpoint": "100.106.230.44,10.134.85.10,100.106.229.38,100.106.229.170,100.106.228.160,10.134.84.24,100.106.230.168,10.90.92.16,10.224.116.42,100.106.228.134",
"mac_address": "00:22:48:03:8c:f8,60:45:bd:a3:8d:ab,60:45:bd:a3:21:88,60:45:bd:a2:e4:39,7c:1e:52:06:89:0f,7c:1e:52:06:8b:cd,60:45:bd:a3:8f:ae,60:45:bd:a2:e8:f9,60:45:bd:a2:e5:ee,60:45:bd:a4:be:3e",
"vni": "7127926,7127926,7127926,7127926,7127926,7127926,7127926,7127926,7127926,7127926",
"metric": "5"
}
}
10 changes: 10 additions & 0 deletions tests/mock_tables/vnet_ecmp/state_db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"VNET_ROUTE_TUNNEL_TABLE|Vnet_7127926|30.0.21.0/24": {
"active_endpoints": "100.106.230.44,10.134.85.10,100.106.229.38,100.106.229.170,100.106.228.160,10.134.84.24,100.106.230.168,10.90.92.16,10.224.116.42,100.106.228.134,100.106.229.171,100.106.228.161",
"state": "active"
},
"VNET_ROUTE_TUNNEL_TABLE|Vnet_7127926|30.0.20.0/24": {
"active_endpoints": "100.106.230.44,10.134.85.10,100.106.229.38,100.106.229.170,100.106.228.160,10.134.84.24,100.106.230.168,10.90.92.16,10.224.116.42,100.106.228.134",
"state": "active"
}
}
Loading
Loading