snmp
Class SNMPv1CommunicationInterface

java.lang.Object
  extended bysnmp.SNMPv1CommunicationInterface

public class SNMPv1CommunicationInterface
extends java.lang.Object

The class SNMPv1CommunicationInterface defines methods for communicating with SNMP entities. The approach is that from version 1 of SNMP, using no encryption of data. Communication occurs via UDP, using port 161, the standard SNMP port.


Field Summary
 int requestID
           
static int SNMPPORT
           
 
Constructor Summary
SNMPv1CommunicationInterface(int version, java.net.InetAddress hostAddress, java.lang.String community)
          Construct a new communication object to communicate with the specified host using the given community name.
 
Method Summary
 void closeConnection()
          Close the "connection" with the device.
 SNMPVarBindList getMIBEntry(java.lang.String itemID)
          Retrieve the MIB variable value corresponding to the object identifier given in itemID (in dotted-integer notation).
 SNMPVarBindList getMIBEntry(java.lang.String[] itemID)
          Retrieve the MIB variable values corresponding to the object identifiers given in the array itemID (in dotted-integer notation).
 SNMPVarBindList getNextMIBEntry(java.lang.String itemID)
          Retrieve the MIB variable value corresponding to the object identifier following that given in itemID (in dotted-integer notation).
 SNMPVarBindList getNextMIBEntry(java.lang.String[] itemID)
          Retrieve the MIB variable value corresponding to the object identifiers following those given in the itemID array (in dotted-integer notation).
 int getReceiveBufferSize()
          Returns the current size of the buffer used to receive response packets.
 SNMPVarBindList retrieveAllMIBInfo(java.lang.String startID)
          Retrieve all MIB variable values subsequent to the starting object identifier given in startID (in dotted-integer notation).
 SNMPVarBindList retrieveMIBTable(java.lang.String baseID)
          Retrieve all MIB variable values whose OIDs start with the supplied baseID.
 SNMPVarBindList retrieveMIBTable(java.lang.String[] baseID)
          Retrieve all MIB variable values whose OIDs start with the supplied baseIDs.
 SNMPVarBindList setMIBEntry(java.lang.String[] itemID, SNMPObject[] newValue)
          Set the MIB variable values of the supplied object identifiers given in the itemID array (in dotted-integer notation).
 SNMPVarBindList setMIBEntry(java.lang.String itemID, SNMPObject newValue)
          Set the MIB variable value of the object identifier given in startID (in dotted-integer notation).
 void setReceiveBufferSize(int receiveBufferSize)
          Set the size of the buffer used to receive response packets.
 void setSocketTimeout(int socketTimeout)
          Permits setting timeout value for underlying datagram socket (in milliseconds).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SNMPPORT

public static final int SNMPPORT
See Also:
Constant Field Values

requestID

public int requestID
Constructor Detail

SNMPv1CommunicationInterface

public SNMPv1CommunicationInterface(int version,
                                    java.net.InetAddress hostAddress,
                                    java.lang.String community)
                             throws java.net.SocketException
Construct a new communication object to communicate with the specified host using the given community name. The version setting should be either 0 (version 1) or 1 (version 2, a la RFC 1157).

Method Detail

setSocketTimeout

public void setSocketTimeout(int socketTimeout)
                      throws java.net.SocketException
Permits setting timeout value for underlying datagram socket (in milliseconds).

Throws:
java.net.SocketException

closeConnection

public void closeConnection()
                     throws java.net.SocketException
Close the "connection" with the device.

Throws:
java.net.SocketException

retrieveAllMIBInfo

public SNMPVarBindList retrieveAllMIBInfo(java.lang.String startID)
                                   throws java.io.IOException,
                                          SNMPBadValueException
Retrieve all MIB variable values subsequent to the starting object identifier given in startID (in dotted-integer notation). Return as SNMPVarBindList object. Uses SNMPGetNextRequests to retrieve variable values in sequence.

Throws:
java.io.IOException - Thrown when timeout experienced while waiting for response to request.
SNMPBadValueException

getMIBEntry

public SNMPVarBindList getMIBEntry(java.lang.String itemID)
                            throws java.io.IOException,
                                   SNMPBadValueException,
                                   SNMPGetException
Retrieve the MIB variable value corresponding to the object identifier given in itemID (in dotted-integer notation). Return as SNMPVarBindList object; if no such variable (either due to device not supporting it, or community name having incorrect access privilege), SNMPGetException thrown

Throws:
java.io.IOException - Thrown when timeout experienced while waiting for response to request.
SNMPBadValueException
SNMPGetException - Thrown if supplied OID has value that can't be retrieved

getMIBEntry

public SNMPVarBindList getMIBEntry(java.lang.String[] itemID)
                            throws java.io.IOException,
                                   SNMPBadValueException,
                                   SNMPGetException
Retrieve the MIB variable values corresponding to the object identifiers given in the array itemID (in dotted-integer notation). Return as SNMPVarBindList object; if no such variable (either due to device not supporting it, or community name having incorrect access privilege), SNMPGetException thrown

