Skip to content

Commit

Permalink
Fixed issue where OID not increasing during snmpwalk of interface MIB (
Browse files Browse the repository at this point in the history
…#12)

* * Bugfix: Fixed issue where OID not increasing during snmpwalk of interface
MIB (#11)

Signed-off-by: Gunasekaran Tamilara <gunasekaran_tamilara@Dell.com>

* Updated get-first if also to return after sorting by ifindex

Signed-off-by: Gunasekaran Tamilara <gunasekaran_tamilara@Dell.com>
  • Loading branch information
mikelazar committed Mar 5, 2020
1 parent 02c8842 commit 61cdb24
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 55 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([opx-snmp], [1.2.2], [ops-dev@lists.openswitch.net])
AC_INIT([opx-snmp], [1.2.3], [ops-dev@lists.openswitch.net])
AM_INIT_AUTOMAKE([foreign])
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_HEADERS([config.h])
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
opx-snmp (1.2.3) unstable; urgency=medium

* Bugfix: Fixed issue where OID not increasing during snmpwalk of interface MIB

-- Dell EMC <ops-dev@lists.openswitch.net> Tue, 03 Mar 2020 04:54:22 -0800

opx-snmp (1.2.2) unstable; urgency=medium

* Update: Display interface names in the same format as linux
Expand Down
115 changes: 61 additions & 54 deletions lib/python/opx_snmp/if_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,9 @@
#

def if_name_get(idx, nextf):
k = {}
if idx is not None:
k['dell-base-if-cmn/if/interfaces/interface/if-index'] = idx
if nextf:
k['cps/object-group/get-next'] = 1
r = cps_get('target',
'dell-base-if-cmn/if/interfaces/interface',
k
)
if r is None or len(r) == 0:
r = cps_get_if(idx, nextf)
if not r:
return None
r = r[0]
return (cps_key_attr_data_get(r, 'dell-base-if-cmn/if/interfaces/interface/if-index'),
cps_key_attr_data_get(r, 'if/interfaces/interface/name')
)
Expand All @@ -55,18 +46,10 @@ def result_get_next(name, pr):
#

def _if_idx_get(idx, nextf):
k = {}
if idx is not None:
k['dell-base-if-cmn/if/interfaces/interface/if-index'] = idx
if nextf:
k['cps/object-group/get-next'] = 1
r = cps_get('target',
'dell-base-if-cmn/if/interfaces/interface',
k
)
if r is None or len(r) == 0:
r = cps_get_if(idx, nextf)
if not r:
return None
return cps_key_attr_data_get(r[0], 'dell-base-if-cmn/if/interfaces/interface/if-index')
return cps_key_attr_data_get(r, 'dell-base-if-cmn/if/interfaces/interface/if-index')


def if_idx_get(module, name):
Expand Down Expand Up @@ -128,18 +111,9 @@ def if_descr_get_next(module, name):


def _if_type_get(idx, nextf):
k = {}
if idx is not None:
k['dell-base-if-cmn/if/interfaces/interface/if-index'] = idx
if nextf:
k['cps/object-group/get-next'] = 1
r = cps_get('target',
'dell-base-if-cmn/if/interfaces/interface',
k
)
if r is None or len(r) == 0:
r = cps_get_if(idx, nextf)
if not r:
return None
r = r[0]
return (cps_key_attr_data_get(r, 'dell-base-if-cmn/if/interfaces/interface/if-index'),
Integer(if_type_map.get(cps_attr_data_get(r, 'if/interfaces/interface/type') , IANAIFTYPE_OTHER))
)
Expand All @@ -162,17 +136,9 @@ def if_type_get_next(module, name):
#

def _if_mtu_get(idx, nextf):
k = {}
if idx is not None:
k['dell-base-if-cmn/if/interfaces/interface/if-index'] = idx
if nextf:
k['cps/object-group/get-next'] = 1
r = cps_get('target',
'dell-base-if-cmn/if/interfaces/interface',
k)
if r is None or len(r) == 0:
r = cps_get_if(idx, nextf)
if not r:
return None
r = r[0]
mtu = cps_attr_data_get(r, 'dell-if/if/interfaces/interface/mtu')
if mtu is None:
mtu = 0
Expand Down Expand Up @@ -232,18 +198,9 @@ def if_speed_get_next(module, name):
#

def _if_phys_addr_get(idx, nextf):
k = {}
if idx is not None:
k['dell-base-if-cmn/if/interfaces/interface/if-index'] = idx
if nextf:
k['cps/object-group/get-next'] = 1
r = cps_get('target',
'dell-base-if-cmn/if/interfaces/interface',
k
)
if r is None or len(r) == 0:
r = cps_get_if(idx, nextf)
if not r:
return None
r = r[0]
phys_addr = cps_attr_data_get(r, 'dell-if/if/interfaces/interface/phys-address');
if phys_addr is None:
phys_addr = ''
Expand Down Expand Up @@ -494,6 +451,56 @@ def if_out_errors_get_next(module, name):
def if_deprecated(module, name):
return None

def cps_get_if(idx, nextf):
'''
Wrapper function get interface details via CPS.
Get all interfaces and return whichever is required
NOTE: We can use cps/object-group/get-next for get-next, but
it is not honoured by nas backend so we simply get all
interfaces
'''
k = {}
if idx is not None and not nextf:
# get exact idx
k['dell-base-if-cmn/if/interfaces/interface/if-index'] = idx
r = cps_get('target',
'dell-base-if-cmn/if/interfaces/interface',
k
)

if not r:
return None

if idx is None:
# get-first
r = get_next_if_from_cpslist(r, idx)
elif idx is not None and nextf:
# get-next
r = get_next_if_from_cpslist(r, idx)
else:
# get exact idx
r = r[0]

return r

def get_next_if_from_cpslist(intf_list, idx):
'''
Get the next interface entry for the given interface index
Sort them based on interface index
'''
sorted_list = sorted(intf_list, key = lambda i: cps_key_attr_data_get(i, 'dell-base-if-cmn/if/interfaces/interface/if-index'))
if not idx:
# get-first
return sorted_list[0]
filtered = [i for i in sorted_list
if cps_key_attr_data_get(i, 'dell-base-if-cmn/if/interfaces/interface/if-index') > idx]

if not filtered:
return None

return filtered[0]

###########################################################################
#
# Table of handlers, for agent
Expand Down

0 comments on commit 61cdb24

Please sign in to comment.