02 / CONFIGURATION AND TOPOLOGY · LESSON 08

Review reciprocal neighbour observations

Match complete reversed link identities without inventing missing observations.

18 min · learn at your pace

An observed neighbour is directional evidence

A collector can record that switch A sees switch B on a particular port. Another collector may provide the reverse observation. The two rows support a reciprocal link only when both endpoint device IDs and both port names reverse exactly.

Matching device names alone is insufficient. Two switches can have several links, and the reverse observation may refer to a different port. Represent an edge with four fields and look up the exact reversed tuple. Duplicate rows from repeated export collection should not create duplicate report entries.

Keep one-sided observations visible

A missing reverse record does not prove the cable is down. Collection timing, access or protocol configuration may explain it. Classify it as one_sided so the limitation stays visible. A reciprocal result means the supplied evidence agrees; it is not a new live connectivity test.

The inputs in this lesson are validated and contain no delimiter characters inside identifiers. Awk's composite array keys therefore provide a convenient representation. Sort all four endpoint fields for a stable report. This is a simplified neighbour export, not raw LLDP or CDP command output, and the script sends no packets or device commands.

Try an example.sh
awk -F '\t' 'NR>1 {printf "%s:%s sees %s:%s\n",$1,$2,$3,$4}' neighbours.tsv
YOUR TURN

Put it into practice.

neighbours.tsv contains validated local_device<TAB>local_port<TAB>peer_device<TAB>peer_port records. Deduplicate identical directed rows. Print those four columns plus state, sorted under LC_ALL=C. State is reciprocal only when the exact reversed four-field row exists, otherwise one_sided. Preserve both directions as separate report rows. A reverse observation on a different port is not reciprocal.

See an explained solution
One way to solve it.sh
export LC_ALL=C
printf 'local_device\tlocal_port\tpeer_device\tpeer_port\tstate\n'
awk -F '\t' 'NR>1{k=$1 SUBSEP $2 SUBSEP $3 SUBSEP $4;rows[k]=$0;reverse[k]=$3 SUBSEP $4 SUBSEP $1 SUBSEP $2}
END{for(k in rows)printf "%s\t%s\n",rows[k],(reverse[k] in rows)?"reciprocal":"one_sided"}' neighbours.tsv | sort

Exact reversed tuples keep parallel links separate. Deduplication prevents repeated collection rows from inflating the report, while the one_sided label accurately describes missing evidence without claiming a physical failure.