Skip to content

Commit

Permalink
Proposed changes have been accepted
Browse files Browse the repository at this point in the history
- Added few more comments
- Adjusted INDEX file to make sure templates are only used when applicable
- Templates are no longer compatible with 'show ip cef 1.1.1.1', or
	'show ip cef Vlan100'. Usage of 'detail' keyword is mandatory, such as
	'show ip cef 1.1.1.1 detail'
  • Loading branch information
Yakuza-UA authored and thomasblass committed Oct 25, 2020
1 parent b3ed26a commit d0f5a68
Show file tree
Hide file tree
Showing 15 changed files with 228 additions and 193 deletions.
40 changes: 29 additions & 11 deletions templates/cisco_ios_show_ip_cef.textfsm
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
#
# This template is only compatible with the following command
# - show ip cef [vrf NAME]
# This is enforced by INDEX file
# Check cisco_ios_show_ip_cef_detail.textfsm for more details
#
Value Required PREFIX ((?:\d{1,3}\.){3}\d{1,3}\/\d{1,2})
Value ETYPE ((?:no\s)?(?:[a-z]+))
# Nexthop and Interface are lists to support ECMP
# Usually these will be single item lists
Value TYPE ((?:no\s)?(?:[a-z]+))
# To support ECMP, NEXTHOP and INTERFACE are defined as lists
# When no ECMP is available, these will be single item lists
# However, if there are multiple paths available
# these will contain one items per route/path
# then expect to see one item per route/path
Value List NEXTHOP ((?:\d{1,3}\.){3}\d{1,3})
Value List INTERFACE ([A-Za-z][A-Za-z0-9\.\/-]+)

# --- HEAD and DETAILED ENTRIES ---
# e.g. show ip cef detail, show ip cef 10.0.0.1, etc
Start
# >>> Parse EXCEPTIONS
# CEF is not enabled
^%IPv4\s+CEF\s+not\s+running$$ -> End
# Invalid prefix
^\s+Invalid\s+prefix/mask -> End
#
# >>> Parse HEADING
^Prefix\s+Next\s+Hop\s+Interface$$ -> Entries

# --- BRIEF ENTRIES
# e.g. show ip cef, or show ip cef vrf <name>
Entries
# >>> Parse CEF ENTRIES
# Entry detected
^(?:\d{1,3}\.){3}\d{1,3}\/\d{1,2} -> Continue.Record
^${PREFIX}\s+${ETYPE}\s*$$
# Parse prefix/type
^${PREFIX}\s+${TYPE}\s*$$
# Parse prefix/nexthop
^${PREFIX}\s+${NEXTHOP}\s*$$
^${PREFIX}\s+${ETYPE}\s+${INTERFACE}$$
# Parse prefix, type and interface
^${PREFIX}\s+${TYPE}\s+${INTERFACE}$$
# Parse prefix, nexthop and interface
^${PREFIX}\s+${NEXTHOP}\s+${INTERFACE}$$
# Parse nexthop and interface for ECMP prefixes
^\s+${NEXTHOP}\s+${INTERFACE}$$
#
# >>> Parse SPECIAL
^\s*$$
^. -> Error
^. -> Error
91 changes: 54 additions & 37 deletions templates/cisco_ios_show_ip_cef_detail.textfsm
Original file line number Diff line number Diff line change
@@ -1,91 +1,109 @@
# Even though this template understands the output from
# - show ip cef [vrf NAME] [PREFIX | INTERFACE] [detail]
# INDEX file forces you to use 'detail' keyword, or there
# will be no match. This is done to simplify INDEX file
# matching logic, otherwise matching regex is too complex.
#
# This template is compatible with IOS v12.x and above,
# including IOS-XE. There are two versions of output
# with significant differences depending on IOS version.
# Template is able to recognize both versions and captures
# same structured data regardless of IOS version.
#
Value Required PREFIX ((?:\d{1,3}\.){3}\d{1,3}\/\d{1,2})
Value List FLAGS ([^,\]\n]+)
Value ETYPE ((?:no\s)?(?:[a-z]+))
Value TYPE ((?:no\s)?(?:[a-z]+))
# Nexthop and Interface are lists to support ECMP
# Usually these will be single item lists
# However, if there are multiple paths available
# these will contain one items per route/path
# these will contain one item per route/path
Value List NEXTHOP ((?:\d{1,3}\.){3}\d{1,3})
Value List INTERFACE ([A-Za-z][A-Za-z0-9\.\/-]+)

