diff --git a/napalm_vyos/vyos.py b/napalm_vyos/vyos.py index 670f4bb..182b6a4 100644 --- a/napalm_vyos/vyos.py +++ b/napalm_vyos/vyos.py @@ -598,6 +598,29 @@ class VyOSDriver(NetworkDriver): (minutes * self._MINUTE_SECONDS) + seconds) return uptime + def get_lldp_neighbors(self): + # Multiple neighbors per port are not implemented + # The show lldp neighbors commands lists port descriptions, not IDs + output = self.device.send_command("show lldp neighbors detail") + pattern = r'''(?s)Interface: +(?P\S+), [^\n]+ +.+? + +SysName: +(?P\S+) +.+? + +PortID: +ifname (?P\S+)''' + + def _get_interface(match): + return [ + { + 'hostname': match.group('hostname'), + 'port': match.group('port'), + } + ] + + return { + match.group('interface'): _get_interface(match) + for match in re.finditer(pattern, output) + } + def get_interfaces_counters(self): # 'rx_unicast_packet', 'rx_broadcast_packets', 'tx_unicast_packets', # 'tx_multicast_packets' and 'tx_broadcast_packets' are not implemented yet diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/normal/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors/normal/expected_result.json new file mode 100644 index 0000000..7eb6370 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/normal/expected_result.json @@ -0,0 +1 @@ +{"eth1": [{"hostname": "branch", "port": "eth0"}], "eth2": [{"hostname": "dmz", "port": "eth0"}]} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/normal/show_lldp_neighbors_detail.text b/test/unit/mocked_data/test_get_lldp_neighbors/normal/show_lldp_neighbors_detail.text new file mode 100644 index 0000000..6657bf0 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/normal/show_lldp_neighbors_detail.text @@ -0,0 +1,69 @@ +------------------------------------------------------------------------------- +LLDP neighbors: +------------------------------------------------------------------------------- +Interface: eth1, via: LLDP, RID: 2, Time: 1 day, 18:17:44 + Chassis: + ChassisID: mac 52:54:00:99:84:8a + SysName: branch + SysDescr: VyOS 1.3-rolling-202005151915 + MgmtIP: 10.0.0.3 + Capability: Bridge, off + Capability: Router, on + Capability: Wlan, off + Capability: Station, off + Port: + PortID: ifname eth0 + PortDescr: to DC + TTL: 120 + PMD autoneg: supported: yes, enabled: yes + Adv: 10Base-T, HD: yes, FD: yes + Adv: 100Base-TX, HD: yes, FD: yes + MAU oper type: 100BaseTXFD - 2 pair category 5 UTP, full duplex mode + LLDP-MED: + Device Type: Network Connectivity Device + Capability: Capabilities, yes + Capability: Policy, yes + Capability: Location, yes + Capability: MDI/PSE, yes + Capability: MDI/PD, yes + Capability: Inventory, yes + Inventory: + Hardware Revision: pc-i440fx-4.2 + Software Revision: 4.19.122-amd64-vyos + Firmware Revision: 1.13.0-1ubuntu1 + Manufacturer: QEMU + Model: Standard PC (i440FX + PIIX, 1996 +------------------------------------------------------------------------------- +Interface: eth2, via: LLDP, RID: 1, Time: 1 day, 18:17:45 + Chassis: + ChassisID: mac 52:54:00:98:e5:9f + SysName: dmz + SysDescr: VyOS 1.3-rolling-202005151915 + MgmtIP: 10.0.0.2 + Capability: Bridge, off + Capability: Router, on + Capability: Wlan, off + Capability: Station, off + Port: + PortID: ifname eth0 + PortDescr: to DC + TTL: 120 + PMD autoneg: supported: yes, enabled: yes + Adv: 10Base-T, HD: yes, FD: yes + Adv: 100Base-TX, HD: yes, FD: yes + MAU oper type: 100BaseTXFD - 2 pair category 5 UTP, full duplex mode + LLDP-MED: + Device Type: Network Connectivity Device + Capability: Capabilities, yes + Capability: Policy, yes + Capability: Location, yes + Capability: MDI/PSE, yes + Capability: MDI/PD, yes + Capability: Inventory, yes + Inventory: + Hardware Revision: pc-i440fx-4.2 + Software Revision: 4.19.122-amd64-vyos + Firmware Revision: 1.13.0-1ubuntu1 + Manufacturer: QEMU + Model: Standard PC (i440FX + PIIX, 1996 +------------------------------------------------------------------------------- \ No newline at end of file