Overview | Package | Class | Tree | Deprecated | Index | Help
| SNMP Stack 4_12
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## uk.co.westhawk.snmp.stack
Class Pdu

    java.lang.Object
      |
      +--java.util.Observable
            |
            +--uk.co.westhawk.snmp.stack.Pdu

Direct Known Subclasses:
  DiscoveryPdu, GetBulkPdu, GetNextPdu, GetPdu_vec, InformPdu, InterfacePdu, OneGetPdu, OneIntPdu, SetPdu, TrapPduv1, TrapPduv2, UpSincePdu

public abstract class Pdu
extends java.util.Observable

This class represents the ASN Pdu object, this is the equivalent of a GetRequest Pdu.

Version:
  $Revision: 3.25 $ $Date: 2002/10/23 09:48:01 $
Author:
  Tim Panton

Field Summary
`protected boolean` | `added`
`protected boolean` | `answered`
`protected SnmpContextBasisFace` | `context`
`protected byte[]` | `encodedPacket`
`protected int` | `errind`
`protected int` | `errstat`
`protected byte` | `msg_type`
`protected java.util.Vector` | `reqVarbinds`
`protected java.util.Vector` | `respVarbinds`

Constructor Summary
`Pdu(SnmpContextBasisFace con)` Constructor.

Method Summary
`void` | `addOid(AsnObjectId oid)` Add an OID (object identifier) to the Pdu.
`void` | `addOid(AsnObjectId oid, AsnObject val)` Add an OID (object identifier) to the Pdu and the value that has to be set.
`void` | `addOid(java.lang.String oid)` Add an OID (object identifier) to the Pdu.
`void` | `addOid(java.lang.String oid, AsnObject val)` Add an OID (object identifier) to the Pdu and the value that has to be set.
`void` | `addOid(varbind var)` Add an OID (object identifier) to the Pdu.
`protected void` | `addToTrans()` Adds the Pdu to its transmitter.
`SnmpContextBasisFace` | `getContext()` Returns the context of this pdu.
`int` | `getErrorIndex()` Returns the error index.
`int` | `getErrorStatus()` Returns the error status as indicated by the error-status field in the reponse pdu.
`java.lang.String` | `getErrorStatusString()` Returns the string representation of the error status.
`byte` | `getMsgType()` Returns the message type, this will indicate what kind of request we are dealing with.
`int` | `getReqId()` Returns the request id of the Pdu.
`varbind[]` | `getRequestVarbinds()` Returns a copy of the varbinds used to build the request.
`varbind[]` | `getResponseVarbinds()` Returns a copy of the varbinds received in the response.
`boolean` | `isTimedOut()` Returns whether or not this Pdu is timed out, i.e.
`protected abstract void` | `new_value(int n, varbind res)` The value of the request is set.
`void` | `notifyObservers(java.lang.Object arg)` Notify all observers.
`boolean` | `send()` Send the Pdu.
`protected boolean` | `send(int error_status, int error_index)` Send the Pdu.
`boolean` | `send(java.lang.String com)` Deprecated. Community name has moved to SnmpContext. Use send().
`protected boolean` | `sendme()` Sends the actual packet and updates the retries.
`protected void` | `setErrorIndex(int ind)` Sets the error index, this indicates which of the OIDs went wrong.
`protected void` | `setErrorStatus(int err)` Sets the error status, indicating what went wrong.
`protected void` | `setErrorStatus(int err, PduException exc)` Sets the error status and the exception, indicating what went wrong.
`protected void` | `setMsgType(byte type)` Sets the message type, this will indicate what kind of request we are dealing with.
`void` | `setRetryIntervals(int[] rinterval)` Sets the retry intervals of the Pdu.
`protected abstract void` | `tell_them()` The methods notifies all observers.
`java.lang.String` | `toString()` Returns the string representation of the Pdu.
`protected java.lang.String` | `toString(boolean withRespVars)` Returns the string representation of the Pdu with or without the response varbinds.
`boolean` | `waitForSelf()` This method will wait until the answer is received, instead of continue with other stuff.

Methods inherited from class java.util.Observable
`addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, setChanged`

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

Field Detail

### reqVarbinds

    protected java.util.Vector reqVarbinds

### respVarbinds

    protected java.util.Vector respVarbinds

### encodedPacket

    protected byte[] encodedPacket

### context

    protected SnmpContextBasisFace context

### added

    protected boolean added

### msg_type

    protected byte msg_type

### errstat

    protected int errstat

