networktocode/ntc-templates

cisco_ios_show_ip_interface.textfsm parsing issue

Closed this issue · 2 comments

ISSUE TYPE
  • Template Issue with error and raw data
TEMPLATE USING
Value Required INTERFACE (\S+)
Value LINK_STATUS (.+?)
Value PROTOCOL_STATUS (.+?)
Value List IP_ADDRESS (\S+?)
Value List PREFIX_LENGTH (\d*)
Value VRF (\S+)
Value MTU (\d+)
Value List IP_HELPER (\d+\.\d+\.\d+\.\d+)
Value OUTGOING_ACL (.*?)
Value INBOUND_ACL (.*?)


Start
  ^\S -> Continue.Record
  ^${INTERFACE}\s+is\s+${LINK_STATUS},\s+line\s+protocol\s+is\s+${PROTOCOL_STATUS}\s*$$
  ^\s+Internet\s+address\s+is\s+${IP_ADDRESS}/?${PREFIX_LENGTH}\s*$$
  ^\s+Internet\s+address\s+will\s+be\s+negotiated
  ^\s+Secondary\s+address\s+${IP_ADDRESS}/?${PREFIX_LENGTH}\s*$$
  ^.+VPN\s+Routing/Forwarding\s+"${VRF}"
  ^\s+MTU\s+is\s+${MTU}\s+bytes
  ^\s+Helper\s+address(es|)\s(is|are)\s+${IP_HELPER}\s*$$ -> HELPERS
  ^\s+Outgoing\s+(?:Common\s+)?access\s+list\s+is\s+not\s+set
  ^\s+Outgoing\s+(?:Common\s+)?access\s+list\s+is\s+${OUTGOING_ACL}\s*$$
  ^\s+Inbound\s+(?:Common\s+)?access\s+list\s+is\s+not\s+set
  ^\s+Inbound\s+(?:Common\s+)?access\s+list\s+is\s+${INBOUND_ACL}\s*$$
  ^\s+Internet\s+protocol
  ^\s+Interface\s+is\s+unnumbered
  ^\s+Peer\s+address
  ^\s+Dialer
  ^\s+Broadcast
  ^\s+Multicast
  ^\s+2[2-5]\d\.
  ^\s+Address\s+determined
  ^\s+Peer
  ^\s+Directed
  ^\s+MTU
  ^\s+Helper
  ^\s+Directed
  ^\s+Outgoing
  ^\s+Inbound
  ^\s+.*Proxy
  ^\s+Security
  ^\s+Split
  ^\s+ICMP
  ^\s+IP\s+(?:fast|Flow|CEF|Null|multicast|route|output|access)
  ^\s+Downstream
  ^\s+Associated
  ^\s+Topology
  ^\s+Router
  ^\s+TCP
  ^\s+RTP
  ^\s+Probe
  ^\s+Policy
  ^\s+Network\s+address\s+
  ^\s+BGP
  ^\s+Sampled\s+Netflow
  ^\s+IP\s+(Routed|Bridged)\s+Flow
  ^\s+(Input|Output|Post)\s+.*features
  ^\s+(IPv4\s+)?WCCP
  ^\s+IP\s+verify\s+source\s+reachable
  ^\s+\d+\s+(suppressed\s+)?verification\s+drop(s)?
  ^\s*IP\s+Distributed\s+switching\s+is
  ^\s*$$
  # Capture time-stamp if vty line has command time-stamping turned on
  ^Load\s+for\s+
  ^Time\s+source\s+is
  ^. -> Error

HELPERS
  ^\s+${IP_HELPER}\s*$$
  ^\s+Directed -> Start
  ^.* -> Error
SAMPLE COMMAND OUTPUT
GigabitEthernet4 is up, line protocol is up
  Internet address is 172.16.1.1/24
  Broadcast address is 255.255.255.255
  Address determined by non-volatile memory
  MTU is 1500 bytes
  Helper address is not set
  Directed broadcast forwarding is disabled
  Outgoing Common access list is not set 
  Outgoing access list is not set
  Inbound Common access list is not set 
  Inbound  access list is not set
  Proxy ARP is enabled
  Local Proxy ARP is disabled
  Security level is default
  Split horizon is enabled
  ICMP redirects are always sent
  ICMP unreachables are always sent
  ICMP mask replies are never sent
  IP fast switching is enabled
  IP Flow switching is disabled
  IP CEF switching is enabled
  IP CEF switching turbo vector
  IP Null turbo vector
  Associated unicast routing topologies:
        Topology "base", operation state is UP
  IP multicast fast switching is enabled
  IP multicast distributed fast switching is disabled
  IP route-cache flags are Fast, CEF
  Router Discovery is disabled
  IP output packet accounting is disabled
  IP access violation accounting is disabled
  TCP/IP header compression is disabled
  RTP/IP header compression is disabled
  Probe proxy name replies are disabled
  Policy routing is disabled
  Network address translation is disabled
  BGP Policy Mapping is disabled
  Input features: MCI Check
  IPv4 WCCP Redirect outbound is disabled
  IPv4 WCCP Redirect inbound is disabled
  IPv4 WCCP Redirect exclude is disabled
  IP Clear Dont Fragment is disabled
