Home | History | Annotate | Download | only in pyasn1_modules
      1 #
      2 # This file is part of pyasn1-modules software.
      3 #
      4 # Copyright (c) 2005-2017, Ilya Etingof <etingof (at] gmail.com>
      5 # License: http://pyasn1.sf.net/license.html
      6 #
      7 # SNMPv2c PDU syntax
      8 #
      9 # ASN.1 source from:
     10 # http://www.ietf.org/rfc/rfc1905.txt
     11 #
     12 from pyasn1.type import constraint
     13 from pyasn1.type import namedtype
     14 from pyasn1.type import namedval
     15 from pyasn1.type import tag
     16 from pyasn1.type import univ
     17 
     18 from pyasn1_modules import rfc1902
     19 
     20 max_bindings = rfc1902.Integer(2147483647)
     21 
     22 
     23 class _BindValue(univ.Choice):
     24     componentType = namedtype.NamedTypes(
     25         namedtype.NamedType('value', rfc1902.ObjectSyntax()),
     26         namedtype.NamedType('unSpecified', univ.Null()),
     27         namedtype.NamedType('noSuchObject',
     28                             univ.Null().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
     29         namedtype.NamedType('noSuchInstance',
     30                             univ.Null().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
     31         namedtype.NamedType('endOfMibView',
     32                             univ.Null().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2)))
     33     )
     34 
     35 
     36 class VarBind(univ.Sequence):
     37     componentType = namedtype.NamedTypes(
     38         namedtype.NamedType('name', rfc1902.ObjectName()),
     39         namedtype.NamedType('', _BindValue())
     40     )
     41 
     42 
     43 class VarBindList(univ.SequenceOf):
     44     componentType = VarBind()
     45     subtypeSpec = univ.SequenceOf.subtypeSpec + constraint.ValueSizeConstraint(
     46         0, max_bindings
     47     )
     48 
     49 
     50 class PDU(univ.Sequence):
     51     componentType = namedtype.NamedTypes(
     52         namedtype.NamedType('request-id', rfc1902.Integer32()),
     53         namedtype.NamedType('error-status', univ.Integer(
     54             namedValues=namedval.NamedValues(('noError', 0), ('tooBig', 1), ('noSuchName', 2), ('badValue', 3),
     55                                              ('readOnly', 4), ('genErr', 5), ('noAccess', 6), ('wrongType', 7),
     56                                              ('wrongLength', 8), ('wrongEncoding', 9), ('wrongValue', 10),
     57                                              ('noCreation', 11), ('inconsistentValue', 12), ('resourceUnavailable', 13),
     58                                              ('commitFailed', 14), ('undoFailed', 15), ('authorizationError', 16),
     59                                              ('notWritable', 17), ('inconsistentName', 18)))),
     60         namedtype.NamedType('error-index',
     61                             univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, max_bindings))),
     62         namedtype.NamedType('variable-bindings', VarBindList())
     63     )
     64 
     65 
     66 class BulkPDU(univ.Sequence):
     67     componentType = namedtype.NamedTypes(
     68         namedtype.NamedType('request-id', rfc1902.Integer32()),
     69         namedtype.NamedType('non-repeaters',
     70                             univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, max_bindings))),
     71         namedtype.NamedType('max-repetitions',
     72                             univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, max_bindings))),
     73         namedtype.NamedType('variable-bindings', VarBindList())
     74     )
     75 
     76 
     77 class GetRequestPDU(PDU):
     78     tagSet = PDU.tagSet.tagImplicitly(
     79         tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)
     80     )
     81 
     82 
     83 class GetNextRequestPDU(PDU):
     84     tagSet = PDU.tagSet.tagImplicitly(
     85         tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)
     86     )
     87 
     88 
     89 class ResponsePDU(PDU):
     90     tagSet = PDU.tagSet.tagImplicitly(
     91         tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2)
     92     )
     93 
     94 
     95 class SetRequestPDU(PDU):
     96     tagSet = PDU.tagSet.tagImplicitly(
     97         tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3)
     98     )
     99 
    100 
    101 class GetBulkRequestPDU(BulkPDU):
    102     tagSet = PDU.tagSet.tagImplicitly(
    103         tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 5)
    104     )
    105 
    106 
    107 class InformRequestPDU(PDU):
    108     tagSet = PDU.tagSet.tagImplicitly(
    109         tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 6)
    110     )
    111 
    112 
    113 class SNMPv2TrapPDU(PDU):
    114     tagSet = PDU.tagSet.tagImplicitly(
    115         tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 7)
    116     )
    117 
    118 
    119 class ReportPDU(PDU):
    120     tagSet = PDU.tagSet.tagImplicitly(
    121         tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 8)
    122     )
    123 
    124 
    125 class PDUs(univ.Choice):
    126     componentType = namedtype.NamedTypes(
    127         namedtype.NamedType('get-request', GetRequestPDU()),
    128         namedtype.NamedType('get-next-request', GetNextRequestPDU()),
    129         namedtype.NamedType('get-bulk-request', GetBulkRequestPDU()),
    130         namedtype.NamedType('response', ResponsePDU()),
    131         namedtype.NamedType('set-request', SetRequestPDU()),
    132         namedtype.NamedType('inform-request', InformRequestPDU()),
    133         namedtype.NamedType('snmpV2-trap', SNMPv2TrapPDU()),
    134         namedtype.NamedType('report', ReportPDU())
    135     )
    136