Class Pdu

java.lang.Object
java.util.Observable
uk.co.westhawk.snmp.stack.Pdu
Direct Known Subclasses:
GetBulkPdu, GetNextPdu, GetPdu, InformPdu, MultiResponsePdu, ReportPdu, ResponsePdu, SetPdu, TrapPduv1, TrapPduv2

public abstract class Pdu extends Observable
This class represents the ASN PDU object, this is the equivalent of a GetRequest PDU.
Version:
$Revision: 3.33 $ $Date: 2008/12/12 14:55:51 $
Author:
Tim Panton
  • Constructor Details

  • Method Details

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

      If used, please set 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 higher.
      Parameters:
      rinterval - The interval in msec of each retry
    • getRetryIntervals

      public int[] getRetryIntervals()
    • send

      public boolean send() throws IOException, PduException
      Sends the PDU. Note that all properties of the context have to be set before this point.
      Throws:
      IOException
      PduException
    • send

      public boolean send(String com) throws IOException, PduException
      Deprecated.
      Community name has moved to SnmpContext. Use SnmpContext.setCommunity(String).
      Sends 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.
      Throws:
      IOException
      PduException
      See Also:
    • addOid

      public void addOid(String oid)
      Adds an OID (object identifier) to the PDU. The OID indicates which MIB variable we request for or which MIB variable should be set.
      Parameters:
      oid - The oid
      See Also:
    • addOid

      public void addOid(AsnObjectId oid)
      Adds an OID (object identifier) to the PDU. The OID indicates which MIB variable we request for or which MIB variable should be set.
      Parameters:
      oid - The oid
      Since:
      4_12
      See Also:
    • addOid

      public void addOid(String oid, AsnObject val)
      Adds 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

      public void addOid(AsnObjectId oid, AsnObject val)
      Adds 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

      public void addOid(varbind var)
      Adds an OID (object identifier) to the PDU.
      Parameters:
      var - The varbind
      See Also:
    • getRequestVarbinds

      public varbind[] getRequestVarbinds()
      Returns a copy of the varbinds used to build the request.
      Returns:
      the request varbinds of this PDU.
    • 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.
      Returns:
      the response varbinds of this PDU.
      Throws:
      PduException - An agent or decoding exception occurred whilst receiving the response.
      See Also:
    • getReqId

      public int getReqId()
      Returns the request id of the PDU.
      Returns:
      The ID
    • getErrorIndex

      public int getErrorIndex()
      Returns the error index. The error index indicates which of the OIDs went wrong.
      Returns:
      the error index
      See Also:
    • getErrorStatus

      public int getErrorStatus()
      Returns the error status as indicated by the error-status field in the reponse PDU. The error index will indicated which OID caused the error. 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:
    • getErrorStatusString

      public String getErrorStatusString()
      Returns the string representation of the error status.
      Returns:
      the error string
      See Also:
    • 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 as well, so getting a AsnObject.SNMP_ERR_GENERR does not necessarily mean that the request is timed out!

      Returns:
      true is the PDU was timed out
      See Also:
    • waitForSelf

      public boolean waitForSelf()
      This method will wait until the answer is received, instead of continue with other stuff.
    • toString

      public String toString()
      Returns the string representation of the PDU.
      Overrides:
      toString in class Object
      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
    • notifyObservers

      public void notifyObservers(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 Observable
      Parameters:
      arg - The argument passed to update, can be a PduException.
      Since:
      4.5
      See Also: