HOME

com.ireasoning.protocol.snmp
Class SnmpPdu

java.lang.Object
  extended bycom.ireasoning.protocol.snmp.VarBindContainer
      extended bycom.ireasoning.protocol.snmp.SnmpPdu
All Implemented Interfaces:
Msg, Serializable, SnmpDataType
Direct Known Subclasses:
SnmpV2Notification

public class SnmpPdu
extends VarBindContainer
implements SnmpDataType

This class represents SNMP Protocol Data Unit (PDU).

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface com.ireasoning.protocol.snmp.SnmpDataType
BITS, BITSTRING, COUNTER32, COUNTER64, END_OF_MIB_VIEW, END_OF_MIB_VIEW_OBJECT, GAUGE32, INTEGER, IPADDRESS, NO_SUCH_INSTANCE, NO_SUCH_INSTANCE_OBJECT, NO_SUCH_OBJECT, NO_SUCH_OBJECT_OBJECT, NULL, OCTETSTRING, OID, OPAQUE, PDU, SEQUENCE, SEQUENCEOF, serialVersionUID, TIMETICKS, UNSIGNED32, VARBIND
 
Fields inherited from interface com.ireasoning.protocol.Msg
ERROR_TYPE
 
Constructor Summary
SnmpPdu(int cmd)
          Constructs an SnmpPdu object
SnmpPdu(int cmd, SnmpVarBind[] varbinds)
          Creates a new pdu with the spcified command and the list of variables.
SnmpPdu(int cmd, SnmpVarBind[] varbinds, int requestID)
          Constructs a new SnmpPdu object
SnmpPdu(SnmpPdu pdu)
          Makes a copy of passed pdu object
 
Method Summary
 SnmpDataType copy()
          Makes a copy of itself
static SnmpPdu decodePdu(byte[] data, int length)
          Constructs an SnmpPdu (SNMP v1/v2c) based on passed byte array
 int encode(com.ireasoning.protocol.snmp.SnmpEncoder encoder)
          For internal use
static byte[] encodePdu(SnmpPdu pdu)
          Encodes passed SNMPv1/v2c SnmpPdu object to byte array
 int getCommand()
          Returns the snmp command contained in this PDU
 String getCommunity()
          Returns the community name contained in this object.
 byte[] getContextEngineID()
          Returns the context engine ID
 String getContextName()
          Returns the context name
 String getDestinationAddress()
          Returns the PDU receiver's ip address or host name
 int getDestinationPort()
          Returns the PDU receiver's socket port number
 int getErrorIndex()
          Returns the error index.
 int getErrorStatus()
          Returns the error status code
 String getErrorStatusString()
          Returns the string representation of this object's error status code
static String getErrorStatusString(int errStatusCode)
          Returns the string representation of passed error status code
 String getErrorString()
          Returns the error string.
 String getIpAddress()
          Returns the PDU sender's IP address or host name.
 int getMaxRepetitions()
          Returns the max-repetition value
 int getNonRepeaters()
          Used with get-bulk command.
 int getRequestID()
          Returns PDU's request ID
 MsgHeader getSnmpV3MsgHeader()
           
 MsgSecurityParameters getSnmpv3MsgSecurityParameters()
           
 String getSourceAddress()
          Returns the PDU sender's IP address or host name
 int getSourcePort()
          Returns the PDU sender's socket port number
 int getType()
          Returns SnmpDataType.PDU
 String getTypeString()
          Returns "PDU"
 int getVersion()
          Returns the version of SNMP.
 boolean hasMore()
          Determines whether there are any more elements.
 boolean isSnmpV3AuthenticationFailed()
          Returns true if SNMPv3 authentication failed.
 void setCommand(int cmd)
          Set new command
 void setCommunity(String community)
          Sets new community string.
 void setContextEngineID(byte[] id)
          Sets the context engine id (SNMPV3)
 void setContextName(String name)
          Sets the context name (SNMPV3)
 void setDestinationAddress(String ipAddress)
          Sets the PDU receiver's ip address or host name
 void setDestinationPort(int port)
           
 void setErrorIndex(int index)
          Sets the error index field of PDU
 void setErrorStatus(int status)
          Sets the error status code
 void setHasMore(boolean b)
          Sets this object's HasMore property
 void setIpAddress(String ipAddr)
          Sets PDU sender's ip address or host name
