SnmpKit.SnmpLib.MIB.AST (snmpkit v0.6.3)

Abstract Syntax Tree definitions for MIB compilation.

Faithfully ported from Erlang OTP snmpc_mib_gram.yrl and related structures. Provides the complete AST representation needed for SNMP MIB compilation.

Summary

Functions

Build an OID tree from definitions for fast lookups.

Determine SNMP version based on MIB content.

Create a new import statement.

Create a new MIB AST node.

Create a new object identity definition.

Create a new object type definition.

Pretty print AST node for debugging.

Validate AST node structure.

Types

access_level()

@type access_level() ::
  :not_accessible
  | :accessible_for_notify
  | :read_only
  | :read_write
  | :read_create
  | :write_only

agent_capabilities()

@type agent_capabilities() :: %{
  __type__: :agent_capabilities,
  name: binary(),
  product_release: binary(),
  status: status(),
  description: binary(),
  reference: binary() | nil,
  modules: [capability_module()],
  oid: oid(),
  line: line_number()
}

capability_module()

@type capability_module() :: %{
  module_name: binary(),
  includes: [binary()],
  variations: [object_variation()]
}

choice_element()

@type choice_element() :: %{name: binary(), syntax: syntax()}

compliance_module()

@type compliance_module() :: %{
  module_name: binary(),
  mandatory_groups: [binary()],
  compliance_objects: [compliance_object()]
}

compliance_object()

@type compliance_object() :: %{
  object: binary(),
  syntax: syntax() | nil,
  write_syntax: syntax() | nil,
  access: access_level() | nil,
  description: binary() | nil
}

constraint()

@type constraint() ::
  {:size, size_constraint()}
  | {:range, range_constraint()}
  | {:named_values, [named_value()]}
  | {:contained_subtype, syntax()}

constraints()

@type constraints() :: [constraint()]

constructed_syntax()

@type constructed_syntax() ::
  {:sequence, [sequence_element()]}
  | {:sequence_of, syntax()}
  | {:choice, [choice_element()]}
  | {:bit_string, [named_bit()]}

default_value()

@type default_value() ::
  nil
  | integer()
  | binary()
  | atom()
  | [default_value()]
  | {:named_value, binary()}
  | {:bit_string, [binary()]}

definition()

import()

@type import() :: %{
  __type__: :import,
  symbols: [binary()],
  from_module: binary(),
  line: line_number()
}

index_element()

@type index_element() :: binary() | {:implied, binary()}

index_spec()

@type index_spec() :: {:index, [index_element()]} | {:implied, [index_element()]}

line_number()

@type line_number() :: integer()

metadata()

@type metadata() :: %{
  compile_time: DateTime.t(),
  compiler_version: binary(),
  source_file: Path.t(),
  snmp_version: :v1 | :v2c,
  dependencies: [binary()],
  warnings: [binary()],
  line_count: integer()
}

mib()

@type mib() :: %{
  __type__: :mib,
  name: binary(),
  last_updated: binary() | nil,
  organization: binary() | nil,
  contact_info: binary() | nil,
  description: binary() | nil,
  revision_history: [revision()],
  imports: [import()],
  definitions: [definition()],
  oid_tree: oid_tree(),
  metadata: metadata()
}

module_compliance()

@type module_compliance() :: %{
  __type__: :module_compliance,
  name: binary(),
  status: status(),
  description: binary(),
  reference: binary() | nil,
  modules: [compliance_module()],
  oid: oid(),
  line: line_number()
}

module_identity()

@type module_identity() :: %{
  __type__: :module_identity,
  name: binary(),
  last_updated: binary(),
  organization: binary(),
  contact_info: binary(),
  description: binary(),
  revision_history: [revision()],
  oid: oid(),
  line: line_number()
}

named_bit()

@type named_bit() :: %{name: binary(), bit_number: integer()}

named_syntax()

@type named_syntax() ::
  {:named_type, binary()}
  | {:application_type, tag(), syntax()}
  | {:context_type, tag(), syntax()}

named_value()

@type named_value() :: %{name: binary(), value: integer()}

notification_group()

@type notification_group() :: %{
  __type__: :notification_group,
  name: binary(),
  notifications: [binary()],
  status: status(),
  description: binary(),
  reference: binary() | nil,
  oid: oid(),
  line: line_number()
}

notification_type()

