Open mtannous opened 8 years ago
Depending on the address family (in your case "1" is IPv4), the management address could be binary data, in which case displaying it without precaution could look "funny" (for address family encodings, check http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml). To get around that, and make the data more visible, just print the "repr" of the data (see example below).
~/t31/src @dhcp-2018-38.sjc+rtr1% /usr/lib/python2.7/site-packages/illdp.py
Welcome to 'interactive lldp'
Use h() for help, ex() for examples.
tab-completion is enabled; tab-tab (or ?) adds the doc string
...
... et1rs=m.lldp_remote_system_iter(eossdk.IntfId("Ethernet1")).next()
... et1nei=eossdk.LldpNeighbor(eossdk.IntfId("Ethernet1"),et1rs)
... mana=m.management_address(et1nei)[0]
...
... mana.to_string()
"lldp_management_address_t(address_family=6, **address='\x00\x00\x01\x02\x00\x00'**, snmp_ifindex=0, oid='')"
... print mana.to_string()
lldp_management_address_t(address_family=6, **address=''**, snmp_ifindex=0, oid='')
... print **repr**(mana.to_string())
"lldp_management_address_t(address_family=6, **address='\x00\x00\x01\x02\x00\x00'**, snmp_ifindex=0, oid='')"
... print repr(mana.address())
'\x00\x00\x01\x02\x00\x00'
...
Unfortunately, the management address type, unlike the other complex data types of lldp, do not have a pretty printer that prints the string representation of the most common encodings. We should definitely add that. Here is an example of such a pretty printer in action (using an lldp neighbor identified by mac address, in which case we print 11:22:33:44:55:66 instead of \x11\x22....) and also uses a more compact notation
... et1nei.to_string()
"lldp_neighbor_t(intf=Ethernet1, remote_system=lldp_remote_system_t(chassis=lldp_chassis_id_t(encoding=LLDP_CHASSIS_MAC_ADDR, value='\x00\x00\x01\x02\x00\x00'), port=lldp_intf_id_t(encoding=LLDP_INTF_NAME, value='Ethernet1')))"
... et1nei.**repr()**
'Ethernet1;MAC:0:0:1:2:0:0;Ethernet1'
...
I'm using the LLDP handler and manger. I'm getting random/weird characters when I output the address in the lldp_management_address_t. Is there something im doing wrong? Or it is an actual issue? Everything else works fine
def on_lldp_management_address(self, lldp_neighbor , list_mgmt): print "mgmt address" print list_mgmt[0].to_string() print list_mgmt[0].oid() print list_mgmt[0].address()
Output: mgmt address lldp_management_address_t(address_family=1, address='▒▒-', snmp_ifindex=2, oid='')
▒▒-
Show lldp neighbor output: leaf-51(config-if-Et5,12)#show lldp neighbors ethernet 3 detail Interface Ethernet3 detected 1 LLDP neighbors:
Neighbor 90e2.ba82.635c/90e2.ba82.635c, age 9 seconds Discovered 0:13:39 ago; Last changed 0:13:39 ago