napalm-automation / napalm

Network Automation and Programmability Abstraction Layer with Multivendor support
Apache License 2.0
2.24k stars 552 forks source link

IOS get_bgp_neighbors_detail breaks when there are dynamic BGP neighbors #1341

Open kaibabbob opened 3 years ago

kaibabbob commented 3 years ago

Description of Issue/Question

The Cisco IOS BGP command:

router bgp 64001
 bgp listen range 10.1.1.0/24 peer-group spokes

will result in neighbors listed with the show ip bgp summary command with a leading asterisk (*)

<snip>
Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.2.253.38     4        64005       0       0        1    0    0 2y51w    Idle
*10.1.1.22  4        64001   47800   47772 10053658    0    0 4w2d            2
*10.1.1.32  4        64001  93054  102541 10053658    0    0 9w1d            1

The problem is that the "ip_bgp_all_sum.tpl" and "ip_bgp_neigh.tpl" textfsm templates return the neighbor address with the leading asterisk which then breaks the code that uses the address.

I am not sure if it is better to capture the leading asterisk as an attribute of the neighbor or just check if its there by including "*?" just before the NEIGHBOR variable. For instance in ip_bgp_all_sum.tpl :

   ^\*?${NEIGHBOR}\s+${BGP_VER}\s+${REMOTE_AS}\s+${MSG_RECV}\s+${MSG_SENT}\s+${TBL_VER}\s+${IN_Q}\s+${OUT_Q}\s+${UP}\s+${PREFIX_RECV} -> R

and

Start
  ^BGP neighbor is \*?${NEIGHBOR},(?:\s+vrf ${VRF},)?\s+remote AS\s+${REMOTE_AS},(?:\s+local AS\s+${LOCAL_AS})?(?:\s+no-prepend)?(?:\s+re

Did you follow the steps from https://github.com/napalm-automation/napalm#faq

(Place an x between the square brackets where applicable)

Setup

napalm version

(Paste verbatim output from pip freeze | grep napalm between quotes below)

napalm==3.2.0

Network operating system version

(Paste verbatim output from show version - or equivalent - between quotes below)

Cisco IOS XE Software, Version 03.16.05.S - Extended Support Release
Cisco IOS Software, ASR1000 Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 15.5(3)S5, RELEASE SOFTWARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2017 by Cisco Systems, Inc.
Compiled Thu 19-Jan-17 09:17 by mcpre

Cisco IOS-XE software, Copyright (c) 2005-2017 by cisco Systems, Inc.
All rights reserved.  Certain components of Cisco IOS-XE software are
licensed under the GNU General Public License ("GPL") Version 2.0.  The
software code licensed under GPL Version 2.0 is free software that comes
with ABSOLUTELY NO WARRANTY.  You can redistribute and/or modify such
GPL code under the terms of GPL Version 2.0.  For more details, see the
documentation or "License Notice" file accompanying the IOS-XE software,
or the applicable URL provided on the flyer accompanying the IOS-XE
software.

ROM: IOS-XE ROMMON

secvbrt05 uptime is 3 years, 43 weeks, 6 days, 12 hours, 40 minutes
Uptime for this control processor is 3 years, 43 weeks, 6 days, 12 hours, 41 minutes
System returned to ROM by reload at 03:58:49 EST Wed Feb 15 2017
System restarted at 04:01:31 EST Wed Feb 15 2017
System image file is "bootflash:asr1001-universalk9.03.16.05.S.155-3.S5-ext.bin"
Last reload reason: Reload Command

This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.

A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html

If you require further assistance please contact us by sending email to
export@cisco.com.

License Level: adventerprise
License Type: Permanent
Next reload license Level: adventerprise

cisco ASR1001 (1RU) processor (revision 1RU) with 1066453K/6147K bytes of memory.
Processor board ID Sxxxx
12 Gigabit Ethernet interfaces
32768K bytes of non-volatile configuration memory.
4194304K bytes of physical memory.
7741439K bytes of eUSB flash at bootflash:.

Configuration register is 0x2102

Steps to Reproduce the Issue

  1. Configure BGP with the listen range to allow for dynamic neighbors
  2. Call the "get_bgp_neighbors_detail" function

Error Traceback

(Paste the complete traceback of the exception between quotes below)

       Traceback (most recent call last):
          File "/usr/lib/python3.6/site-packages/salt/utils/napalm.py", line 178, in call
            out = getattr(napalm_device.get("DRIVER"), method)(*args, **kwargs)
          File "/usr/local/lib/python3.6/site-packages/napalm/ios/ios.py", line 1938, in get_bgp_neighbors_detail
            )[0]
        IndexError: list index out of range
network-shark commented 3 years ago

@kaibabbob I would go for solution one . If you treat the '*' as an attribute then you have the information that this ip is a dynamic neighbor . If you just 'ignore' it you will lose that information.