From 2abfddad24ac2dce2e87ed9f71377c6f81ccb49e Mon Sep 17 00:00:00 2001 From: Sarah Virr Date: Fri, 26 May 2023 15:12:24 -0400 Subject: [PATCH 1/6] sh ip ospf int optimization --- src/genie/libs/parser/iosxe/show_ospf.py | 35 ++++++++++++------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/genie/libs/parser/iosxe/show_ospf.py b/src/genie/libs/parser/iosxe/show_ospf.py index 4a2dc20328..bc8a4affb3 100755 --- a/src/genie/libs/parser/iosxe/show_ospf.py +++ b/src/genie/libs/parser/iosxe/show_ospf.py @@ -1930,6 +1930,18 @@ def cli(self, interface=None, output=None): # TE Opaque LSA: Source of link information OSPF p31_1 = re.compile(r'^TE +Opaque +LSA: +(?P[\S\s]+)$') + # Parse additional commands that are needed + cmd = 'show running-config | section router ospf' + ospf_out = self.device.execute(cmd) + cmd = 'show running-config | i virtual-link' + vl_out = self.device.execute(cmd) + cmd = 'show running-config | i sham-link' + sl_out = self.device.execute(cmd) + cmd = 'show ip ospf virtual-links' + ospfvl_out = self.device.execute(cmd) + cmd = 'show ip ospf sham-links' + ospfsl_out = self.device.execute(cmd) + for line in out.splitlines(): line = line.strip() @@ -2001,10 +2013,7 @@ def cli(self, interface=None, output=None): vl_transit_area_id = None # Execute command to get virtual-link address - cmd = 'show ip ospf virtual-links | i {interface}'.format(interface=interface) - out = self.device.execute(cmd) - - for line in out.splitlines(): + for line in ospfvl_out.splitlines(): line = line.rstrip() # Virtual Link OSPF_VL0 to router 10.100.5.5 is down p = re.search('Virtual +Link +(?P(\S+)) +to +router' @@ -2017,10 +2026,7 @@ def cli(self, interface=None, output=None): # Execute command to get virtual-link transit_area_id if vl_addr is not None: - cmd = 'show running-config | i virtual-link | i {addr}'.format(addr=vl_addr) - out = self.device.execute(cmd) - - for line in out.splitlines(): + for line in vl_out.splitlines(): line = line.rstrip() # area 1 virtual-link 10.100.5.5 q = re.search('area +(?P(\d+)) +virtual-link' @@ -2042,10 +2048,7 @@ def cli(self, interface=None, output=None): sl_remote_id = None # Execute command to get sham-link remote_id - cmd = 'show ip ospf sham-links | i {interface}'.format(interface=interface) - out = self.device.execute(cmd) - - for line in out.splitlines(): + for line in ospfsl_out.splitlines(): line = line.rstrip() # Sham Link OSPF_SL1 to address 10.151.22.22 is up p = re.search('Sham +Link +(?P(\S+)) +to +address' @@ -2057,10 +2060,8 @@ def cli(self, interface=None, output=None): # Execute command to get sham-link local_id if sl_remote_id is not None: - cmd = 'show running-config | i sham-link | i {remote}'.format(remote=sl_remote_id) - out = self.device.execute(cmd) - for line in out.splitlines(): + for line in sl_out.splitlines(): line = line.rstrip() # area 1 sham-link 10.229.11.11 10.151.22.22 cost 111 ttl-security hops 3 q = re.search('area +(?P(\d+)) +sham-link' @@ -2080,10 +2081,8 @@ def cli(self, interface=None, output=None): intf_name = '{} {}'.format(sl_local_id, sl_remote_id) # Get VRF information based on OSPF instance - cmd = 'show running-config | section router ospf {}'.format(instance) - out = self.device.execute(cmd) - for line in out.splitlines(): + for line in ospf_out.splitlines(): line = line.rstrip() # Skip the show command line so as to not match From 3131b45635c320008bd9ccfb9399d7196776310e Mon Sep 17 00:00:00 2001 From: Sarah Virr Date: Mon, 29 May 2023 11:20:33 -0400 Subject: [PATCH 2/6] added changelog for show ip ospf interface --- .../changelog_show_ip_ospf_iosxe_20230529110227.rst | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/undistributed/changelog_show_ip_ospf_iosxe_20230529110227.rst diff --git a/changelog/undistributed/changelog_show_ip_ospf_iosxe_20230529110227.rst b/changelog/undistributed/changelog_show_ip_ospf_iosxe_20230529110227.rst new file mode 100644 index 0000000000..4b4198f08f --- /dev/null +++ b/changelog/undistributed/changelog_show_ip_ospf_iosxe_20230529110227.rst @@ -0,0 +1,6 @@ +-------------------------------------------------------------------------------- + Fix +-------------------------------------------------------------------------------- +* IOSXE + * Modified ShowIpOspfInterface: + * Optimized parser by having it call additional commands once rather than call them for every instance, interface, etc... \ No newline at end of file From 0eb1a58da09f965c843e5d4c98eaa817e196af92 Mon Sep 17 00:00:00 2001 From: Sarah Virr Date: Mon, 29 May 2023 13:54:07 -0400 Subject: [PATCH 3/6] optimized show ip ospf neighbours detail parser --- src/genie/libs/parser/iosxe/show_ospf.py | 44 +++++++++++------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/genie/libs/parser/iosxe/show_ospf.py b/src/genie/libs/parser/iosxe/show_ospf.py index bc8a4affb3..87558f9f2a 100755 --- a/src/genie/libs/parser/iosxe/show_ospf.py +++ b/src/genie/libs/parser/iosxe/show_ospf.py @@ -4302,6 +4302,20 @@ def cli(self, neighbor='', output=None): ' +(?P(\d+)) +msec$') p13 = re.compile(r'^SR +adj +label +(?P\d+)$') + + # Parse additional commands that are needed + cmd = 'show running-config | section router ospf' + ospf_out = self.device.execute(cmd) + cmd = 'show running-config | i virtual-link' + vl_out = self.device.execute(cmd) + cmd = 'show running-config | i sham-link' + sl_out = self.device.execute(cmd) + cmd = 'show ip ospf virtual-links' + ospfvl_out = self.device.execute(cmd) + cmd = 'show ip ospf sham-links' + ospfsl_out = self.device.execute(cmd) + cmd = 'show ip ospf interface' + ospfint_out = self.device.execute(cmd) for line in out.splitlines(): line = line.strip() @@ -4327,10 +4341,7 @@ def cli(self, neighbor='', output=None): router_id = None bfd_state = m.groupdict().get('bfd_state', None) # Get OSPF process ID from 'show ip ospf interface' - cmd = 'show ip ospf interface {}'.format(interface) - out = self.device.execute(cmd) - - for line in out.splitlines(): + for line in ospfint_out.splitlines(): line = line.rstrip() # Process ID 2, Router ID 10.229.11.11, Network Type SHAM_LINK, Cost: 111 @@ -4343,10 +4354,7 @@ def cli(self, neighbor='', output=None): # Get VRF information using the ospf instance if instance is not None: - cmd = 'show running-config | section router ospf {}'.format(instance) - out = self.device.execute(cmd) - - for line in out.splitlines(): + for line in ospf_out.splitlines(): line = line.rstrip() # Skip the show command line so as to not match @@ -4391,10 +4399,7 @@ def cli(self, neighbor='', output=None): vl_transit_area_id = None # Execute command to get virtual-link address - cmd = 'show ip ospf virtual-links | i {interface}'.format(interface=interface) - out = self.device.execute(cmd) - - for line in out.splitlines(): + for line in ospfvl_out.splitlines(): line = line.rstrip() # Virtual Link OSPF_VL0 to router 10.100.5.5 is down p = re.search('Virtual +Link +(?P(\S+)) +to +router' @@ -4407,10 +4412,7 @@ def cli(self, neighbor='', output=None): # Execute command to get virtual-link transit_area_id if vl_addr is not None and router_id is not None: - cmd = 'show running-config | i virtual-link | i {addr}'.format(addr=vl_addr) - out = self.device.execute(cmd) - - for line in out.splitlines(): + for line in vl_out.splitlines(): line = line.rstrip() # area 1 virtual-link 10.100.5.5 q = re.search('area +(?P(\d+)) +virtual-link' @@ -4432,10 +4434,7 @@ def cli(self, neighbor='', output=None): sl_remote_id = None # Execute command to get sham-link remote_id - cmd = 'show ip ospf sham-links | i {interface}'.format(interface=interface) - out = self.device.execute(cmd) - - for line in out.splitlines(): + for line in ospfsl_out.splitlines(): line = line.rstrip() # Sham Link OSPF_SL1 to address 10.151.22.22 is up p = re.search('Sham +Link +(?P(\S+)) +to +address' @@ -4447,10 +4446,7 @@ def cli(self, neighbor='', output=None): # Execute command to get sham-link local_id if sl_remote_id is not None: - cmd = 'show running-config | i sham-link | i {remote}'.format(remote=sl_remote_id) - out = self.device.execute(cmd) - - for line in out.splitlines(): + for line in sl_out.splitlines(): line = line.rstrip() # area 1 sham-link 10.229.11.11 10.151.22.22 cost 111 ttl-security hops 3 q = re.search('area +(?P(\d+)) +sham-link' From 111b282007aad23bc324545ea3c9bc1686085edf Mon Sep 17 00:00:00 2001 From: Sarah Virr Date: Fri, 18 Aug 2023 14:07:46 -0400 Subject: [PATCH 4/6] regex match adjustments --- src/genie/libs/parser/iosxe/show_ospf.py | 26 +++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/genie/libs/parser/iosxe/show_ospf.py b/src/genie/libs/parser/iosxe/show_ospf.py index 42d388f56f..5456317018 100755 --- a/src/genie/libs/parser/iosxe/show_ospf.py +++ b/src/genie/libs/parser/iosxe/show_ospf.py @@ -4344,16 +4344,32 @@ def cli(self, neighbor='', output=None): router_id = None bfd_state = m.groupdict().get('bfd_state', None) # Get OSPF process ID from 'show ip ospf interface' + flag = False + for line in ospfint_out.splitlines(): line = line.rstrip() # Process ID 2, Router ID 10.229.11.11, Network Type SHAM_LINK, Cost: 111 - p = re.search('Process +ID +(?P(\S+)), +Router +ID' - ' +(?P(\S+)) +(.*)', line) + # p = re.search('Process +ID +(?P(\S+)), +Router +ID' + # ' +(?P(\S+)) +(.*)', line) + + p = re.search('^(?P(\S+)) +is( +administratively)?' + ' +(?P(unknown|up|down)), +line +protocol' + ' +is +(?P(up|down))' + '(?: +\(\S+\))?$', line) + if p: - instance = str(p.groupdict()['instance']) - router_id = str(p.groupdict()['router_id']) - break + p_interface = str(p.groupdict()['interface']) + if (p_interface == interface): + flag = True + + if (flag == True): + p = re.search('Process +ID +(?P(\S+)), +Router +ID +(?P(\S+)) +(.*)', line) + if p: + flag = False + instance = str(p.groupdict()['instance']) + router_id = str(p.groupdict()['router_id']) + break # Get VRF information using the ospf instance if instance is not None: From 9e47d44589c62833b5b9d08a77cbc103a18385ed Mon Sep 17 00:00:00 2001 From: Sarah Virr Date: Fri, 18 Aug 2023 14:11:01 -0400 Subject: [PATCH 5/6] updated changelog --- .../changelog_show_ip_ospf_iosxe_20230529110227.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog/undistributed/changelog_show_ip_ospf_iosxe_20230529110227.rst b/changelog/undistributed/changelog_show_ip_ospf_iosxe_20230529110227.rst index 4b4198f08f..75c4015211 100644 --- a/changelog/undistributed/changelog_show_ip_ospf_iosxe_20230529110227.rst +++ b/changelog/undistributed/changelog_show_ip_ospf_iosxe_20230529110227.rst @@ -3,4 +3,6 @@ -------------------------------------------------------------------------------- * IOSXE * Modified ShowIpOspfInterface: + * Optimized parser by having it call additional commands once rather than call them for every instance, interface, etc... + * Modified ShowIpOspfNeighborDetail * Optimized parser by having it call additional commands once rather than call them for every instance, interface, etc... \ No newline at end of file From 89e4ae7a2d97baa1ea79594d76d1388d47ae3f72 Mon Sep 17 00:00:00 2001 From: Sarah Virr Date: Sun, 17 Sep 2023 20:37:36 -0400 Subject: [PATCH 6/6] removed commented lines --- src/genie/libs/parser/iosxe/show_ospf.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/genie/libs/parser/iosxe/show_ospf.py b/src/genie/libs/parser/iosxe/show_ospf.py index 5456317018..6dd87f9f42 100755 --- a/src/genie/libs/parser/iosxe/show_ospf.py +++ b/src/genie/libs/parser/iosxe/show_ospf.py @@ -4348,10 +4348,6 @@ def cli(self, neighbor='', output=None): for line in ospfint_out.splitlines(): line = line.rstrip() - - # Process ID 2, Router ID 10.229.11.11, Network Type SHAM_LINK, Cost: 111 - # p = re.search('Process +ID +(?P(\S+)), +Router +ID' - # ' +(?P(\S+)) +(.*)', line) p = re.search('^(?P(\S+)) +is( +administratively)?' ' +(?P(unknown|up|down)), +line +protocol' @@ -4364,6 +4360,7 @@ def cli(self, neighbor='', output=None): flag = True if (flag == True): + # Process ID 2, Router ID 10.229.11.11, Network Type SHAM_LINK, Cost: 111 p = re.search('Process +ID +(?P(\S+)), +Router +ID +(?P(\S+)) +(.*)', line) if p: flag = False