NAME

Net::Frame::Layer::SNMP - Simple Network Management Protocol layer object

SYNOPSIS

use Net::Frame::Simple;
use Net::Frame::Layer::SNMP qw(:consts);

my $snmp = Net::Frame::Layer::SNMP->new(
   version     => NF_SNMP_VERSION_2,
   community   => 'public',
   requestId   => getRandom16bitsInt(),
   errorStatus => 0,
   errorIndex  => 0,
   varbindlist => [],
);

#
# Read a raw layer
#

my $layer = Net::Frame::Layer::SNMP->new(raw => $raw);

print $layer->print."\n";
print 'PAYLOAD: '.unpack('H*', $layer->payload)."\n"
   if $layer->payload;

DESCRIPTION

This modules implements the encoding and decoding of the SNMP layer.

See also Net::Frame::Layer for other attributes and methods.

ATTRIBUTES

version

SNMP version. This module supports version 1 and version 2(c).

community

SNMP community string.

requestId
errorStatus
errorIndex

SNMP fields for Get, GetNext, Response, Set, Inform, V2Trap and Report PDU types.

entOid
agentAddr
genericTrap
specificTrap
timeticks

SNMP fields for Trap PDU type.

nonRepeaters
maxRepetitions

SNMP fields for GetBulk PDU type.

varbindlist

Variable bindings list.

The following are inherited attributes. See Net::Frame::Layer for more information.

raw
payload
nextLayer

METHODS

new
new (hash)

Object constructor. You can pass attributes that will overwrite default ones. Synonymous with Get. See SYNOPSIS for default values.

Get
Get (hash)
my $snmp = Net::Frame::Layer::SNMP->Get(
   version     => NF_SNMP_VERSION_2,
   community   => 'public',
   requestId   => getRandom16bitsInt(),
   errorStatus => 0,
   errorIndex  => 0,
   varbindlist => [],
);
GetNext
GetNext (hash)
my $snmp = Net::Frame::Layer::SNMP->GetNext(
   version     => NF_SNMP_VERSION_2,
   community   => 'public',
   requestId   => getRandom16bitsInt(),
   errorStatus => 0,
   errorIndex  => 0,
   varbindlist => [],
);
Response
Response (hash)
my $snmp = Net::Frame::Layer::SNMP->Response(
   version     => NF_SNMP_VERSION_2,
   community   => 'public',
   requestId   => getRandom16bitsInt(),
   errorStatus => 0,
   errorIndex  => 0,
   varbindlist => [],
);
Set
Set (hash)
my $snmp = Net::Frame::Layer::SNMP->Set(
   version     => NF_SNMP_VERSION_2,
   community   => 'public',
   requestId   => getRandom16bitsInt(),
   errorStatus => 0,
   errorIndex  => 0,
   varbindlist => [],
);
Trap
Trap (hash)
my $snmp = Net::Frame::Layer::SNMP->Trap(
   version      => NF_SNMP_VERSION_1,
   community    => 'public',
   entOid       => '1.3.6.1.4.1.50000',
   agentAddr    => '127.0.0.1',
   genericTrap  => NF_SNMP_GENERICTRAP_ENTERPRISESPECIFIC,
   specificTrap => 1,
   timeticks    => time(),
   varbindlist  => [],
);
GetBulk
GetBulk (hash)
my $snmp = Net::Frame::Layer::SNMP->GetBulk(
   version        => NF_SNMP_VERSION_2,
   community      => 'public',
   requestId      => getRandom16bitsInt(),
   nonRepeaters   => 0,
   maxRepetitions => 0,
   varbindlist    => [],
);
Inform
Inform (hash)
my $snmp = Net::Frame::Layer::SNMP->Inform(
   version     => NF_SNMP_VERSION_2,
   community   => 'public',
   requestId   => getRandom16bitsInt(),
   errorStatus => 0,
   errorIndex  => 0,
   varbindlist => [],
);
V2Trap
V2Trap (hash)
my $snmp = Net::Frame::Layer::SNMP->V2Trap(
   version     => NF_SNMP_VERSION_2,
   community   => 'public',
   requestId   => getRandom16bitsInt(),
   errorStatus => 0,
   errorIndex  => 0,
   varbindlist => [],
);
Report
Report (hash)
my $snmp = Net::Frame::Layer::SNMP->Report(
   version     => NF_SNMP_VERSION_2,
   community   => 'public',
   requestId   => getRandom16bitsInt(),
   errorStatus => 0,
   errorIndex  => 0,
   varbindlist => [],
);

