Skip to content

Commit

Permalink
[route_check] Filter out VNET routes (sonic-net#1612)
Browse files Browse the repository at this point in the history
* Filter out VNET routes, Fix errors related to VNET routes printed by route_check script
Signed-off-by: Volodymyr Samotiy <[email protected]>
  • Loading branch information
volodymyrsamotiy authored Aug 20, 2021
1 parent 9395ebd commit 04cc047
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scripts/route_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions tests/route_check_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ":"
Expand Down Expand Up @@ -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: {}
}
}
}
}
}

Expand Down

0 comments on commit 04cc047

Please sign in to comment.