[SNMP4J] CommandResponder responding to walk

Torsten Curdt tcurdt at vafer.org
Thu Oct 15 03:05:52 CEST 2009


Hey,

I've got a ComandResponder and some problems with supporting a GETNEXT.

First off: IIUC the response of a GETNEXT should include the following
OID but the value of the original OID. Is that correct?

  public void processPdu(CommandResponderEvent pRequest) {

    final PDU requestPdu = pRequest.getPDU();

    if (requestPdu == null) {
      return;
    }

    System.out.println("request PDU" + requestPdu);

    try {

      final PDU responsePdu = new PDU(requestPdu);
      responsePdu.setType(PDU.RESPONSE);

      if (requestPdu.getType() == PDU.GET) {

        for(VariableBinding binding : responsePdu.toArray()) {
            final OID oid = binding.getOid();
            final Variable variable = resolver.getVariableForOid(oid);
            binding.setVariable(variable);
          }

      } else if (requestPdu.getType() == PDU.GETNEXT) {

        for(VariableBinding binding : responsePdu.toArray()) {
            final OID oid = binding.getOid().successor();
            final Variable variable =
resolver.getVariableForOid(binding.getOid());
            binding.setOid(oid);
            binding.setVariable(variable);
          }

      } else {

      }

      System.out.println("response PDU" + responsePdu);

      pRequest.getStateReference().setTransportMapping(pRequest.getTransportMapping());
      pRequest.getMessageDispatcher().returnResponsePdu(
          pRequest.getMessageProcessingModel(),
          pRequest.getSecurityModel(),
          pRequest.getSecurityName(),
          pRequest.getSecurityLevel(),
          responsePdu,
          pRequest.getMaxSizeResponsePDU(),
          pRequest.getStateReference(),
          new StatusInformation()
          );

//    pRequest.setProcessed(true);

      System.out.println("done");

    } catch (Exception e) {
      e.printStackTrace();
    }
  }

Now what I am wondering is:

- How do I signal an "end of walk" when there are no further OIDs to traverse?
- Is "successor" really the right way to do this? It seems to just add
".0". Wouldn't I need to check the tree what is the real next node?
- Do I need to set "pRequest.setProcessed"?
- Why would one need to copy the transport mapping like this
"pRequest.getStateReference().setTransportMapping(pRequest.getTransportMapping());"
as I've found it in some examples on the web?

cheers
--
Torsten



More information about the SNMP4J mailing list