Junos Automation (Scripting)
Highlighted
Junos Automation (Scripting)

How can I get ethernet-switching table by junos-eznc

‎11-08-2014 06:31 PM

hi,expert

As I know,use this code on python,I can get the information about arp,just like the cli command-show arp

>>> arp_agg=ArpTable(jdev)
>>> arp_agg.get()
ArpTable:192.168.2.1: 5 items

>>> arp_agg.keys()
['3c:97:0e:0b:07:bc', '00:1e:58:8a:b5:97', '2c:6b:f5:11:cf:80', '00:0c:29:1a:9f:
24', '00:0c:29:fd:88:e4']


>>> arp_agg.values()
[[('interface_name', 'vlan.20'), ('ip_address', '192.168.2.10'), ('mac_address',
 '3c:97:0e:0b:07:bc')], [('interface_name', 'vlan.20'), ('ip_address', '192.168.
2.13'), ('mac_address', '00:1e:58:8a:b5:97')], [('interface_name', 'vlan.20'), (
'ip_address', '192.168.2.14'), ('mac_address', '2c:6b:f5:11:cf:80')], [('interfa
ce_name', 'vlan.20'), ('ip_address', '192.168.2.15'), ('mac_address', '00:0c:29:
1a:9f:24')], [('interface_name', 'vlan.101'), ('ip_address', '192.168.101.1'), (
'mac_address', '00:0c:29:fd:88:e4')]]

 

I want to know,what function can be used to get mac-address and physical interface,just like cli command-show ethernet-switching table.

Because I want to get the ip-address and physical interface mapping,so I need to connect the arp table and the mac table.

PLS give me some help,many thanks!

7 REPLIES 7
Highlighted
Junos Automation (Scripting)

Re: How can I get ethernet-switching table by junos-eznc

‎11-10-2014 12:27 PM

Hi zhoumi,

 

At current you would have to get the data from both Tables and manually merge them.

 

I've opened up an issue on GitHub to track adding this feature directly into PyEZ.

https://github.com/Juniper/py-junos-eznc/issues/311

 

Thanks,

-Rick

Highlighted
Junos Automation (Scripting)

Re: How can I get ethernet-switching table by junos-eznc

‎11-11-2014 05:45 PM

hi, 

I creat a yaml file-mac,to get ethernet-switching-table.the key is pyhical interface,use the key,I can find mac address learned from this interface,and then use the mac-address to find ip on arp table.

thanks for your help on this case.

BTW:I follow you to the github,and ask the same question.The user:milchzhou is me on github.^_^

Thanks again !

yama file code:

---
MacTable:
  rpc: get-ethernet-switching-table-information
  item: ethernet-switching-table/mac-table-entry
  key: mac-interfaces-list/mac-interfaces
  view: MacView

MacView:
  fields:
    mac_vlan: mac-vlan
    mac_address: mac-address
    mac_type: mac-type
    mac_interfaces: 'mac-interfaces-list/mac-interfaces'

 

some output:

 

>>> from jnpr.junos import Device
>>> dev_agg=Device(user='python',host='192.168.2.1',password='abc123')
>>> dev_agg.open()
Device(192.168.2.1)
>>> from jnpr.junos.op.mac import MacTable
>>> mac_agg=MacTable(dev_agg)
>>> print mac_agg.get()
MacTable:192.168.2.1: 25 items
>>> print mac_agg.keys()
['Router', 'All-members', 'ge-0/0/10.0', 'Router', 'All-members', 'ge-0/0/10.0',
 'ge-0/0/9.0', 'ge-0/0/9.0', 'ge-0/0/9.0', 'All-members', 'Router', 'All-members
', 'Router', 'All-members', 'Router', 'All-members', 'ge-0/0/2.0', 'ge-0/0/11.0'
, 'ge-0/0/3.0', 'Router', 'ge-0/0/0.0', 'Router', 'Router', 'Router', 'Router']
>>> print mac_agg.values()

[[('mac_interfaces', 'Router'), ('mac_vlan', 'vlan10'), ('mac_type', 'Static'),
('mac_address', '3c:8a:b0:95:47:41')], [('mac_interfaces', 'All-members'), ('mac
_vlan', 'vlan101'), ('mac_type', 'Flood'), ('mac_address', '*')],....... [('mac_interfaces', 'Router')
, ('mac_vlan', 'vlan2002'), ('mac_type', 'Static'), ('mac_address', '3c:8a:b0:95
:47:41')], [('mac_interfaces', 'Router'), ('mac_vlan', 'vlan4000'), ('mac_type',
 'Static'), ('mac_address', '3c:8a:b0:95:47:41')]]

>>> mac_acc=mac_agg['ge-0/0/2.0'].mac_address
>>> print mac_acc
00:0c:29:1a:9f:24
>>>

Highlighted
Junos Automation (Scripting)

Re: How can I get ethernet-switching table by junos-eznc

‎06-08-2015 07:17 AM

Hi Everyone

 

I'm trying to get a learned mac address of an interface with junos-ez. Something that would look on the cli like this:

# show ethernet-switching table interface ge-0/0/0

 

So far I couldn't find a way to do it. Things I tried:

 

- eth = EthPortTable(switch)

eth['ge-0/0/0'].macaddr

 

#This will show me the physical address of the switch interface but not the learned mac address on this interface.

 

- portTable = PhyPortTable(switch)

portTable['ge-0/0/0'].macaddr

 

# This will show the exact same output as the EthPortTable-Entry. So just the physical address of the switch interface.

 

Can anyone please help me with this? I already checked github and the whole internetSmiley Happy 

 

Thanks a lot!!

Highlighted
Junos Automation (Scripting)

Re: How can I get ethernet-switching table by junos-eznc

‎06-10-2015 12:03 PM

Hi n00b,

 

The included Tables/Views are for example purposes, but it is fairly straight forward to create your own.

 

https://techwiki.juniper.net/Automation_Scripting/010_Getting_Started_and_Reference/Junos_PyEZ/Troub...

https://techwiki.juniper.net/Automation_Scripting/010_Getting_Started_and_Reference/Junos_PyEZ/Troub...

 

Here is a solid starting point for you:

import yaml
from jnpr.junos.factory.factory_loader import FactoryLoader
from jnpr.junos import Device

yml = '''
---
EtherSwTable:
  rpc: get-interface-ethernet-switching-table
  item: ethernet-switching-table/mac-table-entry[mac-type='Learn']
  key: mac-address
  view: EtherSwView

EtherSwView:
  fields:
    vlan_name: mac-vlan
    mac: mac-address
    mac_type: mac-type
    mac_age: mac-age
    interface: mac-interfaces-list/mac-interfaces
'''

globals().update(FactoryLoader().load(yaml.load(yml)))

dev=Device('host')
dev.open()


table = EtherSwTable(dev)
table.get()

for i in table:
  print 'vlan_name:', i.vlan_name
  print 'mac:', i.mac
  print 'mac_type:', i.mac_type
  print 'mac_age:', i.mac_age
  print 'interface:', i.interface
  print

Hope this helps!

-Rick Sherman

Highlighted
Junos Automation (Scripting)

Re: How can I get ethernet-switching table by junos-eznc

‎06-15-2015 04:31 AM

HI rsherman

 

Thank you so much! I now managed to understand how it works and ezpy is simply amazing! So you can litteraly do anything you want if it's possible on the cli.

 

Cool stuff, keep it up

 

cheers

n00b

Highlighted
Junos Automation (Scripting)

Re: How can I get ethernet-switching table by junos-eznc

‎06-15-2015 04:34 AM

Nice to see that you have been helped. Please mark the solution as solved. So the right persons gets what he deserves

Marc



-----------------------------------------------------------------
Please Mark My Solution Accepted if it Helped, Kudos are Appreciated Too
-----------------------------------------------------------------
Highlighted
Junos Automation (Scripting)

Re: How can I get ethernet-switching table by junos-eznc

‎06-16-2015 12:26 AM

I gave him kudos but I can't mark his post as solution because Ididn't open the thread I just hijacked it.

 

But he will be in my heart foreverSmiley Happy