Skip to content

Commit e2cc922

Browse files
theasianpianistlolyu
authored andcommitted
[route_check]: Ignore ASIC only SOC IPs (sonic-net#2548)
* [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>
1 parent 4b51e41 commit e2cc922

File tree

4 files changed

+477
-357
lines changed

4 files changed

+477
-357
lines changed

scripts/route_check.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,17 @@ def filter_out_vnet_routes(routes):
447447
return updated_routes
448448

449449

450+
def is_dualtor(config_db):
451+
device_metadata = config_db.get_table('DEVICE_METADATA')
452+
subtype = device_metadata['localhost'].get('subtype', '')
453+
return subtype.lower() == 'dualtor'
454+
455+
450456
def filter_out_standalone_tunnel_routes(routes):
451457
config_db = swsscommon.ConfigDBConnector()
452458
config_db.connect()
453-
device_metadata = config_db.get_table('DEVICE_METADATA')
454-
subtype = device_metadata['localhost'].get('subtype', '')
455459

456-
if subtype.lower() != 'dualtor':
460+
if not is_dualtor(config_db):
457461
return routes
458462

459463
app_db = swsscommon.DBConnector('APPL_DB', 0)
@@ -486,6 +490,45 @@ def filter_out_standalone_tunnel_routes(routes):
486490
return updated_routes
487491

488492

493+
def get_soc_ips(config_db):
494+
mux_table = config_db.get_table('MUX_CABLE')
495+
soc_ips = []
496+
for _, mux_entry in mux_table.items():
497+
if mux_entry.get("cable_type", "") == "active-active" and "soc_ipv4" in mux_entry:
498+
soc_ips.append(mux_entry["soc_ipv4"])
499+
500+
return soc_ips
501+
502+
503+
def filter_out_soc_ip_routes(routes):
504+
"""
505+
Ignore ASIC only routes for SOC IPs
506+
507+
For active-active cables, we want the tunnel route for SOC IPs
508+
to only be programmed to the ASIC and not to the kernel. This is to allow
509+
gRPC connections coming from ycabled to always use the direct link (since this
510+
will use the kernel routing table), but still provide connectivity to any external
511+
traffic in case of a link issue (since this traffic will be forwarded by the ASIC).
512+
"""
513+
config_db = swsscommon.ConfigDBConnector()
514+
config_db.connect()
515+
516+
if not is_dualtor(config_db):
517+
return routes
518+
519+
soc_ips = get_soc_ips(config_db)
520+
521+
if not soc_ips:
522+
return routes
523+
524+
updated_routes = []
525+
for route in routes:
526+
if route not in soc_ips:
527+
updated_routes.append(route)
528+
529+
return updated_routes
530+
531+
489532
def check_routes():
490533
"""
491534
The heart of this script which runs the checks.
@@ -523,6 +566,7 @@ def check_routes():
523566
rt_asic_miss = filter_out_default_routes(rt_asic_miss)
524567
rt_asic_miss = filter_out_vnet_routes(rt_asic_miss)
525568
rt_asic_miss = filter_out_standalone_tunnel_routes(rt_asic_miss)
569+
rt_asic_miss = filter_out_soc_ip_routes(rt_asic_miss)
526570

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

tests/mock_tables/config_db.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,7 @@
827827
"mac": "1d:34:db:16:a6:00",
828828
"platform": "x86_64-mlnx_msn3800-r0",
829829
"peer_switch": "sonic-switch",
830-
"type": "ToRRouter",
831-
"subtype": "DualToR"
830+
"type": "ToRRouter"
832831
},
833832
"SNMP_COMMUNITY|msft": {
834833
"TYPE": "RO"

0 commit comments

Comments
 (0)