The same as setSourceAddress(String ipAddress)
 void setMaxRepetitions(int maxrep)
          Sets the max-repetition value of get-bulk command
 void setNonRepeaters(int nonrep)
          Sets the non-repeater value (SNMPV2 get-bulk command)
 void setOID(SnmpOID oid)
          Sets a new oid, removes all old ones.
 void setOID(String oid)
          Sets a new oid, removes all old ones.
 void setOIDs(SnmpOID[] oids)
          Sets a new set of oids
 void setOIDs(String[] oids)
          Sets a new set of oids, removes all old ones.
 void setRequestID(int reqid)
          Sets new reuqest ID
 void setSourceAddress(String ipAddress)
          Sets PDU sender's ip address or host name
 void setSourcePort(int port)
           
 void setVersion(int version)
          Sets the version of SNMP.
 String toString()
           
 
Methods inherited from class com.ireasoning.protocol.snmp.VarBindContainer
addVarBind, addVarBinds, addVarBinds, getFirstVarBind, getLastVarBind, getVarBind, getVarBindCount, getVarBinds, removeAllVarBinds, removeAllVarBinds, removeVarBind, setVarBinds, setVarBinds
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.ireasoning.protocol.snmp.SnmpDataType
equals, hashCode
 

Constructor Detail

SnmpPdu

public SnmpPdu(SnmpPdu pdu)
Makes a copy of passed pdu object


SnmpPdu

public SnmpPdu(int cmd)
Constructs an SnmpPdu object

Parameters:
cmd - the snmp command, such as SnmpConst.GET, SnmpConst.GET_NEXT, etc.

SnmpPdu

public SnmpPdu(int cmd,
               SnmpVarBind[] varbinds)
Creates a new pdu with the spcified command and the list of variables.

Parameters:
cmd - the snmp command, such as SnmpConst.GET, SnmpConst.GET_NEXT, etc.
varbinds - The variable bindings

SnmpPdu

public SnmpPdu(int cmd,
               SnmpVarBind[] varbinds,
               int requestID)
Constructs a new SnmpPdu object

Parameters:
cmd - the snmp command, such as SnmpConst.GET, SnmpConst.GET_NEXT, etc.
varbinds - The variable bindings
requestID - the request id
Method Detail

decodePdu

public static SnmpPdu decodePdu(byte[] data,
                                int length)
                         throws SnmpDecodingException
Constructs an SnmpPdu (SNMP v1/v2c) based on passed byte array

Parameters:
data - byte array representation of SNMP v1/v2c PDU
length - the number of bytes of data to be decoded
Returns:
decoded PDU. Or null if passed data is not a v1/v2c PDU
Throws:
SnmpDecodingException

encodePdu

public static byte[] encodePdu(SnmpPdu pdu)
                        throws SnmpEncodingException
Encodes passed SNMPv1/v2c SnmpPdu object to byte array

Parameters:
pdu - SNMPv1/v2c PDU object
Throws:
SnmpEncodingException

hasMore

public boolean hasMore()
Determines whether there are any more elements.

Returns:
false if end of mib view reached, or this object's setHasMore(false) has been set, or getErrorStatus() return true; otherwise return true
See Also:
setHasMore(boolean)

setHasMore

public void setHasMore(boolean b)
Sets this object's HasMore property

Parameters:
b - a boolean variable determining the result of hasMore() method
See Also:
hasMore()

setCommand

public void setCommand(int cmd)
Set new command

Parameters:
cmd - The new command.

getRequestID

public int getRequestID()
Returns PDU's request ID

Returns:
request ID

setRequestID

public void setRequestID(int reqid)
Sets new reuqest ID


setOID

public void setOID(String oid)
Sets a new oid, removes all old ones.

Parameters:
oid - new oid

setOID

public void setOID(SnmpOID oid)
Sets a new oid, removes all old ones.

Parameters:
oid - new oid

setOIDs

public void setOIDs(String[] oids)
Sets a new set of oids, removes all old ones.

Parameters:
oids - new set of oids

setOIDs

public void setOIDs(SnmpOID[] oids)
Sets a new set of oids

Parameters:
oids - new set of oids

getCommand

public int getCommand()
Returns the snmp command contained in this PDU

Returns:
The current PDU command, such as SnmpConst.GET, SnmpConst.GET_NEXT, SnmpConst.SET, SnmpConst.RESPONSE, etc.

getType

public int getType()
Returns SnmpDataType.PDU

Specified by:
getType in interface SnmpDataType
Returns:
the object data type

getTypeString

public String getTypeString()
Returns "PDU"

Specified by:
getTypeString in interface SnmpDataType

getVersion

