From c03c08702a655c32d1459b44afe31f7f69678f5d Mon Sep 17 00:00:00 2001 From: Prabhat Aravind Date: Wed, 14 May 2025 21:40:26 +0000 Subject: [PATCH] Fix route_check.py to ignore local p2p IP prefixes * In some cases where there are repeated link flaps, route_check.py flags local p2p IP prefixes as missing in APPL_DB. These /31 IPv4 or /126 IPv6 IPs are not expected to be present in APPL_DB after a link goes down. This change tries to filter out such entries. Failure results: {{ "missed_ROUTE_TABLE_routes": [ "10.10.196.16/31", "2603:10b0:31f:753::24/126" ] }} Failed. Look at reported mismatches above add: [] del: [ "10.10.196.16/31", "2603:10b0:31f:753::24/126" ] Signed-off-by: Prabhat Aravind --- scripts/route_check.py | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/scripts/route_check.py b/scripts/route_check.py index 98f7aeb353..44a78dd334 100755 --- a/scripts/route_check.py +++ b/scripts/route_check.py @@ -398,6 +398,66 @@ def get_interfaces(namespace): return sorted(intf) +def is_point_to_point_prefix(prefix): + """ + check if a given prefix is a p2p /31 ipv4 prefix or a /126 ipv6 prefix + :return sorted list of local p2p IP prefixes + """ + try: + network = ipaddress.ip_network(prefix, strict=False) + if isinstance(network, ipaddress.IPv4Network) and network.prefixlen == 31: + return True + if isinstance(network, ipaddress.IPv6Network) and network.prefixlen == 126: + return True + return False + except ValueError: + return False + + +def get_local_p2p_ips(namespace): + """ + helper to read p2p2 local IPs from interface table in APPL-DB. + :return sorted list of local p2p IP addresses + """ + db = swsscommon.DBConnector(APPL_DB_NAME, REDIS_TIMEOUT_MSECS, True, namespace) + print_message(syslog.LOG_DEBUG, "APPL DB connected for interfaces") + tbl = swsscommon.Table(db, 'INTF_TABLE') + keys = tbl.getKeys() + + intf = [] + for k in keys: + lst = re.split(':', k.lower(), maxsplit=1) + if len(lst) == 1: + # No IP address in key; ignore + continue + + ip = lst[1] + + if is_point_to_point_prefix(ip): + intf.append(ip) + + print_message(syslog.LOG_DEBUG, json.dumps({"APPL_DB_INTF": sorted(intf)}, indent=4)) + return sorted(intf) + + +def filter_out_local_p2p_ips(namespace, keys): + """ + helper to filter out local p2p IPs + :param keys: APPL-DB:ROUTE_TABLE Routes to check. + :return keys filtered out of local + """ + rt = [] + if_tbl_ips = set(get_local_p2p_ips(namespace)) + + for k in keys: + if k in if_tbl_ips: + continue + + rt.append(k) + + return rt + + def filter_out_local_interfaces(namespace, keys): """ helper to filter out local interfaces @@ -772,6 +832,10 @@ def check_routes_for_namespace(namespace): # Drop all those for which DEL received rt_asic_miss, _ = diff_sorted_lists(rt_asic_miss, deletes) + # Filter local p2p IPs if any that are reported as missing in APPL_DB + if rt_appl_miss: + rt_appl_miss = filter_out_local_p2p_ips(namespace, rt_appl_miss) + if rt_appl_miss: results["missed_ROUTE_TABLE_routes"] = rt_appl_miss