SNMP GETNEXT

 

The SNMP GETNEXT operation is similar to the SNMP GET operation. The GETNEXT operation retrieves the value of the next OID in the tree. The GETNEXT operation is particularly useful for retrieving the table data and also for variables that cannot be specifically named. It is used for traversing the MIB tree.

 

Unlike SNMP GET, providing the instance value as part of the OID is not mandatory. The SNMP GETNEXT operation always returns the next OID in the MIB tree regardless of whether we specify the particular instance of OID.

 

Using High-Level API explains the usage of high-level API in performing SNMP GETNEXT operation.

 

Using Low-Level API explains the usage of low-level API in performing SNMP GETNEXT operation.

 

Using High-Level API

 

To perform the SNMP GETNEXT operation, the snmpGetNext() method can be used. Following are the steps involved in performing a simple GETNEXT operation using the SnmpTarget bean.

 

//instantiate the SnmpTarget

SnmpTarget target = new Snmptarget();

//set the host in which the SNMP agent is running

target.setTargetHost("localhost");

//set the OID

target.setObjectID(".1.3.6.1.2.1.1.1");

//perform GETNEXT

String result = target.snmpGetNext();

System.out.println("Response: " + result);

 

The above code snippet performs a GETNEXT operation, with the SNMP agent running on localhost, to get the value of the variable 1.2. (sysObject ID) and displays the results. Note that it does not return the value of 1.1 but 1.2, the OID next to 1.1. View the complete example present in <tutorials/highlevelapi/SnmpGetNext.java>.

 

The following methods can also be used for doing SNMP GETNEXT requests.

Multiple OIDs can be set using the setObjectIDList() method and the snmpGetNextList() method is used to query the agent.

 

The following methods can also be used for performing SNMP GETNEXT operation with multiple OIDs.

Using Low-Level API

 

Refer the topic SNMP GET Using Low-level API, which discusses the SNMP GET operation.

 

To perform the SNMP GETNEXT operation, we need to use the GETNEXT_REQ_MSG command constant instead of GET_REQ_MSG.

 

 

//Build GET Request PDU

SnmpPDU pdu = new SnmpPDU();

UDPProtocolOptions option = new UDPProtocolOptions("localhost");

session.setProtocolOptions(option); //sets the host in which the agent is running

pdu.setCommand(SnmpAPI.GETNEXT_REQ_MSG);

 

The rest of the steps remain the same as SNMP GET. View the complete example present in <tutorials/lowlevelapi/SnmpGetNext.java>.

 

 



Copyright © 1996-2006, AdventNet Inc. All Rights Reserved.