@type notification_type() :: %{
  __type__: :notification_type,
  name: binary(),
  objects: [binary()],
  status: status(),
  description: binary(),
  reference: binary() | nil,
  oid: oid(),
  line: line_number()
}

object_group()

@type object_group() :: %{
  __type__: :object_group,
  name: binary(),
  objects: [binary()],
  status: status(),
  description: binary(),
  reference: binary() | nil,
  oid: oid(),
  line: line_number()
}

object_identifier_assignment()

@type object_identifier_assignment() :: %{
  __type__: :object_identifier_assignment,
  name: binary(),
  oid: oid(),
  line: line_number()
}

object_identity()

@type object_identity() :: %{
  __type__: :object_identity,
  name: binary(),
  status: status(),
  description: binary(),
  reference: binary() | nil,
  oid: oid(),
  line: line_number()
}

object_type()

@type object_type() :: %{
  __type__: :object_type,
  name: binary(),
  syntax: syntax(),
  units: binary() | nil,
  max_access: access_level(),
  status: status(),
  description: binary(),
  reference: binary() | nil,
  index: index_spec() | nil,
  augments: binary() | nil,
  defval: default_value() | nil,
  oid: oid(),
  line: line_number()
}

object_variation()

@type object_variation() :: %{
  object: binary(),
  syntax: syntax() | nil,
  write_syntax: syntax() | nil,
  access: access_level() | nil,
  creation: boolean(),
  defval: default_value() | nil,
  description: binary()
}

oid()

@type oid() :: [integer()] | [oid_element()]

oid_element()

@type oid_element() :: integer() | {binary(), integer()}

oid_tree()

@type oid_tree() :: :ets.tid() | map()

primitive_syntax()

@type primitive_syntax() ::
  :integer
  | :octet_string
  | :object_identifier
  | :null
  | :real
  | {:integer, constraints()}
  | {:octet_string, constraints()}
  | {:object_identifier, constraints()}

range_constraint()

@type range_constraint() :: {integer(), integer()} | [range_spec()]

range_spec()

@type range_spec() :: integer() | {integer(), integer()}

revision()

@type revision() :: %{
  __type__: :revision,
  date: binary(),
  description: binary(),
  line: line_number()
}

sequence_element()

@type sequence_element() :: %{
  name: binary(),
  syntax: syntax(),
  optional: boolean(),
  default: default_value() | nil
}

size_constraint()

@type size_constraint() :: integer() | {integer(), integer()} | [size_range()]

size_range()

@type size_range() :: integer() | {integer(), integer()}

status()

@type status() :: :current | :deprecated | :obsolete | :mandatory

syntax()

@type syntax() :: primitive_syntax() | constructed_syntax() | named_syntax()

tag()

@type tag() :: integer()

textual_convention()

@type textual_convention() :: %{
  __type__: :textual_convention,
  name: binary(),
  display_hint: binary() | nil,
  status: status(),
  description: binary(),
  reference: binary() | nil,
  syntax: syntax(),
  line: line_number()
}

trap_type()

@type trap_type() :: %{
  __type__: :trap_type,
  name: binary(),
  enterprise: oid(),
  variables: [binary()],
  description: binary() | nil,
  reference: binary() | nil,
  trap_number: integer(),
  line: line_number()
}

Functions

build_oid_tree(definitions)

@spec build_oid_tree([definition()]) :: :ets.tid()

Build an OID tree from definitions for fast lookups.

determine_snmp_version(definitions)

@spec determine_snmp_version([definition()]) :: :v1 | :v2c

Determine SNMP version based on MIB content.

Per Erlang implementation: presence of MODULE-IDENTITY indicates SNMPv2.

new_import(symbols, from_module, line)

@spec new_import([binary()], binary(), line_number()) :: import()

Create a new import statement.

new_mib(name, opts \\ [])

@spec new_mib(
  binary(),
  keyword()
) :: mib()

Create a new MIB AST node.

new_object_identity(name, opts)

@spec new_object_identity(
  binary(),
  keyword()
) :: object_identity()

Create a new object identity definition.

new_object_type(name, opts)

@spec new_object_type(
  binary(),
  keyword()
) :: object_type()

Create a new object type definition.

pretty_print(other)

@spec pretty_print(term()) :: binary()

Pretty print AST node for debugging.

validate_node(node)

@spec validate_node(term()) :: {:ok, term()} | {:error, binary()}

Validate AST node structure.