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

StackOverflow https://stackoverflow.com/questions/17719404

  •  03-06-2022
  •  | 
  •  

Question

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.

Was it helpful?

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.

OTHER TIPS

This is expected behaviour, and can happen for a few reasons.

Quoting RFC 3416 §4.2.3 "The GetBulkRequest-PDU" (emphasis mine):

[..] The receiving SNMP entity produces a Response-PDU with up to the total number of requested variable bindings communicated by the request.

[..] While the maximum number of variable bindings in the Response-PDU is bounded by N + (M * R), the response may be generated with a lesser number of variable bindings (possibly zero) for either of three reasons.

  1. If the size of the message encapsulating the Response-PDU containing the requested number of variable bindings would be greater than either a local constraint or the maximum message size of the originator, then the response is generated with a lesser number of variable bindings. This lesser number is the ordered set of variable bindings with some of the variable bindings at the end of the set removed, such that the size of the message encapsulating the Response-PDU is approximately equal to but no greater than either a local constraint or the maximum message size of the originator. Note that the number of variable bindings removed has no relationship to the values of N, M, or R.

  2. The response may also be generated with a lesser number of variable bindings if for some value of iteration i, such that i is greater than zero and less than or equal to M, that all of the generated variable bindings have the value field set to "endOfMibView". In this case, the variable bindings may be truncated after the (N + (i * R))-th variable binding.

  3. In the event that the processing of a request with many repetitions requires a significantly greater amount of processing time than a normal request, then a command responder application may terminate the request with less than the full number of repetitions, providing at least one repetition is completed.

[..]

In your case, you're most likely exceeding the maximum message size.

If you get fewer objects than you wanted, you can just do another GetBulk request starting where you left off. (This is the same as how you handle TCP/IP sockets in C code — you have to keep read()ing in turn until you have everything you want.)

For example, implementations such as Net-SNMP's snmptable (a table walker that can be instructed to use GetBulk) will do this until the end of the table has been reached.

I would just like to point out that the original poster had the solution : use GETNEXT instead of GETBULK and you will get all of the records. GETBULK will only work for you if your returns are within the size PP. specified.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top