Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

cisco_ios_show_interfaces_switchport.textfsm (Does not parse interfaces after multiline VLAN list is encountered) #903

Closed
mickyhale opened this issue Mar 17, 2021 · 1 comment

Comments

@mickyhale
Copy link
Contributor

ISSUE TYPE
  • Bug Report
TEMPLATE USING
Value Required INTERFACE (\S+)
Value SWITCHPORT (.+?)
Value SWITCHPORT_MONITOR (.+?)
Value SWITCHPORT_NEGOTIATION (.+?)
Value MODE (.+?)
Value ADMIN_MODE (.+?)
Value ACCESS_VLAN (\d+|unassigned)
Value NATIVE_VLAN (\d+)
Value VOICE_VLAN (\S+)
Value List TRUNKING_VLANS (\S+?)

Start
  ^Name: -> Continue.Record
  ^Name:\s+${INTERFACE}
  ^\s*Switchport:\s+${SWITCHPORT}$$
  ^\s*Switchport\s+Monitor:\s+${SWITCHPORT_MONITOR}$$
  ^\s*Operational\s+Mode:\s+${MODE}$$
  ^\s*Negotiation\s+of\s+Trunking:\s+${SWITCHPORT_NEGOTIATION}$$
  ^\s*Access\s+Mode\s+VLAN:\s+${ACCESS_VLAN}
  ^\s*Trunking\s+Native\s+Mode\s+VLAN:\s+${NATIVE_VLAN}
  ^\s*Voice\s+VLAN:\s+${VOICE_VLAN}
  ^\s*Trunking\s+VLANs\s+Enabled:\s+${TRUNKING_VLANS},\s*$$ -> Trunk
  ^\s*Trunking\s+VLANs\s+Enabled:\s+${TRUNKING_VLANS}$$
  ^\s+${TRUNKING_VLANS}$$
  ^\s*Administrative\s+Mode:\s+${ADMIN_MODE}$$
  ^\s*(?:Operational|Administrative)\s+(?:Trunking|Native\s+VLAN|private-vlan)
  ^\s*Voice\s+VLAN:
  ^\s*Pruning\s+VLANs
  ^\s*Capture\s+(?:Mode|VLANs)
  ^\s*Autostate\s+mode\s+exclude
  ^\s*Protected
  ^\s*Unknown\s+(unicast|multicast)
  ^\s*Vepa\s+Enabled
  ^\s*Appliance\s+trust
  ^\s*Operational\s+Dot1q\s+Ethertype
  ^\s*$$
  # Capture time-stamp if vty line has command time-stamping turned on
  ^Load\s+for\s+
  ^Time\s+source\s+is
  ^. -> Error

Trunk
  ^\s+${TRUNKING_VLANS},\s*$$ -> Start
  ^\s+${TRUNKING_VLANS}\s*$$

SAMPLE COMMAND OUTPUT
Name: Gi2/2/16
Switchport: Enabled
Administrative Mode: trunk
Operational Mode: down
Administrative Trunking Encapsulation: dot1q
Negotiation of Trunking: On
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 69 (Native_Edge)
Administrative Native VLAN tagging: enabled
Operational Native VLAN tagging: disabled
Voice VLAN: none
Administrative private-vlan host-association: none 
Administrative private-vlan mapping: none 
Operational private-vlan: none
Trunking VLANs Enabled: 586-589
Pruning VLANs Enabled: 2-1001
Capture Mode Disabled
Capture VLANs Allowed: ALL

Unknown unicast blocked: disabled
Unknown multicast blocked: disabled

Name: Gi2/2/17
Switchport: Enabled
Administrative Mode: trunk
Operational Mode: down
Administrative Trunking Encapsulation: dot1q
Negotiation of Trunking: On
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 1 (default)
Administrative Native VLAN tagging: enabled
Operational Native VLAN tagging: disabled
Voice VLAN: none
Administrative private-vlan host-association: none 
Administrative private-vlan mapping: none 
Operational private-vlan: none
Trunking VLANs Enabled: 501,504,517,522,526,529,556,567,568,577-579,582,583,
     595,980,981,993,995,999
