com.adventnet.snmp.snmp2
Class SnmpPDU

java.lang.Object
  |
  +--com.adventnet.snmp.snmp2.SnmpPDU
All Implemented Interfaces:
java.io.Serializable

public class SnmpPDU
extends java.lang.Object
implements java.io.Serializable

The SnmpPDU class represents the SNMP PDU used in protocol operations.

Any SNMP operation can be performed using this class.

The following should be set on it before performing any SNMP operation:
1. The SNMP command. It may be SnmpAPI.GET_REQ_MSG or SnmpAPI.SET_REQ_MSG or SnmpAPI.GETNEXT_REQ_MSG
2. The SnmpVarBinds that should be present in this PDU.
3. The network communication variables such as remoteHost and remotePort ( in case of UDP ). This is not needed if it is already present in SnmpSession. But it is always good to set it on pdu rather than on SnmpSession.

The following code snippet will give a clear idea of how to do a SNMP operation using this class:
This code snippet does a simple SNMP GET request for the oid ".1.3.6.1.2.1.1.1.0", to the host "remoteHost" and port "remotePort".

SnmpPDU pdu = new SnmpPDU();
pdu.setCommand(SnmpAPI.GET_REQ_MSG);
pdu.addNull(new SnmpOID(".1.3.6.1.2.1.1.1.0"));

If the under lying protocol that is used is UDP, then an instance of UDPProtocolOptions should be instantiated to set the remotePort and remoteHost variables.
Note: By default AdventNet SNMP Stack uses UDP as the underlying protocol.
If SAS is used for communications, then an instance of SASProtocolOptions should be instantiated to set the remotePort and remoteHost.

UDPProtocolOptions opt = new UDPProtocolOptions();
opt.setRemoteHost(remoteHost);
opt.setRemotePort(remotePort);
pdu.setProtocolOptions(opt);

SnmpPDU response_pdu = session.syncSend(pdu);

When a PDU is re-used, ensure the reqid field is set properly. If reqid is set non-zero, the API leaves it as it is. If it is 0, then the API assigns a unique reqid, to ensure no conflict with other requests. So, if you do not want to manage the reqids yourself, set it to 0 before each request. With SnmpSession.syncSend() you don't need to store the value for later reference. With SnmpSession.send(), the reqid assigned is returned, and you will need it later to check up on the response.

v3 only The SnmpPDU is encapsulated in a message, where the message could be SNMPv1, SNMPv2c or an SNMPv3 message. Applications do not have to be aware of the message classes Snmp3Message and SnmpMessage and they can work with the SnmpPDU alone, to be able to interact with peers. The SnmpPDU provides a getMsg( ) method to access the SnmpMessage associated with it. Similarly when a SnmpPDU is instantiated, it instantiates the appropriate message object along with it. Applications must not instantiate Snmp3Message and SnmpMessage objects and should always use SnmpPDU.

The SnmpPDU provides most of the communication parameters' related methods that are available with the SnmpSession. Wherever the value of the parameter is set in the pdu, it overrides the value in the session.

See Also:
Serialized Form

Constructor Summary
SnmpPDU()
          Creates a new SnmpPDU instance.
 
Method Summary
 void addNull(SnmpOID oid)
          This method will add a vairable binding which contains this SnmpOID and a placeholder ( NULL ) as the value.
 void addVariableBinding(int index, SnmpVarBind varbind)
          Adds SNMP variable at specified index in PDUs list of variable bindings.
 void addVariableBinding(SnmpVarBind varbind)
          Adds SNMP variable at the end of PDU's list of variable bindings.
 SnmpPDU copy()
          Makes a copy of entire SnmpPDU including the SnmpMessage it encapsulates.
 SnmpPDU copyWithoutVarbinds()
           
 boolean decode()
          Decodes the remainder of the PDU.
 void fix()
          Fixes PDU to eliminate erred variable binding, determined by errindex
 java.net.InetAddress getAddress()
          Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)SnmpPDU.getProtocolOptions();
