Skip to content

Commit 04cc047

Browse files
[route_check] Filter out VNET routes (sonic-net#1612)
* Filter out VNET routes, Fix errors related to VNET routes printed by route_check script Signed-off-by: Volodymyr Samotiy <[email protected]>
1 parent 9395ebd commit 04cc047

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

scripts/route_check.py

+31
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,36 @@ def filter_out_default_routes(lst):
413413
return upd
414414

415415

416+
def filter_out_vnet_routes(routes):
417+
"""
418+
Helper to filter out VNET routes
419+
:param routes: list of routes to filter
420+
:return filtered list of routes.
421+
"""
422+
db = swsscommon.DBConnector('APPL_DB', 0)
423+
424+
vnet_route_table = swsscommon.Table(db, 'VNET_ROUTE_TABLE')
425+
vnet_route_tunnel_table = swsscommon.Table(db, 'VNET_ROUTE_TUNNEL_TABLE')
426+
427+
vnet_routes_db_keys = vnet_route_table.getKeys() + vnet_route_tunnel_table.getKeys()
428+
429+
vnet_routes = []
430+
431+
for vnet_route_db_key in vnet_routes_db_keys:
432+
vnet_route_attrs = vnet_route_db_key.split(':')
433+
vnet_name = vnet_route_attrs[0]
434+
vnet_route = vnet_route_attrs[1]
435+
vnet_routes.append(vnet_route)
436+
437+
updated_routes = []
438+
439+
for route in routes:
440+
if not (route in vnet_routes):
441+
updated_routes.append(route)
442+
443+
return updated_routes
444+
445+
416446
def check_routes():
417447
"""
418448
The heart of this script which runs the checks.
@@ -448,6 +478,7 @@ def check_routes():
448478
# Check missed ASIC routes against APPL-DB INTF_TABLE
449479
_, rt_asic_miss = diff_sorted_lists(intf_appl, rt_asic_miss)
450480
rt_asic_miss = filter_out_default_routes(rt_asic_miss)
481+
rt_asic_miss = filter_out_vnet_routes(rt_asic_miss)
451482

452483
# Check APPL-DB INTF_TABLE with ASIC table route entries
453484
intf_appl_miss, _ = diff_sorted_lists(intf_appl, rt_asic)

tests/route_check_test.py

+40
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
OP_DEL = "DEL"
2525

2626
ROUTE_TABLE = 'ROUTE_TABLE'
27+
VNET_ROUTE_TABLE = 'VNET_ROUTE_TABLE'
2728
INTF_TABLE = 'INTF_TABLE'
2829
RT_ENTRY_TABLE = 'ASIC_STATE'
2930
SEPARATOR = ":"
@@ -252,6 +253,45 @@
252253
"10.10.196.30/31"
253254
]
254255
}
256+
},
257+
"6": {
258+
DESCR: "Good one with VNET routes",
259+
ARGS: "route_check",
260+
PRE: {
261+
APPL_DB: {
262+
ROUTE_TABLE: {
263+
"0.0.0.0/0" : { "ifname": "portchannel0" },
264+
"10.10.196.12/31" : { "ifname": "portchannel0" },
265+
"10.10.196.20/31" : { "ifname": "portchannel0" },
266+
"10.10.196.30/31" : { "ifname": "lo" }
267+
},
268+
VNET_ROUTE_TABLE: {
269+
"Vnet1:30.1.10.0/24": { "ifname": "Vlan3001" },
270+
"Vnet1:50.1.1.0/24": { "ifname": "Vlan3001" },
271+
"Vnet1:50.2.2.0/24": { "ifname": "Vlan3001" }
272+
},
273+
INTF_TABLE: {
274+
"PortChannel1013:10.10.196.24/31": {},
275+
"PortChannel1023:2603:10b0:503:df4::5d/126": {},
276+
"PortChannel1024": {},
277+
"Vlan3001": { "vnet_name": "Vnet1" },
278+
"Vlan3001:30.1.10.1/24": {}
279+
}
280+
},
281+
ASIC_DB: {
282+
RT_ENTRY_TABLE: {
283+
RT_ENTRY_KEY_PREFIX + "10.10.196.12/31" + RT_ENTRY_KEY_SUFFIX: {},
284+
RT_ENTRY_KEY_PREFIX + "10.10.196.20/31" + RT_ENTRY_KEY_SUFFIX: {},
285+
RT_ENTRY_KEY_PREFIX + "10.10.196.24/32" + RT_ENTRY_KEY_SUFFIX: {},
286+
RT_ENTRY_KEY_PREFIX + "2603:10b0:503:df4::5d/128" + RT_ENTRY_KEY_SUFFIX: {},
287+
RT_ENTRY_KEY_PREFIX + "0.0.0.0/0" + RT_ENTRY_KEY_SUFFIX: {},
288+
RT_ENTRY_KEY_PREFIX + "30.1.10.1/32" + RT_ENTRY_KEY_SUFFIX: {},
289+
RT_ENTRY_KEY_PREFIX + "30.1.10.0/24" + RT_ENTRY_KEY_SUFFIX: {},
290+
RT_ENTRY_KEY_PREFIX + "50.1.1.0/24" + RT_ENTRY_KEY_SUFFIX: {},
291+
RT_ENTRY_KEY_PREFIX + "50.2.2.0/24" + RT_ENTRY_KEY_SUFFIX: {}
292+
}
293+
}
294+
}
255295
}
256296
}
257297

0 commit comments

Comments
 (0)