pysnmp-sky/pysnmp/proto/rfc1905.py

179 lines
5.6 KiB
Python
Raw Normal View History

2015-11-20 21:57:28 +01:00
#
# This file is part of pysnmp software.
#
# Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com>
2015-11-20 21:57:28 +01:00
# License: http://pysnmp.sf.net/license.html
#
2005-06-14 12:05:06 +02:00
from pyasn1.type import univ, tag, constraint, namedtype, namedval
from pysnmp.proto import rfc1902
__all__ = ['unSpecified', 'EndOfMibView', 'ReportPDU', 'UnSpecified',
'BulkPDU', 'SNMPv2TrapPDU', 'GetRequestPDU', 'NoSuchObject',
'GetNextRequestPDU', 'GetBulkRequestPDU', 'NoSuchInstance',
'ResponsePDU', 'noSuchObject', 'InformRequestPDU', 'endOfMibView',
'SetRequestPDU', 'noSuchInstance']
# Value reference -- max bindings in VarBindList
max_bindings = rfc1902.Integer(2147483647)
# Take SNMP exception values out of BindValue structure for convenience
UnSpecified = univ.Null
unSpecified = UnSpecified()
2016-04-03 11:29:27 +02:00
2010-11-15 00:11:26 +01:00
class NoSuchObject(univ.Null):
tagSet = univ.Null.tagSet.tagImplicitly(
tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0x00)
2015-10-17 11:54:53 +02:00
)
2010-11-18 18:43:48 +01:00
def prettyPrint(self, scope=0):
return 'No Such Object currently exists at this OID'
2015-10-17 11:54:53 +02:00
2016-04-03 11:29:27 +02:00
2010-11-15 00:11:26 +01:00
noSuchObject = NoSuchObject()
2016-04-03 11:29:27 +02:00
2010-11-15 00:11:26 +01:00
class NoSuchInstance(univ.Null):
tagSet = univ.Null.tagSet.tagImplicitly(
tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0x01)
2015-10-17 11:54:53 +02:00
)
2010-11-18 18:43:48 +01:00
def prettyPrint(self, scope=0):
return 'No Such Instance currently exists at this OID'
2016-04-03 11:29:27 +02:00
2010-11-15 00:11:26 +01:00
noSuchInstance = NoSuchInstance()
2016-04-03 11:29:27 +02:00
2010-11-15 00:11:26 +01:00
class EndOfMibView(univ.Null):
tagSet = univ.Null.tagSet.tagImplicitly(
tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0x02)
2015-10-17 11:54:53 +02:00
)
2010-11-18 18:43:48 +01:00
def prettyPrint(self, scope=0):
return 'No more variables left in this MIB View'
2015-10-17 11:54:53 +02:00
2016-04-03 11:29:27 +02:00
2010-11-15 00:11:26 +01:00
endOfMibView = EndOfMibView()
2016-04-03 11:29:27 +02:00
# Made a separate class for better readability
class _BindValue(univ.Choice):
2005-06-14 12:05:06 +02:00
componentType = namedtype.NamedTypes(
namedtype.NamedType('value', rfc1902.ObjectSyntax()),
namedtype.NamedType('unSpecified', unSpecified),
namedtype.NamedType('noSuchObject', noSuchObject),
namedtype.NamedType('noSuchInstance', noSuchInstance),
namedtype.NamedType('endOfMibView', endOfMibView)
2015-10-17 11:54:53 +02:00
)
2016-04-03 11:29:27 +02:00
2005-06-14 12:05:06 +02:00
class VarBind(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('name', rfc1902.ObjectName()),
namedtype.NamedType('', _BindValue())
2015-10-17 11:54:53 +02:00
)
2016-04-03 11:29:27 +02:00
2005-06-14 12:05:06 +02:00
class VarBindList(univ.SequenceOf):
componentType = VarBind()
subtypeSpec = univ.SequenceOf.subtypeSpec + constraint.ValueSizeConstraint(
0, max_bindings
2015-10-17 11:54:53 +02:00
)
2016-04-03 11:29:27 +02:00
errorStatus = univ.Integer(
namedValues=namedval.NamedValues(('noError', 0), ('tooBig', 1), ('noSuchName', 2), ('badValue', 3), ('readOnly', 4),
('genErr', 5), ('noAccess', 6), ('wrongType', 7), ('wrongLength', 8),
('wrongEncoding', 9), ('wrongValue', 10), ('noCreation', 11),
('inconsistentValue', 12), ('resourceUnavailable', 13), ('commitFailed', 14),
('undoFailed', 15), ('authorizationError', 16), ('notWritable', 17),
('inconsistentName', 18)))
2005-06-14 12:05:06 +02:00
# Base class for a non-bulk PDU
class PDU(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('request-id', rfc1902.Integer32()),
2016-04-02 23:43:14 +02:00
namedtype.NamedType('error-status', errorStatus),
2016-04-03 11:29:27 +02:00
namedtype.NamedType('error-index',
univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, max_bindings))),
2005-06-14 12:05:06 +02:00
namedtype.NamedType('variable-bindings', VarBindList())
2015-10-17 11:54:53 +02:00
)
2016-04-03 11:29:27 +02:00
2016-04-02 23:43:14 +02:00
nonRepeaters = univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, max_bindings))
maxRepetitions = univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, max_bindings))
2016-04-03 11:29:27 +02:00
2005-06-14 12:05:06 +02:00
# Base class for bulk PDU
class BulkPDU(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('request-id', rfc1902.Integer32()),
2016-04-02 23:43:14 +02:00
namedtype.NamedType('non-repeaters', nonRepeaters),
namedtype.NamedType('max-repetitions', maxRepetitions),
2005-06-14 12:05:06 +02:00
namedtype.NamedType('variable-bindings', VarBindList())
2015-10-17 11:54:53 +02:00
)
2016-04-03 11:29:27 +02:00
2005-06-14 12:05:06 +02:00
class GetRequestPDU(PDU):
tagSet = PDU.tagSet.tagImplicitly(
tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)
2015-10-17 11:54:53 +02:00
)
2016-04-03 11:29:27 +02:00
2005-06-14 12:05:06 +02:00
class GetNextRequestPDU(PDU):
tagSet = PDU.tagSet.tagImplicitly(
tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)
2015-10-17 11:54:53 +02:00
)
2016-04-03 11:29:27 +02:00
2005-06-14 12:05:06 +02:00
class ResponsePDU(PDU):
tagSet = PDU.tagSet.tagImplicitly(
tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2)
2015-10-17 11:54:53 +02:00
)
2016-04-03 11:29:27 +02:00
2005-06-14 12:05:06 +02:00
class SetRequestPDU(PDU):
tagSet = PDU.tagSet.tagImplicitly(
tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3)
2015-10-17 11:54:53 +02:00
)
2016-04-03 11:29:27 +02:00
2005-06-14 12:05:06 +02:00
class GetBulkRequestPDU(BulkPDU):
tagSet = PDU.tagSet.tagImplicitly(
tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 5)
2015-10-17 11:54:53 +02:00
)
2016-04-03 11:29:27 +02:00
2005-06-14 12:05:06 +02:00
class InformRequestPDU(PDU):
tagSet = PDU.tagSet.tagImplicitly(
tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 6)
2015-10-17 11:54:53 +02:00
)
2016-04-03 11:29:27 +02:00
2005-06-14 12:05:06 +02:00
class SNMPv2TrapPDU(PDU):
tagSet = PDU.tagSet.tagImplicitly(
tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 7)
2015-10-17 11:54:53 +02:00
)
2016-04-03 11:29:27 +02:00
2005-06-14 12:05:06 +02:00
class ReportPDU(PDU):
tagSet = PDU.tagSet.tagImplicitly(
tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 8)
2015-10-17 11:54:53 +02:00
)
2016-04-03 11:29:27 +02:00
2005-06-14 12:05:06 +02:00
class PDUs(univ.Choice):
componentType = namedtype.NamedTypes(
namedtype.NamedType('get-request', GetRequestPDU()),
namedtype.NamedType('get-next-request', GetNextRequestPDU()),
namedtype.NamedType('get-bulk-request', GetBulkRequestPDU()),
namedtype.NamedType('response', ResponsePDU()),
namedtype.NamedType('set-request', SetRequestPDU()),
namedtype.NamedType('inform-request', InformRequestPDU()),
namedtype.NamedType('snmpV2-trap', SNMPv2TrapPDU()),
namedtype.NamedType('report', ReportPDU())
2015-10-17 11:54:53 +02:00
)