napalm-automation / napalm-junos

Apache License 2.0
22 stars 42 forks source link

get_mac_address_table doesn't work with JunOS 12.3R6.6 #23

Closed kaage closed 8 years ago

kaage commented 8 years ago

get_mac_address_table doesn't seem to work with JunOS 12.3R6.6 while get_facts for example is working well:

>>> from napalm import get_network_driver
>>> driver = get_network_driver('junos')
>>> device = driver('10.0.0.1', '<username_removed>', '<password_removed>')
>>> device.open()
>>> print device.get_facts()
{'os_version': u'12.3R6.6', 'uptime': 56577120, 'interface_list': ['ge-0/0/0', 'ge-0/0/20', 'ge-0/0/21', 'ge-0/0/22', 'ge-0/0/23', 'xe-0/1/0', 'xe-0/1/1', 'ge-1/0/0', 'ge-1/0/1', 'ge-1/0/2', 'ge-1/0/3', 'ge-1/0/4', 'ge-1/0/5', 'ge-1/0/6', 'ge-1/0/7', 'ge-1/0/8', 'ge-1/0/9', 'ge-1/0/10', 'ge-1/0/11', 'ge-1/0/12', 'ge-1/0/13', 'ge-1/0/14', 'ge-1/0/15', 'ge-1/0/16', 'ge-1/0/17', 'ge-1/0/18', 'ge-1/0/19', 'ge-1/0/20', 'ge-1/0/21', 'ge-1/0/22', 'ge-1/0/23', 'xe-1/1/0', 'xe-1/1/1', '.local.', 'vcp-0', 'vcp-1', 'ae0', 'ae1', 'ae2', 'bme0', 'dsc', 'gre', 'ipip', 'lo0', 'lsi', 'me0', 'mtun', 'pimd', 'pime', 'tap', 'vlan', 'vme'], 'vendor': u'Juniper', 'serial_number': u'CL0201230451', 'model': u'Virtual Chassis', 'hostname': u'labcorertr01', 'fqdn': u'labcorertr01.company.com'}
>>> print device.get_mac_address_table()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/napalm_junos/junos.py", line 860, in get_mac_address_table
    mac_table.get()
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/factory/optable.py", line 63, in get
    self.xml = getattr(self.RPC, self.GET_RPC)(**rpc_args)
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/rpcmeta.py", line 143, in _exec_rpc
    return self._junos.execute(rpc, **dec_args)
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/decorators.py", line 58, in wrapper
    result = function(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/decorators.py", line 26, in wrapper
    return function(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py", line 570, in execute
    raise e(cmd=rpc_cmd_e, rsp=rsp, errs=err)
jnpr.junos.exception.RpcError: RpcError(severity: error, bad_element: get-bridge-mac-table, message: error: syntax error
error: syntax error)
mirceaulinic commented 8 years ago

Can you run on the CLI the following command and share the output?

show bridge mac-table | display xml rpc
dbarrosop commented 8 years ago

When are vendors going to start being consistent?

mirceaulinic commented 8 years ago

There were a couple of changes between JunOS 12 and JunOS 13. I was aware about the changes for LLDP and fixed them via #9, but I'm surprised they changed it also for MAC Addr Table. There's no much work to fix, but first we need @kaage to provide the XML RPC he sees on his device.

kaage commented 8 years ago

There is now such command: "show bridge mac-table"

Could this help:

username@switch> show ethernet-switching table | display xml rpc 
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/12.3R6/junos">
    <rpc>
        <get-ethernet-switching-table-information>
        </get-ethernet-switching-table-information>
    </rpc>
    <cli>
        <banner>{master:0}</banner>
    </cli>
</rpc-reply>
kaage commented 8 years ago

Show bridge commands are for MX-routers only. I'm having EX-switches.

mirceaulinic commented 8 years ago

Yes, seems to be what I was looking for. I don't have any EX to test, can you come with a PR similar to https://github.com/napalm-automation/napalm-junos/pull/9/files and check if the device model begins with EX make a different RPC call (https://github.com/napalm-automation/napalm-junos/pull/9/files#diff-afaba48ce3c0bbd9a251e7f992db0a49R363)?

Example:

if self.device.facts.get('model', '').startswith('EX'):
    mac_table.GET_RPC = 'get-ethernet-switching-table-information'
kaage commented 8 years ago

I'm not so familiar with python yet. However, in the first comment you can see device model is "Virtual Chassis". This is because this switch contains two separate physical switches. I'm not sure how this information is seen if there is just one single standalone EX-series switch but I can try to figure out.

mirceaulinic commented 8 years ago

Since the RPC seems to be application specific, I definitely need an entity of information in order to make the right decision.

Can you please run the following command on the device and share the output (first 6 lines should be enough -- but make sure that <description></description> is included)?

show chassis hardware | display xml
kaage commented 8 years ago

Here's the compete output. Serial numbers has been changed:

user@switch> show chassis hardware | display xml        
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/12.3R6/junos">
    <chassis-inventory xmlns="http://xml.juniper.net/junos/12.3R6/junos-chassis">
        <chassis junos:style="inventory">
            <name>Chassis</name>
            <serial-number>CL0123450011</serial-number>
            <description>Virtual Chassis</description>
            <chassis-module>
                <name>Routing Engine 0</name>
                <version>REV 03B</version>
                <part-number>750-025719</part-number>
                <serial-number>CL02012345011</serial-number>
                <description>EX4200-24F</description>
                <clei-code>COMWT00DRA</clei-code>
                <model-number>EX4200-24F</model-number>
            </chassis-module>
            <chassis-module>
                <name>Routing Engine 1</name>
                <version>REV 11</version>
                <part-number>750-021256</part-number>
                <serial-number>BM1232137663</serial-number>
                <description>EX4200-24T, 8 POE</description>
                <clei-code>COMUY00CRA</clei-code>
                <model-number>EX4200-24T</model-number>
            </chassis-module>
            <chassis-module>
                <name>FPC 0</name>
                <version>REV 03B</version>
                <part-number>750-025719</part-number>
                <serial-number>12321312</serial-number>
                <description>EX4200-24F</description>
                <clei-code>COMWT00DRA</clei-code>
                <model-number>EX4200-24F</model-number>
                <chassis-sub-module>
                    <name>CPU</name>
                    <part-number>BUILTIN</part-number>
                    <serial-number>BUILTIN</serial-number>
                    <description>FPC CPU</description>
                </chassis-sub-module>
                <chassis-sub-module>
                    <name>PIC 0</name>
                    <part-number>BUILTIN</part-number>
                    <serial-number>BUILTIN</serial-number>
                    <description>24x 100 Base-FX/1000 Base-X</description>
                    <clei-code>COMWT00DRA</clei-code>
                    <model-number>EX4200-24F</model-number>
                    <chassis-sub-sub-module>
                        <name>Xcvr 0</name>
                        <version>REV 01</version>
                        <part-number>740-011613</part-number>
                        <serial-number>1213213</serial-number>
                        <description>SFP-SX</description>
                    </chassis-sub-sub-module>
                    <chassis-sub-sub-module>
                        <name>Xcvr 20</name>
                        <version>REV 01</version>
                        <part-number>740-013111</part-number>
                        <serial-number>123123</serial-number>
                        <description>SFP-T</description>
                    </chassis-sub-sub-module>
                    <chassis-sub-sub-module>
                        <name>Xcvr 21</name>
                        <version>REV 01</version>
                        <part-number>740-011174</part-number>
                        <serial-number>123213</serial-number>
                        <description>SFP-T</description>
                    </chassis-sub-sub-module>
                    <chassis-sub-sub-module>
                        <name>Xcvr 22</name>
                        <version>REV 01</version>
                        <part-number>740-013111</part-number>
                        <serial-number>123213</serial-number>
                        <description>SFP-T</description>
                    </chassis-sub-sub-module>
                    <chassis-sub-sub-module>
                        <name>Xcvr 23</name>
                        <version>REV 01</version>
                        <part-number>740-013111</part-number>
                        <serial-number>123213</serial-number>
                        <description>SFP-T</description>
                    </chassis-sub-sub-module>
                </chassis-sub-module>
                <chassis-sub-module>
                    <name>PIC 1</name>
                    <version>REV 03B</version>
                    <part-number>711-021271</part-number>
                    <serial-number>1231231</serial-number>
                    <description>2x 10GE XFP</description>
                    <clei-code>COUIARDBTA</clei-code>
                    <model-number>EX-UM-2XFP</model-number>
                    <chassis-sub-sub-module>
                        <name>Xcvr 0</name>
                        <version>V</version>
                        <part-number>NON-JNPR</part-number>
                        <serial-number>123213</serial-number>
                        <description>XFP-10G-SR</description>
                    </chassis-sub-sub-module>
                    <chassis-sub-sub-module>
                        <name>Xcvr 1</name>
                        <version>z</version>
                        <part-number>NON-JNPR</part-number>
                        <serial-number>123213</serial-number>
                        <description>XFP-10G-SR</description>
                    </chassis-sub-sub-module>
                </chassis-sub-module>
                <chassis-sub-module>
                    <name>Power Supply 0</name>
                    <version>REV 05</version>
                    <part-number>740-020957</part-number>
                    <serial-number>123213</serial-number>
                    <description>PS 320W AC</description>
                    <clei-code>COUPACCEAC</clei-code>
                    <model-number>EX-PWR-320-AC</model-number>
                </chassis-sub-module>
                <chassis-sub-module>
                    <name>Power Supply 1</name>
                    <version>REV 05</version>
                    <part-number>740-020957</part-number>
                    <serial-number>123213</serial-number>
                    <description>PS 320W AC</description>
                    <clei-code>COUPACCEAC</clei-code>
                    <model-number>EX-PWR-320-AC</model-number>
                </chassis-sub-module>
                <chassis-sub-module>
                    <name>Fan Tray</name>
                    <description>Fan Tray</description>
                </chassis-sub-module>
            </chassis-module>
            <chassis-module>
                <name>FPC 1</name>
                <version>REV 11</version>
                <part-number>750-021256</part-number>
                <serial-number>123213</serial-number>
                <description>EX4200-24T, 8 POE</description>
                <clei-code>COMUY00CRA</clei-code>
                <model-number>EX4200-24T</model-number>
                <chassis-sub-module>
                    <name>CPU</name>
                    <part-number>BUILTIN</part-number>
                    <serial-number>BUILTIN</serial-number>
                    <description>FPC CPU</description>
                </chassis-sub-module>
                <chassis-sub-module>
                    <name>PIC 0</name>
                    <part-number>BUILTIN</part-number>
                    <serial-number>BUILTIN</serial-number>
                    <description>24x 10/100/1000 Base-T</description>
                    <clei-code>COMUY00CRA</clei-code>
                    <model-number>EX4200-24T</model-number>
                </chassis-sub-module>
                <chassis-sub-module>
                    <name>PIC 1</name>
                    <version>REV 03A</version>
                    <part-number>711-021271</part-number>
                    <serial-number>123213</serial-number>
                    <description>2x 10GE XFP</description>
                    <clei-code>COUIARDBTA</clei-code>
                    <model-number>EX-UM-2XFP</model-number>
                    <chassis-sub-sub-module>
                        <name>Xcvr 0</name>
                        <version>REV 01</version>
                        <part-number>740-014289</part-number>
                        <serial-number>123213</serial-number>
                        <description>XFP-10G-SR</description>
                    </chassis-sub-sub-module>
                    <chassis-sub-sub-module>
                        <name>Xcvr 1</name>
                        <version>REV 02</version>
                        <part-number>740-014289</part-number>
                        <serial-number>123213</serial-number>
                        <description>XFP-10G-SR</description>
                    </chassis-sub-sub-module>
                </chassis-sub-module>
                <chassis-sub-module>
                    <name>Power Supply 0</name>
                    <version>REV 03</version>
                    <part-number>740-020957</part-number>
                    <serial-number>123213</serial-number>
                    <description>PS 320W AC</description>
                    <clei-code>COUPACCEAA</clei-code>
                    <model-number>EX-PWR-320-AC</model-number>
                </chassis-sub-module>
                <chassis-sub-module>
                    <name>Fan Tray</name>
                    <description>Fan Tray</description>
                </chassis-sub-module>
            </chassis-module>
        </chassis>
    </chassis-inventory>
    <cli>
        <banner>{master:0}</banner>
    </cli>
</rpc-reply>
mirceaulinic commented 8 years ago

Unfortunately there's no much to do about that since <description>Virtual Chassis</description> is what the underneath library PyEZ is using: https://github.com/Juniper/py-junos-eznc/blob/71725d80e4a25b1cf39974d8e9dbd4e006832630/lib/jnpr/junos/facts/chassis.py#L44

Firstly try to find out why it says Virtual Chassis instead of the real device model, if you are indeed running agains a physical device.

kaage commented 8 years ago

Virtual-Chassis is the concept of making two or more physical switches to act like one. They have one management IP, one configuration etc. One of them is running Routing Engine (Control Plane) and others are backups if active Routing Engine fails. However, all physical switch ports (data plane) in all of the switches are active and can be used.

As you can see from the last output this virtual chassis contains two switches. One of them is EX4200-24F and another is EX4200-24T. There can be more switches in the virtual-chassis as well. There can be different models in the virtual-chassis as in my example. Therefore it would be wrong to say model is for example "EX4200-24T" as there is also another switch with different model number in the same virtual-chassis. That's why they are saying model is "Virtual-Chassis". This makes sense.

Virtual-chassis technology is supported in EX-series and QFX-series switches only. They both support "show ethernet-switching table" command as well. In my opinion it is safe to say if model is "Virtual-Chassis" MAC-address table can be seen by that command.

mirceaulinic commented 8 years ago

Fair enough, this is an acceptable compromise.

kaage commented 8 years ago

And in addition to Virtual-Chassis also models starting with EX or QFX should be handled same way.

mirceaulinic commented 8 years ago

Even easier: using the native PyEZ facts (https://github.com/Juniper/py-junos-eznc/blob/71725d80e4a25b1cf39974d8e9dbd4e006832630/lib/jnpr/junos/facts/personality.py#L18):

if self.device.facts.get('personality', '') in ['SWITCH']:  # in case will be needed also on other platforms
    mac_table.GET_RPC = 'get-ethernet-switching-table-information'