Skip to content

Commit 44dcf95

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 44dcf95

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

scripts/route_check.py

+46
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,48 @@ 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():
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, 0)
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+
401443
def filter_out_local_interfaces(namespace, keys):
402444
"""
403445
helper to filter out local interfaces
@@ -413,6 +455,7 @@ def filter_out_local_interfaces(namespace, keys):
413455

414456
db = swsscommon.DBConnector(APPL_DB_NAME, REDIS_TIMEOUT_MSECS, True, namespace)
415457
tbl = swsscommon.Table(db, 'ROUTE_TABLE')
458+
if_tbl_ips = set(get_local_p2p_ips())
416459

417460
for k in keys:
418461
e = dict(tbl.get(k)[1])
@@ -426,6 +469,9 @@ def filter_out_local_interfaces(namespace, keys):
426469
if not nh or ipaddress.ip_address(nh).is_unspecified:
427470
continue
428471

472+
if k in if_tbl_ips:
473+
continue
474+
429475
rt.append(k)
430476

431477
return rt

0 commit comments

Comments
 (0)