networktocode / ntc-templates

TextFSM templates for parsing show commands of network devices
https://ntc-templates.readthedocs.io/
Other
1.1k stars 718 forks source link

cisco_ios_show_ip_bgp_neighbors.textfsm returns empty values #914

Closed armartirosyan closed 1 year ago

armartirosyan commented 3 years ago
ISSUE TYPE
TEMPLATE USING
Value NEIGHBOR (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})
Value REMOTE_AS (\d+)
Value PEER_GROUP (\S+)
Value REMOTE_ROUTER_ID (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})
Value BGP_STATE (\w+)
Value LOCALHOST_IP (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})
Value LOCALHOST_PORT (\d+)
Value REMOTE_IP (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})
Value REMOTE_PORT (\d+)
Value INBOUND_ROUTEMAP (\S+)
Value OUTBOUND_ROUTEMAP (\S+)

Start
  # Capture first line, which shows the BGP neighor and remote AS number
  ^BGP\s+neighbor\s+is -> Continue.Record
  ^BGP\s+neighbor\s+is\s+${NEIGHBOR},\s+remote\s+AS\s+${REMOTE_AS}
  # Capture BGP peer group
  # Example: 'Member of peer-group RR_SERVERS for session parameters'
  ^\s*Member\s+of\s+peer-group\s+${PEER_GROUP}
  # 
  # Capture remote router ID
  # Example: ' BGP state = Established, up for 7w3d'
  ^.+remote\s+router\s+ID\s+${REMOTE_ROUTER_ID}
  #
  # Capture BGP state
  # Example: ' BGP state = Established, up for 7w3d'
  ^\s+BGP\s+state\s+=\s+${BGP_STATE}
  #
  # Capture Inbound/Outbound Route Maps
  # Example: 'Route map for incoming advertisements is BGP_Vendor_in'
  # Example: 'Route map for outgoing advertisements is BGP_Vendor_out'
  ^\s+Route\s+map\s+for\s+incoming\s+advertisements\s+is\s+${INBOUND_ROUTEMAP}
  ^\s+Route\s+map\s+for\s+outgoing\s+advertisements\s+is\s+${OUTBOUND_ROUTEMAP}
  #
  # Match local host and port
  # Example: 'Local host: 10.10.255.13, Local port: 39443'
  ^Local\s+host:\s+${LOCALHOST_IP},\s+Local\s+port:\s+${LOCALHOST_PORT}
  # 
  # Match local host and port
  # Example: 'Local host: 10.10.255.13, Local port: 39443'
  ^Foreign\s+host:\s+${REMOTE_IP},\s+Foreign\s+port:\s+${REMOTE_PORT}
  #^.+ -> Error
