com.sun.jaw.snmp.common
Class SnmpMessage

java.lang.Object
  |
  +--com.sun.jaw.snmp.common.SnmpMessage

public class SnmpMessage
extends java.lang.Object
implements SnmpDefinitions

An SnmpMessage object is a partially decoded representation of an SNMP packet.

You normally don't need to use this class except if you decide to implement your own SnmpPduFactoryIf object.

The SnmpMessage class is directly mapped on the Message syntax defined in RFC1157 and RFC1902.

 Message ::= SEQUENCE {
    version       INTEGER { version(1) }, -- for SNMPv2
    community     OCTET STRING,           -- community name
    data          ANY                     -- an SNMPv2 PDU
 }
 

See Also:
SnmpPduFactoryIf, SnmpPduFactory, SnmpPduPacket

Field Summary
 java.net.InetAddress address
          Source or destination address.
 byte[] community
          Community name.
 byte[] data
          Encoding of the PDU.
 int dataLength
          Number of useful bytes in the data field.
 int port
          Source or destination port.
 int version
          The protocol version.
 
Constructor Summary
SnmpMessage()
           
 
Method Summary
 SnmpPduPacket decodePdu()
          Gets the pdu encoded in this message.
static java.lang.String dumpHexBuffer(byte[] b, int offset, int len)
          Dumps the content of a byte buffer using hexadecimal form.
 void encodePdu(SnmpPduPacket pdu, int maxDataLength)
          Initializes this message with the specified pdu.
 java.lang.String printMessage()
          Dumps this message in a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

public int version
The protocol version.

decodeMessage and encodeMessage do not perform any check on this value.
decodePdu and encodePdu accept only the values 0 (for SNMPv1) and 1 (for SNMPv2).


community

public byte[] community
Community name.

data

public byte[] data
Encoding of the PDU.

This is normally the BER encoding of the PDUs syntax defined in RFC1157 and RFC1902. However this can be authenticated or encrypted data (but you need to implemented your own SnmpPduFactoryIf class).


dataLength

public int dataLength
Number of useful bytes in the data field.

address

public java.net.InetAddress address
Source or destination address.

For an incoming message it's the source. For an outgoing message it's the destination.


port

public int port
Source or destination port.

For an incoming message it's the source. For an outgoing message it's the destination.

Constructor Detail

SnmpMessage

public SnmpMessage()
Method Detail

encodePdu

public void encodePdu(SnmpPduPacket pdu,
                      int maxDataLength)
               throws SnmpStatusException,
                      SnmpTooBigException
Initializes this message with the specified pdu.

This method initializes the data field with an array of maxDataLength bytes. It encodes the pdu. The resulting encoding is stored in the data field and the length of the encoding is stored in dataLength.

If the encoding length exceeds maxDataLength, the method throws an exception.

Parameters:
pdu - The pdu to be encoded.
maxDataLength - The maximum length permitted for the data field.
Throws:
SnmpStatusException - If the specified pdu is not valid.
SnmpTooBigException - If the resulting encoding does not fit in maxDataLength bytes.
ArrayIndexOutOfBoundsException - If the encoding exceeds maxDataLength.

decodePdu

public SnmpPduPacket decodePdu()
                        throws SnmpStatusException
Gets the pdu encoded in this message.

This method decodes the data field and return the resulting pdu.

Throws:
SnmpStatusException - If the encoding is not valid.

printMessage

public java.lang.String printMessage()
Dumps this message in a string.
Returns:
The string containing the dump.

dumpHexBuffer

public static java.lang.String dumpHexBuffer(byte[] b,
                                             int offset,
                                             int len)
Dumps the content of a byte buffer using hexadecimal form.
Parameters:
b - The buffer to dump.
offset - The position of the first byte to be dumped.
len - The number of bytes to be dumped starting from offset.
Returns:
The string containing the dump.