### errind

    protected int errind

### answered

    protected boolean answered

Constructor Detail

### Pdu

    public Pdu(SnmpContextBasisFace con)

  Constructor.
  Parameters:
    `con` - The context of the Pdu
  See Also:
    `SnmpContext`, `SnmpContextv2c`, `SnmpContextv3`

Method Detail

### new_value

    protected abstract void new_value(int n,
                                      varbind res)

  The value of the request is set. This will be called by Pdu.fillin().

### tell_them

    protected abstract void tell_them()

  The methods notifies all observers. This will be called by Pdu.fillin().

  The Object to the update() method of the Observer will be a varbind, unless an exception occurred. In the case of an exception, that exception will be passed. So watch out casting!

### getContext

    public SnmpContextBasisFace getContext()

  Returns the context of this pdu.
  Returns:
    The context

### setRetryIntervals

    public void setRetryIntervals(int[] rinterval)

  Sets the retry intervals of the Pdu. The length of the array corresponds with the number of retries. Each entry in the array is the number of milliseconds of each try. Please use this method before sending. The default is {500, 1000, 2000, 5000, 5000}. It is good practice to make the interval bigger with each retry, if the numbers are the same the chance of collision is bigger.
  Parameters:
    `rinterval` - The interval in msec of each retry

### send

    public boolean send()
                 throws java.io.IOException,
                        PduException

  Send the Pdu. Note that all properties of the context have to be set before this point.

### send

    protected boolean send(int error_status,
                           int error_index)
                    throws java.io.IOException,
                           PduException

  Send the Pdu. This method accommodates the GetBulk request.
  Parameters:
    `error_status` - The value of the error_status field.
    `error_index` - The value of the error_index field.
  See Also:
    `send()`

### addToTrans

    protected void addToTrans()

  Adds the Pdu to its transmitter. The transmitter is the thread that will send the Pdu and then waits for the answer.
  See Also:
    `send()`

### sendme

    protected boolean sendme()

  Sends the actual packet and updates the retries.
  See Also:
    `AbstractSnmpContext.sendPacket(byte[] p)`

### send

    public boolean send(java.lang.String com)
                 throws java.io.IOException,
                        PduException

  Deprecated. Community name has moved to SnmpContext. Use send().

  Send the Pdu. For backwards compatibility only. Please use send() instead. The community name will be passed to the SnmpContext. If using SnmpContextv3, the community name will be ignored.
  Parameters:
    `com` - The community name of the Pdu in SNMPv1 and SNMPv2c.
  See Also:
    `SnmpContext.setCommunity(java.lang.String)`, `send()`

### addOid

    public void addOid(java.lang.String oid)

  Add an OID (object identifier) to the Pdu. The OID indicates WHAT MIB variable we request for or WHAT MIB variable should be set.
  Parameters:
    `oid` - The oid
  See Also:
    `addOid(varbind)`, `varbind`

### addOid

    public void addOid(AsnObjectId oid)

  Add an OID (object identifier) to the Pdu. The OID indicates WHAT MIB variable we request for or WHAT MIB variable should be set.
  Parameters:
    `oid` - The oid
  Since:
    4_12
  See Also:
    `addOid(varbind)`, `varbind`

### addOid

    public void addOid(java.lang.String oid,
                       AsnObject val)

  Add an OID (object identifier) to the Pdu and the value that has to be set. This method has moved from SetPdu to this class in version 4_12.
  Parameters:
    `oid` - The oid
    `val` - The value
  Since:
    4_12
  See Also:
    `addOid(java.lang.String)`, `varbind`

### addOid

    public void addOid(AsnObjectId oid,
                       AsnObject val)

  Add an OID (object identifier) to the Pdu and the value that has to be set.

  Thanks to Eli Bishop (eli@graphesthesia.com) for the suggestion.

  Parameters:
    `oid` - The oid
    `val` - The value
  Since:
    4_12
  See Also:
    `addOid(java.lang.String)`, `varbind`

### addOid

    public void addOid(varbind var)

  Add an OID (object identifier) to the Pdu.
  Parameters:
    `var` - The varbind
  See Also:
    `addOid(String)`

### getRequestVarbinds

    public varbind[] getRequestVarbinds()

  Returns a copy of the varbinds used to build the request.

### getResponseVarbinds

    public varbind[] getResponseVarbinds()
                                  throws PduException

  Returns a copy of the varbinds received in the response. If there was no response (yet), null will be returned.
  Throws:
    `PduException` - An agent or decoding exception occurred whilst receiving the response.
  See Also:
    `getErrorStatus()`, `notifyObservers(java.lang.Object)`

