public abstract class

SnmpMsg

extends Object
implements SnmpDefinitions
java.lang.Object
   ↳ com.sun.jmx.snmp.SnmpMsg
Known Direct Subclasses

Class Overview

A partially decoded representation of an SNMP packet. It contains the information contained in any SNMP message (SNMPv1, SNMPv2 or SNMPv3).

This API is a Sun Microsystems internal API and is subject to change without notice.

Summary

[Expand]
Inherited Constants
From interface com.sun.jmx.snmp.SnmpDefinitions
Fields
public InetAddress address Source or destination address.
public byte[] data Encoding of the PDU.
public int dataLength Number of useful bytes in the data field.
public int port Source or destination port.
public SnmpSecurityParameters securityParameters Security parameters.
public int version The protocol version.
Public Constructors
SnmpMsg()
Public Methods
abstract void decodeMessage(byte[] inputBytes, int byteCount)
Decodes the specified bytes and initializes this message.
abstract SnmpPdu decodeSnmpPdu()
Gets the PDU encoded in this message.
SnmpVarBind[] decodeVarBindList(BerDecoder bdec)
For SNMP Runtime private use only.
static String dumpHexBuffer(byte[] b, int offset, int len)
Dumps the content of a byte buffer using hexadecimal form.
abstract int encodeMessage(byte[] outputBytes)
Encodes this message and puts the result in the specified byte array.
abstract void encodeSnmpPdu(SnmpPdu pdu, int maxDataLength)
Initializes this message with the specified pdu.
void encodeVarBindList(BerEncoder benc, SnmpVarBind[] varBindList)
For SNMP Runtime private use only.
static int getProtocolVersion(byte[] data)
Returns the encoded SNMP version present in the passed byte array.
abstract int getRequestId(byte[] data)
Returns the associated request ID.
String printMessage()
Dumps this message in a string.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public InetAddress address

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

public byte[] data

Encoding of the PDU.

This is usually the BER encoding of the PDU's syntax defined in RFC1157 and RFC1902. However, this can be authenticated or encrypted data (but you need to implemented your own SnmpPduFactory class).

public int dataLength

Number of useful bytes in the data field.

public int port

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

public SnmpSecurityParameters securityParameters

Security parameters. Contain informations according to Security Model (Usm, community string based, ...).

public int version

The protocol version.

decodeMessage and encodeMessage do not perform any check on this value.
decodeSnmpPdu and encodeSnmpPdu only accept the values 0 (for SNMPv1), 1 (for SNMPv2) and 3 (for SNMPv3).

Public Constructors

public SnmpMsg ()

Public Methods

public abstract void decodeMessage (byte[] inputBytes, int byteCount)

Decodes the specified bytes and initializes this message. For internal use only.

Parameters
inputBytes The bytes to be decoded.
Throws
SnmpStatusException If the specified bytes are not a valid encoding.

public abstract SnmpPdu decodeSnmpPdu ()

Gets the PDU encoded in this message.

This method decodes the data field and returns the resulting PDU.

Returns
  • The resulting PDU.
Throws
SnmpStatusException If the encoding is not valid.

public SnmpVarBind[] decodeVarBindList (BerDecoder bdec)

For SNMP Runtime private use only.

Throws
BerException

public static 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.

public abstract int encodeMessage (byte[] outputBytes)

Encodes this message and puts the result in the specified byte array. For internal use only.

Parameters
outputBytes An array to receive the resulting encoding.
Throws
ArrayIndexOutOfBoundsException If the result does not fit into the specified array.
SnmpTooBigException

public abstract void encodeSnmpPdu (SnmpPdu pdu, int maxDataLength)

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 into maxDataLength bytes.
ArrayIndexOutOfBoundsException If the encoding exceeds maxDataLength.

public void encodeVarBindList (BerEncoder benc, SnmpVarBind[] varBindList)

For SNMP Runtime private use only.

public static int getProtocolVersion (byte[] data)

Returns the encoded SNMP version present in the passed byte array.

Parameters
data The unmarshalled SNMP message.
Returns
  • The SNMP version (0, 1 or 3).

public abstract int getRequestId (byte[] data)

Returns the associated request ID.

Parameters
data The flat message.
Returns
  • The request ID.

public String printMessage ()

Dumps this message in a string.

Returns
  • The string containing the dump.