[SNMP4J] Problem in understanding the code

AMRUTH KUMAR JUTURU akjuturub04 at gmail.com
Fri Jun 20 12:39:38 CEST 2008


Hi all,

                I am new to the snmp4j. I am trying to use this api in my
project. I have a problem in understanding the following code. I can make
out a bit of it, but a more detailed explanation can be very helpful to me.
Thank you very much in advance for any one who is ready to help.

 private static boolean processWalk(PDU response, PDU request, OID rootOID)
{
        if ((response == null) || (response.getErrorStatus() != 0)
            || (response.getType() == PDU.REPORT)) {
            return true;
        }
        boolean finished = false;
        OID lastOID = request.get(0).getOid();
        for (int i=0; (!finished) && (i<response.size()); i++) {
            VariableBinding vb = response.get(i);
            if ((vb.getOid() == null) || (vb.getOid().size() <
rootOID.size())
                || (rootOID.leftMostCompare(rootOID.size(), vb.getOid()) !=
0)) {
                finished = true;
            } else if (Null.isExceptionSyntax(vb.getVariable().getSyntax()))
{
                System.out.println(vb.toString());
                finished = true;
            } else if (vb.getOid().compareTo(lastOID) <= 0) {
                System.out.println("Variable received is not lexicographic
successor of requested one:");
                System.out.println(vb.toString() + " <= "+lastOID);
                finished = true;
            } else {
                System.out.println("Here I am printing the Variable Binding
"+vb.toString());
                lastOID = vb.getOid();
            }
        }
        if (response.size() == 0) {
            finished = true;
        }
        if (!finished) {
            VariableBinding next = response.get(response.size()-1);
            next.setVariable(new Null());
            request.set(0, next);
            request.setRequestID(new Integer32(0));
        }
        return finished;
    }

              This function is actually used in the process of an snmpwalk.
What does PDU.REPORT mean? What does OID.size() actually return and why are
we doing (   vb.getOid().size() < rootOID.size() )  and what is the use of
(rootOID.leftMostCompare(rootOID.size(), vb.getOid()) != 0)).

I dont understand the usage of
Null.isExceptionSyntax(vb.getVariable().getSyntax())) and when does such an
error occur?

               Thanks again for any help.

                                                           Regards,
                                                           Amruth Kumar
Juturu.



More information about the SNMP4J mailing list