Throws:
java.io.IOException - Thrown when timeout experienced while waiting for response to request.
SNMPBadValueException
SNMPGetException - Thrown if one of supplied OIDs has value that can't be retrieved

getNextMIBEntry

public SNMPVarBindList getNextMIBEntry(java.lang.String itemID)
                                throws java.io.IOException,
                                       SNMPBadValueException,
                                       SNMPGetException
Retrieve the MIB variable value corresponding to the object identifier following that given in itemID (in dotted-integer notation). Return as SNMPVarBindList object; if no such variable (either due to device not supporting it, or community name having incorrect access privilege), variable value will be SNMPNull object

Throws:
java.io.IOException - Thrown when timeout experienced while waiting for response to request.
SNMPBadValueException
SNMPGetException - Thrown if one the OID following the supplied OID has value that can't be retrieved

getNextMIBEntry

public SNMPVarBindList getNextMIBEntry(java.lang.String[] itemID)
                                throws java.io.IOException,
                                       SNMPBadValueException,
                                       SNMPGetException
Retrieve the MIB variable value corresponding to the object identifiers following those given in the itemID array (in dotted-integer notation). Return as SNMPVarBindList object; if no such variable (either due to device not supporting it, or community name having incorrect access privilege), SNMPGetException thrown

Throws:
java.io.IOException - Thrown when timeout experienced while waiting for response to request.
SNMPBadValueException
SNMPGetException - Thrown if OID following one of supplied OIDs has value that can't be retrieved

setMIBEntry

public SNMPVarBindList setMIBEntry(java.lang.String itemID,
                                   SNMPObject newValue)
                            throws java.io.IOException,
                                   SNMPBadValueException,
                                   SNMPSetException
Set the MIB variable value of the object identifier given in startID (in dotted-integer notation). Return SNMPVarBindList object returned by device in its response; can be used to check that setting was successful. Uses SNMPGetNextRequests to retrieve variable values in sequence.

Throws:
java.io.IOException - Thrown when timeout experienced while waiting for response to request.
SNMPBadValueException
SNMPSetException

setMIBEntry

public SNMPVarBindList setMIBEntry(java.lang.String[] itemID,
                                   SNMPObject[] newValue)
                            throws java.io.IOException,
                                   SNMPBadValueException,
                                   SNMPSetException
Set the MIB variable values of the supplied object identifiers given in the itemID array (in dotted-integer notation). Return SNMPVarBindList returned by device in its response; can be used to check that setting was successful. Uses SNMPGetNextRequests to retrieve variable values in sequence.

Throws:
java.io.IOException - Thrown when timeout experienced while waiting for response to request.
SNMPBadValueException
SNMPSetException

retrieveMIBTable

public SNMPVarBindList retrieveMIBTable(java.lang.String baseID)
                                 throws java.io.IOException,
                                        SNMPBadValueException,
                                        SNMPGetException
Retrieve all MIB variable values whose OIDs start with the supplied baseID. Since the entries of an SNMP table have the form .., this will retrieve all of the table data as an SNMPVarBindList object consisting of sequence of SNMPVariablePairs. Uses SNMPGetNextRequests to retrieve variable values in sequence.

Throws:
java.io.IOException - Thrown when timeout experienced while waiting for response to request.
SNMPBadValueException
SNMPGetException

retrieveMIBTable

public SNMPVarBindList retrieveMIBTable(java.lang.String[] baseID)
                                 throws java.io.IOException,
                                        SNMPBadValueException,
                                        SNMPGetException
Retrieve all MIB variable values whose OIDs start with the supplied baseIDs. The normal way for this to be used is for the base OID array to consist of the base OIDs of the columns of a table. This method will then retrieve all of the entries of the table corresponding to these columns, one row at a time (i.e., the entries for each row will be retrieved in a single SNMP request). This will retrieve the table data as an SNMPVarBindList object consisting of sequence of SNMPVariablePairs, with the entries for each row grouped together. This may provide a more convenient arrangement of the table data than the simpler retrieveMIBTable method taking a single OID as argument; in addition, it's more efficient, requiring one SNMP request per row rather than one request per entry. Uses SNMPGetNextRequests to retrieve variable values for each row in sequence.

Throws:
java.io.IOException - Thrown when timeout experienced while waiting for response to request.
SNMPBadValueException
SNMPGetException - Thrown if incomplete row retrieved

setReceiveBufferSize

public void setReceiveBufferSize(int receiveBufferSize)
Set the size of the buffer used to receive response packets. RFC 1157 stipulates that an SNMP implementation must be able to receive packets of at least 484 bytes, so if you try to set the size to a value less than this, the receive buffer size will be set to 484 bytes. In addition, the maximum size of a UDP packet payload is 65535 bytes, so setting the buffer to a larger size will just waste memory. The default value is 512 bytes. The value may need to be increased if get-requests are issued for multiple OIDs.


getReceiveBufferSize

public int getReceiveBufferSize()
Returns the current size of the buffer used to receive response packets.