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..75c4015211 --- /dev/null +++ b/changelog/undistributed/changelog_show_ip_ospf_iosxe_20230529110227.rst @@ -0,0 +1,8 @@ +-------------------------------------------------------------------------------- + Fix +-------------------------------------------------------------------------------- +* 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 diff --git a/src/genie/libs/parser/iosxe/show_ospf.py b/src/genie/libs/parser/iosxe/show_ospf.py index 491ac6eb7a..6dd87f9f42 100755 --- a/src/genie/libs/parser/iosxe/show_ospf.py +++ b/src/genie/libs/parser/iosxe/show_ospf.py @@ -1933,6 +1933,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() @@ -2004,10 +2016,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' @@ -2020,10 +2029,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' @@ -2045,10 +2051,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' @@ -2060,10 +2063,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' @@ -2083,10 +2084,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 @@ -4306,6 +4305,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() @@ -4331,26 +4344,33 @@ 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) + flag = False - for line in out.splitlines(): + for line in ospfint_out.splitlines(): line = line.rstrip() + + p = re.search('^(?P(\S+)) +is( +administratively)?' + ' +(?P(unknown|up|down)), +line +protocol' + ' +is +(?P(up|down))' + '(?: +\(\S+\))?$', line) - # 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: - 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): + # 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 + 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: - 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 @@ -4395,10 +4415,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' @@ -4411,10 +4428,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' @@ -4436,10 +4450,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' @@ -4451,10 +4462,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'