# --- HEAD and DETAILED ENTRIES ---
# e.g. show ip cef detail, show ip cef 10.0.0.1, etc
Start
# Detect errors and/or disabled CEF
# >>> Parse EXCEPTIONS
# CEF is not enabled
^%IPv4\s+CEF\s+not\s+running$$ -> End
# Invalid prefix
^\s+Invalid\s+prefix/mask -> End
# Ignore JUNK in HEAD
#
# >>> Parse HEADING
# Ignore Junk (irrelevant output)
^IP(?:v4)?\s+CEF
^VRF|Adjacency
^\s+\d+\s+(?:routes|instant|leaves|load|prefixes|in-place)
^\s+(?:Default|Table|Database|Resolution|Non-stop|Switchover)
^\s+(?:universal|refcounts)
^.*?CEF\s+resets
#
# >>> Parse CEF ENTRIES
# Entry detected, begin analysis
^(?:\d{1,3}\.){3}\d{1,3}\/\d{1,2} -> Continue.Record
#
# --- Parse CEF table from Cisco IOS >v15.x
#
# >>>>>> Cisco IOS >v15.x
# Extract prefix (no flags)
^${PREFIX},\s+epoch(?:(?!flags).)*$$
# Extract prefix with Flags
# Extract prefix with flags
^${PREFIX}.*?flags -> Continue
# Attempt to extract first Flag (if present)
# Attempt to extract first flag (if present)
^\d.*?flags\s+\[?${FLAGS} -> Continue
# Attempt to extract other Flags (up to 6)
# Attempt to extract other flags (up to 6)
^\d.*?flags\s+\[?(?:[^\]\n]+?,\s+){1}${FLAGS} -> Continue
^\d.*?flags\s+\[?(?:[^\]\n]+?,\s+){2}${FLAGS} -> Continue
^\d.*?flags\s+\[?(?:[^\]\n]+?,\s+){3}${FLAGS} -> Continue
^\d.*?flags\s+\[?(?:[^\]\n]+?,\s+){4}${FLAGS} -> Continue
^\d.*?flags\s+\[?(?:[^\]\n]+?,\s+){5}${FLAGS} -> Continue
# Stop processing Flags (6+)
# Stop processing flags (6+)
^\d.*?flags.*?$$
# Attempt to extract details via source info
# Supported Type (IOS >v15.x):
# Extract nexthop IP address
^\s+recursive\s+via\s+${NEXTHOP}
# Extract type and interface/nexthop, if available)
# Type values (IOS >v15.x):
# - attached
# - receive
# - drop
# - no route
# - nexthop
# - multicast
^\s+recursive\s+via\s+${NEXTHOP}
^\s+${ETYPE}(?<=receive)\s+for\s+${INTERFACE}
^\s+${ETYPE}(?<=attached)\s+to\s+${INTERFACE}
^\s+${ETYPE}(?<=drop)$$
^\s+${ETYPE}(?<=no route)$$
^\s+${ETYPE}(?<=receive)$$
^\s+${ETYPE}(?<=multicast)$$
^\s+${ETYPE}(?<=nexthop)\s+${NEXTHOP}\s+${INTERFACE}
#
# --- Parse CEF table from Cisco IOS 12.x ISR G1
^\s+${TYPE}(?<=receive)\s+for\s+${INTERFACE}
^\s+${TYPE}(?<=attached)\s+to\s+${INTERFACE}
^\s+${TYPE}(?<=drop)$$
^\s+${TYPE}(?<=no route)$$
^\s+${TYPE}(?<=receive)$$
^\s+${TYPE}(?<=multicast)$$
^\s+${TYPE}(?<=nexthop)\s+${NEXTHOP}\s+${INTERFACE}
#
# Legacy CEF formatting
# Extract Prefix and Flags
# >>>>>> Cisco IOS 12.x ISR G1 (legacy CEF formatting)
# Extract prefix
^${PREFIX},\s+version -> Continue
# Extract flags (if available)
^.*?epoch\s+\d+,\s+${FLAGS} -> Continue
^.*?epoch\s+\d+,\s+(?:[^,\n]+,\s+){1}${FLAGS} -> Continue
^.*?epoch\s+\d+,\s+(?:[^,\n]+,\s+){2}${FLAGS} -> Continue
^.*?epoch\s+\d+,\s+(?:[^,\n]+,\s+){3}${FLAGS} -> Continue
# Stop processing Flags (max 4)
# Stop processing flags (max 4)
^.*?epoch.*?$$
# Extract extra Flag, such as recursive
# Extract extra flag, such as recursive
^.*?dependenc(?:y|ies),\s+${FLAGS} -> Continue
# Extract interface for glean adjacency (it's the only place)
^\s+via\s+${INTERFACE},\s+\d+\s+depend
# Stop procssing line with 'dependencies'
# Interface and flags are extracted by now
^.*?depend
# Extract Nexthop and Interface
# Extract nexthop IP address
^\s+next\s+hop\s+${NEXTHOP}\s*$$
# Extract nexthop IP address and interface
^\s+next\s+hop\s+${NEXTHOP},\s+${INTERFACE}
# Extract Type, where available
# Available Type (IOS v12.x ISR G1):
# Extract type, where available
# Type values (IOS v12.x ISR G1):
# - null (same as receive with Null0 interface in IOS v15.x)
# - glean (same as attached in IOS v15.x)
# - cached (same as nexthop in IOS v15.x)
# - drop
# - if type is None, then it's receive (check flags)
^\s+valid\s+${ETYPE}\s+adjacency$$
#
# Ignore JUNK
^\s+valid\s+${TYPE}\s+adjacency$$
#
# >>> Parse OTHER BODY (irrelevant output)
^\s+Adj\s+source
^\s+Special\s+source
^\s+Interface\s+source
Expand All @@ -103,7 +121,6 @@ Start
^\s+\d+\s+IPL\s+source
^\d+\s+packets
#
# End of processing
#
# >>> Parse SPECIAL
^\s*$$
^. -> Error
^. -> Error
4 changes: 2 additions & 2 deletions templates/index
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ cisco_ios_show_snmp_community.textfsm, .*, cisco_ios, sh[[ow]] sn[[mp]] com[[mun
cisco_ios_show_cdp_neighbors.textfsm, .*, cisco_ios, sh[[ow]] c[[dp]] neig[[hbors]]
cisco_ios_show_controller_t1.textfsm, .*, cisco_ios, sh[[ow]] cont[[rollers]] t1
cisco_ios_show_hosts_summary.textfsm, .*, cisco_ios, sh[[ow]] ho[[sts]] summary
cisco_ios_show_ip_cef_detail.textfsm, .*, cisco_ios, sh[[ow]] i[[p]] ce[[f]] de[[tail]]
cisco_ios_show_ip_cef_detail.textfsm, .*, cisco_ios, sh[[ow]] ip ce[[f]].+?d[[etail]]
cisco_ios_show_platform_diag.textfsm, .*, cisco_ios, sh[[ow]] plat[[form]] di[[ag]]
cisco_ios_show_processes_cpu.textfsm, .*, cisco_ios, sh[[ow]] proc[[esses]] [[cpu]]
cisco_ios_show_spanning-tree.textfsm, .*, cisco_ios, sh[[ow]] sp[[anning-tree]]
Expand All @@ -215,7 +215,7 @@ cisco_ios_show_standby.textfsm, .*, cisco_ios, sh[[ow]] sta[[ndby]]
cisco_ios_show_version.textfsm, .*, cisco_ios, sh[[ow]] ver[[sion]]
cisco_ios_show_ip_arp.textfsm, .*, cisco_ios, sh[[ow]] i[[p]] a[[rp]]
cisco_ios_show_ip_bgp.textfsm, .*, cisco_ios, sh[[ow]] i[[p]] bgp
cisco_ios_show_ip_cef.textfsm, .*, cisco_ios, sh[[ow]] i[[p]] ce[[f]]
cisco_ios_show_ip_cef.textfsm, .*, cisco_ios, sh[[ow]] ip ce[[f]](?: vrf? \S+)?\s*$
cisco_ios_show_tacacs.textfsm, .*, cisco_ios, sh[[ow]] tacacs
cisco_ios_show_clock.textfsm, .*, cisco_ios, sh[[ow]] clo[[ck]]
cisco_ios_show_dmvpn.textfsm, .*, cisco_ios, sh[[ow]] dm[[vpn]]
Expand Down
24 changes: 12 additions & 12 deletions tests/cisco_ios/show_ip_cef/show_ip_cef_c2800_v1.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
---
parsed_sample:
- prefix: "0.0.0.0/0"
etype: ""
type: ""
nexthop:
- "172.17.40.1"
interface:
- "Tunnel0"
- prefix: "0.0.0.0/8"
etype: "drop"
type: "drop"
nexthop: []
interface: []
- prefix: "0.0.0.0/32"
etype: "receive"
type: "receive"
nexthop: []
interface: []
- prefix: "10.0.0.0/16"
etype: ""
type: ""
nexthop:
- "172.17.40.1"
interface:
- "Tunnel0"
- prefix: "10.0.120.0/24"
etype: ""
type: ""
nexthop:
- "172.17.40.1"
interface:
- "Tunnel0"
- prefix: "10.191.64.0/24"
etype: "attached"
type: "attached"
nexthop: []
interface:
- "GigabitEthernet0/0"
- prefix: "10.191.64.0/32"
etype: "receive"
type: "receive"
nexthop: []
interface:
- "GigabitEthernet0/0"
- prefix: "10.191.64.2/32"
etype: "attached"
type: "attached"
nexthop: []
interface:
- "GigabitEthernet0/0"
- prefix: "224.0.0.0/4"
etype: "drop"
type: "drop"
nexthop: []
interface: []
- prefix: "224.0.0.0/24"
etype: "receive"
type: "receive"
nexthop: []
interface: []
- prefix: "240.0.0.0/4"
etype: "drop"
type: "drop"
nexthop: []
interface: []
- prefix: "255.255.255.255/32"
etype: "receive"
type: "receive"
nexthop: []
interface: []
26 changes: 13 additions & 13 deletions tests/cisco_ios/show_ip_cef/show_ip_cef_c2800_v2.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
---
parsed_sample:
- prefix: "0.0.0.0/0"
etype: ""
type: ""
nexthop:
- "192.168.0.181"
interface:
- "GigabitEthernet0/1"
- prefix: "0.0.0.0/8"
etype: "drop"
type: "drop"
nexthop: []
interface: []
- prefix: "0.0.0.0/32"
etype: "receive"
type: "receive"
nexthop: []
interface: []
- prefix: "10.0.0.0/16"
etype: ""
type: ""
nexthop:
- "192.168.0.181"
interface:
- "GigabitEthernet0/1"
- prefix: "10.158.0.0/19"
etype: ""
type: ""
nexthop:
- "0.0.0.0"
interface:
- "Null0"
- prefix: "10.158.0.192/29"
etype: ""
type: ""
nexthop:
- "10.158.0.209"
interface:
- "GigabitEthernet0/0.1821"
- prefix: "10.158.0.208/29"
etype: "attached"
type: "attached"
nexthop: []
interface:
- "GigabitEthernet0/0.1821"
- prefix: "10.158.0.208/32"
etype: "receive"
type: "receive"
nexthop: []
interface: []
- prefix: "192.168.0.180/30"
etype: "attached"
type: "attached"
nexthop: []
interface:
- "GigabitEthernet0/1"
- prefix: "224.0.0.0/4"
etype: "drop"
type: "drop"
nexthop: []
interface: []
- prefix: "224.0.0.0/24"
etype: "receive"
type: "receive"
nexthop: []
interface: []
- prefix: "240.0.0.0/4"
etype: "drop"
type: "drop"
nexthop: []
interface: []
- prefix: "255.255.255.255/32"
etype: "receive"
type: "receive"
nexthop: []
interface: []
Loading

0 comments on commit d0f5a68

Please sign in to comment.