Package uk.co.westhawk.snmp.stack
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
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an OID (object identifier) to the PDU.void
Adds an OID (object identifier) to the PDU and the value that has to be set.void
addOid
(AsnObjectId oid) Adds an OID (object identifier) to the PDU.void
addOid
(AsnObjectId oid, AsnObject val) Adds an OID (object identifier) to the PDU and the value that has to be set.void
Adds an OID (object identifier) to the PDU.Returns the context of this PDU.int
Returns the error index.int
Returns the error status as indicated by the error-status field in the reponse PDU.Returns the string representation of the error status.byte
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[]
Returns a copy of the varbinds used to build the request.varbind[]
Returns a copy of the varbinds received in the response.int[]
boolean
Returns whether or not this PDU is timed out, i.e. it did not get a response.void
notifyObservers
(Object arg) Notify all observers.boolean
send()
Sends the PDU.boolean
Deprecated.Community name has moved to SnmpContext.void
setRetryIntervals
(int[] rinterval) Sets the retry intervals of the PDU.toString()
Returns the string representation of the PDU.boolean
This method will wait until the answer is received, instead of continue with other stuff.Methods inherited from class java.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers
-
Constructor Details
-
Pdu
Constructor.- Parameters:
con
- The context of the PDU- See Also:
-
-
Method Details
-
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
Sends the PDU. Note that all properties of the context have to be set before this point.- Throws:
IOException
PduException
-
send
Deprecated.Community name has moved to SnmpContext. UseSnmpContext.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
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
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
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 oidval
- The value- Since:
- 4_12
- See Also:
-
addOid
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 oidval
- The value- Since:
- 4_12
- See Also:
-
addOid
Adds an OID (object identifier) to the PDU.- Parameters:
var
- The varbind- See Also:
-
getRequestVarbinds
Returns a copy of the varbinds used to build the request.- Returns:
- the request varbinds of this PDU.
-
getResponseVarbinds
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 parameterarg
. -
-
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
Returns the string representation 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
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 parameterarg
in theupdate(Observable obs, Object arg)
method.- Overrides:
notifyObservers
in classObservable
- Parameters:
arg
- The argument passed to update, can be a PduException.- Since:
- 4.5
- See Also:
-