diff --git a/scripts/route_check.py b/scripts/route_check.py index 1e03a9c6bde0..8beaf42c8b41 100755 --- a/scripts/route_check.py +++ b/scripts/route_check.py @@ -413,6 +413,36 @@ def filter_out_default_routes(lst): return upd +def filter_out_vnet_routes(routes): + """ + Helper to filter out VNET routes + :param routes: list of routes to filter + :return filtered list of routes. + """ + db = swsscommon.DBConnector('APPL_DB', 0) + + vnet_route_table = swsscommon.Table(db, 'VNET_ROUTE_TABLE') + vnet_route_tunnel_table = swsscommon.Table(db, 'VNET_ROUTE_TUNNEL_TABLE') + + vnet_routes_db_keys = vnet_route_table.getKeys() + vnet_route_tunnel_table.getKeys() + + vnet_routes = [] + + for vnet_route_db_key in vnet_routes_db_keys: + vnet_route_attrs = vnet_route_db_key.split(':') + vnet_name = vnet_route_attrs[0] + vnet_route = vnet_route_attrs[1] + vnet_routes.append(vnet_route) + + updated_routes = [] + + for route in routes: + if not (route in vnet_routes): + updated_routes.append(route) + + return updated_routes + + def check_routes(): """ The heart of this script which runs the checks. @@ -448,6 +478,7 @@ def check_routes(): # Check missed ASIC routes against APPL-DB INTF_TABLE _, rt_asic_miss = diff_sorted_lists(intf_appl, rt_asic_miss) rt_asic_miss = filter_out_default_routes(rt_asic_miss) + rt_asic_miss = filter_out_vnet_routes(rt_asic_miss) # Check APPL-DB INTF_TABLE with ASIC table route entries intf_appl_miss, _ = diff_sorted_lists(intf_appl, rt_asic) diff --git a/tests/route_check_test.py b/tests/route_check_test.py index a39015c07f35..7dd4035640f2 100644 --- a/tests/route_check_test.py +++ b/tests/route_check_test.py @@ -24,6 +24,7 @@ OP_DEL = "DEL" ROUTE_TABLE = 'ROUTE_TABLE' +VNET_ROUTE_TABLE = 'VNET_ROUTE_TABLE' INTF_TABLE = 'INTF_TABLE' RT_ENTRY_TABLE = 'ASIC_STATE' SEPARATOR = ":" @@ -252,6 +253,45 @@ "10.10.196.30/31" ] } + }, + "6": { + DESCR: "Good one with VNET routes", + ARGS: "route_check", + PRE: { + APPL_DB: { + ROUTE_TABLE: { + "0.0.0.0/0" : { "ifname": "portchannel0" }, + "10.10.196.12/31" : { "ifname": "portchannel0" }, + "10.10.196.20/31" : { "ifname": "portchannel0" }, + "10.10.196.30/31" : { "ifname": "lo" } + }, + VNET_ROUTE_TABLE: { + "Vnet1:30.1.10.0/24": { "ifname": "Vlan3001" }, + "Vnet1:50.1.1.0/24": { "ifname": "Vlan3001" }, + "Vnet1:50.2.2.0/24": { "ifname": "Vlan3001" } + }, + INTF_TABLE: { + "PortChannel1013:10.10.196.24/31": {}, + "PortChannel1023:2603:10b0:503:df4::5d/126": {}, + "PortChannel1024": {}, + "Vlan3001": { "vnet_name": "Vnet1" }, + "Vlan3001:30.1.10.1/24": {} + } + }, + ASIC_DB: { + RT_ENTRY_TABLE: { + RT_ENTRY_KEY_PREFIX + "10.10.196.12/31" + RT_ENTRY_KEY_SUFFIX: {}, + RT_ENTRY_KEY_PREFIX + "10.10.196.20/31" + RT_ENTRY_KEY_SUFFIX: {}, + RT_ENTRY_KEY_PREFIX + "10.10.196.24/32" + RT_ENTRY_KEY_SUFFIX: {}, + RT_ENTRY_KEY_PREFIX + "2603:10b0:503:df4::5d/128" + RT_ENTRY_KEY_SUFFIX: {}, + RT_ENTRY_KEY_PREFIX + "0.0.0.0/0" + RT_ENTRY_KEY_SUFFIX: {}, + RT_ENTRY_KEY_PREFIX + "30.1.10.1/32" + RT_ENTRY_KEY_SUFFIX: {}, + RT_ENTRY_KEY_PREFIX + "30.1.10.0/24" + RT_ENTRY_KEY_SUFFIX: {}, + RT_ENTRY_KEY_PREFIX + "50.1.1.0/24" + RT_ENTRY_KEY_SUFFIX: {}, + RT_ENTRY_KEY_PREFIX + "50.2.2.0/24" + RT_ENTRY_KEY_SUFFIX: {} + } + } + } } }