### getReqId

    public int getReqId()

  Returns the request id of the Pdu.
  Returns:
    The ID

### getErrorIndex

    public int getErrorIndex()

  Returns the error index.
  Returns:
    the error index
  See Also:
    `getErrorStatus()`

### getErrorStatus

    public int getErrorStatus()

  Returns the error status as indicated by the error-status field in the reponse pdu. In case of a decoding exception the error status will be set to one of the decoding errors:
  - `SnmpConstants.SNMP_ERR_DECODING_EXC`.
  - `SnmpConstants.SNMP_ERR_DECODINGASN_EXC`.
  - `SnmpConstants.SNMP_ERR_DECODINGPKTLNGTH_EXC`.

  The actual exception will be passed to your `update(Observable ob, Object arg)` method via the the parameter `arg`.

  Returns:
    the error status
  See Also:
    `notifyObservers(java.lang.Object)`, `getResponseVarbinds()`, `SnmpConstants.SNMP_ERR_NOERROR`, `SnmpConstants.SNMP_ERR_DECODING_EXC`, `SnmpConstants.SNMP_ERR_DECODINGASN_EXC`, `SnmpConstants.SNMP_ERR_DECODINGPKTLNGTH_EXC`, `getErrorStatusString()`

### getErrorStatusString

    public java.lang.String getErrorStatusString()

  Returns the string representation of the error status.
  Returns:
    the error string
  See Also:
    `getErrorStatus()`

### isTimedOut

    public boolean isTimedOut()

  Returns whether or not this Pdu is timed out, i.e. it did not get a response. Its errorStatus will be set to AsnObject.SNMP_ERR_GENERR . Note that a SNMP agent can respond with an errorStatus of AsnObject.SNMP_ERR_GENERR.
  Returns:
    true is the Pdu was timed out
  See Also:
    `getErrorStatus()`, `SnmpConstants.SNMP_ERR_GENERR`

### waitForSelf

    public boolean waitForSelf()

  This method will wait until the answer is received, instead of continue with other stuff.

### toString

    public java.lang.String toString()

  Returns the string representation of the Pdu.
  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    The string of the Pdu

### toString

    protected java.lang.String toString(boolean withRespVars)

  Returns the string representation of the Pdu with or without the response varbinds.
  Parameters:
    `withRespVars` - Include the response varbinds or not
  Returns:
    The string of the Pdu

### getMsgType

    public byte getMsgType()

  Returns the message type, this will indicate what kind of request we are dealing with. By default it will be set to the GET_REQ_MSG
  Returns:
    The message type

### setMsgType

    protected void setMsgType(byte type)

  Sets the message type, this will indicate what kind of request we are dealing with. By default it will be set to the GET_REQ_MSG
  Parameters:
    `type` - The message type

### setErrorStatus

    protected void setErrorStatus(int err)

  Sets the error status, indicating what went wrong.
  Parameters:
    `err` - the error status
  See Also:
    `getErrorIndex()`, `getErrorStatusString()`, `getErrorStatus()`

### setErrorStatus

    protected void setErrorStatus(int err,
                                  PduException exc)

  Sets the error status and the exception, indicating what went wrong.
  Parameters:
    `err` - the error status
    `exc` - the Pdu Exception that was thrown whilst decoding
  See Also:
    `getErrorIndex()`, `getErrorStatusString()`, `getErrorStatus()`

### setErrorIndex

    protected void setErrorIndex(int ind)

  Sets the error index, this indicates which of the OIDs went wrong.
  Parameters:
    `ind` - the error index
  See Also:
    `setErrorStatus(int)`, `getErrorIndex()`

### notifyObservers

    public void notifyObservers(java.lang.Object arg)

  Notify all observers. If a decoding exception had occurred, the argument will be replaced with the exception.

  In the case of an exception, the error status will be set to one of the decoding errors (see `getErrorStatus`) and passed as the parameter `arg` in the `update(Observable obs, Object arg)` method.

  Overrides:
    `notifyObservers` in class `java.util.Observable`
  Parameters:
    `arg` - The argument passed to update, can be a PduException.
  Since:
    4.5
  See Also:
    `SnmpConstants.SNMP_ERR_DECODING_EXC`, `getErrorStatus()`, `getResponseVarbinds()`

Overview | Package | Class | Tree | Deprecated | Index | Help
| SNMP Stack 4_12
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD