com.sun.management.snmp
Class SnmpMsg

java.lang.Object
  extended by com.sun.management.snmp.SnmpMsg
All Implemented Interfaces:
SnmpDefinitions
Direct Known Subclasses:
SnmpMessage, SnmpV3Message

public abstract class SnmpMsg
extends Object
implements SnmpDefinitions

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

Since:
Java DMK 5.1

Field Summary
 InetAddress address
          Source or destination address.
 byte[] data
          Encoding of the PDU.
 int dataLength
          Number of useful bytes in the data field.
 int port
          Source or destination port.
 SnmpSecurityParameters securityParameters
          Security parameters.
 int version
          The protocol version.
 
Fields inherited from interface com.sun.management.snmp.SnmpDefinitions
authMask, authNoPriv, authPriv, authPrivMask, CtxtConsFlag, noAuthNoPriv, noGroupName, noSuchContext, noSuchView, notInView, pduGetBulkRequestPdu, pduGetNextRequestPdu, pduGetRequestPdu, pduGetResponsePdu, pduInformRequestPdu, pduReportPdu, pduSetRequestPdu, pduV1TrapPdu, pduV2TrapPdu, pduWalkRequest, privMask, reportableFlag, snmpAuthNotSupported, snmpBadSecurityLevel, snmpPrivNotSupported, snmpReqAborted, snmpReqEncodingError, snmpReqHandleTooBig, snmpReqInternalError, snmpReqPacketOverflow, snmpReqRefireAfterVbFix, snmpReqSocketIOError, snmpReqTimeout, snmpReqTooBigImpossible, snmpReqUnknownError, snmpRspAuthorizationError, snmpRspBadValue, snmpRspCommitFailed, snmpRspDecodingError, snmpRspEndOfTable, snmpRspGenErr, snmpRspInconsistentName, snmpRspInconsistentValue, snmpRspNoAccess, snmpRspNoCreation, snmpRspNoError, snmpRspNoSuchName, snmpRspNotWritable, snmpRspReadOnly, snmpRspResourceUnavailable, snmpRspTooBig, snmpRspUndoFailed, snmpRspWrongEncoding, snmpRspWrongLength, snmpRspWrongType, snmpRspWrongValue, snmpUnknownPrincipal, snmpUsmBadEngineId, snmpUsmInvalidTimeliness, snmpUsmSecurityModel, snmpV1AccessControlModel, snmpV1MsgProcessingModel, snmpV1SecurityModel, snmpV2AccessControlModel, snmpV2MsgProcessingModel, snmpV2SecurityModel, snmpV3AccessControlModel, snmpV3MsgProcessingModel, snmpVersionOne, snmpVersionThree, snmpVersionTwo, snmpWrongSnmpVersion, trapAuthenticationFailure, trapColdStart, trapEgpNeighborLoss, trapEnterpriseSpecific, trapLinkDown, trapLinkUp, trapWarmStart
 
Constructor Summary
SnmpMsg()
           
 
Method Summary
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 Java DMK 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 Java DMK 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.
 
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.
decodeSnmpPdu and encodeSnmpPdu only accept the values 0 (for SNMPv1), 1 (for SNMPv2) and 3 (for SNMPv3).


data

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).


dataLength

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


address

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


securityParameters

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

Constructor Detail

SnmpMsg

public SnmpMsg()
Method Detail

getProtocolVersion

public static int getProtocolVersion(byte[] data)
                              throws SnmpStatusException
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).
Throws:
SnmpStatusException

getRequestId

public abstract int getRequestId(byte[] data)
                          throws SnmpStatusException
Returns the associated request ID.

Parameters:
data - The flat message.
Returns:
The request ID.
Throws:
SnmpStatusException

encodeMessage

public abstract int encodeMessage(byte[] outputBytes)
                           throws SnmpTooBigException
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

decodeMessage

public abstract void decodeMessage(byte[] inputBytes,
                                   int byteCount)
                            throws SnmpStatusException
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.

encodeSnmpPdu

public abstract void encodeSnmpPdu(SnmpPdu 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 into maxDataLength bytes.
ArrayIndexOutOfBoundsException - If the encoding exceeds maxDataLength.

decodeSnmpPdu

public abstract SnmpPdu decodeSnmpPdu()
                               throws SnmpStatusException
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.

dumpHexBuffer

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.

printMessage

public String printMessage()
Dumps this message in a string.

Returns:
The string containing the dump.

encodeVarBindList

public void encodeVarBindList(BerEncoder benc,
                              SnmpVarBind[] varBindList)
                       throws SnmpStatusException,
                              SnmpTooBigException
For Java DMK private use only.

Throws:
SnmpStatusException
SnmpTooBigException

decodeVarBindList

public SnmpVarBind[] decodeVarBindList(BerDecoder bdec)
                                throws BerException
For Java DMK private use only.

Throws:
BerException

Open Source build 02
opendmk-1.0-b02 2007.10.01_19:17:46_MEST

Copyright 1998-2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.