networktocode/ntc-templates

cisco_nxos_show_ip_bgp.textfsm not parsing correctly

Closed this issue · 2 comments

ISSUE TYPE
  • Bug Report
TEMPLATE USING

Value STATUS ([acdehiIlrsSx*>])
Value PATH_SELECTION ([acdehiIlrsSx*>| ])
Value ROUTE_SOURCE ([acdehiIlrsSx*> ])
#Value STATUS (.)
#Value PATH_SELECTION (.)
#Value ROUTE_SOURCE (.)
Value Filldown NETWORK (\S{0,18})
#Value Required NEXT_HOP (\S{0,20})
Value NEXT_HOP (\S{0,15})
Value METRIC (\S{0,10})
Value LOCAL_PREF (\S{0,11})
Value WEIGHT (\S{0,10})
Value AS_PATH (.*?)
Value ORIGIN ([ie?])

Start

Since using mostly position, play it safe and ensure we see header first

^\s+Network\s+Next Hop\s+Metric\s+LocPrf\s+Weight\s+Path -> Bgp_table

Bgp_table

Match first when there is no network, since previous line had it already (compliment and filldown below)

Example: * e 10.10.1.1 0 64101 64201 i

^${STATUS}${PATH_SELECTION}${ROUTE_SOURCE}\s{0,1}\s{18}\s(?=${NEXT_HOP}).{15}\s(?=\s{0,10}${METRIC}).{10}\s(?=\s{0,11}${LOCAL_PREF}).{11}\s(?=\s{0,10}${WEIGHT}).{10}\s*${AS_PATH}\s*${ORIGIN}$$ -> Record

Full normal example. metric, and as_path might not exist, regex defaults to blank line.

Example: *>e10.10.101.4/30 10.10.2.1 0 64102 i

^${STATUS}${PATH_SELECTION}${ROUTE_SOURCE}\s{0,1}(?=${NETWORK}).{18}\s(?=${NEXT_HOP}).{15}\s(?=\s{0,10}${METRIC}).{10}\s(?=\s{0,11}${LOCAL_PREF}).{11}\s(?=\s{0,10}${WEIGHT}).{10}\s*${AS_PATH}\s*${ORIGIN}$$ -> Record

EOF

SAMPLE COMMAND OUTPUT

n/a

SUMMARY

the template doesn't pickup the prefixes, because the METRIC value has more characters, 10, in our case and the template is expecting maximum 6 characters. Also NEXT_HOP variable the max should be changed from 15 19 characters.

STEPS TO REPRODUCE

you can use this output from Cisco Nexus 7K

BGP routing table information for VRF default, address family IPv4 Unicast
BGP table version is 61496349, local router ID is 10.68.255.210
Status: s-suppressed, x-deleted, S-stale, d-dampened, h-history, *-valid, >-best
Path type: i-internal, e-external, c-confed, l-local, a-aggregate, r-redist, I-injected
Origin codes: i - IGP, e - EGP, ? - incomplete, | - multipath, & - backup

Network Next Hop Metric LocPrf Weight Path

  • e0.0.0.0/0 1.2.3.4 4294967295 0 12345.102 i
  • i 2.3.4.5 4294967295 100 0 i
    *>i 1.1.1.1 4294967295 100 0 i
    *>i3.126.20.182/32 2.2.2.2 0 100 0 ?
    *|e10.1.0.0/19 3.3.3.3 4294967295 0 12345 i
  • i 4.4.4.4 4294967295 100 0 12345 i
    *>e 5.5.5.5 4294967295 0 12345 i
  • e 1.2.3.4 4294967295 0 12345.102 12345 i
    *|e10.1.32.0/21 3.3.3.3 4294967295 0 12345 i
  • i 4.4.4.4 4294967295 100 0 12345 i
    *>e 5.5.5.5 4294967295 0 12345 i
  • e 1.2.3.4 4294967295 0 12345.102 12345 i
    *|e10.1.40.0/24 3.3.3.3 4294967295 0 12345 12345 12345.12345 i
    *>e 5.5.5.5 4294967295 0 12345 12345 12345.12345 i
  • i 4.4.4.4 4294967295 100 0 12345 12345 12345.12345 i
  • e 1.2.3.4 4294967295 0 12345.102 12345 12345 12345.12345 i
    *|e10.1.41.0/24 3.3.3.3 4294967295 0 12345 12345 12345.12345 i
  • i 4.4.4.4 4294967295 100 0 12345 12345 12345.12345 i
    *>e 5.5.5.5 4294967295 0 12345 12345 12345.12345 i
  • e 1.2.3.4 4294967295 0 12345.102 12345 12345 12345.12345 i
    *|e10.1.42.0/25 3.3.3.3 4294967295 0 12345 12345 12345.12345 i
    *>e 5.5.5.5 4294967295 0 12345 12345 12345.12345 i
  • i 4.4.4.4 4294967295 100 0 12345 12345 12345.12345 i
  • e 1.2.3.4 4294967295 0 12345.102 12345 12345 12345.12345 i
    *|e10.1.44.0/24 3.3.3.3 4294967295 0 12345 12345 12345.12345 i
  • i 4.4.4.4 4294967295 100 0 12345 12345 12345.12345 i
    *>e 5.5.5.5 4294967295 0 12345 12345 12345.12345 i
  • e 1.2.3.4 4294967295 0 12345.102 12345 12345 12345.12345 i
    *|e10.1.45.0/24 3.3.3.3 4294967295 0 12345 12345 12345.12345 i
    *>e 5.5.5.5 4294967295 0 12345 12345 12345.12345 i
  • i 4.4.4.4 4294967295 100 0 12345 12345 12345.12345 i
  • e 1.2.3.4 4294967295 0 12345.102 12345 12345 12345.12345 i
    *|e10.1.46.0/24 3.3.3.3 4294967295 0 12345 12345 12345.12345 i
  • i 4.4.4.4 4294967295 100 0 12345 12345 12345.12345 i
    *>e 5.5.5.5 4294967295 0 12345 12345 12345.12345 i
  • e 1.2.3.4 4294967295 0 12345.102 12345 12345 12345.12345 i
    *|e10.1.47.0/24 3.3.3.3 4294967295 0 12345 12345 12345.12345 i
    *>e 5.5.5.5 4294967295 0 12345 12345 12345.12345 i
  • i 4.4.4.4 4294967295 100 0 12345 12345 12345.12345 i
  • e 1.2.3.4 4294967295 0 12345.102 12345 12345 12345.12345 i
EXPECTED RESULTS

expecting to pickup all routes.

ACTUAL RESULTS

doesn't pickup all routes, it even wrongly multiply the prefix 3.126.20.182/32, because it has single character METRIC

@milos-javornik the example output under
'''STEPS TO REPRODUCE
you can use this output from Cisco Nexus 7K
''
does not seem very clean, can you put it in a code block ?
e.g 1st line no space after e , and . in AS_PATH ?
e0.0.0.0/0 1.2.3.4 4294967295 0 12345.102 i

Also looks like *(stars) converted to bullets