diff options
author | elie <elie> | 2012-07-20 15:36:05 +0000 |
---|---|---|
committer | elie <elie> | 2012-07-20 15:36:05 +0000 |
commit | af39cbda5f5c3f123a0fdc0d6378ddf009c4dd8c (patch) | |
tree | f1f4f70b3ae09e97d0ea8215b85e7d40ab4e42b1 /pysnmp/entity/rfc3413 | |
parent | bbdcdff7ce29bbafae3454cda5b19adf780704ba (diff) | |
download | pysnmp-git-af39cbda5f5c3f123a0fdc0d6378ddf009c4dd8c.tar.gz |
fix to Notification Originator to make it communicating a single
sendPduHandle to an application when multiple INFORMs are triggered
and processed by a single call by way of transport tagging feature
Diffstat (limited to 'pysnmp/entity/rfc3413')
-rw-r--r-- | pysnmp/entity/rfc3413/ntforg.py | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/pysnmp/entity/rfc3413/ntforg.py b/pysnmp/entity/rfc3413/ntforg.py index e8527f62..45978bc0 100644 --- a/pysnmp/entity/rfc3413/ntforg.py +++ b/pysnmp/entity/rfc3413/ntforg.py @@ -13,6 +13,7 @@ class NotificationOriginator: acmID = 3 # default MIB access control method to use def __init__(self, snmpContext): self.__pendingReqs = {} + self.__pendingNotifications = {} self.__context = snmpContext def processResponsePdu( @@ -45,21 +46,26 @@ class NotificationOriginator: origTimeout, origRetryCount, origRetries, - origSendRequestHandle + metaSendPduHandle ) = self.__pendingReqs[sendPduHandle] del self.__pendingReqs[sendPduHandle] + self.__pendingNotifications[metaSendPduHandle] -= 1 + snmpEngine.transportDispatcher.jobFinished(id(self)) if statusInformation: - debug.logger & debug.flagApp and debug.logger('processResponsePdu: sendPduHandle %s statusInformation %s' % (sendPduHandle, statusInformation)) + debug.logger & debug.flagApp and debug.logger('processResponsePdu: metaSendPduHandle %s, sendPduHandle %s statusInformation %s' % (metaSendPduHandle, sendPduHandle, statusInformation)) if origRetries == origRetryCount: - debug.logger & debug.flagApp and debug.logger('processResponsePdu: sendPduHandle %s retry count %d exceeded' % (sendPduHandle, origRetries)) - self._handleResponse( - origSendRequestHandle, - statusInformation['errorIndication'], - cbFun, - cbCtx) + debug.logger & debug.flagApp and debug.logger('processResponsePdu: metaSendPduHandle %s, sendPduHandle %s retry count %d exceeded' % (metaSendPduHandle, sendPduHandle, origRetries)) + if not self.__pendingNotifications[metaSendPduHandle]: + del self.__pendingNotifications[metaSendPduHandle] + self._handleResponse( + metaSendPduHandle, + statusInformation['errorIndication'], + cbFun, + cbCtx + ) return # Convert timeout in seconds into timeout in timer ticks @@ -84,9 +90,11 @@ class NotificationOriginator: (cbFun, cbCtx) ) + self.__pendingNotifications[metaSendPduHandle] += 1 + snmpEngine.transportDispatcher.jobStarted(id(self)) - debug.logger & debug.flagApp and debug.logger('processResponsePdu: sendPduHandle %s, timeout %d, retry %d of %d' % (sendPduHandle, origTimeout, origRetries, origRetryCount)) + debug.logger & debug.flagApp and debug.logger('processResponsePdu: metaSendPduHandle %s, sendPduHandle %s, timeout %d, retry %d of %d' % (metaSendPduHandle, sendPduHandle, origTimeout, origRetries, origRetryCount)) # 3.3.6b self.__pendingReqs[sendPduHandle] = ( @@ -103,12 +111,14 @@ class NotificationOriginator: origTimeout, origRetryCount, origRetries + 1, - sendPduHandle + metaSendPduHandle ) return # 3.3.6c - self._handleResponse(origSendRequestHandle, None, cbFun, cbCtx) + if not self.__pendingNotifications[metaSendPduHandle]: + del self.__pendingNotifications[metaSendPduHandle] + self._handleResponse(metaSendPduHandle, None, cbFun, cbCtx) def _handleResponse( self, @@ -134,7 +144,9 @@ class NotificationOriginator: snmpEngine, notificationTarget ) - debug.logger & debug.flagApp and debug.logger('sendNoification: notifyTag %s, notifyType %s' % (notifyTag, notifyType)) + metaSendPduHandle = getNextHandle() + + debug.logger & debug.flagApp and debug.logger('sendNotification: metaSendPduHandle %s, notifyTag %s, notifyType %s' % (metaSendPduHandle, notifyTag, notifyType)) contextMibInstrumCtl = self.__context.getMibInstrum( contextName @@ -151,7 +163,7 @@ class NotificationOriginator: securityName, securityLevel ) = config.getTargetParams(snmpEngine, params) - debug.logger & debug.flagApp and debug.logger('sendNoification: notifyTag %s yields: transportDomain %s, transportAddress %r, securityModel %s, securityName %s, securityLevel %s' % (notifyTag, transportDomain, transportAddress, securityModel, securityName, securityLevel)) + debug.logger & debug.flagApp and debug.logger('sendNotification: metaSendPduHandle %s, notifyTag %s yields: transportDomain %s, transportAddress %r, securityModel %s, securityName %s, securityLevel %s' % (metaSendPduHandle, notifyTag, transportDomain, transportAddress, securityModel, securityName, securityLevel)) # 3.3.1 XXX # XXX filtering's yet to be implemented @@ -209,7 +221,7 @@ class NotificationOriginator: securityLevel, 'notify', contextName, varName ) except error.SmiError: - debug.logger & debug.flagApp and debug.logger('sendNoification: OID %s not allowed for %s, droppping notification' % (varName, securityName)) + debug.logger & debug.flagApp and debug.logger('sendNotification: OID %s not allowed for %s, droppping notification' % (varName, securityName)) return else: varBinds.append((varName, varVal)) @@ -270,7 +282,7 @@ class NotificationOriginator: (cbFun, cbCtx) ) - debug.logger & debug.flagApp and debug.logger('sendNoification: sendPduHandle %s, timeout %d' % (sendPduHandle, timeout)) + debug.logger & debug.flagApp and debug.logger('sendNotification: metaSendPduHandle %s, sendPduHandle %s, timeout %d' % (metaSendPduHandle, sendPduHandle, timeout)) # 3.3.6b self.__pendingReqs[sendPduHandle] = ( @@ -287,12 +299,18 @@ class NotificationOriginator: timeout, retryCount, 1, - getNextHandle() - ) - + metaSendPduHandle + ) + + if metaSendPduHandle not in self.__pendingNotifications: + self.__pendingNotifications[metaSendPduHandle] = 0 + self.__pendingNotifications[metaSendPduHandle] += 1 + snmpEngine.transportDispatcher.jobStarted(id(self)) - return sendPduHandle + debug.logger & debug.flagApp and debug.logger('sendNotification: metaSendPduHandle %s, notification(s) sent' % metaSendPduHandle) + + return metaSendPduHandle # XXX # move/group/implement config setting/retrieval at a stand-alone module |