Object constructors for SNMP PDU types.

getKey
getKeyReverse

These two methods are basically used to increase the speed when using recv method from Net::Frame::Simple. Usually, you write them when you need to write match method.

match (Net::Frame::Layer::SNMP object)

This method is mostly used internally. You pass a Net::Frame::Layer::SNMP layer as a parameter, and it returns true if this is a response corresponding for the request, or returns false if not.

The following are inherited methods. Some of them may be overriden in this layer, and some others may not be meaningful in this layer. See Net::Frame::Layer for more information.

layer
computeLengths
pack
unpack
encapsulate
getLength
getPayloadLength
print
dump

USEFUL SUBROUTINES

Load them: use Net::Frame::Layer::SNMP qw(:subs);

varbinds (hash)
my $varbind = Net::Frame::Layer::SNMP->varbinds(
   oid   => '1.3.6.1.4.1.50000',
   type  => NF_SNMP_VARBINDTYPE_INTEGER,
   value => 1,
);

Creates variable bindings.

v2trap_varbinds (hash)
my @varbinds = Net::Frame::Layer::SNMP->v2trap_varbinds(
   timeticks => time(),
   oid       => '1.3.6.1.4.1.50000'
);

Creates the first two variable bindings for SNMPv2 traps.

CONSTANTS

Load them: use Net::Frame::Layer::SNMP qw(:consts);

NF_SNMP_VERSION_1
NF_SNMP_VERSION_2

SNMP versions.

NF_SNMP_PDUTYPE_GET
NF_SNMP_PDUTYPE_GETNEXT
NF_SNMP_PDUTYPE_RESPONSE
NF_SNMP_PDUTYPE_SET
NF_SNMP_PDUTYPE_TRAP
NF_SNMP_PDUTYPE_GETBULK
NF_SNMP_PDUTYPE_INFORM
NF_SNMP_PDUTYPE_V2TRAP
NF_SNMP_PDUTYPE_REPORT

SNMP PDU types.

NF_SNMP_GENERICTRAP_COLDSTART
NF_SNMP_GENERICTRAP_WARMSTART
NF_SNMP_GENERICTRAP_LINKDOWN
NF_SNMP_GENERICTRAP_LINKUP
NF_SNMP_GENERICTRAP_AUTHFAIL
NF_SNMP_GENERICTRAP_EGPNEIGHBORLOSS
NF_SNMP_GENERICTRAP_ENTERPRISESPECIFIC

SNMP version 1 generic trap types.

NF_SNMP_VARBINDTYPE_INTEGER
NF_SNMP_VARBINDTYPE_STRING
NF_SNMP_VARBINDTYPE_OID
NF_SNMP_VARBINDTYPE_IPADDR
NF_SNMP_VARBINDTYPE_COUNTER32
NF_SNMP_VARBINDTYPE_GUAGE32
NF_SNMP_VARBINDTYPE_TIMETICKS
NF_SNMP_VARBINDTYPE_OPAQUE
NF_SNMP_VARBINDTYPE_COUNTER64
NF_SNMP_VARBINDTYPE_NULL

SNMP variable binding types.

LIMITATIONS

All OIDs must be entered in numerical format.

SEE ALSO

Net::Frame::Layer

For a non Net::Frame::Layer SNMP solution in Perl, Net::SNMP.

AUTHOR

Michael Vincent

COPYRIGHT AND LICENSE

Copyright (c) 2013, Michael Vincent

You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive.