summaryrefslogtreecommitdiff
path: root/pysnmp/entity/rfc3413/ntfrcv.py
diff options
context:
space:
mode:
Diffstat (limited to 'pysnmp/entity/rfc3413/ntfrcv.py')
-rw-r--r--pysnmp/entity/rfc3413/ntfrcv.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/pysnmp/entity/rfc3413/ntfrcv.py b/pysnmp/entity/rfc3413/ntfrcv.py
new file mode 100644
index 0000000..f8b256b
--- /dev/null
+++ b/pysnmp/entity/rfc3413/ntfrcv.py
@@ -0,0 +1,87 @@
+from pysnmp.proto import rfc3411, error
+from pysnmp.proto.api import v1, v2c # backend is always SMIv2 compliant
+from pysnmp.proto.proxy import rfc2576
+
+# 3.4
+class NotificationReceiver:
+ pduTypes = (
+ v1.TrapPDU.tagSet,
+ v2c.SNMPv2TrapPDU.tagSet,
+ v2c.InformRequestPDU.tagSet
+ )
+
+ def __init__(self, snmpEngine, cbFun, cbCtx=None):
+ snmpEngine.msgAndPduDsp.registerContextEngineId(
+ '', self.pduTypes, self.processPdu # '' is a wildcard
+ )
+ self.__cbFun = cbFun
+ self.__cbCtx = cbCtx
+
+ def close(self, snmpEngine):
+ snmpEngine.msgAndPduDsp.unregisterContextEngineId(
+ self.snmpContext.contextEngineId, self.pduTypes
+ )
+
+ def processPdu(
+ self,
+ snmpEngine,
+ messageProcessingModel,
+ securityModel,
+ securityName,
+ securityLevel,
+ contextEngineID,
+ contextName,
+ pduVersion,
+ PDU,
+ maxSizeResponseScopedPDU,
+ stateReference
+ ):
+
+ # Agent-side API complies with SMIv2
+ if messageProcessingModel == 0:
+ PDU = rfc2576.v1ToV2(PDU)
+
+ errorStatus = 'noError'; errorIndex = 0
+ varBinds = v2c.apiPDU.getVarBinds(PDU)
+
+ # 3.4
+ if rfc3411.confirmedClassPDUs.has_key(PDU.tagSet):
+ # 3.4.1 --> no-op
+
+ # 3.4.2
+ v2c.apiPDU.setErrorStatus(rspPDU, errorStatus)
+ v2c.apiPDU.setErrorIndex(rspPDU, errorIndex)
+ v2c.apiPDU.setVarBinds(rspPDU, varBinds)
+
+ # Agent-side API complies with SMIv2
+ if messageProcessingModel == 0:
+ rspPDU = rfc2576.v2ToV1(rspPDU)
+
+ # 3.4.3
+ try:
+ snmpEngine.msgAndPduDsp.returnResponsePdu(
+ snmpEngine,
+ messageProcessingModel,
+ securityModel,
+ securityName,
+ securityLevel,
+ contextEngineID,
+ contextName,
+ pduVersion,
+ rspPDU,
+ maxSizeResponseScopedPDU,
+ stateReference,
+ statusInformation
+ )
+ except error.StatusInformation:
+ snmpSilentDrops, = snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder.importSymbols('SNMPv2-MIB', 'snmpSilentDrops')
+ snmpSilentDrops.syntax = snmpSilentDrops.syntax + 1
+
+ elif rfc3411.unconfirmedClassPDUs.has_key(PDU.tagSet):
+ pass
+ else:
+ raise error.ProtocolError('Unexpected PDU class %s' % PDU.tagSet)
+
+ self.__cbFun(
+ self.snmpEngine, contextEngineID, contextName, varBinds, cbCtx
+ )