InetAddress address = opt.getRemoteAddress();

 java.lang.String getAgentAddr()
          Gets the address of object generating trap in String foramt.
 java.net.InetAddress getAgentAddress()
          Gets address of object generating trap.
 int getClientID()
          This method will return the id for the source which sent this pdu
 byte getCommand()
          Gets command type of this PDU.
 java.lang.String getCommunity()
          Gets community string received/sent.
 byte[] getContextID()
          v3 only Gets context ID sent/received with this PDU.
 byte[] getContextName()
          v3 only Gets the context name sent/received with this PDU.
 byte[] getData()
          Gets encoded data to be sent, or received.
 int getEncodedLength(SnmpSession session)
          Returns the length of the encoded pdu.
 byte[] getEngineID()
          v3 only This method returns the engineID that is previously specified or null.
 SnmpOID getEnterprise()
          Gets the enterprise OID, i.e., get the enterprise field, of the Trap-PDU.
 int getErrindex()
          Gets error index of this PDU.
 java.lang.String getError()
          Gets error information as a String, with offending varbind if any.
 int getErrstat()
          Gets error status of this PDU.
 int getMaxRepetitions()
          GetsMax-Repetitions value of this PDU.
 SnmpMessage getMsg()
          Returns the SnmpMessage instance for this pdu.
 int getNonRepeaters()
          Gets Non-Repeaters value of this PDU.
 SnmpOID getObjectID(int index)
          Gets the specified SNMP ObjectID from PDUs list of variable bindings.
 ProtocolOptions getProtocolOptions()
          This method will return the transport mechanism's protocol options
 java.lang.String getRemoteHost()
          Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)SnmpPDU.getProtocolOptions();
String remoteHost = opt.getRemoteHost();

 int getRemotePort()
          Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)SnmpPDU.getProtocolOptions();
int remotePort = opt.getRemotePort();

 int getReqid()
          Gets request id of this PDU.
 int getRetries()
          Gets number of retries for this PDU before timeout.
 long getRoundTripDelay()
          Returns round-trip delay if received response PDU
 int getSecurityModel()
          v3 only Gets the securityModel associated with this PDU.
 int getSpecificType()
          Gets specific trap type.
 int getTimeout()
          Gets the timeout value.
 SnmpOID getTrapOID()
          v2c and v3 only This method returns the trap-oid for this SNMPv2 trap-pdu.
 int getTrapType()
          Gets the generic type of the trap.
 long getUpTime()
          Gets the timeStamp of the object which has generated the trap.
 byte[] getUserName()
          v3 only Gets the principal on whose behalf SNMPv3 requests are made.
 SnmpVar getVariable(int index)
          Gets specified SNMP variable from PDUs list of variables.
 SnmpVar getVariable(SnmpOID oid)
          Gets specified SNMP variable from PDUs list of variables.
 SnmpVarBind getVariableBinding(int index)
          Gets specified variable binding from PDUs list of variable bindings.
 java.util.Vector getVariableBindings()
          Gets list of SnmpVarBind objects as a vector.
 int getVersion()
          Gets snmp Version number in PDU.
 java.lang.String getWriteCommunity()
          Gets writeCommunity string received/sent.
 boolean isBroadCastEnabled()
          This method says whether this pdu is a broadCastpdu or not.
 java.lang.String printVarBinds()
          Returns String of all variable bindings with Tags, e.g.
 void removeVariableBinding(int index)
          Removes SNMP variable binding at specified index in PDUs list of variable bindings.
 void removeVariableBinding(SnmpVarBind varbind)
          Removes specified SNMP variable binding from PDUs list of variable bindings.
 void setAddress(java.net.InetAddress address)
          Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)SnmpPDU.getProtocolOptions();
opt.setRemoteAddress(address);

 void setAgentAddr(java.lang.String agentaddr)
          sets the agent address as a string.
 void setAgentAddress(java.net.InetAddress addr)
          Sets Address of object generating trap.
 void setBroadCastEnable(boolean bool)
          Calling this method with a "true" value will indicate that this pdu is a broadcast pdu.
 void setClientID(int id)
          This method will indicate the id for source which sent this pdu
 void setCommand(byte type)
          Sets command type of this PDU.
 void setCommunity(java.lang.String t)
          Sets community string received/sent.
 void setCommunityEncoding(java.lang.String enc)
          Sets the encoding to use for community string.
 void setContextID(byte[] id)
          v3 only Sets context ID associated with the PDU.
 void setContextName(byte[] name)
          v3 only Sets the context name associated with the PDU
 void setData(byte[] b)
          Sets encoded data to be sent, or received.
 void setDebug(boolean debug)
          Defines whether debugging output should be generated for this PDU.
 void setDNSLookup(boolean lookup)
          Deprecated. since no lookup will be done unnecessarily.
 void setEngineID(byte[] eid)
          v3 only Sets the engineID of the remote SNMPv3 agent.
 void setEnterprise(SnmpOID oid)
          Sets the enterprise OID, i.e., the enterprise field, of the Trap-PDU.
 void setErrindex(int index)
          Sets Error index for this PDU.
 void setErrstat(int stat)
          Set Error status for this PDU.
 void setMaxRepetitions(int max_rep)
          Sets Max-Repetitions value for this PDU.
 void setNonRepeaters(int non_rep)
          Sets Non-Repeaters value for this PDU.
 void setProtocolOptions(ProtocolOptions tParam)
          This sets the transport mechanism's protocol options.
 void setReEncode(boolean reEncode)
          Controls ASN.1 encoding (default true).
 void setRemoteHost(java.lang.String host)
          Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)SnmpPDU.getProtocolOptions();
