OpenNMS API 1.2.9

## org.opennms.protocols.snmp
Class SnmpPduPacket

    java.lang.Object
      org.opennms.protocols.snmp.SnmpPduPacket

All Implemented Interfaces:
  java.lang.Cloneable, SnmpSyntax

Direct Known Subclasses:
  SnmpPduBulk, SnmpPduRequest

public abstract class SnmpPduPacket
extends java.lang.Object
implements SnmpSyntax, java.lang.Cloneable

Base class for all Protocol Data Unit (PDU) implementations. The class defines methods to handle most v1 and v2 implementation of SNMP with only minor work needed by the derived class.

Version:
  1.1.1.1
Author:
  Brian Weaver
See Also:
  `SnmpPduRequest`, `SnmpPduBulk`

Field Summary
`static int` `ErrAuthorizationError` The authorization failed.
`static int` `ErrBadValue` If the object type does not match the object value in the agent's tables.
`static int` `ErrCommitFailed` Unable to commit the required values.
`static int` `ErrGenError` A generic SNMPv1 error occured.
`static int` `ErrInconsistentName` The passed object identifier is not consistent.
`static int` `ErrInconsistentValue` The specified value are not consistant.
`static int` `ErrNoAccess` The specified SET request could not access the specified instance.
`static int` `ErrNoCreation` The manager does not have the permission to create the specified object(s).
`static int` `ErrNoError` No error occured in the request.
`static int` `ErrNoSuchName` There was no such object identifier defined in the agent's tables.
`static int` `ErrNotWritable` The specified instance or table is not writable
`static int` `ErrReadOnly` Attempting to set a read-only object in the agent's tables.
`static int` `ErrResourceUnavailable` The requested resource are not available.
`static int` `ErrTooBig` The PDU was too large for the agent to process
`static int` `ErrUndoFailed` Unable to perform the undo request
`static int` `ErrWrongEncoding` The specified object is not correctly encoded.
`static int` `ErrWrongLength` The specified object is not the correct length.
`static int` `ErrWrongType` The specified object is not the correct type.
`static int` `ErrWrongValue` The specified object doe not have the correct value.
`static int` `GET` Defines a SNMPv1 Get Request PDU message.
`static int` `GETBULK` Defines a SNMPv2 Get Bulk Request message.
`static int` `GETNEXT` Defines a SNMPv1 Get Next Request PDU message.
`static int` `INFORM` Defines a SNMPv2 Inform Request message
`private int` `m_command` The SNMP command for the pdu.
`protected int` `m_errIndex` The error index in a normal pdu, it is used as the maximum repititions in the get bulk pdu.
`protected int` `m_errStatus` The error status in a normal pdu, is is used as the non-repeaters in the getbulk.
`private SnmpPeer` `m_peer` The peer of this packet, if we are agent
`private int` `m_requestId` The request id for this specific packet.
`private java.util.ArrayList` `m_variables` The list of variables for this particular PDU.
`static int` `REPORT` Defines a SNMPv2 Report message.
`static int` `RESPONSE` Defines a SNMPv1 Response PDU message.
`static int` `SET` Defines a SNMPv1 PDU Set Request message.
`private static int` `sm_seq` The static variable for the class.
`static int` `V2TRAP` Defines a SNMPv2 Trap message

Constructor Summary
`protected` `SnmpPduPacket()` Default class constructor.
`protected` `SnmpPduPacket(int command)` creates a new pdu with the command set to the passed value.
`protected` `SnmpPduPacket(int command, SnmpVarBind[] vars)` Creates a new pdu with the spcified command and the list of variables.
`protected` `SnmpPduPacket(SnmpPduPacket second)` Class copy constructor.

Method Summary
`void` `addVarBind(SnmpVarBind vb)` Adds a new variable to the protocol data unit.
`void` `addVarBindAt(int ndx, SnmpVarBind vb)` Adds a variable at a specific index.
`abstract java.lang.Object` `clone()` Defined for derived classes to return a duplicate of self.
`int` `decodeASN(byte[] buf, int offset, AsnEncoder encoder)` Decodes the protocol data unit from the passed buffer.
`abstract SnmpSyntax` `duplicate()` Defined for derived classes to return a duplicate of self.
`int` `encodeASN(byte[] buf, int offset, AsnEncoder encoder)` Encodes the protocol data unit using the passed encoder and stores the results in the passed buffer.
`int` `getCommand()` Returns the type of PDU.
`int` `getLength()` /** Returns the number of variables in the data unit.
`SnmpPeer` `getPeer()` Returns the current peer for this packet.
`int` `getRequestId()` Returns the current request id for this packet.
`SnmpVarBind` `getVarBindAt(int ndx)` Retrieves the variable at the specific index.
`static int` `nextSequence()` Use to sequence the all pdu request across the entire library.
`SnmpVarBind` `removeVarBindAt(int ndx)` Removes the variable as defined by the index
`void` `setCommand(int cmd)` Sets the PDU's current command
`void` `setPeer(SnmpPeer peer)` Sets the Peer for the Packet
`void` `setRequestId(int reqid)` Sets the protocol data unit's sequence identifer
`void` `setVarBindAt(int ndx, SnmpVarBind vb)` Sets the specific variable at the requested location.
`SnmpVarBind[]` `toVarBindArray()` Returns a list of all the variables managed by this protocol data unit.
`byte` `typeId()` Returns the PDU commmand in an 8-bit format

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### sm_seq

    private static int sm_seq

  The static variable for the class. This variable is used to get a "unique" sequence number for each PDU

### m_command

    private int m_command

  The SNMP command for the pdu. See the list of command later on in the module for more information.

  See Also:
    `GET`, `GETNEXT`, `SET`, `RESPONSE`, `INFORM`, `REPORT`, `GETBULK`

### m_requestId

    private int m_requestId

  The request id for this specific packet.

### m_peer

    private SnmpPeer m_peer

  The peer of this packet, if we are agent

### m_variables

    private java.util.ArrayList m_variables

  The list of variables for this particular PDU. The list may be quite large so long as the packet can be received by the remote appliction

### m_errStatus

    protected int m_errStatus

  The error status in a normal pdu, is is used as the non-repeaters in the getbulk.

  See Also:
    `SnmpPduRequest`, `SnmpPduBulk`

### m_errIndex

    protected int m_errIndex

  The error index in a normal pdu, it is used as the maximum repititions in the get bulk pdu.

  See Also:
    `SnmpPduRequest`, `SnmpPduBulk`

### GET

    public static final int GET

  Defines a SNMPv1 Get Request PDU message.

  See Also:
    Constant Field Values

### GETNEXT

    public static final int GETNEXT

  Defines a SNMPv1 Get Next Request PDU message.

  See Also:
    Constant Field Values

### RESPONSE

    public static final int RESPONSE

  Defines a SNMPv1 Response PDU message.

  See Also:
    Constant Field Values

### SET

    public static final int SET

  Defines a SNMPv1 PDU Set Request message. The set request uses the write-only string from the session. All others use the read-only community string.

  See Also:
    Constant Field Values

### GETBULK

    public static final int GETBULK

  Defines a SNMPv2 Get Bulk Request message.

  See Also:
    Constant Field Values

### INFORM

    public static final int INFORM

  Defines a SNMPv2 Inform Request message

  See Also:
    Constant Field Values

### V2TRAP

    public static final int V2TRAP

  Defines a SNMPv2 Trap message

  See Also:
    Constant Field Values

### REPORT

    public static final int REPORT

  Defines a SNMPv2 Report message.

  See Also:
    Constant Field Values

### ErrNoError

    public static final int ErrNoError

  No error occured in the request. Also known as a successful request.

  See Also:
    Constant Field Values

### ErrTooBig

    public static final int ErrTooBig

  The PDU was too large for the agent to process

  See Also:
    Constant Field Values

### ErrNoSuchName

    public static final int ErrNoSuchName

  There was no such object identifier defined in the agent's tables.

  See Also:
    Constant Field Values

### ErrBadValue

    public static final int ErrBadValue

  If the object type does not match the object value in the agent's tables.

  See Also:
    Constant Field Values

### ErrReadOnly

    public static final int ErrReadOnly

  Attempting to set a read-only object in the agent's tables.

  See Also:
    Constant Field Values

### ErrGenError

    public static final int ErrGenError

  A generic SNMPv1 error occured.

  See Also:
    Constant Field Values

### ErrNoAccess

    public static final int ErrNoAccess

  The specified SET request could not access the specified instance.

  See Also:
    Constant Field Values

### ErrWrongType

    public static final int ErrWrongType

  The specified object is not the correct type.

  See Also:
    Constant Field Values

### ErrWrongLength

    public static final int ErrWrongLength

  The specified object is not the correct length.

  See Also:
    Constant Field Values

### ErrWrongEncoding

    public static final int ErrWrongEncoding

  The specified object is not correctly encoded.

  See Also:
    Constant Field Values

### ErrWrongValue

    public static final int ErrWrongValue

  The specified object doe not have the correct value.

  See Also:
    Constant Field Values

### ErrNoCreation

    public static final int ErrNoCreation

  The manager does not have the permission to create the specified object(s).

  See Also:
    Constant Field Values

### ErrInconsistentValue

    public static final int ErrInconsistentValue

  The specified value are not consistant.

  See Also:
    Constant Field Values

### ErrResourceUnavailable

    public static final int ErrResourceUnavailable

  The requested resource are not available.

  See Also:
    Constant Field Values

### ErrCommitFailed

    public static final int ErrCommitFailed

  Unable to commit the required values.

  See Also:
    Constant Field Values

### ErrUndoFailed

    public static final int ErrUndoFailed

  Unable to perform the undo request

  See Also:
    Constant Field Values

### ErrAuthorizationError

    public static final int ErrAuthorizationError

  The authorization failed.

  See Also:
    Constant Field Values

### ErrNotWritable

    public static final int ErrNotWritable

  The specified instance or table is not writable

  See Also:
    Constant Field Values

### ErrInconsistentName

    public static final int ErrInconsistentName

  The passed object identifier is not consistent.

  See Also:
    Constant Field Values

Constructor Detail

### SnmpPduPacket

    protected SnmpPduPacket()

  Default class constructor. Initialzies all primitive members to zero, and allocates a new array list for the variables.

### SnmpPduPacket

    protected SnmpPduPacket(SnmpPduPacket second)

  Class copy constructor. Constructs the object with all the same values as the passed packet. The variables are duplicated into a new array so that changes to the source pdu will not affect the newly create pdu.

Parameters:
  `second` - The source pdu to copy values from.

### SnmpPduPacket

    protected SnmpPduPacket(int command)

  creates a new pdu with the command set to the passed value.

Parameters:
  `command` - The type of pdu packet.

### SnmpPduPacket

    protected SnmpPduPacket(int command,
                            SnmpVarBind[] vars)

  Creates a new pdu with the spcified command and the list of variables.

Parameters:
  `command` - The type of pdu packet.
  `vars` - The variable list for the pdu.

Method Detail

### nextSequence

    public static int nextSequence()

  Use to sequence the all pdu request across the entire library. If the sequence id is equal to zero then a random number generator is created and is used to seed the sequence.

  Returns:
    The new sequnce identifier

### getCommand

    public int getCommand()

  Returns the type of PDU.

  Returns:
    The current PDU command

### setCommand

    public void setCommand(int cmd)

  Sets the PDU's current command

  Parameters:
    `cmd` - The new command.

### getRequestId

    public int getRequestId()

  Returns the current request id for this packet.

  Returns:
    The sequence identifier

### setPeer

    public void setPeer(SnmpPeer peer)

  Sets the Peer for the Packet

  Parameters:
    `peer` - The peer of this packet

### getPeer

    public SnmpPeer getPeer()

  Returns the current peer for this packet.

  Returns:
    The peer or null, if its a own request

### setRequestId

    public void setRequestId(int reqid)

  Sets the protocol data unit's sequence identifer

  Parameters:
    `reqid` - The new request id

### getLength

    public int getLength()

  /** Returns the number of variables in the data unit.

  Returns:
    The number of variables.

### addVarBind

    public void addVarBind(SnmpVarBind vb)

  Adds a new variable to the protocol data unit. The variable is added at the end of the list

  Parameters:
    `vb` - The new variable to add

### addVarBindAt

    public void addVarBindAt(int ndx,
                             SnmpVarBind vb)

  Adds a variable at a specific index.

  Parameters:
    `ndx` - The index of the variable
    `vb` - The new variable.

### getVarBindAt

    public SnmpVarBind getVarBindAt(int ndx)

  Retrieves the variable at the specific index.

  Parameters:
    `ndx` - The index of the variable
  Returns:
    The variable at the specified index

### setVarBindAt

    public void setVarBindAt(int ndx,
                             SnmpVarBind vb)

  Sets the specific variable at the requested location.

  Parameters:
    `ndx` - The location to set
    `vb` - The new variable

### removeVarBindAt

    public SnmpVarBind removeVarBindAt(int ndx)

  Removes the variable as defined by the index

  Parameters:
    `ndx` - The index of the variable to remove
  Returns:
    The removed variable

### toVarBindArray

    public SnmpVarBind[] toVarBindArray()

  Returns a list of all the variables managed by this protocol data unit.

  Returns:
    An array of the internal variable.

### typeId

    public byte typeId()

  Returns the PDU commmand in an 8-bit format

  Specified by:
    `typeId` in interface `SnmpSyntax`
  Returns:
    The pdu command

### encodeASN

    public int encodeASN(byte[] buf,
                         int offset,
                         AsnEncoder encoder)
                  throws AsnEncodingException

  Encodes the protocol data unit using the passed encoder and stores the results in the passed buffer. An exception is thrown if an error occurs with the encoding of the information.

  Specified by:
    `encodeASN` in interface `SnmpSyntax`
  Parameters:
    `buf` - The buffer to write the encoded information.
    `offset` - The offset to start writing information
    `encoder` - The encoder object.
  Returns:
    The offset of the byte immediantly after the last encoded byte.
  Throws:
    `AsnEncodingException` - Thrown if the encoder finds an error in the buffer.

### decodeASN

    public int decodeASN(byte[] buf,
                         int offset,
                         AsnEncoder encoder)
                  throws AsnDecodingException

  Decodes the protocol data unit from the passed buffer. If an error occurs during the decoding sequence then an AsnDecodingException is thrown by the method. The value is decoded using the AsnEncoder passed to the object.

  Specified by:
    `decodeASN` in interface `SnmpSyntax`
  Parameters:
    `buf` - The encode buffer
    `offset` - The offset byte to begin decoding
    `encoder` - The decoder object.
  Returns:
    The index of the byte immediantly after the last decoded byte of information.
  Throws:
    `AsnDecodingException` - Thrown by the encoder if an error occurs trying to decode the data buffer.

### duplicate

    public abstract SnmpSyntax duplicate()

  Defined for derived classes to return a duplicate of self. This method not defined.

  Specified by:
    `duplicate` in interface `SnmpSyntax`

### clone

    public abstract java.lang.Object clone()

  Defined for derived classes to return a duplicate of self. This method not defined.

OpenNMS API 1.2.9

Generated by ranger on May 19 2007 2335.