10
10
from pysnmp .proto .proxy import rfc2576
11
11
from pysnmp .proto import rfc3411
12
12
from pysnmp .proto .api import v2c
13
- from pysnmp .proto import error
13
+ from pysnmp .proto import errind , error
14
14
from pysnmp .smi import view , rfc1902
15
15
from pysnmp import nextid
16
16
from pysnmp import debug
21
21
class NotificationOriginator (object ):
22
22
acmID = 3 # default MIB access control method to use
23
23
24
- def __init__ (self , snmpContext = None ):
24
+ def __init__ (self , ** options ):
25
25
self .__pendingReqs = {}
26
26
self .__pendingNotifications = {}
27
- self .snmpContext = snmpContext # this is deprecated
27
+ self .snmpContext = options .pop ('snmpContext' , None ) # this is deprecated
28
+ self .__options = options
28
29
29
30
def processResponsePdu (self , snmpEngine , messageProcessingModel ,
30
31
securityModel , securityName , securityLevel ,
@@ -40,20 +41,29 @@ def processResponsePdu(self, snmpEngine, messageProcessingModel,
40
41
origMessageProcessingModel , origSecurityModel ,
41
42
origSecurityName , origSecurityLevel , origContextEngineId ,
42
43
origContextName , origPdu , origTimeout ,
43
- origRetryCount , origRetries ) = self .__pendingReqs .pop (sendPduHandle )
44
+ origRetryCount , origRetries , origDiscoveryRetries ) = self .__pendingReqs .pop (sendPduHandle )
44
45
45
46
snmpEngine .transportDispatcher .jobFinished (id (self ))
46
47
47
48
if statusInformation :
48
49
debug .logger & debug .flagApp and debug .logger (
49
50
'processResponsePdu: sendRequestHandle %s, sendPduHandle %s statusInformation %s' % (
50
51
sendRequestHandle , sendPduHandle , statusInformation ))
51
- if origRetries == origRetryCount :
52
+
53
+ errorIndication = statusInformation ['errorIndication' ]
54
+
55
+ if errorIndication in (errind .notInTimeWindow , errind .unknownEngineID ):
56
+ origDiscoveryRetries += 1
57
+ origRetries = 0
58
+ else :
59
+ origDiscoveryRetries = 0
60
+ origRetries += 1
61
+
62
+ if origRetries > origRetryCount or origDiscoveryRetries > self .__options .get ('discoveryRetries' , 4 ):
52
63
debug .logger & debug .flagApp and debug .logger (
53
64
'processResponsePdu: sendRequestHandle %s, sendPduHandle %s retry count %d exceeded' % (
54
65
sendRequestHandle , sendPduHandle , origRetries ))
55
- cbFun (snmpEngine , sendRequestHandle ,
56
- statusInformation ['errorIndication' ], None , cbCtx )
66
+ cbFun (snmpEngine , sendRequestHandle , errorIndication , None , cbCtx )
57
67
return
58
68
59
69
# Convert timeout in seconds into timeout in timer ticks
@@ -98,7 +108,7 @@ def processResponsePdu(self, snmpEngine, messageProcessingModel,
98
108
origMessageProcessingModel , origSecurityModel ,
99
109
origSecurityName , origSecurityLevel ,
100
110
origContextEngineId , origContextName , origPdu ,
101
- origTimeout , origRetryCount , origRetries + 1
111
+ origTimeout , origRetryCount , origRetries , origDiscoveryRetries
102
112
)
103
113
return
104
114
@@ -148,7 +158,7 @@ def sendPdu(self, snmpEngine, targetName, contextEngineId,
148
158
self .__pendingReqs [sendPduHandle ] = (
149
159
transportDomain , transportAddress , messageProcessingModel ,
150
160
securityModel , securityName , securityLevel , contextEngineId ,
151
- contextName , pdu , timeout , retryCount , True
161
+ contextName , pdu , timeout , retryCount , 0 , 0
152
162
)
153
163
snmpEngine .transportDispatcher .jobStarted (id (self ))
154
164
else :
0 commit comments