• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 constraint
16from pyasn1.type import namedtype
17from pyasn1.type import tag
18from pyasn1.type import univ
19
20
21class ObjectName(univ.ObjectIdentifier):
22    pass
23
24
25class SimpleSyntax(univ.Choice):
26    componentType = namedtype.NamedTypes(
27        namedtype.NamedType('number', univ.Integer()),
28        namedtype.NamedType('string', univ.OctetString()),
29        namedtype.NamedType('object', univ.ObjectIdentifier()),
30        namedtype.NamedType('empty', univ.Null())
31    )
32
33
34class IpAddress(univ.OctetString):
35    tagSet = univ.OctetString.tagSet.tagImplicitly(
36        tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0)
37    )
38    subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueSizeConstraint(
39        4, 4
40    )
41
42
43class NetworkAddress(univ.Choice):
44    componentType = namedtype.NamedTypes(
45        namedtype.NamedType('internet', IpAddress())
46    )
47
48
49class Counter(univ.Integer):
50    tagSet = univ.Integer.tagSet.tagImplicitly(
51        tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 1)
52    )
53    subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
54        0, 4294967295
55    )
56
57
58class Gauge(univ.Integer):
59    tagSet = univ.Integer.tagSet.tagImplicitly(
60        tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 2)
61    )
62    subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
63        0, 4294967295
64    )
65
66
67class TimeTicks(univ.Integer):
68    tagSet = univ.Integer.tagSet.tagImplicitly(
69        tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 3)
70    )
71    subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
72        0, 4294967295
73    )
74
75
76class Opaque(univ.OctetString):
77    tagSet = univ.OctetString.tagSet.tagImplicitly(
78        tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 4)
79    )
80
81
82class ApplicationSyntax(univ.Choice):
83    componentType = namedtype.NamedTypes(
84        namedtype.NamedType('address', NetworkAddress()),
85        namedtype.NamedType('counter', Counter()),
86        namedtype.NamedType('gauge', Gauge()),
87        namedtype.NamedType('ticks', TimeTicks()),
88        namedtype.NamedType('arbitrary', Opaque())
89    )
90
91
92class ObjectSyntax(univ.Choice):
93    componentType = namedtype.NamedTypes(
94        namedtype.NamedType('simple', SimpleSyntax()),
95        namedtype.NamedType('application-wide', ApplicationSyntax())
96    )
97