public int getVersion()
Returns the version of SNMP. Possible values are { SnmpConst.SNMPV1, SnmpConst.SNMPV2, SnmpConst.SNMPV3 }

Returns:
the version of SNMP

setVersion

public void setVersion(int version)
Sets the version of SNMP. Possible values are { SnmpConst.SNMPV1, SnmpConst.SNMPV2, SnmpConst.SNMPV3 }


getCommunity

public String getCommunity()
Returns the community name contained in this object. The default community string of this object is "public"

Returns:
the community name

setCommunity

public void setCommunity(String community)
Sets new community string. The default community string of this object is "public"


isSnmpV3AuthenticationFailed

public boolean isSnmpV3AuthenticationFailed()
Returns true if SNMPv3 authentication failed.


getErrorString

public String getErrorString()
Returns the error string. It's the same as getErrorStatusString() except it can also report SNMPv3 authentication failure.


getErrorStatusString

public String getErrorStatusString()
Returns the string representation of this object's error status code


getErrorStatusString

public static String getErrorStatusString(int errStatusCode)
Returns the string representation of passed error status code

Parameters:
errStatusCode - error status code

getErrorStatus

public int getErrorStatus()
Returns the error status code

Returns:
the error status field of PDU

setErrorStatus

public void setErrorStatus(int status)
Sets the error status code


getErrorIndex

public int getErrorIndex()
Returns the error index.

Returns:
the error index field of PDU. 0 means no error contained in this PDU object

setErrorIndex

public void setErrorIndex(int index)
Sets the error index field of PDU


getNonRepeaters

public int getNonRepeaters()
Used with get-bulk command. Returns the non-repeaters value

Returns:
the non-repeater value of PDU

setNonRepeaters

public void setNonRepeaters(int nonrep)
Sets the non-repeater value (SNMPV2 get-bulk command)


getMaxRepetitions

public int getMaxRepetitions()
Returns the max-repetition value

Returns:
the max-repetition value of get-bulk command

setMaxRepetitions

public void setMaxRepetitions(int maxrep)
Sets the max-repetition value of get-bulk command


getContextName

public String getContextName()
Returns the context name

Returns:
the context name (SNMPV3)

setContextName

public void setContextName(String name)
Sets the context name (SNMPV3)


getContextEngineID

public byte[] getContextEngineID()
Returns the context engine ID

Returns:
context engine id (SNMPV3)

setContextEngineID

public void setContextEngineID(byte[] id)
Sets the context engine id (SNMPV3)


getSourceAddress

public String getSourceAddress()
Returns the PDU sender's IP address or host name


setSourceAddress

public void setSourceAddress(String ipAddress)
Sets PDU sender's ip address or host name


getSourcePort

public int getSourcePort()
Returns the PDU sender's socket port number


setSourcePort

public void setSourcePort(int port)

getDestinationPort

public int getDestinationPort()
Returns the PDU receiver's socket port number


setDestinationPort

public void setDestinationPort(int port)

getDestinationAddress

public String getDestinationAddress()
Returns the PDU receiver's ip address or host name


setDestinationAddress

public void setDestinationAddress(String ipAddress)
Sets the PDU receiver's ip address or host name


getIpAddress

public String getIpAddress()
Returns the PDU sender's IP address or host name.
The same as getSourceAddress() method

See Also:
getSourceAddress()

setIpAddress

public void setIpAddress(String ipAddr)
Sets PDU sender's ip address or host name
The same as setSourceAddress(String ipAddress)

See Also:
setSourceAddress(java.lang.String)

getSnmpV3MsgHeader

public MsgHeader getSnmpV3MsgHeader()
Returns:
SNMPv3 PDU's header, including security level and security model.

getSnmpv3MsgSecurityParameters

public MsgSecurityParameters getSnmpv3MsgSecurityParameters()
Returns:
SNMPv3 PDU's security parameters, such as SNMPv3 user name, engineBoots, and engineTime.

toString

public String toString()

copy

public SnmpDataType copy()
Description copied from interface: SnmpDataType
Makes a copy of itself

Specified by:
copy in interface SnmpDataType
Returns:
a deep copy of this object

encode

public int encode(com.ireasoning.protocol.snmp.SnmpEncoder encoder)
           throws SnmpEncodingException
Description copied from interface: SnmpDataType
For internal use

Specified by:
encode in interface SnmpDataType
Throws:
SnmpEncodingException

HOME

Copyright © 2002 iReasoning Inc. All Rights Reserved.