SAMPLE COMMAND OUTPUT
BGP neighbor is 10.254.142.45,  vrf AZ_USEAST,  remote AS 65007, external link
 Member of peer-group eBGP_COLO_AZ_USEAST for session parameters
  BGP version 4, remote router ID 149.77.35.201
  BGP state = Established, up for 1w3d
  Last read 00:00:00, last write 00:00:00, hold time is 12, keepalive interval is 2 seconds
  Configured hold time is 12, keepalive interval is 2 seconds
  Minimum holdtime from neighbor is 0 seconds
  Neighbor sessions:
    1 active, is not multisession capable (disabled)
  Neighbor capabilities:
    Route refresh: advertised and received(new)
    Four-octets ASN Capability: advertised and received
    Address family IPv4 Unicast: advertised and received
    Graceful Restart Capability: received
      Remote Restart timer is 120 seconds
      Address families advertised by peer:
        IPv4 Unicast (was not preserved
      Address families advertised by peer before restart:
        VPNv4 Unicast
    Enhanced Refresh Capability: advertised
    Multisession Capability: 
    Stateful switchover support enabled: NO for session 1
  Message statistics:
    InQ depth is 0
    OutQ depth is 0

                         Sent       Rcvd
    Opens:                  1          1
    Notifications:          0          0
    Updates:                9         28
    Keepalives:        451681     461025
    Route Refresh:          2          0
    Total:             451693     461054
  Default minimum time between advertisement runs is 0 seconds

 For address family: VPNv4 Unicast
  Translates address family IPv4 Unicast for VRF AZ_USEAST
  Session: 10.254.142.45
  BGP table version 980, neighbor version 980/0
  Output queue size : 0
  Index 38, Advertise bit 2
  38 update-group member
  eBGP_COLO_AZ_USEAST peer-group member
  Inbound path policy configured
  Outbound path policy configured
  Route map for incoming advertisements is RCV_FROM_ASH_COLO_TEST
  Route map for outgoing advertisements is ADV_TO_ASH_COLO
  Default weight 100
  Slow-peer detection is disabled
  Slow-peer split-update-group dynamic is disabled
                                 Sent       Rcvd
  Prefix activity:               ----       ----
    Prefixes Current:               1          2 (Consumes 160 bytes)
    Prefixes Total:                12         16
    Implicit Withdraw:              9         12
    Explicit Withdraw:              0          2
    Used as bestpath:             n/a          2
    Used as multipath:            n/a          0

                                   Outbound    Inbound
  Local Policy Denied Prefixes:    --------    -------
    route-map:                            0          7
    Other Policies:                      52        n/a
    Total:                               52          7
  Number of NLRIs in the update sent: max 1, min 0
  Last detected as dynamic slow peer: never
  Dynamic slow peer recovered: never
  Refresh Epoch: 1
  Last Sent Refresh Start-of-rib: never
  Last Sent Refresh End-of-rib: never
  Last Received Refresh Start-of-rib: never
  Last Received Refresh End-of-rib: never
                       Sent   Rcvd
    Refresh activity:          ----   ----
      Refresh Start-of-RIB          0          0
      Refresh End-of-RIB            0          0

  Address tracking is enabled, the RIB does have a route to 10.254.142.45
  Connections established 44; dropped 43
  Last reset 1w3d, due to Active open failed
  External BGP neighbor may be up to 5 hops away.
  Transport(tcp) path-mtu-discovery is enabled
  Graceful-Restart is disabled
Connection state is ESTAB, I/O status: 1, unread input bytes: 0            
Connection is ECN Disabled, Mininum incoming TTL 0, Outgoing TTL 5
Local host: 10.254.142.46, Local port: 179
Foreign host: 10.254.142.45, Foreign port: 18135
Connection tableid (VRF): 4
Maximum output segment queue size: 50

Enqueued packets for retransmit: 0, input: 0  mis-ordered: 0 (0 bytes)

Event Timers (current time is 0x44E91B0B9):
Timer          Starts    Wakeups            Next
Retrans        451689          0             0x0
TimeWait            0          0             0x0
AckHold        461034     410609             0x0
SendWnd             0          0             0x0
KeepAlive           0          0             0x0
GiveUp              0          0             0x0
PmtuAger            0          0             0x0
DeadWait            0          0             0x0
Linger              0          0             0x0
ProcessQ            0          0             0x0

iss: 2373198407  snduna: 2381780833  sndnxt: 2381780833
irs: 3990103425  rcvnxt: 3998864699

sndwnd:  27528  scale:      0  maxrcvwnd:  16384
rcvwnd:  15605  scale:      0  delrcvwnd:    779

SRTT: 1000 ms, RTTO: 1003 ms, RTV: 3 ms, KRTT: 0 ms
minRTT: 0 ms, maxRTT: 1000 ms, ACK hold: 200 ms
Status Flags: passive open, gen tcbs
Option Flags: VRF id set, nagle, path mtu capable, md5, 0x1000000
IP Precedence value : 6

Datagrams (max data segment is 1460 bytes):
Rcvd: 912725 (out of order: 0), with data: 461037, total data bytes: 8761273
Sent: 868290 (retransmit: 0, fastretransmit: 0, partialack: 0, Second Congestion: 0), with data: 451688, total data bytes: 8582425

 Packets received in fast path: 0, fast processed: 0, slow path: 0
 fast lock acquisition failures: 0, slow path: 0
TCP Semaphore      0x4145D8D4  FREE
SUMMARY
STEPS TO REPRODUCE
>>> from ntc_templates.parse import parse_output
>>> with open("show_ip_bgp_neighbors.txt") as f:
...     data= f.read()
>>> data
'BGP neighbor is 10.254.142.45,  vrf AZ_USEAST,  remote AS 65007, external link\n Member of peer-group eBGP_COLO_AZ_USEAST for session parameters\n  BGP version 4, remote router ID 149.77.35.201\n  BGP state = Established, up for 1w3d\n  Last read 00:00:01, last write 00:00:00, hold time is 12, keepalive interval is 2 seconds\n  Configured hold time is 12, keepalive interval is 2 seconds\n  Minimum holdtime from neighbor is 0 seconds\n  Neighbor sessions:\n    1 active, is not multisession capable (disabled)\n  Neighbor capabilities:\n    Route refresh: advertised and received(new)\n    Four-octets ASN Capability: advertised and received\n    Address family IPv4 Unicast: advertised and received\n    Graceful Restart Capability: received\n      Remote Restart timer is 120 seconds\n      Address families advertised by peer:\n        IPv4 Unicast (was not preserved\n      Address families advertised by peer before restart:\n        VPNv4 Unicast\n    Enhanced Refresh Capability: advertised\n    Multisession Capability: \n    Stateful switchover support enabled: NO for session 1\n  Message statistics:\n    InQ depth is 0\n    OutQ depth is 0\n    \n                         Sent       Rcvd\n    Opens:                  1          1\n    Notifications:          0          0\n    Updates:                9         34\n    Keepalives:        451785     461132\n    Route Refresh:          3          0\n    Total:             451798     461167\n  Default minimum time between advertisement runs is 0 seconds\n\n For address family: VPNv4 Unicast\n  Translates address family IPv4 Unicast for VRF AZ_USEAST\n  Session: 10.254.142.45\n  BGP table version 982, neighbor version 982/0\n  Output queue size : 0\n  Index 38, Advertise bit 2\n  38 update-group member\n  eBGP_COLO_AZ_USEAST peer-group member\n  Inbound path policy configured\n  Outbound path policy configured\n  Route map for incoming advertisements is RCV_FROM_ASH_COLO_TEST\n  Route map for outgoing advertisements is ADV_TO_ASH_COLO\n  Default weight 100\n  Slow-peer detection is disabled\n  Slow-peer split-update-group dynamic is disabled\n                                 Sent       Rcvd\n  Prefix activity:               ----       ----\n    Prefixes Current:               1          1 (Consumes 80 bytes)\n    Prefixes Total:                12         17\n    Implicit Withdraw:              9         14\n    Explicit Withdraw:              0          2\n    Used as bestpath:
    n/a          1\n    Used as multipath:            n/a          0\n\n                                   Outbound    Inbound\n  Local Policy Denied Prefixes:    --------    -------\n    route-map:                            0         11\n    Other Policies:                      53        n/a\n    Total:                               53         11\n  Number of NLRIs in the update sent: max 1, min 0\n  Last detected as dynamic slow peer: never\n  Dynamic slow peer recovered: never\n  Refresh Epoch: 1\n  Last Sent Refresh Start-of-rib: never\n  Last Sent Refresh End-of-rib: never\n  Last Received Refresh Start-of-rib: never\n  Last Received Refresh End-of-rib: never\n\t\t\t\t       Sent\t  Rcvd\n\tRefresh activity:\t       ----\t  ----\n\t  Refresh Start-of-RIB          0          0\n\t  Refresh End-of-RIB            0          0\n\n  Address tracking is enabled, the RIB does have a route to 10.254.142.45\n  Connections established 44; dropped 43\n  Last reset 1w3d, due to Active open failed\n  External BGP neighbor may be up to 5 hops away.\n  Transport(tcp) path-mtu-discovery is enabled\n  Graceful-Restart is disabled\nConnection state is ESTAB, I/O status: 1, unread input bytes: 0            \nConnection is ECN Disabled, Mininum incoming TTL 0, Outgoing TTL 5\nLocal host: 10.254.142.46, Local port: 179\nForeign host: 10.254.142.45, Foreign port: 18135\nConnection tableid (VRF): 4\nMaximum output segment queue size: 50\n\nEnqueued packets for retransmit: 0, input: 0  mis-ordered: 0 (0 bytes)\n\nEvent Timers (current time is 0x44E94F4BA):\nTimer          Starts    Wakeups            Next\nRetrans        451794          0             0x0\nTimeWait            0          0
 0x0\nAckHold        461140     410703             0x0\nSendWnd             0          0             0x0\nKeepAlive           0          0             0x0\nGiveUp              0          0             0x0\nPmtuAger            0          0             0x0\nDeadWait            0          0             0x0\nLinger              0          0             0x0\nProcessQ            0          0             0x0\n\niss: 2373198407  snduna: 2381782832  sndnxt: 2381782832\nirs: 3990103425  rcvnxt: 3998867103\n\nsndwnd:  27528  scale:      0  maxrcvwnd:  16384\nrcvwnd:  16137  scale:      0  delrcvwnd:    247\n\nSRTT: 1000 ms, RTTO: 1003 ms, RTV: 3 ms, KRTT: 0 ms\nminRTT: 0 ms, maxRTT: 1000 ms, ACK hold: 200 ms\nStatus Flags: passive open, gen tcbs\nOption Flags: VRF id set, nagle, path mtu capable, md5, 0x1000000\nIP Precedence value : 6\n\nDatagrams (max data segment is 1460 bytes):\nRcvd: 912937 (out of order: 0), with data: 461144, total data bytes: 8763677\nSent: 868492 (retransmit: 0, fastretransmit: 0, partialack: 0, Second Congestion: 0), with data: 451793, total data bytes: 8584424\n\n Packets received in fast path: 0, fast processed: 0, slow path: 0\n fast lock acquisition failures: 0, slow path: 0\nTCP Semaphore      0x4145D8D4  FREE'
>>> 
>>> 
>>> 
>>> 
>>> 
>>> parse_output(platform="cisco_ios", command="show ip bgp neighbors", data=data)
[{u'bgp_state': 'Established', u'remote_port': '18135', u'localhost_ip': '10.254.142.46', u'peer_group': 'eBGP_COLO_AZ_USEAST', u'neighbor': '', u'remote_as': '', u'remote_router_id': '149.77.35.201', u'localhost_port': '179', u'remote_ip': '10.254.142.45'}]
EXPECTED RESULTS
[
   {
      "bgp_state": "Established",
      "remote_port": "18135",
      "localhost_ip": "10.254.142.46",
      "peer_group": "eBGP_COLO_AZ_USEAST",
      "neighbor": "10.254.142.45",
      "remote_as": "65007",
      "remote_router_id": "149.77.35.201",
      "localhost_port": "179",
      "remote_ip": "10.254.142.45"
   }
]
ACTUAL RESULTS

neighbor and remote_as fields are empty.

[
   {
      "bgp_state": "Established",
      "remote_port": "18135",
      "localhost_ip": "10.254.142.46",
      "peer_group": "eBGP_COLO_AZ_USEAST",
      "neighbor": "",
      "remote_as": "",
      "remote_router_id": "149.77.35.201",
      "localhost_port": "179",
      "remote_ip": "10.254.142.45"
   }
]
itdependsnetworks commented 1 year ago

Let's track in #915