Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vnet_route_check for active and inactive routes, add --all option #3763

Merged
merged 10 commits into from
Feb 20, 2025
48 changes: 44 additions & 4 deletions scripts/vnet_route_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import syslog
import subprocess
import argparse
from swsscommon import swsscommon

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


def filter_active_vnet_routes(vnet_routes: dict):
""" Filters a dictionary containing VNet routes configured for each VNet in APP_DB.
For each VNet in "vnet_routes", only active routes are included in the returned dictionary.
Format (for both input and output):
{ <vnet_name>: { 'routes': [ <pfx/pfx_len> ], 'vrf_oid': <oid> } }
"""
state_db = swsscommon.DBConnector("STATE_DB", 0, True)
vnet_route_tunnel_table = swsscommon.Table(state_db, "VNET_ROUTE_TUNNEL_TABLE")

vnet_active_routes = {}
for vnet_name, vnet_info in vnet_routes.items():
active_routes = []
for prefix in vnet_info["routes"]:
key = f"{vnet_name}|{prefix}"
exists, fvs = vnet_route_tunnel_table.get(key)
if not exists:
print_message(syslog.LOG_WARNING, f"VNET_ROUTE_TUNNEL_TABLE|{key} does not exist in STATE DB.")
active_routes.append(prefix) # Treating "prefix" as an active route
continue
fvs_dict = dict(fvs)
if fvs_dict.get("state") == "active":
active_routes.append(prefix)
if len(active_routes) > 0:
vnet_active_routes[vnet_name] = {"routes": active_routes, "vrf_oid": vnet_info["vrf_oid"]}

return vnet_active_routes


def main():
parser = argparse.ArgumentParser(
description="A script that checks for VNet route mismatches between APP DB, ASIC DB, and SDK.")
parser.add_argument("-a", "--all", action="store_true",
help="Find routes missed in ASIC DB by checking both active and inactive routes in APP DB.")
args = parser.parse_args()

rc = RC_OK

Expand All @@ -365,14 +399,20 @@ def main():
return rc
asic_db = swsscommon.DBConnector('ASIC_DB', 0, True)
virtual_router = swsscommon.Table(asic_db, 'ASIC_STATE:SAI_OBJECT_TYPE_VIRTUAL_ROUTER')
if virtual_router.getKeys() != []:
global default_vrf_oid
default_vrf_oid = virtual_router.getKeys()[0]
global default_vrf_oid
default_vrf_oid = ""
vr_keys = virtual_router.getKeys()
if vr_keys:
default_vrf_oid = vr_keys[0]

app_db_vnet_routes = get_vnet_routes_from_app_db()
active_app_db_vnet_routes = filter_active_vnet_routes(app_db_vnet_routes)
asic_db_vnet_routes = get_vnet_routes_from_asic_db()

missed_in_asic_db_routes = get_vnet_routes_diff(asic_db_vnet_routes, app_db_vnet_routes,True)
if args.all:
missed_in_asic_db_routes = get_vnet_routes_diff(asic_db_vnet_routes, app_db_vnet_routes, True)
else:
missed_in_asic_db_routes = get_vnet_routes_diff(asic_db_vnet_routes, active_app_db_vnet_routes, True)
missed_in_app_db_routes = get_vnet_routes_diff(app_db_vnet_routes, asic_db_vnet_routes)
missed_in_sdk_routes = get_sdk_vnet_routes_diff(asic_db_vnet_routes)

Expand Down
Loading
Loading