Pruning VLANs Enabled: 2-1001
Capture Mode Disabled
Capture VLANs Allowed: ALL

Unknown unicast blocked: disabled
Unknown multicast blocked: disabled

Name: Gi2/2/45
Switchport: Enabled
Administrative Mode: trunk
Operational Mode: down
Administrative Trunking Encapsulation: dot1q
Negotiation of Trunking: On
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 69 (Native_Edge)
Administrative Native VLAN tagging: enabled
Operational Native VLAN tagging: disabled
Voice VLAN: none
Administrative private-vlan host-association: none 
Administrative private-vlan mapping: none 
Operational private-vlan: none
Trunking VLANs Enabled: 69
Pruning VLANs Enabled: 2-1001
Capture Mode Disabled
Capture VLANs Allowed: ALL

Unknown unicast blocked: disabled
Unknown multicast blocked: disabled

Name: Te2/9/1
Switchport: Enabled
Administrative Mode: trunk
Operational Mode: trunk (member of bundle Po1)
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: dot1q
Operational Dot1q Ethertype:  0x8100
Negotiation of Trunking: On
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 69 (Native_Edge)
Administrative Native VLAN tagging: enabled
Operational Native VLAN tagging: disabled
Voice VLAN: none
Administrative private-vlan host-association: none 
Administrative private-vlan mapping: none 
Operational private-vlan: none
Trunking VLANs Enabled: 584-589,596,597,788,1500,1525,2040
Pruning VLANs Enabled: 2-1001
Capture Mode Disabled
Capture VLANs Allowed: ALL

Unknown unicast blocked: disabled
Unknown multicast blocked: disabled

Name: Te2/9/2
Switchport: Enabled
Administrative Mode: trunk
Operational Mode: trunk (member of bundle Po2)
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: dot1q
Operational Dot1q Ethertype:  0x8100
Negotiation of Trunking: On
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 69 (Native_Edge)
Administrative Native VLAN tagging: enabled
Operational Native VLAN tagging: disabled
Voice VLAN: none
Administrative private-vlan host-association: none 
Administrative private-vlan mapping: none 
Operational private-vlan: none
Trunking VLANs Enabled: 584-589,965,1500,1525,1579,3600
Pruning VLANs Enabled: 2-1001
Capture Mode Disabled
Capture VLANs Allowed: ALL

Unknown unicast blocked: disabled
Unknown multicast blocked: disabled

SUMMARY

The template stops parsing interfaces after it hits a multiline VLAN list for “Trunking VLANs Enabled”. It appears that the custom trunk state either isn't necessary or needs to be modified. I've had success with something like the following...

Value Required INTERFACE (\S+)
Value SWITCHPORT (.+?)
Value SWITCHPORT_MONITOR (.+?)
Value SWITCHPORT_NEGOTIATION (.+?)
Value MODE (.+?)
Value ADMIN_MODE (.+?)
Value ACCESS_VLAN (\d+|unassigned)
Value NATIVE_VLAN (\d+)
Value VOICE_VLAN (\S+)
Value List TRUNKING_VLANS (\S+?)

Start
  ^Name: -> Continue.Record
  ^Name:\s+${INTERFACE}
  ^\s*Switchport:\s+${SWITCHPORT}$$
  ^\s*Switchport\s+Monitor:\s+${SWITCHPORT_MONITOR}$$
  ^\s*Operational\s+Mode:\s+${MODE}$$
  ^\s*Negotiation\s+of\s+Trunking:\s+${SWITCHPORT_NEGOTIATION}$$
  ^\s*Access\s+Mode\s+VLAN:\s+${ACCESS_VLAN}
  ^\s*Trunking\s+Native\s+Mode\s+VLAN:\s+${NATIVE_VLAN}
  ^\s*Voice\s+VLAN:\s+${VOICE_VLAN}
  ^\s*Trunking\s+VLANs\s+Enabled:\s+${TRUNKING_VLANS},\s*$$ -> Trunk
  ^\s*Trunking\s+VLANs\s+Enabled:\s+${TRUNKING_VLANS}$$
  ^\s*Administrative\s+Mode:\s+${ADMIN_MODE}$$
  ^\s*(?:Operational|Administrative)\s+(?:Trunking|Native\s+VLAN|private-vlan)
  ^\s*Voice\s+VLAN:
  ^\s*Pruning\s+VLANs
  ^\s*Capture\s+(?:Mode|VLANs)
  ^\s*Autostate\s+mode\s+exclude
  ^\s*Protected
  ^\s*Unknown\s+(unicast|multicast)
  ^\s*Vepa\s+Enabled
  ^\s*Appliance\s+trust
  ^\s*Operational\s+Dot1q\s+Ethertype
  ^\s*$$
  # Capture time-stamp if vty line has command time-stamping turned on
  ^Load\s+for\s+
  ^Time\s+source\s+is
  ^. -> Error

