Skip to content

Commit

Permalink
Fixed pathfinding bugs:
Browse files Browse the repository at this point in the history
- Added testrand.py to massively test pathfinding
  • Loading branch information
yantisj committed Aug 23, 2016
1 parent 2b8fb50 commit 65954fb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
37 changes: 21 additions & 16 deletions nglib/query/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ def get_full_path(src, dst, popt, rtype="NGTREE"):

srctree, dsttree, srcswp, dstswp = None, None, None, None

if 'vrfcidr' not in n1tree['_child001']:
print("Warning: Could not locate", src, file=sys.stderr)
return
if 'vrfcidr' not in n2tree['_child001']:
print("Warning: Could not locate", dst, file=sys.stderr)
return

# Routing Check
routing = True
if n1tree['_child001']['vrfcidr'] == n2tree['_child001']['vrfcidr']:
Expand All @@ -94,28 +101,26 @@ def get_full_path(src, dst, popt, rtype="NGTREE"):
router = n1tree['_child001']['Router']
if 'StandbyRouter' in n1tree['_child001']:
router = router + '|' + n1tree['_child001']['StandbyRouter']
if routing:
if 'Switch' in srctree and srctree['Switch']:
srcswp = get_switched_path(srctree['Switch'], router, popt)
else:
srctree = None
print("Warning: Could not find source switch data in NetDB", file=sys.stderr)
if 'Switch' in srctree and srctree['Switch']:
srcswp = get_switched_path(srctree['Switch'], router, popt)
else:
srctree = None
print("Warning: Could not find source switch data in NetDB:", src, file=sys.stderr)

# Find Switched Path from Router to Destination
if dsttree:
router = n2tree['_child001']['Router']
if 'StandbyRouter' in n2tree['_child001']:
router = router + '|' + n2tree['_child001']['StandbyRouter']
if routing:
if 'Switch' in dsttree and dsttree['Switch']:
dstswp = get_switched_path(router, dsttree['Switch'], popt)
else:
dsttree = None
print("Warning: Could not find destination switch data in NetDB", \
file=sys.stderr)
if 'Switch' in dsttree and dsttree['Switch']:
dstswp = get_switched_path(router, dsttree['Switch'], popt)
else:
dsttree = None
print("Warning: Could not find destination switch data in NetDB", \
dst, file=sys.stderr)

# If only switching, update srcswp to show switched path
else:
if not routing and srctree and dsttree:
srcswp = get_switched_path(srctree['Switch'], dsttree['Switch'], popt)

# Same switch/vlan check
Expand All @@ -141,9 +146,9 @@ def get_full_path(src, dst, popt, rtype="NGTREE"):
ngtree["Traversal Type"] = 'All Paths'

## Add the SRC Data
if '_child002' in n2tree:
if '_child002' in n1tree:
n1tree['_child002']['_type'] = "SRC"
if 'SwitchPort' in n2tree['_child002']:
if 'SwitchPort' in n1tree['_child002']:
n1tree['_child002']['Name'] = src + ' ' + n1tree['_child002']['MAC'] \
+ ' ' + str(n1tree['_child002']['Switch']) + '(' \
+ str(n1tree['_child002']['SwitchPort']) \
Expand Down
28 changes: 28 additions & 0 deletions test/testrand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
""" Test Random IP's for errors"""
import subprocess

ip1 = open('/tmp/ip1.txt', 'r')
ip2 = open('/tmp/ip2.txt', 'r')

verbose = True

for e1, e2 in zip(ip1, ip2):
e1 = e1.strip()
e2 = e2.strip()
#print(e1, e2)

cmd = './netgrph.py ' + e1 + ' ' + e2

proc = subprocess.Popen(
[cmd],
stdout=subprocess.PIPE,
shell=True,
universal_newlines=True)

(out, err) = proc.communicate()

if err:
print(cmd, err)
elif out and verbose:
print(out)

0 comments on commit 65954fb

Please sign in to comment.