1# 2# This file is part of pyasn1-modules software. 3# 4# Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com> 5# License: http://pyasn1.sf.net/license.html 6# 7# SNMPv1 message syntax 8# 9# ASN.1 source from: 10# http://www.ietf.org/rfc/rfc1155.txt 11# 12# Sample captures from: 13# http://wiki.wireshark.org/SampleCaptures/ 14# 15from pyasn1.type import univ, namedtype, tag, constraint 16 17 18class ObjectName(univ.ObjectIdentifier): 19 pass 20 21 22class SimpleSyntax(univ.Choice): 23 componentType = namedtype.NamedTypes( 24 namedtype.NamedType('number', univ.Integer()), 25 namedtype.NamedType('string', univ.OctetString()), 26 namedtype.NamedType('object', univ.ObjectIdentifier()), 27 namedtype.NamedType('empty', univ.Null()) 28 ) 29 30 31class IpAddress(univ.OctetString): 32 tagSet = univ.OctetString.tagSet.tagImplicitly( 33 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0) 34 ) 35 subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueSizeConstraint( 36 4, 4 37 ) 38 39 40class NetworkAddress(univ.Choice): 41 componentType = namedtype.NamedTypes( 42 namedtype.NamedType('internet', IpAddress()) 43 ) 44 45 46class Counter(univ.Integer): 47 tagSet = univ.Integer.tagSet.tagImplicitly( 48 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 1) 49 ) 50 subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint( 51 0, 4294967295 52 ) 53 54 55class Gauge(univ.Integer): 56 tagSet = univ.Integer.tagSet.tagImplicitly( 57 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 2) 58 ) 59 subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint( 60 0, 4294967295 61 ) 62 63 64class TimeTicks(univ.Integer): 65 tagSet = univ.Integer.tagSet.tagImplicitly( 66 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 3) 67 ) 68 subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint( 69 0, 4294967295 70 ) 71 72 73class Opaque(univ.OctetString): 74 tagSet = univ.OctetString.tagSet.tagImplicitly( 75 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 4) 76 ) 77 78 79class ApplicationSyntax(univ.Choice): 80 componentType = namedtype.NamedTypes( 81 namedtype.NamedType('address', NetworkAddress()), 82 namedtype.NamedType('counter', Counter()), 83 namedtype.NamedType('gauge', Gauge()), 84 namedtype.NamedType('ticks', TimeTicks()), 85 namedtype.NamedType('arbitrary', Opaque()) 86 ) 87 88 89class ObjectSyntax(univ.Choice): 90 componentType = namedtype.NamedTypes( 91 namedtype.NamedType('simple', SimpleSyntax()), 92 namedtype.NamedType('application-wide', ApplicationSyntax()) 93 ) 94