Skip to content

Commit

Permalink
Fix vnet_route_check for active and inactive routes, add --all op…
Browse files Browse the repository at this point in the history
…tion (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.
  • Loading branch information
mramezani95 authored Feb 20, 2025
1 parent 40ba225 commit 3c50dee
Show file tree
Hide file tree
Showing 2 changed files with 431 additions and 58 deletions.
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

0 comments on commit 3c50dee

Please sign in to comment.