Skip to content

Commit c03c087

Browse files
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 <[email protected]>
1 parent 1d6e050 commit c03c087

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

scripts/route_check.py

+64
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,66 @@ def get_interfaces(namespace):
398398
return sorted(intf)
399399

400400

401+
def is_point_to_point_prefix(prefix):
402+
"""
403+
check if a given prefix is a p2p /31 ipv4 prefix or a /126 ipv6 prefix
404+
:return sorted list of local p2p IP prefixes
405+
"""
406+
try:
407+
network = ipaddress.ip_network(prefix, strict=False)
408+
if isinstance(network, ipaddress.IPv4Network) and network.prefixlen == 31:
409+
return True
410+
if isinstance(network, ipaddress.IPv6Network) and network.prefixlen == 126:
411+
return True
412+
return False
413+
except ValueError:
414+
return False
415+
416+
417+
def get_local_p2p_ips(namespace):
418+
"""
419+
helper to read p2p2 local IPs from interface table in APPL-DB.
420+
:return sorted list of local p2p IP addresses
421+
"""
422+
db = swsscommon.DBConnector(APPL_DB_NAME, REDIS_TIMEOUT_MSECS, True, namespace)
423+
print_message(syslog.LOG_DEBUG, "APPL DB connected for interfaces")
424+
tbl = swsscommon.Table(db, 'INTF_TABLE')
425+
keys = tbl.getKeys()
426+
427+
intf = []
428+
for k in keys:
429+
lst = re.split(':', k.lower(), maxsplit=1)
430+
if len(lst) == 1:
431+
# No IP address in key; ignore
432+
continue
433+
434+
ip = lst[1]
435+
436+
if is_point_to_point_prefix(ip):
437+
intf.append(ip)
438+
439+
print_message(syslog.LOG_DEBUG, json.dumps({"APPL_DB_INTF": sorted(intf)}, indent=4))
440+
return sorted(intf)
441+
442+
443+
def filter_out_local_p2p_ips(namespace, keys):
444+
"""
445+
helper to filter out local p2p IPs
446+
:param keys: APPL-DB:ROUTE_TABLE Routes to check.
447+
:return keys filtered out of local
448+
"""
449+
rt = []
450+
if_tbl_ips = set(get_local_p2p_ips(namespace))
451+
452+
for k in keys:
453+
if k in if_tbl_ips:
454+
continue
455+
456+
rt.append(k)
457+
458+
return rt
459+
460+
401461
def filter_out_local_interfaces(namespace, keys):
402462
"""
403463
helper to filter out local interfaces
@@ -772,6 +832,10 @@ def check_routes_for_namespace(namespace):
772832
# Drop all those for which DEL received
773833
rt_asic_miss, _ = diff_sorted_lists(rt_asic_miss, deletes)
774834

835+
# Filter local p2p IPs if any that are reported as missing in APPL_DB
836+
if rt_appl_miss:
837+
rt_appl_miss = filter_out_local_p2p_ips(namespace, rt_appl_miss)
838+
775839
if rt_appl_miss:
776840
results["missed_ROUTE_TABLE_routes"] = rt_appl_miss
777841

0 commit comments

Comments
 (0)