opt.setRemoteHost(host);

 void setRemotePort(int port)
          Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)SnmpPDU.getProtocolOptions();
opt.setRemotePort(port);

 void setReqid(int id)
          Sets Request id for this PDU.
 void setRetries(int N)
          Sets number of retries for this PDU before timeout.
 void setSecurityModel(int model)
          v3 only Sets the securityModel to be associated with the PDU.
 void setSpecificType(int type)
          Sets Specific trap type.
 void setTimeout(int t)
          Sets the timeout value.
 void setTrapType(int type)
          Sets the generic type of the Trap.
 void setUpTime(long uptime)
          Sets the timeStamp of the object which has to generate the trap.
 void setUserName(byte[] name)
          v3 only Sets the principal on whose behalf SNMPv3 requests are to be made.
 void setVariable(int index, SnmpVar var)
          Sets SNMP variable at specified index in PDUs list of variables, to value var.
 void setVersion(int v)
          Sets snmp Version number in PDU.
 void setWriteCommunity(java.lang.String t)
          Sets writeCommunity string received/sent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SnmpPDU

public SnmpPDU()
Creates a new SnmpPDU instance. It also instantiates the SnmpMessage it encapsulates.

Method Detail

isBroadCastEnabled

public boolean isBroadCastEnabled()
This method says whether this pdu is a broadCastpdu or not.

Returns:
the boolean which says whether this pdu is a broadCastpdu or not.

setBroadCastEnable

public void setBroadCastEnable(boolean bool)
Calling this method with a "true" value will indicate that this pdu is a broadcast pdu.

Parameters:
bool - the boolean value which says, whether this pdu is a broadCast pdu or not.

getMsg

public SnmpMessage getMsg()
Returns the SnmpMessage instance for this pdu.


setAddress

public void setAddress(java.net.InetAddress address)
Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)SnmpPDU.getProtocolOptions();
opt.setRemoteAddress(address);

Sets InetAddress of SNMP peer

Parameters:
address - the inetaddress to which this pdu should be sent.

getEngineID

public byte[] getEngineID()
v3 only This method returns the engineID that is previously specified or null.

Returns:
The engineID of the remote SNMPv3 agent.
Since:
AdventNet SNMP API 4 SP2 ( Release 4.0.2 )
See Also:
setEngineID(byte[])

setEngineID

public void setEngineID(byte[] eid)
v3 only Sets the engineID of the remote SNMPv3 agent. When the engineID is set, then the api will directly take the usm details from USMUserTable without looking at the SnmpEngineTable for engineID, engineTime and engineBoots.

Parameters:
eid - The engineID of the remote SNMPv3 agent.
Since:
AdventNet SNMP API 4 SP2 ( Release 4.0.2 )

getAddress

public java.net.InetAddress getAddress()
Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)SnmpPDU.getProtocolOptions();
InetAddress address = opt.getRemoteAddress();

Returns the InetAddress corresponding to the host.

Returns:
the Inet address corresponding to the remote host. null if not specified or is not an InetAddress.

getRemoteHost

public java.lang.String getRemoteHost()
Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)SnmpPDU.getProtocolOptions();
String remoteHost = opt.getRemoteHost();

Gets name of SNMP peer - needed for Applets that cannot resolve hosts. The remoteHost attribute of SnmpPDU overrides the peername in SnmpSession. This means, when remoteHost is null in SnmpPDU, messages are sent to the host, peername, in session. When remoteHost is not null in SnmpPDU, messages are sent to the remoteHost in SnmpPDU.

Returns:
The name of the SNMP peer to which requests are sent.

setRemoteHost

public void setRemoteHost(java.lang.String host)
Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)SnmpPDU.getProtocolOptions();
opt.setRemoteHost(host);

Sets name of SNMP peer - needed for Applets that cannot resolve hosts. The remoteHost attribute of SnmpPDU overrides the peername in SnmpSession. This means, when remoteHost is null in SnmpPDU, messages are sent to the host, peername, in session. When remoteHost is not null in SnmpPDU, messages are sent to the remoteHost in SnmpPDU.

Parameters:
host - The name of the SNMP peer to which requests should be sent.

getRemotePort

public int getRemotePort()
Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)SnmpPDU.getProtocolOptions();
int remotePort = opt.getRemotePort();

Gets the Remote port of SNMP peer. The remotePort parameter in SnmpPDU overrides the one in session. When remotePort in SnmpPDU is 0, the message is sent to remotePort specified in the session.

Returns:
The remotePort of the SNMP peer to which requests are sent.

setRemotePort

public void setRemotePort(int port)
Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)SnmpPDU.getProtocolOptions();
opt.setRemotePort(port);

Sets the Remote port of SNMP peer. The remotePort parameter in SnmpPDU overrides the one in session. When remotePort in SnmpPDU is 0, the message is sent to remotePort specified in the session.

Parameters:
port - The port of the SNMP peer to which requests should be sent.

This method accepts port values such that * port >= 0 and < 65536


getCommand

public byte getCommand()
Gets command type of this PDU. The command type is one of the constants defined in the SnmpAPI.

Returns:
the command type of the PDU.

setCommand

public void setCommand(byte type)
Sets command type of this PDU. The command type is one of the constants defined in the SnmpAPI.

Parameters:
type - The command type to be set for this PDU.

The various command types that can be passed as argument to this method are:
SnmpAPI.GET_REQ_MSG, SnmpAPI.GETNEXT_REQ_MSG, SnmpAPI.SET_REQ_MSG, SnmpAPI.TRP_REQ_MSG, SnmpAPI.GET_RSP_MSG, v2c and v3 only SnmpAPI.TRP2_REQ_MSG, SnmpAPI.GETBULK_REQ_MSG, SnmpAPI.INFORM_REQ_MSG and SnmpAPI.REPORT_MSG

This method will not accept values other than the one mentioned above.


getReqid

public int getReqid()
Gets request id of this PDU.

Returns:
The requestID of this PDU.

setReqid

public void setReqid(int id)
Sets Request id for this PDU. If requestID is set to non-zero, the API leaves it alone. If it is 0, the API assigns a unique requestID to ensure no conflict with other requests. So, if you do not want to manage the request ids yourself, it should be 0. The default value is 0. If you are reusing the PDU and do not want to manage the requestID yourself, set it to 0 each time.

Parameters:
id - The requestID for this PDU. The valid values ranges from 1 to 2147483647(both inclusive).

getErrstat

public int getErrstat()
Gets error status of this PDU.

Returns:
The error status of this PDU.

getError

public java.lang.String getError()
Gets error information as a String, with offending varbind if any.

Returns:
The error information in the PDU as a String with offending varbind if any.

setErrstat

public void setErrstat(int stat)
Set Error status for this PDU.

Parameters:
stat - The error status to be set for this PDU. v2c and v3 only The error status values that can be set using this method are
SnmpAPI.SNMP_ERR_NOERROR, SnmpAPI.SNMP_ERR_TOOBIG, SnmpAPI.SNMP_ERR_NOSUCHNAME, SnmpAPI.SNMP_ERR_BADVALUE, SnmpAPI.SNMP_ERR_READONLY, SnmpAPI.SNMP_ERR_GENERR, SnmpAPI.SNMP_ERR_NOACCESS, SnmpAPI.SNMP_ERR_WRONGTYPE, SnmpAPI.SNMP_ERR_WRONGLENGTH, SnmpAPI.SNMP_ERR_WRONGENCODING, SnmpAPI.SNMP_ERR_WRONGVALUE, SnmpAPI.SNMP_ERR_NOCREATION, SnmpAPI.SNMP_ERR_INCONSISTENTVALUE, SnmpAPI.SNMP_ERR_RESOURCEUNAVAILABLE, SnmpAPI.SNMP_ERR_COMMITFAILED, SnmpAPI.SNMP_ERR_UNDOFAILED, SnmpAPI.SNMP_ERR_AUTHORIZATIONERROR, SnmpAPI.SNMP_ERR_NOTWRITABLE and SnmpAPI.SNMP_ERR_INCONSISTENTNAME

This method will not accept values other than the one mentioned above.


getErrindex

public int getErrindex()
Gets error index of this PDU.

Returns:
The error index of this PDU.

setErrindex

public void setErrindex(int index)
Sets Error index for this PDU.

Parameters:
index - The error index to be set for this PDU. Only values >= zero will be accepted by this method.

getNonRepeaters

public int getNonRepeaters()
Gets Non-Repeaters value of this PDU.

Returns:
the Non-Repeaters value for this PDU.

setNonRepeaters

public void setNonRepeaters(int non_rep)
Sets Non-Repeaters value for this PDU.

Parameters:
non_rep - The Non-Repeaters value for this PDU.

getMaxRepetitions

public int getMaxRepetitions()
GetsMax-Repetitions value of this PDU.

Returns:
The Max-Repetitions value of this PDU.

setMaxRepetitions

public void setMaxRepetitions(int max_rep)
Sets Max-Repetitions value for this PDU.

Parameters:
max_rep - The Max-Repetitions value for this PDU. The valid values ranges from 0 to 65535(both inclusive).

getEnterprise

public SnmpOID getEnterprise()
Gets the enterprise OID, i.e., get the enterprise field, of the Trap-PDU.

Returns:
The enterprise field of the PDU.

setEnterprise

public void setEnterprise(SnmpOID oid)
Sets the enterprise OID, i.e., the enterprise field, of the Trap-PDU.

Parameters:
oid - The SnmpOID representing the entriprise field of PDU to be set.

getAgentAddress

public java.net.InetAddress getAgentAddress()
Gets address of object generating trap. In the case of SNMPv2 TRAP PDU if one of the varbind contains the snmpTrapAddress.0 oid the corresponding value is returned as the agent address.

Returns:
The address of object generating trap.

setAgentAddress

public void setAgentAddress(java.net.InetAddress addr)
Sets Address of object generating trap. In the case of SNMPv2c TRAP PDU an additional varbind is added, if its not already present in the varbind list. The varbind contains the snmpTrapAddress.0 (defined in RFC2576) as the oid and the value (SnmpVar) will be the agent address. There is no need to add this varbind explicitly.

Parameters:
addr - The address of object generating trap.

getAgentAddr

public java.lang.String getAgentAddr()
Gets the address of object generating trap in String foramt. In the case of SNMPv2 TRAP PDU if one of the varbind contains the snmpTrapAddress.0 oid the corresponding value is returned as the agent address.

Returns:
The address of object generating trap as a String.

setAgentAddr

public void setAgentAddr(java.lang.String agentaddr)
sets the agent address as a string. If the agentaddr is invalid, then value is set as "0.0.0.0".

Parameters:
agentaddr - the agent address as a string. This can be hostname or an address in the dotted form.

getTrapType

public int getTrapType()
Gets the generic type of the trap.

Returns:
The generic type of the trap of this PDU.

setTrapType

public void setTrapType(int type)
Sets the generic type of the Trap.

Parameters:
type - The generic type of the trap for this PDU. This method will accept values only from 0 to 6(both inclusive).

getSpecificType

public int getSpecificType()
Gets specific trap type.

Returns:
The specific type of this PDU.

setSpecificType

public void setSpecificType(int type)
Sets Specific trap type.

Parameters:
type - The Specific trap type for this PDU.

getUpTime

public long getUpTime()
Gets the timeStamp of the object which has generated the trap. The timeStamp value is in milliseconds.

Returns:
The timeStamp of the object which has generated the trap. This will return the value that is present in the time-stamp field present in a SNMPv1 trap-pdu. v2c and v3 only In case of a SNMPv2 trap-pdu, this method will return the sysUpTime value that is present in the first varbind. If this PDU is not a trap PDU, then this method will return '0'.

getTrapOID

public SnmpOID getTrapOID()
v2c and v3 only This method returns the trap-oid for this SNMPv2 trap-pdu.

Returns:
returns the trap oid that will be present in the second variable binding of a SNMPv2 trap-pdu. If this is not a SNMPv2 trap-pdu, then the method will return null.

setUpTime

public void setUpTime(long uptime)
Sets the timeStamp of the object which has to generate the trap. The timeStamp value is in milliseconds.

Parameters:
uptime - The timeStamp for the object which has to generate the trap.

This method will accept values such that uptime >= 0 and uptime < 4294967296L


getVariableBindings

public java.util.Vector getVariableBindings()
Gets list of SnmpVarBind objects as a vector.

Returns:
A vector of SnmpVarBind objects associated with this PDU.

getVariableBinding

public SnmpVarBind getVariableBinding(int index)
Gets specified variable binding from PDUs list of variable bindings. Indexes start at 0, so subtract one when using errindex.

Parameters:
index - The index of the SnmpVarBind which should be returned from the PDU's list of variable bindings.
Returns:
The SnmpVarBind corresponding to the index in the PDU's list of variable bindings.

getVariable

public SnmpVar getVariable(int index)
Gets specified SNMP variable from PDUs list of variables. Indexes start at 0, so subtract one when using errindex.

Parameters:
index - The index of the SnmpVarBind from the PDU's list of variable bindings.
Returns:
The SnmpVar of the SnmpVarBind corresponding to the index in the PDU's list of variable bindings.

setVariable

public void setVariable(int index,
                        SnmpVar var)
Sets SNMP variable at specified index in PDUs list of variables, to value var. Indexes start at 0.

Parameters:
index - The index for the PDU's list of varaible bindings for which the SnmpVar has to be set.
var - The SnmpVar which has to be set in the PDU's list of variable binding into the index specified by the index parameter.

addVariableBinding

public void addVariableBinding(int index,
                               SnmpVarBind varbind)
Adds SNMP variable at specified index in PDUs list of variable bindings. Indexes start at 0.

Parameters:
index - The index for the PDU's list of variable bindings for which the SnmpVarBind has to be added.
varbind - The SnmpVarBind which has to be added in the specified position specified by the index in the PDU's list of variable bindings.

The varbind will not be added to the list of variable bindings if any one of the following condition is true:
1. The varbind object is null
2. The index specified is invalid, that is, if the index is less than 0 or greater than the variable bindings size.
3. The SnmpOID in the SnmpVarBind is invalid or null.


addVariableBinding

public void addVariableBinding(SnmpVarBind varbind)
Adds SNMP variable at the end of PDU's list of variable bindings.

Parameters:
varbind - The SnmpVarBind to be added at the end of PDU's list of variable bindings.

The varbind will not be added to the list of variable bindings if any one of the following condition is true:
1. The varbind object is null
2. The SnmpOID in the SnmpVarBind is invalid or null.


removeVariableBinding

public void removeVariableBinding(int index)
Removes SNMP variable binding at specified index in PDUs list of variable bindings. Indexes start at 0.

Parameters:
index - The index value in the PDU's list of variable bindings for which the SnmpVarBind has to be removed.

removeVariableBinding

public void removeVariableBinding(SnmpVarBind varbind)
Removes specified SNMP variable binding from PDUs list of variable bindings.

Parameters:
varbind - The SnmpVarbind which has to be removed from the PDU's list of variable bindings.

getObjectID

public SnmpOID getObjectID(int index)
Gets the specified SNMP ObjectID from PDUs list of variable bindings. Indexes start at 0, so subtract one when using errindex.

Parameters:
index - The index value in the PDU's list of variable bindings for which the SnmpOID is to be retrived.
Returns:
the SnmpOID which is present in the specified index.

getCommunity

public java.lang.String getCommunity()
Gets community string received/sent. The community string in the pdu overrides the community set in session. This means, only when the community string in the pdu is null, the one in session is used.

Returns:
the community of this PDU.

setCommunity

public void setCommunity(java.lang.String t)
Sets community string received/sent. The community string in the pdu overrides the community set in session. This means, only when the community string in the pdu is null, the one in session is used.

Parameters:
t - The community to be set for this PDU.

getWriteCommunity

public java.lang.String getWriteCommunity()
Gets writeCommunity string received/sent. This is used in SET operations only. The writeCommunity string in the pdu overrides the writeCommunity in session. This means, only when the writeCommunity string in the pdu is null, the one in session is used. If the writeCommunity is not specified, then value in community field is used.

Returns:
The writeCommunity of this PDU.

setWriteCommunity

public void setWriteCommunity(java.lang.String t)
Sets writeCommunity string received/sent. This is used in SET operations only. The writeCommunity string in the pdu overrides the writeCommunity in session. This means, only when the writeCommunity string in the pdu is null, the one in session is used. If the writeCommunity is not specified, then value in community field is used.

Parameters:
t - The writeCommunity to be set for this PDU.

getTimeout

public int getTimeout()
Gets the timeout value. The timeout is the time to wait for the first response in milli-seconds, before attempting a retransmission. The timeout value grows exponentially, after the first retransmission. For example, if the timeout is set to 5000 (meaning 5 seconds) and retries is set to 3, the first retransmission will happen after 5 seconds, the second after 15 seconds etc. The timeout in the pdu overrides the timeout value in session. This means, only when the timeout in the pdu is 0, the session timeout value is used. The default value of timeout is 0 milliseconds.

Returns:
The timeout value of this PDU.

setTimeout

public void setTimeout(int t)
Sets the timeout value. The timeout is the time to wait for the first response in milli-seconds, before attempting a retransmission. The timeout value grows exponentially, after the first retransmission. For example, if the timeout is set to 5000 (meaning 5 seconds) and retries is set to 3, the first retransmission will happen after 5 seconds, the second after 15 seconds etc. The timeout in the pdu overrides the timeout value in session. This means, only when the timeout in the pdu is 0, the session timeout value is used. The default value of timeout is 0 milliseconds. The timeout value to be set should be in milliseconds.

Parameters:
t - The timeout value for this PDU. This method accepts values which are greater than zero.

getRetries

public int getRetries()
Gets number of retries for this PDU before timeout. The retries in the pdu overrides the retries value in session. This means, only when the retries in the pdu is 0, the session value is used. The default value of retries is 0.

Returns:
The retries value of this PDU.

setRetries

public void setRetries(int N)
Sets number of retries for this PDU before timeout. The retries in the pdu overrides the retries value in session. This means, only when the retries in the pdu is 0, the session value is used. The default value of retries is 0.

Parameters:
N - The retries value for this PDU. This method accepts value such that N >= 0.

getData

public byte[] getData()
Gets encoded data to be sent, or received.

Returns:
The encoded data to be sent, or received. v3 only In case of SNMPv3 auth-priv packet, this method will return the encrypted data.

setData

public void setData(byte[] b)
Sets encoded data to be sent, or received.

Parameters:
b - The encoded data to be sent, or received.

getVersion

public int getVersion()
Gets snmp Version number in PDU. v3 only When using this SNMPv3 API to build applications, all the SNMPv1, SNMPv2c and SNMPv3 messages can be sent and received using the same session, irrespective of the version set in the session object. The version set in SnmpPDU overrides the version in the session. For example, if a session version is set to SnmpAPI.SNMP_VERSION_3, and a pdu is sent without setting its version explicitly (the pdu will have the default version of SnmpAPI.SNMP_VERSION_1), then an SNMPv3 message is sent to the peer SNMP entity. On the other hand, if the pdu version is set explicitly to SnmpAPI.SNMP_VERSION_2C, an SNMPv2c message will be sent to the peer entity.

Returns:
The version of outgoing SNMP requests.

setVersion

public void setVersion(int v)
Sets snmp Version number in PDU. v3 only When using this SNMPv3 API to build applications, all the SNMPv1, SNMPv2c and SNMPv3 messages can be sent and received using the same session, irrespective of the version set in the session object. The version set in SnmpPDU overrides the version in the session. For example, if a session version is set to SnmpAPI.SNMP_VERSION_3, and a pdu is sent without setting its version explicitly (the pdu will have the default version of SnmpAPI.SNMP_VERSION_1), then an SNMPv3 message is sent to the peer SNMP entity. On the other hand, if the pdu version is set explicitly to SnmpAPI.SNMP_VERSION_2C, an SNMPv2c message will be sent to the peer entity.

Parameters:
v - The version for outgoing SNMP requests. v3 only This method will accept the value only when the value is SnmpAPI.SNMP_VERSION_1 or SnmpAPI.SNMP_VERSION2C or SnmpAPI.SNMP_VERSION_3

setUserName

public void setUserName(byte[] name)
v3 only Sets the principal on whose behalf SNMPv3 requests are to be made. While sending an SNMPv3 request this userName has to be set.

Parameters:
name - The principal on whose behalf, SNMPv3 requests are to be sent.

getUserName

public byte[] getUserName()
v3 only Gets the principal on whose behalf SNMPv3 requests are made. While sending an SNMPv3 request this userName has to be set.

Returns:
The principal on whose behalf, SNMPv3 requests are sent.

setContextID

public void setContextID(byte[] id)
v3 only Sets context ID associated with the PDU.

Parameters:
id - The context ID associated with the PDU.

getContextID

public byte[] getContextID()
v3 only Gets context ID sent/received with this PDU.

Returns:
The context ID associated with the PDU.

