From 1a21ea2fdaec2a08ba6716340439c25ea985c15d Mon Sep 17 00:00:00 2001 From: Joris Beckers Date: Thu, 25 Oct 2018 19:22:23 +0200 Subject: [PATCH] Improve LLDP neighbor detail parsing on older IOS versions (#846) --- .../show_lldp_neighbors_detail.tpl | 6 +- .../older_ios/expected_result.json | 26 +++++++ .../older_ios/show_lldp_neighbors.txt | 11 +++ .../older_ios/show_lldp_neighbors_detail.txt | 68 +++++++++++++++++++ 4 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 test/ios/mocked_data/test_get_lldp_neighbors_detail/older_ios/expected_result.json create mode 100644 test/ios/mocked_data/test_get_lldp_neighbors_detail/older_ios/show_lldp_neighbors.txt create mode 100644 test/ios/mocked_data/test_get_lldp_neighbors_detail/older_ios/show_lldp_neighbors_detail.txt diff --git a/napalm/ios/utils/textfsm_templates/show_lldp_neighbors_detail.tpl b/napalm/ios/utils/textfsm_templates/show_lldp_neighbors_detail.tpl index 8bd69b8b1..8747f3bf0 100644 --- a/napalm/ios/utils/textfsm_templates/show_lldp_neighbors_detail.tpl +++ b/napalm/ios/utils/textfsm_templates/show_lldp_neighbors_detail.tpl @@ -8,10 +8,6 @@ Value REMOTE_SYSTEM_CAPAB (.*) Value REMOTE_SYSTEM_ENABLE_CAPAB (.*) Start - # A line of hyphens delimits neighbor records - ^------+ -> Record Neighbor - -Neighbor ^Local Intf\s*?[:-]\s+${LOCAL_INTERFACE} ^Chassis id\s*?[:-]\s+${REMOTE_CHASSIS_ID} ^Port id\s*?[:-]\s+${REMOTE_PORT} @@ -25,4 +21,4 @@ Neighbor Description # Capture the entire line and go back to Neighbor state - ^${REMOTE_SYSTEM_DESCRIPTION} -> Neighbor + ^${REMOTE_SYSTEM_DESCRIPTION} -> Start diff --git a/test/ios/mocked_data/test_get_lldp_neighbors_detail/older_ios/expected_result.json b/test/ios/mocked_data/test_get_lldp_neighbors_detail/older_ios/expected_result.json new file mode 100644 index 000000000..079f89e26 --- /dev/null +++ b/test/ios/mocked_data/test_get_lldp_neighbors_detail/older_ios/expected_result.json @@ -0,0 +1,26 @@ +{ + "GigabitEthernet0/24": [ + { + "parent_interface": "N/A", + "remote_chassis_id": "f4a7.39cd.2e40", + "remote_port": "ge-0/0/23", + "remote_port_description": "ptp to switch", + "remote_system_capab": "B,R", + "remote_system_description": "Juniper Networks, Inc. ex3300-24p , version 12.3R12.4 Build date: 2016-01-20 05:03:06 UTC", + "remote_system_enable_capab": "B,R", + "remote_system_name": "switch1" + } + ], + "GigabitEthernet0/1": [ + { + "parent_interface": "N/A", + "remote_chassis_id": "a8b1.d41d.8680", + "remote_port": "Gi0/2", + "remote_port_description": "GigabitEthernet0/2", + "remote_system_capab": "B", + "remote_system_description": "Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(1)SE2, RELEASE SOFTWARE (fc3)", + "remote_system_enable_capab": "B", + "remote_system_name": "switch2" + } + ] +} diff --git a/test/ios/mocked_data/test_get_lldp_neighbors_detail/older_ios/show_lldp_neighbors.txt b/test/ios/mocked_data/test_get_lldp_neighbors_detail/older_ios/show_lldp_neighbors.txt new file mode 100644 index 000000000..6311c78fd --- /dev/null +++ b/test/ios/mocked_data/test_get_lldp_neighbors_detail/older_ios/show_lldp_neighbors.txt @@ -0,0 +1,11 @@ + +Capability codes: + (R) Router, (B) Bridge, (T) Telephone, (C) DOCSIS Cable Device + (W) WLAN Access Point, (P) Repeater, (S) Station, (O) Other + +Device ID Local Intf Hold-time Capability Port ID +switch1 Gi0/24 120 B,R ge-0/0/23 +switch2 Gi0/1 120 B Gi0/2 + +Total entries displayed: 2 + diff --git a/test/ios/mocked_data/test_get_lldp_neighbors_detail/older_ios/show_lldp_neighbors_detail.txt b/test/ios/mocked_data/test_get_lldp_neighbors_detail/older_ios/show_lldp_neighbors_detail.txt new file mode 100644 index 000000000..c87fe5f59 --- /dev/null +++ b/test/ios/mocked_data/test_get_lldp_neighbors_detail/older_ios/show_lldp_neighbors_detail.txt @@ -0,0 +1,68 @@ + + +Chassis id: f4a7.39cd.2e40 +Port id: ge-0/0/23 +Port Description: ptp to switch +System Name: switch1 + +System Description: +Juniper Networks, Inc. ex3300-24p , version 12.3R12.4 Build date: 2016-01-20 05:03:06 UTC + +Time remaining: 105 seconds +System Capabilities: B,R +Enabled Capabilities: B,R +Management Addresses - not advertised +Auto Negotiation - supported, enabled +Physical media capabilities: + Other/unknown + 100base-TX(HD) + Symm Pause(FD) + Symm, Asym Pause(FD) + 1000baseX(FD) + 1000baseT(HD) +Media Attachment Unit type - not advertised + +MED Information: + + MED Codes: + (NP) Network Policy, (LI) Location Identification + (PS) Power Source Entity, (PD) Power Device + (IN) Inventory + + Inventory information - not advertised + Capabilities: NP, LI, PS + Device type: Network connectivity + Network Policies - not advertised + Power requirements - not advertised +--------------------------------------------- + + +Chassis id: a8b1.d41d.8680 +Port id: Gi0/2 +Port Description: GigabitEthernet0/2 +System Name: switch2 + +System Description: +Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(1)SE2, RELEASE SOFTWARE (fc3) +Technical Support: http://www.cisco.com/techsupport +Copyright (c) 1986-2011 by Cisco Systems, Inc. +Compiled Thu 22-Dec-11 00:46 by prod_rel_team + +Time remaining: 115 seconds +System Capabilities: B +Enabled Capabilities: B +Management Addresses: + IP: 10.10.10.10 +Auto Negotiation - supported, enabled +Physical media capabilities: + Other/unknown + Symm Pause(FD) + Symm, Asym Pause(FD) + 1000baseX(FD) + 1000baseT(HD) +Media Attachment Unit type: 30 +--------------------------------------------- + + +Total entries displayed: 2 +