[SNMP4J] Get Subtree Problem

bvinod bvinod at barc.gov.in
Thu Jul 29 11:30:01 CEST 2010


Hi,

I have been using SNMP4J and made a GetSubtree function with the 
following code:

public class GetSubtree {

    int noOfRetries, timeOut;

    UdpAddress udpAddress;
    DefaultUdpTransportMapping dutm;

    OctetString communityString;
    CommunityTarget udpTarget;
    OID oid;
    VariableBinding variableBinding;

    public GetSubtree(String strUdpAddress, String strCommunityString, 
String strOid,
            int noOfRetries, int timeOut)
           throws HostUnknownException, IOException{
        this.noOfRetries = noOfRetries;
        this.timeOut = timeOut;
        try{
            udpAddress = new 
UdpAddress(InetAddress.getByName(strUdpAddress), 161);
        }catch(UnknownHostException uhe){
            throw new HostUnknownException(strUdpAddress);
        }

        try{
            dutm = new DefaultUdpTransportMapping();
            dutm.listen();
        }catch(IOException ie){
            System.out.println(ie.getMessage());
            throw ie;
        }


        communityString = new OctetString(strCommunityString);
        udpTarget = new CommunityTarget(udpAddress, communityString);

        udpTarget.setRetries(noOfRetries);
        udpTarget.setTimeout(timeOut);

        oid = new OID(strOid);

        variableBinding = new VariableBinding(oid);
    }
    public void getResponseValues(LinkedList<String> listResponseValues)
                throws NoResponseException, HostUnknownException, 
IOException, InterruptedException{
        Snmp snmp = new Snmp(dutm);
        DefaultPDUFactory pduFactory = new DefaultPDUFactory();
        TreeUtils tree = new TreeUtils(snmp, pduFactory);
        List l = tree.getSubtree(udpTarget, oid);
        Iterator i = l.iterator();
        while(i.hasNext()){
            TreeEvent treeEvent = (TreeEvent)i.next();
            VariableBinding[] vb = treeEvent.getVariableBindings();
            for(int i2=0;i2<vb.length;i2++){
                listResponseValues.add(vb[i2].getVariable().toString());
            }
        }
        dutm.close();
        snmp.close();
    }
}


When i use this class as follows:
                  String strOIDs = "1.3.6.1.2.1.1";
                 GetSubtree getTable = new GetSubtree(ipAddr, 
communityString, strOIDs, noOfRetries, timeOut);
                 getTable.getResponseValues(allSNMPdata);

I am experencing variable delays for the output. I am using the same 
machine as client (where this program is running) and run (to which i am 
sending getsubtree request). Few times the output is coming very fast 
(in 1-2 secs). Very often, the program is taking 1-2 minutes for getting 
the output. I could only found out that the call "Snmp snmp = new 
Snmp(dutm);"  is taking more time. Please help in me in this issue.

Thank You very much,
Vinod Kumar Boppanna





More information about the SNMP4J mailing list