Fix cisco_ios show lldp neighbors blank-capability parsing#2328
Conversation
When a neighbor row has no Capability code and a multi-word Port ID (for example "Port 6"), the CAPABILITIES (\S*) value greedily consumed the first word of the Port ID, so the row parsed as capabilities="Port", neighbor_interface="6". Constrain CAPABILITIES to the documented LLDP capability-code letters and make the field optional, and allow NEIGHBOR_INTERFACE to hold a multi-word Port ID. Add a test fixture covering blank capabilities with single-word, multi-word and MAC-address Port IDs. Fixes networktocode#2327
matt852
left a comment
There was a problem hiding this comment.
Recommendation: Changes Suggested
Breaking Change: No
Thanks @olasupo. This is a clean fix with great fixture coverage of the blank-capability edge cases. One suggestion before merge:
-
Add
^. -> Errortermination (and the supporting header/blank-line rules) to both states. Our parser conventions ask that each state end with^. -> Errorso every line of raw output is accounted for, and since this PR already reworks bothLLDPrules it's a natural moment to bring the template up to convention. Inntc_templates/templates/cisco_ios_show_lldp_neighbors.textfsm, theStartstate:Start ^Device.*ID -> LLDP # Capture time-stamp if vty line has command time-stamping turned on ^Load\s+for\s+ ^Time\s+source\s+is + ^Capability codes: + ^\s+\( + ^\s*$$ + ^. -> Error
And the
LLDPstate (the^Total\s+entries\s+displayedand^\s*$$rules must sit above the^${NEIGHBOR_NAME}rule, which otherwise matches nearly any line):LLDP ^${NEIGHBOR_NAME}\s*${LOCAL_INTERFACE}\s+\d+\s+(?:${CAPABILITIES}\s+)?${NEIGHBOR_INTERFACE}\s*$$ -> Record + ^Total\s+entries\s+displayed + ^\s*$$ ^${NEIGHBOR_NAME} ^\s+${LOCAL_INTERFACE}\s+\d+\s+(?:${CAPABILITIES}\s+)?${NEIGHBOR_INTERFACE}\s*$$ -> Record + ^. -> ErrorAll existing and new fixtures pass unchanged with these additions.
Fixes #2327
Problem
cisco_ios_show_lldp_neighborsmis-parses a neighbor row when the Capability column is blank and the Port ID contains a space (for examplePort 6). BecauseCAPABILITIESwas(\S*), it greedily consumed the first word of the Port ID:ABC-Ultra-210W Gi2/0/16 110 <blank> Port 6capabilities="Port", neighbor_interface="6"A blank-capability row whose Port ID is a single token (e.g.
Gi0/1or a MAC) already parsed correctly — only multi-word Port IDs were affected. Reported against a WS-C3750X running 15.0(2)SE10a.Fix
CAPABILITIESto the documented LLDP capability-code letters ([BRCWPSTO,]+) and make the field optional. It can no longer match a Port ID word such asPort, because the lowercase continuation breaks the match while the capability codes are always uppercase.NEIGHBOR_INTERFACEto hold a multi-word Port ID.After the fix the same row parses as
capabilities="", neighbor_interface="Port 6".Tests
Added
cisco_ios_show_lldp_neighbors3.raw/.ymlfrom the reporter's capture, covering blank capabilities with single-word, multi-word (Port 6) and MAC-address Port IDs, plus normal and multi-code (B,R) rows. The two existing fixtures are unchanged and still pass, and the full test suite passes.