napalm-automation / napalm-ios

Apache License 2.0
31 stars 40 forks source link

get_mac_address_table not returning expected results #62

Closed ericrochow closed 7 years ago

ericrochow commented 7 years ago

Different IOS platforms format show mac address-table differently (different order and/or different number of fields), which can cause ValueError exceptions or in some cases empty result sets depending on the format.

Some examples:

6500

Error:

In [26]: device.get_mac_address_table()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-26-2c330fa5b90b> in <module>()
----> 1 mac_table = device.get_mac_address_table()

/opt/napalm/env/local/lib/python2.7/site-packages/napalm_ios/ios.pyc in get_mac_address_table(self)
   1274                     'mac': mac,
   1275                     'interface': interface,
-> 1276                     'vlan': int(vlan),
   1277                     'static': static,
   1278                     'active': active,

ValueError: invalid literal for int() with base 10: 'not'

Table format:

Legend: * - primary entry
        age - seconds since last seen
        n/a - not available

  vlan   mac address     type    learn     age              ports
------+----------------+--------+-----+----------+--------------------------
*  999  1111.2222.3333   dynamic  Yes          0   Port-channel1

4948

Error

In [41]: device.get_mac_address_table()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-41-dcfc80b6b664> in <module>()
----> 1 device.get_mac_address_table()

/opt/napalm/env/local/lib/python2.7/site-packages/napalm_ios/ios.pyc in get_mac_address_table(self)
   1282                 mac_address_table.append(entry)
   1283             else:
-> 1284                 raise ValueError("Unexpected output from: {}".format(line.split()))
   1285         return mac_address_table
   1286 

ValueError: Unexpected output from: [u'-------+---------------+--------+---------------------+--------------------']

Table format

Unicast Entries
 vlan   mac address     type        protocols               port
-------+---------------+--------+---------------------+--------------------
 999    1111.2222.3333   dynamic ip                    Port-channel1      

2960

Error

None, but result set is empty

Table format

Mac Address Table
-------------------------------------------

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----
All    1111.2222.3333    STATIC      CPU
dbarrosop commented 7 years ago

Would you mind sending for each platform the output of: show mac-address-table?

Feel free to hide/replace sensitive information if any.

ericrochow commented 7 years ago

That should be in the issue under 'table format' for each platform. I only included one scrubbed example for each.

dbarrosop commented 7 years ago

oh! sorry, I overlooked them somehow.

Thanks!

ericrochow commented 7 years ago

No worries! :)

Let me know if there is any further information required.

ktbyers commented 7 years ago

These should all be covered in this PR.