public abstract class Pdu
extends java.util.Observable
Modifier and Type | Field and Description |
---|---|
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 |
protected java.lang.Integer |
snmpv3MsgId |
Constructor and Description |
---|
Pdu(SnmpContextBasisFace con)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
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 |
addOid(java.lang.String oid)
Adds an OID (object identifier) to the PDU.
|
void |
addOid(java.lang.String oid,
AsnObject val)
Adds an OID (object identifier) to the PDU and the value that has
to be set.
|
void |
addOid(varbind var)
Adds 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.
|
int[] |
getRetryIntervals() |
protected boolean |
isExpectingResponse()
Returns whether or not this type of PDU is expecting some kind of response.
|
boolean |
isTimedOut()
Returns whether or not this PDU is timed out, i.e. it did not get
a response.
|
protected void |
new_value(int n,
varbind res)
The value of the response is set.
|
void |
notifyObservers(java.lang.Object arg)
Notify all observers.
|
protected java.lang.StringBuffer |
printVars(java.lang.String title,
java.util.Vector vars)
Returns the string representation of the varbinds of the PDU.
|
boolean |
send()
Sends the PDU.
|
protected boolean |
send(int error_status,
int error_index)
Sends the PDU.
|
boolean |
send(java.lang.String com)
Deprecated.
Community name has moved to SnmpContext. Use
SnmpContext.setCommunity(String) . |
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 void |
tell_them()
This method 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.
|
protected java.util.Vector reqVarbinds
protected java.util.Vector respVarbinds
protected byte[] encodedPacket
protected SnmpContextBasisFace context
protected boolean added
protected byte msg_type
protected java.lang.Integer snmpv3MsgId
protected int errstat
protected int errind
protected boolean answered
public Pdu(SnmpContextBasisFace con)
con
- The context of the PDUSnmpContext
,
SnmpContextv2c
,
SnmpContextv3
protected void new_value(int n, varbind res)
protected void tell_them()
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!
public SnmpContextBasisFace getContext()
public void setRetryIntervals(int[] rinterval)
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.rinterval
- The interval in msec of each retrypublic int[] getRetryIntervals()
public boolean send() throws java.io.IOException, PduException
java.io.IOException
PduException
protected boolean send(int error_status, int error_index) throws java.io.IOException, PduException
error_status
- The value of the error_status field.error_index
- The value of the error_index field.java.io.IOException
PduException
send()
protected void addToTrans()
send()
protected boolean sendme()
AbstractSnmpContext.sendPacket(byte[] p)
public boolean send(java.lang.String com) throws java.io.IOException, PduException
SnmpContext.setCommunity(String)
.com
- The community name of the PDU in SNMPv1 and SNMPv2c.java.io.IOException
PduException
SnmpContext.setCommunity(java.lang.String)
,
send()
public void addOid(java.lang.String oid)
oid
- The oidaddOid(varbind)
,
varbind
public void addOid(AsnObjectId oid)
oid
- The oidaddOid(varbind)
,
varbind
public void addOid(java.lang.String oid, AsnObject val)
oid
- The oidval
- The valueaddOid(java.lang.String)
,
varbind
public void addOid(AsnObjectId oid, AsnObject val)
Thanks to Eli Bishop (eli@graphesthesia.com) for the suggestion.
oid
- The oidval
- The valueaddOid(java.lang.String)
,
varbind
public void addOid(varbind var)
var
- The varbindaddOid(String)
public varbind[] getRequestVarbinds()
public varbind[] getResponseVarbinds() throws PduException
PduException
- An agent or decoding exception occurred
whilst receiving the response.getErrorStatus()
,
notifyObservers(java.lang.Object)
public int getReqId()
public int getErrorIndex()
getErrorStatus()
public int getErrorStatus()
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
.
public java.lang.String getErrorStatusString()
getErrorStatus()
public boolean isTimedOut()
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!
getErrorStatus()
,
SnmpConstants.SNMP_ERR_GENERR
public boolean waitForSelf()
public java.lang.String toString()
toString
in class java.lang.Object
protected java.lang.String toString(boolean withRespVars)
withRespVars
- Include the response varbinds or notprotected java.lang.StringBuffer printVars(java.lang.String title, java.util.Vector vars)
toString(boolean)
public byte getMsgType()
protected void setMsgType(byte type)
type
- The message typeprotected void setErrorStatus(int err)
err
- the error statusgetErrorIndex()
,
getErrorStatusString()
,
getErrorStatus()
protected void setErrorStatus(int err, PduException exc)
err
- the error statusexc
- the PDU Exception that was thrown whilst decodinggetErrorIndex()
,
getErrorStatusString()
,
getErrorStatus()
protected void setErrorIndex(int ind)
ind
- the error indexsetErrorStatus(int)
,
getErrorIndex()
protected boolean isExpectingResponse()
public void notifyObservers(java.lang.Object arg)
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.
notifyObservers
in class java.util.Observable
arg
- The argument passed to update, can be a PduException.SnmpConstants.SNMP_ERR_DECODING_EXC
,
getErrorStatus()
,
getResponseVarbinds()