Search code examples
snmpsnmp4j

SNMP GETBULK Issue: Only could get parts records(Such as 59 records, but there are more than 100 records)


I would like to get the interface information for the router by snmp GETBULK, but when I use it, only parts of the record were returned.

The code is below:

public static void main(String[] args) throws IOException, InterruptedException {
    Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
    snmp.listen();

    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));
    target.setVersion(SnmpConstants.version2c);
    target.setAddress(new UdpAddress("127.0.0.1/161"));
    target.setTimeout(3000);    //3s
    target.setRetries(1);

    PDU pdu = new PDU();
    pdu.setType(PDU.GETBULK);
    pdu.setMaxRepetitions(200); 
    pdu.setNonRepeaters(0);
    pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.31.1.1.1.1"))); 

    ResponseEvent responseEvent = snmp.send(pdu, target);
    PDU response = responseEvent.getResponse();

    if (response == null) {
        System.out.println("TimeOut...");
    } 
    else 
    {
        if (response.getErrorStatus() == PDU.noError) 
        {
            Vector<? extends VariableBinding> vbs = response.getVariableBindings();
            for (VariableBinding vb : vbs) {
                System.out.println(vb + " ," + vb.getVariable().getSyntaxString());
            }
        } 
        else 
        {
            System.out.println("Error:" + response.getErrorStatusText());
        }
    }
}

After executing it, there are 59 records be returned, but if I use GETNEXT to get them, there are about 197 records be returned.

Any ideas?

Hope anyone could help me, thanks in advance.


Solution

  • How big are your responses? Remember - a getbulk response has to fit in a single UDP packet. That's an absolute limit of 65,535 bytes - or if you've got MTU limitations potentially as small as 1,500 bytes.