Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize IP OSPF Parsers #780

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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...
103 changes: 57 additions & 46 deletions src/genie/libs/parser/iosxe/show_ospf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<te_opaque_lsa>[\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()

Expand Down Expand Up @@ -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<intf>(\S+)) +to +router'
Expand All @@ -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<q_area>(\d+)) +virtual-link'
Expand All @@ -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<intf>(\S+)) +to +address'
Expand All @@ -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<q_area>(\d+)) +sham-link'
Expand All @@ -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
Expand Down Expand Up @@ -4306,6 +4305,20 @@ def cli(self, neighbor='', output=None):
' +(?P<num2>(\d+)) +msec$')

p13 = re.compile(r'^SR +adj +label +(?P<sr_adj_label>\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()
Expand All @@ -4331,26 +4344,36 @@ 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()

# Process ID 2, Router ID 10.229.11.11, Network Type SHAM_LINK, Cost: 111
p = re.search('Process +ID +(?P<instance>(\S+)), +Router +ID'
' +(?P<router_id>(\S+)) +(.*)', line)
# p = re.search('Process +ID +(?P<instance>(\S+)), +Router +ID'
# ' +(?P<router_id>(\S+)) +(.*)', line)
virrsa marked this conversation as resolved.
Show resolved Hide resolved

p = re.search('^(?P<interface>(\S+)) +is( +administratively)?'
' +(?P<enable>(unknown|up|down)), +line +protocol'
' +is +(?P<line_protocol>(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<instance>(\S+)), +Router +ID +(?P<router_id>(\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
Expand Down Expand Up @@ -4395,10 +4418,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<intf>(\S+)) +to +router'
Expand All @@ -4411,10 +4431,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<q_area>(\d+)) +virtual-link'
Expand All @@ -4436,10 +4453,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<intf>(\S+)) +to +address'
Expand All @@ -4451,10 +4465,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<q_area>(\d+)) +sham-link'
Expand Down
Loading