Skip to content

Commit

Permalink
[route_check]: Ignore ASIC only SOC IPs (#2548)
Browse files Browse the repository at this point in the history
* [tests]: Improve route check test

- Split test into separate methods based on functionality being tested
- Parametrize main test method for better granularity when viewing results/running test cases
- Add config DB mocking support
- Move some setup/teardown code to fixtures for better consistency
- Extract test data to separate file
- Ignore routes for SOC IPs that are only present in the ASIC
- Add test case to cover ASIC only SOC IPs

Signed-off-by: Lawrence Lee <lawlee@microsoft.com>
  • Loading branch information
theasianpianist authored and StormLiangMS committed Dec 30, 2022
1 parent d296780 commit 0137467
Show file tree
Hide file tree
Showing 4 changed files with 477 additions and 384 deletions.
50 changes: 47 additions & 3 deletions scripts/route_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,17 @@ def filter_out_vnet_routes(routes):
return updated_routes


def is_dualtor(config_db):
device_metadata = config_db.get_table('DEVICE_METADATA')
subtype = device_metadata['localhost'].get('subtype', '')
return subtype.lower() == 'dualtor'


def filter_out_standalone_tunnel_routes(routes):
config_db = swsscommon.ConfigDBConnector()
config_db.connect()
device_metadata = config_db.get_table('DEVICE_METADATA')
subtype = device_metadata['localhost'].get('subtype', '')

if subtype.lower() != 'dualtor':
if not is_dualtor(config_db):
return routes

app_db = swsscommon.DBConnector('APPL_DB', 0)
Expand Down Expand Up @@ -489,6 +493,45 @@ def filter_out_standalone_tunnel_routes(routes):
return updated_routes


def get_soc_ips(config_db):
mux_table = config_db.get_table('MUX_CABLE')
soc_ips = []
for _, mux_entry in mux_table.items():
if mux_entry.get("cable_type", "") == "active-active" and "soc_ipv4" in mux_entry:
soc_ips.append(mux_entry["soc_ipv4"])

return soc_ips


def filter_out_soc_ip_routes(routes):
"""
Ignore ASIC only routes for SOC IPs
For active-active cables, we want the tunnel route for SOC IPs
to only be programmed to the ASIC and not to the kernel. This is to allow
gRPC connections coming from ycabled to always use the direct link (since this
will use the kernel routing table), but still provide connectivity to any external
traffic in case of a link issue (since this traffic will be forwarded by the ASIC).
"""
config_db = swsscommon.ConfigDBConnector()
config_db.connect()

if not is_dualtor(config_db):
return routes

soc_ips = get_soc_ips(config_db)

if not soc_ips:
return routes

updated_routes = []
for route in routes:
if route not in soc_ips:
updated_routes.append(route)

return updated_routes


def check_routes():
"""
The heart of this script which runs the checks.
Expand Down Expand Up @@ -526,6 +569,7 @@ def check_routes():
rt_asic_miss = filter_out_default_routes(rt_asic_miss)
rt_asic_miss = filter_out_vnet_routes(rt_asic_miss)
rt_asic_miss = filter_out_standalone_tunnel_routes(rt_asic_miss)
rt_asic_miss = filter_out_soc_ip_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
3 changes: 1 addition & 2 deletions tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,7 @@
"mac": "1d:34:db:16:a6:00",
"platform": "x86_64-mlnx_msn3800-r0",
"peer_switch": "sonic-switch",
"type": "ToRRouter",
"subtype": "DualToR"
"type": "ToRRouter"
},
"SNMP_COMMUNITY|msft": {
"TYPE": "RO"
Expand Down
Loading

0 comments on commit 0137467

Please sign in to comment.