Trunk
  ^\s+${TRUNKING_VLANS},\s*$$
  ^\s+${TRUNKING_VLANS}\s*$$
  ^\s*Pruning\s+VLANs -> Start
  ^. -> Error
STEPS TO REPRODUCE

Use the template to parse output that includes interfaces after an interface that includes a multiline trunking VLAN list.

EXPECTED RESULTS
[{'interface': 'Gi2/2/16',
  'switchport': 'Enabled',
  'switchport_monitor': '',
  'switchport_negotiation': 'On',
  'mode': 'down',
  'admin_mode': 'trunk',
  'access_vlan': '1',
  'native_vlan': '69',
  'voice_vlan': 'none',
  'trunking_vlans': ['586-589']},
 {'interface': 'Gi2/2/17',
  'switchport': 'Enabled',
  'switchport_monitor': '',
  'switchport_negotiation': 'On',
  'mode': 'down',
  'admin_mode': 'trunk',
  'access_vlan': '1',
  'native_vlan': '1',
  'voice_vlan': 'none',
  'trunking_vlans': ['501,504,517,522,526,529,556,567,568,577-579,582,583',
   '595,980,981,993,995,999']},
 {'interface': 'Gi2/2/45',
  'switchport': 'Enabled',
  'switchport_monitor': '',
  'switchport_negotiation': 'On',
  'mode': 'down',
  'admin_mode': 'trunk',
  'access_vlan': '1',
  'native_vlan': '69',
  'voice_vlan': 'none',
  'trunking_vlans': ['69']},
 {'interface': 'Te2/9/1',
  'switchport': 'Enabled',
  'switchport_monitor': '',
  'switchport_negotiation': 'On',
  'mode': 'trunk (member of bundle Po1)',
  'admin_mode': 'trunk',
  'access_vlan': '1',
  'native_vlan': '69',
  'voice_vlan': 'none',
  'trunking_vlans': ['584-589,596,597,788,1500,1525,2040']},
 {'interface': 'Te2/9/2',
  'switchport': 'Enabled',
  'switchport_monitor': '',
  'switchport_negotiation': 'On',
  'mode': 'trunk (member of bundle Po2)',
  'admin_mode': 'trunk',
  'access_vlan': '1',
  'native_vlan': '69',
  'voice_vlan': 'none',
  'trunking_vlans': ['584-589,965,1500,1525,1579,3600']}]
ACTUAL RESULTS
[{'interface': 'Gi2/2/16',
  'switchport': 'Enabled',
  'switchport_monitor': '',
  'switchport_negotiation': 'On',
  'mode': 'down',
  'admin_mode': 'trunk',
  'access_vlan': '1',
  'native_vlan': '69',
  'voice_vlan': 'none',
  'trunking_vlans': ['586-589']},
 {'interface': 'Gi2/2/17',
  'switchport': 'Enabled',
  'switchport_monitor': '',
  'switchport_negotiation': 'On',
  'mode': 'down',
  'admin_mode': 'trunk',
  'access_vlan': '1',
  'native_vlan': '1',
  'voice_vlan': 'none',
  'trunking_vlans': ['501,504,517,522,526,529,556,567,568,577-579,582,583',
   '595,980,981,993,995,999']}]
@FragmentedPacket
Copy link
Contributor

@mickyhale I think your fix is acceptable. Could you submit a PR with the changes and new raw/test files?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants