com.sun.jaw.snmp.common.SnmpPduFactoryIf
com.sun.jaw.snmp.common.SnmpPduFactory
com.sun.jaw.snmp.common.SnmpPduPacket
com.sun.jaw.snmp.common.SnmpMessage
The goal of this document is to explain how to use these classes.
The first section describes how JDMK encodes and decodes SNMP packets
(and introduces SnmpPduPacket
and SnmpMessage
).
The second section explains the conversion between SnmpPduPacket
and SnmpMessage
(and introduces SnmpPduFactoryIf
and SnmpPduFactory
).
The last section describes how to implement and set up a new
SnmpPduFactoryIf
object.
SnmpMessage
object.
SnmpMessage
object is translated into an SnmpPduPacket
object.
SnmpPduPacket
is analyzed and the corresponding operation is performed.
SnmpPduPacket
object is initialized according to the requested operation.
SnmpPduPacket
object is translated into an SnmpMessage
.
SnmpMessage
is translated into bytes.
SnmpPduPacket
is the fully decoded description of
the SNMP request. In particular, it includes the operation type (get, set...),
the list of variables to be operated upon, the request identifier, the protocol version...
Theclass SnmpPduPacket { ... public int version public byte[] community ; public int type ; public int requestId ; public SnmpVarBind[] varBindList ; ... }
SnmpMessage
is a partially decoded representation of the
SNMP request. Only the protocol version and the community string
are decoded. All the other parameters remain encoded.
The SnmpMessage
class is derived from the Message
syntax from RFC 1157 and RFC 1902.
class SnmpMessage { ... public int version ; public byte[] community ; public byte[] data ; ... }
SnmpPduFactoryIf
interfaceSnmpMessage
into an
SnmpPduPacket
, it delegates this task to an object
which implements SnmpPduFactoryIf
, as follows:
JDMK provides a default implementation of this interface: it is namedinterface SnmpPduFactoryIf { // Makes an SnmpPduPacket from an SnmpMessage public SnmpPduPacket decodePdu(SnmpMessage msg) throws SnmpStatusException ; // Makes an SnmpMessage from an SnmpPduPacket public SnmpMessage encodePdu(SnmpPduPacket pdu, int maxPktSize) throws SnmpStatusException, SnmpTooBigException ; }
SnmpPduFactory
and it is used automatically unless stated
otherwise. This implementation is straightforward.
Theclass SnmpPduFactory { public SnmpPduPacket decodePdu(SnmpMessage msg) throws SnmpStatusException { return msg.decodePdu() ; // msg.decodePdu() decodes msg.data as defined in the SNMP // protocol and initializes an SnmpPduPacket accordingly. } public SnmpMessage encodePdu(SnmpPduPacket pdu, int maxPktSize) throws SnmpStatusException, SnmpTooBigException { SnmpMessage result = new SnmpMessage() ; result.encodePdu(pdu, maxPktSize) ; return result ; // msg.encodePdu() encodes pdu as defined in the SNMP protocol // and stores the encoding in msg.data. } }
SnmpPduFactory
methods control every incoming or
outgoing SNMP packets:
decodePdu()
returns null, JDMK will assume that
the SnmpMessage
is unsafe and will drop it.
encodePdu()
returns null, JDMK will assume that
it cannot send the SnmpPduPacket
safely and will abort
the current request.
SnmpPduFactoryIf
class, .
SnmpPduFactoryIf
classdecodePdu()
to behave as follows:
SnmpMessage
and returns a fully
initialized SnmpPduPacket
,
SnmpMessage
to be unsafe.
In this case, JDMK will drop the SnmpMessage
.
SmpStatusException
if decoding failed
or if the pdu contains out-of-bounds values. In this case, JDMK will
drop the SnmpMessage
.
encodePdu()
to behave as follows:
SnmpPduPacket
and returns a fully
initialized SnmpMessage
.
SnmpStatusException
if the
SnmpPduPacket
contains out-of-bounds values.
SnmpTooBigException
if the
SnmpPduPacket
does not fit into the internal buffer used by JDMK.
SnmpPduPacket
.
In this case, JDMK will abort the current request and reports an error.
This probably means that the agent/manager contains a bug.
The usePduFactory()
method enables the
SnmpPduFactoryIf
object used by the SNMP adaptor
to be changed, as follows:
... myAdaptor.usePduFactory(new MyFireWallPduFactory()) ; ...
On the manager side, the SnmpPduFactoryIf
object is
attached to an SnmpPeer
object. It can be changed
using the setPduFactory
method, as follows:
... SnmpPeer myPeer = new SnmpPeer() ; myPeer.setPduFactory(new MyFireWallPduFactory()) ; mySession.snmpGet(myPeer, this, myVarBindList) ; ...