Skip to content

Commit b2eca37

Browse files
[route_check]: Ignore ASIC only SOC IPs (#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 <[email protected]>
1 parent 208824d commit b2eca37

File tree

4 files changed

+477
-384
lines changed

4 files changed

+477
-384
lines changed

scripts/route_check.py

+47-3
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,17 @@ def filter_out_vnet_routes(routes):
450450
return updated_routes
451451

452452

453+
def is_dualtor(config_db):
454+
device_metadata = config_db.get_table('DEVICE_METADATA')
455+
subtype = device_metadata['localhost'].get('subtype', '')
456+
return subtype.lower() == 'dualtor'
457+
458+
453459
def filter_out_standalone_tunnel_routes(routes):
454460
config_db = swsscommon.ConfigDBConnector()
455461
config_db.connect()
456-
device_metadata = config_db.get_table('DEVICE_METADATA')
457-
subtype = device_metadata['localhost'].get('subtype', '')
458462

459-
if subtype.lower() != 'dualtor':
463+
if not is_dualtor(config_db):
460464
return routes
461465

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

491495

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

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

tests/mock_tables/config_db.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -831,8 +831,7 @@
831831
"mac": "1d:34:db:16:a6:00",
832832
"platform": "x86_64-mlnx_msn3800-r0",
833833
"peer_switch": "sonic-switch",
834-
"type": "ToRRouter",
835-
"subtype": "DualToR"
834+
"type": "ToRRouter"
836835
},
837836
"SNMP_COMMUNITY|msft": {
838837
"TYPE": "RO"

0 commit comments

Comments
 (0)