Skip to content

Conversation

@albarytu
Copy link

@albarytu albarytu commented Nov 3, 2015

get_next didn't work correctly with a big tree of different-length oids when asking for a mid-range oid. This new algorithm works for me

@rayed
Copy link
Collaborator

rayed commented Jan 26, 2016

Thank you albarytu for the patch, it had an error on line 119.
But to be honest I couldn't figure out the bug it self, do you have a sample code for the error.

@albarytu
Copy link
Author

Sorry for that bug... a parenthesis was missing.

find attached to this mail a code sample comparing the result of both
algorithms. The input values (oid, endoid) don't fit the same length, which
happens when getting a list of values from snmpwalk

I also include a new_new method, implementing the new one in a more
pythonic way, which also looks cleaner and implies less changes from the
original one.

2016-01-26 12:24 GMT+01:00 Rayed Alrashed [email protected]:

Thank you albarytu for the patch, it had an error on line 119.
But to be honest I couldn't figure out the bug it self, do you have a
sample code for the error.


Reply to this email directly or view it on GitHub
#9 (comment).

Álvaro Fernández Conejero
[email protected]

#!/usr/bin/python

#the original algorithm
def old(data_idx, slist, elist):
for tmp_oid in data_idx:
tlist=tmp_oid.split(".")
for i in range(len(tlist)):
try:
sok= int(slist[i]) <= int(tlist[i])
eok= int(elist[i]) >= int(tlist[i])
if not (sok and eok):
break
except IndexError:
pass
if sok and eok:
return tmp_oid
return "no match"

#my original patch
def new(data_idx, slist, elist):
for tmp_oid in data_idx:
tlist=tmp_oid.split(".")
ok=True
for i in range(len(slist)):
s=int(slist[i])
if i<len(tlist):
t=int(tlist[i])
if s > t:
ok=False
break
if i<len(elist):
e=int(elist[i])
if t > e:
ok=False
break
if ok:
return tmp_oid
return "no match"

#new - pythonic version
def new_new(data_idx, slist, elist):
for tmp_oid in data_idx:
tlist=tmp_oid.split(".")
for i in range(len(tlist)):
try:
sok= int(slist[i]) <= int(tlist[i])
if not sok:
break
eok= int(elist[i]) >= int(tlist[i])
if not eok:
break
except IndexError:
pass
if sok and eok:
return tmp_oid
return "no match"

#These are the oids we are publishing
data_idx=("1.2.3", "1.2.4.1.2", "1.2.4.1.3", "1.2.4.2.1", "1.2.4.2.3")

#User is navigating 1.2. from snmpwalk.

#This operation is supposed to read everything between 1.2 and 1.3
#_get_next_oid gets called for each different oid, but endoid is always "1.3"

#in this process, we get to a point where we have read 1.2.4.2.1 and
#get a query for the next available oid, so:
slist=[1,2,4,2,2]
elist=[1,3]
print("Looking for (%s-%s) in %s"%(slist,elist,data_idx))
#the original method returns 1.2.4.1.2, which is incorrect (it's not after 1.2.4.2.1)
print("old algorithm result: %s"%old(data_idx, slist, elist))
#returns 1.2.4.2.1
print("new algorithm result: %s"%new(data_idx, slist, elist))
#returns 1.2.4.2.1
print("new_new algorithm result: %s"%new_new(data_idx, slist, elist))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants