Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions scripts/route_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,65 @@ 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 p2p 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
Expand Down Expand Up @@ -818,6 +877,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

Expand Down
59 changes: 59 additions & 0 deletions tests/route_check_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,4 +1295,63 @@
},
RET: -1,
},
"28": {
DESCR: "failure case with local p2p IPs in APP_DB",
MULTI_ASIC: False,
NAMESPACE: [''],
ARGS: "route_check -i 15",
RET: -1,
PRE: {
DEFAULTNS: {
APPL_DB: {
ROUTE_TABLE: {
"0.0.0.0/0": {"ifname": "portchannel0"},
"10.10.196.12/31": {"ifname": "portchannel0"},
"10.10.196.20/31": {"ifname": "portchannel0"},
"10.10.196.40/31": {"ifname": "portchannel0"},
"90.10.196.32/32": {"ifname": "portchannel0"},
"fc02::78/126": {"ifname": "portchannel0"},
"fc03::2c/126": {"ifname": "portchannel0"},
"10.10.196.30/31": {"ifname": "lo"}
},
INTF_TABLE: {
"PortChannel1013:90.10.196.24/31": {},
"PortChannel1015:10.10.196.12/31": {},
"PortChannel1017:fc03::2c/126": {},
"PortChannel1021:9603:10b0:503:df4::5e/126": {},
"PortChannel1023:9603:10b0:503:df4::5d/126": {},
"PortChannel1024": {}
}
},
ASIC_DB: {
RT_ENTRY_TABLE: {
ASIC_RT_ENTRY_KEY_PREFIX + "20.10.196.24/32" + ASIC_RT_ENTRY_KEY_SUFFIX: {},
ASIC_RT_ENTRY_KEY_PREFIX + "10.10.196.40/31" + ASIC_RT_ENTRY_KEY_SUFFIX: {},
ASIC_RT_ENTRY_KEY_PREFIX + "3603:10b0:503:df4::5d/128" + ASIC_RT_ENTRY_KEY_SUFFIX: {},
ASIC_RT_ENTRY_KEY_PREFIX + "0.0.0.0/0" + ASIC_RT_ENTRY_KEY_SUFFIX: {}
}
}
}
},
RESULT: {
DEFAULTNS: {
"missed_ROUTE_TABLE_routes": [
"10.10.196.20/31",
"90.10.196.32/32",
"fc02::78/126"
],
"missed_INTF_TABLE_entries": [
"10.10.196.12/32",
"90.10.196.24/32",
"9603:10b0:503:df4::5d/128",
"9603:10b0:503:df4::5e/128",
"fc03::2c/128"
],
"Unaccounted_ROUTE_ENTRY_TABLE_entries": [
"20.10.196.24/32",
"3603:10b0:503:df4::5d/128"
]
}
}
},
}
Loading