Skip to content

Commit 3c50dee

Browse files
authored
Fix vnet_route_check for active and inactive routes, add --all option (sonic-net#3763)
What I did Added the options -a and --all to scripts/vnet_route_check.py. Both options are equivalent. If none of them is provided, then when finding the VNET routes that are in APP DB but not in ASIC DB, we will ignore routes in APP DB that are not active. Mock tests in tests/test_vnet_route_check.py are added to test this behavior. How I did it If -a and --all are not provided, we first filter routes in APP DB to find active routes and then check which active routes are not in ASIC DB. The status of each route is retrieved from STATE DB. If a route is not found in STATE DB, then it is considered to be active. How to verify it You can verify the behavior by running mock tests in tests/test_vnet_route_check.py, or by manually running the vnet_route_check.py script on a DUT.
1 parent 40ba225 commit 3c50dee

File tree

2 files changed

+431
-58
lines changed

2 files changed

+431
-58
lines changed

scripts/vnet_route_check.py

+44-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import syslog
66
import subprocess
7+
import argparse
78
from swsscommon import swsscommon
89

910
''' vnet_route_check.py: tool that verifies VNET routes consistancy between SONiC and vendor SDK DBs.
@@ -356,7 +357,40 @@ def get_sdk_vnet_routes_diff(routes):
356357
return routes_diff
357358

358359

360+
def filter_active_vnet_routes(vnet_routes: dict):
361+
""" Filters a dictionary containing VNet routes configured for each VNet in APP_DB.
362+
For each VNet in "vnet_routes", only active routes are included in the returned dictionary.
363+
Format (for both input and output):
364+
{ <vnet_name>: { 'routes': [ <pfx/pfx_len> ], 'vrf_oid': <oid> } }
365+
"""
366+
state_db = swsscommon.DBConnector("STATE_DB", 0, True)
367+
vnet_route_tunnel_table = swsscommon.Table(state_db, "VNET_ROUTE_TUNNEL_TABLE")
368+
369+
vnet_active_routes = {}
370+
for vnet_name, vnet_info in vnet_routes.items():
371+
active_routes = []
372+
for prefix in vnet_info["routes"]:
373+
key = f"{vnet_name}|{prefix}"
374+
exists, fvs = vnet_route_tunnel_table.get(key)
375+
if not exists:
376+
print_message(syslog.LOG_WARNING, f"VNET_ROUTE_TUNNEL_TABLE|{key} does not exist in STATE DB.")
377+
active_routes.append(prefix) # Treating "prefix" as an active route
378+
continue
379+
fvs_dict = dict(fvs)
380+
if fvs_dict.get("state") == "active":
381+
active_routes.append(prefix)
382+
if len(active_routes) > 0:
383+
vnet_active_routes[vnet_name] = {"routes": active_routes, "vrf_oid": vnet_info["vrf_oid"]}
384+
385+
return vnet_active_routes
386+
387+
359388
def main():
389+
parser = argparse.ArgumentParser(
390+
description="A script that checks for VNet route mismatches between APP DB, ASIC DB, and SDK.")
391+
parser.add_argument("-a", "--all", action="store_true",
392+
help="Find routes missed in ASIC DB by checking both active and inactive routes in APP DB.")
393+
args = parser.parse_args()
360394

361395
rc = RC_OK
362396

@@ -365,14 +399,20 @@ def main():
365399
return rc
366400
asic_db = swsscommon.DBConnector('ASIC_DB', 0, True)
367401
virtual_router = swsscommon.Table(asic_db, 'ASIC_STATE:SAI_OBJECT_TYPE_VIRTUAL_ROUTER')
368-
if virtual_router.getKeys() != []:
369-
global default_vrf_oid
370-
default_vrf_oid = virtual_router.getKeys()[0]
402+
global default_vrf_oid
403+
default_vrf_oid = ""
404+
vr_keys = virtual_router.getKeys()
405+
if vr_keys:
406+
default_vrf_oid = vr_keys[0]
371407

372408
app_db_vnet_routes = get_vnet_routes_from_app_db()
409+
active_app_db_vnet_routes = filter_active_vnet_routes(app_db_vnet_routes)
373410
asic_db_vnet_routes = get_vnet_routes_from_asic_db()
374411

375-
missed_in_asic_db_routes = get_vnet_routes_diff(asic_db_vnet_routes, app_db_vnet_routes,True)
412+
if args.all:
413+
missed_in_asic_db_routes = get_vnet_routes_diff(asic_db_vnet_routes, app_db_vnet_routes, True)
414+
else:
415+
missed_in_asic_db_routes = get_vnet_routes_diff(asic_db_vnet_routes, active_app_db_vnet_routes, True)
376416
missed_in_app_db_routes = get_vnet_routes_diff(app_db_vnet_routes, asic_db_vnet_routes)
377417
missed_in_sdk_routes = get_sdk_vnet_routes_diff(asic_db_vnet_routes)
378418

0 commit comments

Comments
 (0)