[SNMP4J] TreeUtils getSubTree returning partial results

Hema Gupta hemagupta at hotmail.com
Mon Apr 25 16:13:35 CEST 2011



 


Hi,
 
I am using TreeUtils.getSubtree to retrieve some mibs from a  a CISCO router.
 
The issue is that sometimes the response comes out as smaller than other times if I run it
a couple of times. On few occassions the variable bindings returned is an empty list .
Tried printing out the error and status from each tree event , but it never gives an error.
The issue is more pronounced when running the program in multithreaded env with each thread trying to get a different mib on the router in parallel.
 
As a result my program assumes that the query was successful but it gets only partial data for that MIB.
Sometime no data is returned at all for the same mib object that in another run would return more than 1000 lines.
 
I tried adjusting the timeout on the target oject, but doesn't help.
I want to be able to detect when the result is incomplete due to timeouts or some error, so that we know an error occyrred and can retry.
 
 
Code snippet:
                        Snmp snmp4j = new Snmp(new DefaultUdpTransportMapping());
                        snmp4j.listen();
                        Address add = new UdpAddress(ipAddr+"/"+snmpPort);
                        CommunityTarget target = new CommunityTarget();
                        target.setAddress(add);
                        target.setTimeout(snmpTimeout);
                        target.setAddress(add);
                        target.setRetries(numRetries);
                        target.setVersion(SnmpConstants.version2c);
                        target.setMaxSizeRequestPDU(65535);
                        target.setCommunity(new OctetString(commStr));

                       OID oID = new OID(strOid);
                                
                                         PDU request = new PDU();
                                        request.setType(PDU.GETBULK);
                                        request.setMaxRepetitions( 100);
                                        request.setNonRepeaters( 0);
                                        request.add(new VariableBinding(oID));
                                        OID rootOID = request.get(0).getOid();
                                        VariableBinding vb,ar[];
                                        TreeUtils treeUtils = new TreeUtils(snmp4j,
                                                        new DefaultPDUFactory());
                                        LinkedList l = (LinkedList)treeUtils.getSubtree(target, rootOID);
                                        if(l == null) {
                                                logger.logWarning(className, methodName,
                                                        "subTree:" + strOid+ " results:null");
                                                continue;
                                        }
                                         if (l.size() == 0 ) {
 
                                            logger.logWarning(className, methodName,
                                                        "returned tree has no content");
                                        }
                                        else {
                                          logger.logDebug( className, methodName,"list size="+l.size());
                                          ListIterator lt = l.listIterator(0);
                                          boolean bBreak = false;
                                          while (lt.hasNext()) {
                                                TreeEvent t = (TreeEvent)lt.next();
                                                if ( t.getStatus() != 0 )
                                                                logger.logWarning( className, methodName," Treeevnt.status="+t.getStatus());
                                                 logger.logDebug( className, methodName," Treeevnt.report PDU="+t.getReportPDU());
                                                ar = t.getVariableBindings();
                                                if(ar == null ) {
                                                        logger.logWarning(className, methodName,
                                                                "ar == null");
                                                 }
                                                else
                                                  logger.logDebug( className, methodName, "array length="+Array.getLength(ar));
                                                for(int i = 0; (ar != null) && i < Array.getLength(ar);
                                                        i++) {
                                                        vb = ar[i];
                                                        System.out.println(vb.toString());
                                                }
                                           }

Ispent a day trying to address this issue, any help is greatly appreciated.
 
Thanks
-Hema
 
 		 	   		  


More information about the SNMP4J mailing list