Loopback0 is up, line protocol is up
  Internet address is 10.254.1.2/32
  Broadcast address is 255.255.255.255
  Address determined by non-volatile memory
  MTU is 1514 bytes
  Helper address is not set
  Directed broadcast forwarding is disabled
  Outgoing Common access list is not set 
  Outgoing access list is not set
  Inbound Common access list is not set 
  Inbound  access list is not set
  Proxy ARP is enabled
  Local Proxy ARP is disabled
  Security level is default
  Split horizon is enabled
  ICMP redirects are always sent
  ICMP unreachables are always sent
  ICMP mask replies are never sent
  IP fast switching is enabled
  IP Flow switching is disabled
  IP CEF switching is enabled
  IP CEF switching turbo vector
  IP Null turbo vector
  Associated unicast routing topologies:
        Topology "base", operation state is UP
  IP multicast fast switching is enabled
  IP multicast distributed fast switching is disabled
  IP route-cache flags are Fast, CEF
  Router Discovery is disabled
  IP output packet accounting is disabled
  IP access violation accounting is disabled
  TCP/IP header compression is disabled
  RTP/IP header compression is disabled
  Probe proxy name replies are disabled
  Policy routing is disabled
  Network address translation is disabled
  BGP Policy Mapping is disabled
  Input features: MCI Check
  IPv4 WCCP Redirect outbound is disabled
  IPv4 WCCP Redirect inbound is disabled
  IPv4 WCCP Redirect exclude is disabled
  IP Clear Dont Fragment is disabled
SUMMARY

There is a parsing issue with the cisco_ios_show_ip_interface.textfsm template where it does not handle the IP Clear Dont Fragment is disabled output line and raises an exception. Based on some quick research, it's a command related to SD-WAN and can be enabled/disabled under the interface configuration with the command ip clear-dont-fragment. This command looks to be introduced in IOS-XE 17.5.1a (https://www.cisco.com/c/en/us/td/docs/routers/sdwan/command/iosxe/qualified-cli-command-reference-guide/m-ip-commands.html#r_clear_dont_fragment_3049.xml). I tested on a Cat 8000v device running 17.6.1a in CML.

Suggested fix:
Add ^IP Clear\s+ right before the ^. -> Error line. This will catch the output line and not raise an exception. I confirmed this works in my local dev environment. I can open a PR with the changes.

STEPS TO REPRODUCE
show ip interface
EXPECTED RESULTS

I expected the output to be parsed.

ACTUAL RESULTS

Raised a TextFSMError exception.

Traceback (most recent call last):
  File "/Users/danwade/Documents/Coding/project/.venv/lib/python3.11/site-packages/nornir/core/task.py", line 99, in start
    r = self.task(self, **self.params)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/danwade/Documents/Coding/project/src/project/configuration.py", line 46, in get_svis
    parsed_result = get_structured_data_textfsm(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/danwade/Documents/Coding/project/.venv/lib/python3.11/site-packages/netmiko/utilities.py", line 379, in get_structured_data_textfsm
    output = _textfsm_parse(textfsm_obj, raw_output, attrs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/danwade/Documents/Coding/project/.venv/lib/python3.11/site-packages/netmiko/utilities.py", line 343, in _textfsm_parse
    tfsm_parse(raw_output, attrs)
  File "/Users/danwade/Documents/Coding/project/.venv/lib/python3.11/site-packages/textfsm/clitable.py", line 282, in ParseCmd
    self.table = self._ParseCmdItem(self.raw, template_file=template_files[0])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/danwade/Documents/Coding/project/.venv/lib/python3.11/site-packages/textfsm/clitable.py", line 315, in _ParseCmdItem
    for record in fsm.ParseText(cmd_input):
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/danwade/Documents/Coding/project/.venv/lib/python3.11/site-packages/textfsm/parser.py", line 897, in ParseText
    self._CheckLine(line)
  File "/Users/danwade/Documents/Coding/project/.venv/lib/python3.11/site-packages/textfsm/parser.py", line 946, in _CheckLine
    if self._Operations(rule, line):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/danwade/Documents/Coding/project/.venv/lib/python3.11/site-packages/textfsm/parser.py", line 1026, in _Operations
    raise TextFSMError('State Error raised. Rule Line: %s. Input Line: %s'
textfsm.parser.TextFSMError: State Error raised. Rule Line: 67. Input Line:   IP Clear Dont Fragment is disabled

this is a duplicate:
#1532
PR:
#1533

Thanks @mncrftfrcnm. Closing it as a duplicate.