Review both sides of a neighbour relationship
Compare directional discovery exports without treating a single observation as complete confirmation.
Discovery observations have a direction
A neighbour export records what one local interface reported about a remote interface. The reverse observation is a different record. Two reports from the same direction do not establish that both devices agree.
Represent an endpoint as a tuple of normalized device and interface. Represent an observation as an ordered pair of endpoints. A set removes duplicate reports without confusing their direction. An expected link then has two possible confirming observations.
Conflicting evidence takes precedence
This teaching policy labels zero directions missing, one partial and both matched. If either expected endpoint reports a different neighbour, mark the link mismatch even when confirming reports also exist. Contradictory evidence should not disappear simply because one record matches the desired topology.
Ignore observations from unrelated local endpoints. They may describe other links, and the expected-link list defines this audit's scope. Validate unique link IDs and distinct nonempty expected endpoints before returning sorted results.
These statuses describe evidence quality, not a diagnosis of a physical cable. Discovery can be disabled, collected at different times or filtered by a device. A partial or missing report calls for investigation; it does not prove a disconnected network. The browser evaluates supplied records and does not run LLDP, CDP or any live discovery protocol.
left = ("edge-a", "wan0")
right = ("edge-b", "wan0")
observations = {(left, right)}
print((left, right) in observations, (right, left) in observations)
Put it into practice.
Define review_links(expected, observed). Expected rows have id, left, right; endpoints contain device/interface strings. Observed rows have local, remote endpoints with validated nonempty strings. Normalize endpoint labels and IDs using strip().casefold(). Reject empty/duplicate expected IDs, empty endpoints or equal expected endpoints with ValueError. Deduplicate directional observations. For each expected link return normalized id, status, seen_directions (0..2). A contradictory report from either expected local endpoint gives mismatch; otherwise 0=>missing, 1=>partial, 2=>matched. Ignore unrelated local endpoints, sort by id and preserve inputs.
See an explained solution
def review_links(expected, observed):
def endpoint(row):
return (row["device"].strip().casefold(),row["interface"].strip().casefold())
reports = set()
for row in observed:
reports.add((endpoint(row["local"]),endpoint(row["remote"])))
seen, result = set(), []
for row in expected:
identifier = row["id"].strip().casefold()
left, right = endpoint(row["left"]), endpoint(row["right"])
if not identifier or identifier in seen or not all(left+right) or left == right:
raise ValueError("Invalid expected link")
seen.add(identifier)
count = int((left,right) in reports) + int((right,left) in reports)
mismatch = any((local == left and remote != right) or (local == right and remote != left) for local,remote in reports)
status = "mismatch" if mismatch else {0:"missing",1:"partial",2:"matched"}[count]
result.append({"id":identifier,"status":status,"seen_directions":count})
return sorted(result,key=lambda row:row["id"])
if __name__ == "__main__":
a={"device":"edge-a","interface":"wan0"}
b={"device":"edge-b","interface":"wan0"}
print(review_links([{"id":"uplink","left":a,"right":b}], [{"local":a,"remote":b}]))
A directional set distinguishes repeated evidence from independent confirmation. The mismatch rule exposes contradictory observations without making claims about physical connectivity.