setContextName

public void setContextName(byte[] name)
v3 only Sets the context name associated with the PDU

Parameters:
name - The contextName to be sent with the PDU.

getContextName

public byte[] getContextName()
v3 only Gets the context name sent/received with this PDU.

Returns:
The context name sent/received with this PDU.

setSecurityModel

public void setSecurityModel(int model)
v3 only Sets the securityModel to be associated with the PDU.

Parameters:
model - The securityModel to be sent with the PDU. The valid values ranges from 1 to 2147483647(both inclusive).

getSecurityModel

public int getSecurityModel()
v3 only Gets the securityModel associated with this PDU.

Returns:
The securityModel sent/received with this PDU.

setReEncode

public void setReEncode(boolean reEncode)
Controls ASN.1 encoding (default true). Normally a PDU is ASN.1 encoded during every send process. If you have a PDU that has been sent already, you can save time on subsequent resends by setting this to false.

Parameters:
reEncode - The boolean value which specifies if the PDU is to be encoded each time for a send request.

setCommunityEncoding

public void setCommunityEncoding(java.lang.String enc)
Sets the encoding to use for community string. Default is UTF8

Parameters:
enc - A character-encoding name This method will set the string only when enc is a non-null valid encoding string.

setDebug

public void setDebug(boolean debug)
Defines whether debugging output should be generated for this PDU. In the debug mode, the PDU data is printed in hex format. If you want to enable the debug option for all snmp communications that happens through the SnmpAPI, you can use the method setDebug in SnmpAPI.

Parameters:
debug - boolean value. If set to true, the debugging output will be generated for this PDU.
See Also:
SnmpAPI.getDebug()

copy

public SnmpPDU copy()
Makes a copy of entire SnmpPDU including the SnmpMessage it encapsulates.

Returns:
The copy of PDU

copyWithoutVarbinds

public SnmpPDU copyWithoutVarbinds()

addNull

public void addNull(SnmpOID oid)
This method will add a vairable binding which contains this SnmpOID and a placeholder ( NULL ) as the value.
Only non-null, valid SnmpOID will be added to the list of variable bindings. This method is used while doing a GET or GETNEXT request.

Parameters:
oid - the SnmpOID object to add to the VarBind list
See Also:
getVariableBindings()

fix

public void fix()
Fixes PDU to eliminate erred variable binding, determined by errindex


getRoundTripDelay

public long getRoundTripDelay()
Returns round-trip delay if received response PDU


printVarBinds

public java.lang.String printVarBinds()
Returns String of all variable bindings with Tags, e.g. STRING:...


getEncodedLength

public int getEncodedLength(SnmpSession session)
Returns the length of the encoded pdu.

Returns:
The length of the encoded pdu.

decode

public boolean decode()
               throws SnmpException
Decodes the remainder of the PDU. Decodes the PDU starting from the error status value. The constructor already decodes down to the request ID.

Throws:
SnmpException - thrown upon decode errors.

setProtocolOptions

public void setProtocolOptions(ProtocolOptions tParam)
This sets the transport mechanism's protocol options.

Parameters:
tParam - protocol options to be set.

getProtocolOptions

public ProtocolOptions getProtocolOptions()
This method will return the transport mechanism's protocol options

Returns:
the protocol options corresponding to this pdu.

setClientID

public void setClientID(int id)
This method will indicate the id for source which sent this pdu


getClientID

public int getClientID()
This method will return the id for the source which sent this pdu


setDNSLookup

public void setDNSLookup(boolean lookup)
Deprecated. since no lookup will be done unnecessarily.

This method will set the DNS Lookup flag. If this flag is set to false, DNS lookup will not be done only when remoteHost is being set on this SnmpPDU instance. By default the flag is set to true (ie) DNS lookup will be done.

Parameters:
lookup - The DNS lookup flag to be set. WARNING : This flag can be set to false while doing non-SNMP operations if the user wants to just set the remoteHost field with no DNS lookup done.

getVariable

public SnmpVar getVariable(SnmpOID oid)
Gets specified SNMP variable from PDUs list of variables.

Parameters:
oid - The SnmpOID of the SnmpVarBind from the PDU's list of variable bindings.
Returns:
The SnmpVar of the SnmpVarBind corresponding to the SnmpOID in the PDU's list of variable bindings.
Since:
AdventNet SNMP API 4 SP2 ( Release 4.0.2 )


Copyright (c)ZOHO Corp. 1996-2012