napalm-automation-community / napalm-s350

NAPALM driver for Cisco SMB switches (SF3xx, SF5xx, SG3xx, SG5xx).
Apache License 2.0
16 stars 13 forks source link

parsing show lldp neighbors #23

Closed Phill93 closed 3 years ago

Phill93 commented 3 years ago

I am working my way through the development branch and came across the parser for lldp neigbors. I don't think it works reliably. I have seen the case that both the system name and the port ID can be wrapped.

Examples:

switchf5bcdb#show lldp neighbors

System capability legend:
B - Bridge; R - Router; W - Wlan Access Point; T - telephone;
D - DOCSIS Cable Device; H - Host; r - Repeater;
TP - Two Ports MAC Relay; S - S-VLAN; C - C-VLAN; O - Other

  Port        Device ID        Port ID       System Name    Capabilities  TTL
--------- ----------------- ------------- ----------------- ------------ -----
gi7       00:a5:bf:c2:3c:f0      gi8        switchc23cf0        B, R      91
gi8       f2:18:98:43:be:9b 9c:eb:e8:52:b    iai-sti006         B, W      115
                            d:7c
System capability legend:
B - Bridge; R - Router; W - Wlan Access Point; T - telephone;
D - DOCSIS Cable Device; H - Host; r - Repeater;
TP - Two Ports MAC Relay; S - S-VLAN; C - C-VLAN; O - Other

  Port        Device ID          Port ID         System Name    Capabilities  TTL
--------- ----------------- ----------------- ----------------- ------------ -----
te1/0/1   a0:f8:49:f2:4b:b6     te1/0/22       xx-rackswitch9      B, R      100
te1/0/2   a0:f8:49:f2:4b:b6     te2/0/22       xx-rackswitch9      B, R      105
te1/0/22  00:25:45:03:a5:c0       Te1/2       scn-0123-r004-3.t     B, R      98
                                              mn.xxx.xxx.xxx

Lines: https://github.com/napalm-automation-community/napalm-s350/blob/657bcc570ddcb0115e017fc2819aa38f95bde177/napalm_s350/s350.py#L360-L396

qaxi commented 3 years ago

You are right ... I never saw so long Port ID ...

May be it will be better to parse it as columns of chars [0-8] [10-xxx] ... and then react on partially empty line ...

qaxi commented 3 years ago

@Phill93 Are both output from devices with terminal width 512 as there is fields length diference ...

  Port        Device ID        Port ID       System Name    Capabilities  TTL
--------- ----------------- ------------- ----------------- ------------ -----
  Port        Device ID          Port ID         System Name    Capabilities  TTL
--------- ----------------- ----------------- ----------------- ------------ -----

What device types are that exactly, and what is os_version ?

It could lead to counting of - ...

Phill93 commented 3 years ago

Hello, the first output comes from my Lab SG300-10 (OS: 1.4.11) the second from a productive SG550XG-24F (OS: 2.5.0.92), both with terminal width 512.

I posted this in the Cisco Forum a few days ago, according to them terminal width doesn't change anything in the column widths. => https://community.cisco.com/t5/small-business-switches/set-column-width/m-p/4176384

Phill93 commented 3 years ago

get_lldp_neighbors fails on SG500 devices

see test for SG500-28-K9: daeb208fe73ab512af3cea1f7549d31b444a00b7

AssertionError: Expected result varies on some keys {"gi1/1/3": {"result": [{"hostname": "pc123.cli      Hents.test.net", "port": "00:23:24:02:66:e4"}], "expected": [{"hostname": "pc123.clients.test.net", "port": "00:23:24:02:66:e4"}]}}