Skip to content

Commit 227374e

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 227374e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

scripts/route_check.py

+48
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,50 @@ 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+
db = swsscommon.DBConnector(APPL_DB_NAME, 0)
407+
try:
408+
network = ipaddress.ip_network(prefix, strict=False)
409+
if isinstance(network, ipaddress.IPv4Network) and network.prefixlen == 31:
410+
return True
411+
if isinstance(network, ipaddress.IPv6Network) and network.prefixlen == 126:
412+
return True
413+
return False
414+
except ValueError:
415+
return False
416+
417+
418+
def get_local_p2p_ips():
419+
"""
420+
helper to read p2p2 local IPs from interface table in APPL-DB.
421+
:return sorted list of local p2p IP addresses
422+
"""
423+
db = swsscommon.DBConnector(APPL_DB_NAME, 0)
424+
print_message(syslog.LOG_DEBUG, "APPL DB connected for interfaces")
425+
tbl = swsscommon.Table(db, 'INTF_TABLE')
426+
keys = tbl.getKeys()
427+
428+
intf = []
429+
for k in keys:
430+
pdb.set_trace()
431+
lst = re.split(':', k.lower(), maxsplit=1)
432+
if len(lst) == 1:
433+
# No IP address in key; ignore
434+
continue
435+
436+
ip = lst[1]
437+
438+
if is_point_to_point_prefix(ip):
439+
intf.append(ip)
440+
441+
print_message(syslog.LOG_DEBUG, json.dumps({"APPL_DB_INTF": sorted(intf)}, indent=4))
442+
return sorted(intf)
443+
444+
401445
def filter_out_local_interfaces(namespace, keys):
402446
"""
403447
helper to filter out local interfaces
@@ -413,6 +457,7 @@ def filter_out_local_interfaces(namespace, keys):
413457

414458
db = swsscommon.DBConnector(APPL_DB_NAME, REDIS_TIMEOUT_MSECS, True, namespace)
415459
tbl = swsscommon.Table(db, 'ROUTE_TABLE')
460+
if_tbl_ips = set(get_local_p2p_ips())
416461

417462
for k in keys:
418463
e = dict(tbl.get(k)[1])
@@ -426,6 +471,9 @@ def filter_out_local_interfaces(namespace, keys):
426471
if not nh or ipaddress.ip_address(nh).is_unspecified:
427472
continue
428473

474+
if k in if_tbl_ips:
475+
continue
476+
429477
rt.append(k)
430478

431479
return rt

0 commit comments

Comments
 (0)