Why is the last index missing from the query when using snmp4j?


When I use NET-SNMP, I can get the total data,but when I use snmp4j,I find that last data is missing.
It only return 8193.and getnext 8193 the responseEvent.getResponse() is null . What is the reason?
TheThe NET-SNMP command is: snmpwalk -v 2c -c ‘password’ ip 1.3.6.1.2.1.31.1.1.1.7
image
and the snmp4j code is here:
Snmp snmp = SnmpComunication.getSession(snmpTarget.getSnmpVersion());
Target target = SnmpComunication.getSnmpTarget(snmp, snmpTarget, false);
Map<String, String> resultMap = new HashMap<String, String>();
try {
PDU pdu = null;
if (snmpTarget.getSnmpVersion() == MessageProcessingModel.MPv3) {
pdu = new ScopedPDU();
} else {
pdu = new PDU();
}
pdu.setType(PDU.GETNEXT);
OID targetOId = new OID(oid);
pdu.add(new VariableBinding(targetOId));
boolean matched = true;
while (matched) {
ResponseEvent responseEvent = snmp.send(pdu, target);
if (responseEvent == null || responseEvent.getResponse() == null) {
log.warn(“result is null!responseEvent:{},pdu:{}”,
JsonUtil.obj2Json(responseEvent),
JsonUtil.obj2Json(pdu.getVariableBindings()));
break;
}
PDU response = responseEvent.getResponse();
String nextOid = null;
List<? extends VariableBinding> variableBindings = response.getVariableBindings();
for (int i = 0; i < variableBindings.size(); i++) {
VariableBinding variableBinding = variableBindings.get(i);
nextOid = variableBinding.getOid().toDottedString();
if (nextOid.length() > oid.length() && resultMap.containsKey(nextOid.substring(oid.length() + 1))) {
log.info(“matched false! oid:{} have same subOid:{}”, oid, nextOid);
matched = false;
break;
}
if (!nextOid.startsWith(oid)) {
log.warn(“matched false!nextOid:{},oid:{}”,nextOid,oid);
matched = false;
break;
} else {
String varString = variableBinding.getVariable().toString();
log.info(“current oid:{},value:{}”,nextOid.substring(oid.length() + 1),varString);
resultMap.put(nextOid.substring(oid.length() + 1), varString);
}
}
if (!matched) {
break;
}
pdu.clear();
pdu.add(new VariableBinding(new OID(nextOid)));
log.info(“next oid:{},response.oid:{}”,nextOid);
}
return resultMap;
} catch (Exception e) {
}
return null;

The NET-SNMP walk command most likely uses GETBULK, whereas you are using GETNEXT. Independent from that, the agent is broken (i.e, has a bug regarding lexicographic ordering). The different PDU types in the request only explain, why the response could be different.

Please check you logic too. It will fail on certain OIDs, because you are using string comparison instead of numeric sub-identifier comparison. This will cause wrong results in some situations.

I have change GETNEXT TO GETBULK, and set setMaxRepetitions(10), the result is still same with getnext.and the last request responseEvent is:{“error”:null,“peerAddress”:null,“request”:{“bERLength”:33,“bERPayloadLength”:31,“confirmedPdu”:true,“errorIndex”:10,“errorStatus”:0,“errorStatusText”:“Success”,“maxRepetitions”:10,“nonRepeaters”:0,“requestID”:{“bERLength”:6,“bERPayloadLength”:6,“dynamic”:false,“exception”:false,“syntax”:2,“syntaxString”:“Integer32”,“value”:1039161836},“responsePdu”:false,“type”:-91,“variableBindings”:[{“bERLength”:17,“bERPayloadLength”:15,“exception”:false,“oid”:{“bERLength”:13,“bERPayloadLength”:13,“dynamic”:false,“exception”:false,“syntax”:6,“syntaxString”:“OBJECT IDENTIFIER”,“valid”:true,“value”:[1,3,6,1,2,1,31,1,1,1,7,100]},“syntax”:5,“variable”:{“bERLength”:2,“bERPayloadLength”:2,“dynamic”:false,“exception”:false,“syntax”:5,“syntaxString”:“Null”}}]},“response”:null,“userObject”:null},pdu:[{“bERLength”:17,“bERPayloadLength”:15,“exception”:false,“oid”:{“bERLength”:13,“bERPayloadLength”:13,“dynamic”:false,“exception”:false,“syntax”:6,“syntaxString”:“OBJECT IDENTIFIER”,“valid”:true,“value”:[1,3,6,1,2,1,31,1,1,1,7,100]},“syntax”:5,“variable”:{“bERLength”:2,“bERPayloadLength”:2,“dynamic”:false,“exception”:false,“syntax”:5,“syntaxString”:“Null”}}]