Skip to content

Fix cisco_ios show lldp neighbors blank-capability parsing#2328

Open
olasupo wants to merge 1 commit into
networktocode:masterfrom
olasupo:fix-cisco-ios-lldp-neighbors-blank-capability
Open

Fix cisco_ios show lldp neighbors blank-capability parsing#2328
olasupo wants to merge 1 commit into
networktocode:masterfrom
olasupo:fix-cisco-ios-lldp-neighbors-blank-capability

Conversation

@olasupo

@olasupo olasupo commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #2327

Problem

cisco_ios_show_lldp_neighbors mis-parses a neighbor row when the Capability column is blank and the Port ID contains a space (for example Port 6). Because CAPABILITIES was (\S*), it greedily consumed the first word of the Port ID:

Raw row Parsed (before)
ABC-Ultra-210W Gi2/0/16 110 <blank> Port 6 capabilities="Port", neighbor_interface="6"

A blank-capability row whose Port ID is a single token (e.g. Gi0/1 or a MAC) already parsed correctly — only multi-word Port IDs were affected. Reported against a WS-C3750X running 15.0(2)SE10a.

Fix

  • Constrain CAPABILITIES to the documented LLDP capability-code letters ([BRCWPSTO,]+) and make the field optional. It can no longer match a Port ID word such as Port, because the lowercase continuation breaks the match while the capability codes are always uppercase.
  • Allow NEIGHBOR_INTERFACE to 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/.yml from 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.

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 matt852 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ^. -> Error termination (and the supporting header/blank-line rules) to both states. Our parser conventions ask that each state end with ^. -> Error so every line of raw output is accounted for, and since this PR already reworks both LLDP rules it's a natural moment to bring the template up to convention. In ntc_templates/templates/cisco_ios_show_lldp_neighbors.textfsm, the Start state:

     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 LLDP state (the ^Total\s+entries\s+displayed and ^\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
    +  ^. -> Error

    All existing and new fixtures pass unchanged with these additions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug-cisco_ios_show_lldp_neighbors

2 participants