Skip to content

Commit

Permalink
changed script to account for tunnel routes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahzad Iqbal (SHAHZADIQBAL) authored and Shahzad Iqbal (SHAHZADIQBAL) committed Aug 2, 2022
1 parent c2db718 commit fb4d138
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions scripts/vnet_route_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def filter_out_vnet_ip2me_routes(vnet_routes):
vnet_routes.pop(vnet)


def get_vnet_routes_from_app_db():
def get_vnet_routes_from_app_db(default_vrf_oid):
''' Returns dictionary of VNET routes configured per each VNET in APP_DB.
Format: { <vnet_name>: { 'routes': [ <pfx/pfx_len> ], 'vrf_oid': <oid> } }
'''
Expand Down Expand Up @@ -224,8 +224,7 @@ def get_vnet_routes_from_app_db():
vnet_table = swsscommon.Table(db, 'VNET_TABLE')
scope = vnet_table.get(vnet_name)[1][1][1]
if scope == 'default':
del vnet_routes[vnet_name]
continue
vnet_routes[vnet_name]['vrf_oid'] = default_vrf_oid
else:
assert "Non-default VRF route present without vnet interface."
else:
Expand All @@ -237,7 +236,7 @@ def get_vnet_routes_from_app_db():
return vnet_routes


def get_vnet_routes_from_asic_db():
def get_vnet_routes_from_asic_db(default_vrf_oid):
''' Returns dictionary of VNET routes configured per each VNET in ASIC_DB.
Format: { <vnet_name>: { 'routes': [ <pfx/pfx_len> ], 'vrf_oid': <oid> } }
'''
Expand All @@ -247,10 +246,12 @@ def get_vnet_routes_from_asic_db():

vnet_vrfs = get_vrf_entries()
vnet_vrfs_oids = [vnet_vrfs[k] for k in vnet_vrfs]
vnet_vrfs_oids.append(default_vrf_oid)

vnet_intfs = get_vnet_intfs()

vrf_oid_to_vnet_map = {}
vrf_oid_to_vnet_map[default_vrf_oid] = 'default_VRF'

for vnet_name, vnet_rifs in vnet_intfs.items():
for vnet_rif, vrf_oid in vnet_vrfs.items():
Expand Down Expand Up @@ -286,23 +287,36 @@ def get_vnet_routes_from_asic_db():
return vnet_routes


def get_vnet_routes_diff(routes_1, routes_2):
def get_vnet_routes_diff(default_vrf_oid, routes_1, routes_2, verify_default_vrf_routes = False):
''' Returns all routes present in routes_2 dictionary but missed in routes_1
Format: { <vnet_name>: { 'routes': [ <pfx/pfx_len> ] } }
'''

routes = {}

for vnet_name, vnet_attrs in routes_2.items():
if vnet_name not in routes_1:
routes[vnet_name] = routes
if vnet_attrs['vrf_oid'] == default_vrf_oid:
if verify_default_vrf_routes:
for vnet_route in vnet_attrs['routes']:
ispresent = False
for vnet_name_other, vnet_attrs_other in routes_1.items():
if vnet_route in vnet_attrs_other['routes']:
ispresent = True
if not ispresent:
if vnet_name not in routes:
routes[vnet_name] = {}
routes[vnet_name]['routes'] = []
routes[vnet_name]['routes'].append(vnet_route)
else:
for vnet_route in vnet_attrs['routes']:
if vnet_route not in routes_1[vnet_name]['routes']:
if vnet_name not in routes:
routes[vnet_name] = {}
routes[vnet_name]['routes'] = []
routes[vnet_name]['routes'].append(vnet_route)
if vnet_name not in routes_1:
routes[vnet_name] = vnet_attrs['routes'].copy()
else:
for vnet_route in vnet_attrs['routes']:
if vnet_route not in routes_1[vnet_name]['routes']:
if vnet_name not in routes:
routes[vnet_name] = {}
routes[vnet_name]['routes'] = []
routes[vnet_name]['routes'].append(vnet_route)

return routes

Expand Down Expand Up @@ -336,12 +350,15 @@ def main():
# Don't run VNET routes consistancy logic if there is no VNET configuration
if not check_vnet_cfg():
return rc
asic_db = swsscommon.DBConnector('ASIC_DB', 0)
virtual_router = swsscommon.Table(asic_db, 'ASIC_STATE:SAI_OBJECT_TYPE_VIRTUAL_ROUTER')
default_vrf_oid = virtual_router.getKeys()[0]

app_db_vnet_routes = get_vnet_routes_from_app_db()
asic_db_vnet_routes = get_vnet_routes_from_asic_db()
app_db_vnet_routes = get_vnet_routes_from_app_db(default_vrf_oid)
asic_db_vnet_routes = get_vnet_routes_from_asic_db(default_vrf_oid)

missed_in_asic_db_routes = get_vnet_routes_diff(asic_db_vnet_routes, app_db_vnet_routes)
missed_in_app_db_routes = get_vnet_routes_diff(app_db_vnet_routes, asic_db_vnet_routes)
missed_in_asic_db_routes = get_vnet_routes_diff(default_vrf_oid, asic_db_vnet_routes, app_db_vnet_routes,True)
missed_in_app_db_routes = get_vnet_routes_diff(default_vrf_oid, app_db_vnet_routes, asic_db_vnet_routes)
missed_in_sdk_routes = get_sdk_vnet_routes_diff(asic_db_vnet_routes)

res = {}
Expand Down

0 comments on commit fb4d138

Please sign in to comment.