[SNMP4J] SNMP4J-AgentX and shared tables

Peder Toftegaard Olsen p.olsen at mobilethink.dk
Tue Feb 6 11:48:19 CET 2007


Hi,

 

With the aid of SNMP4J-AgentX I am working on an AgentX subagent utilizing
shared tables. During the development I have run into some problems with
index allocation (using ANY_INDEX) and registration of rows.

 

The problems have manifested themselves as - and were solved as described:

 

* NPE's: Missing instantiation of VariableBinding.

* noOpen errors received from the master agent (NET-SNMP v. 5.4): Missing
setSessionAttributes.

* Not setting allocated index: Use resp.getVariableBindings() instead of
vbs.

* AgentXSharedMOTableSupport.allocateIndex() returning AGENTX_DISCONNECT on
success: Return AGENTX_SUCCESS on success.

 

Below is a proposed patch to SNMP4J-AgentX which has solved my problems.

 

 

Best regards

 

Peder Toftegaard Olsen

Senior Software Architect

Mobilethink A/S

 

 

Unified patch for SNMP4J-AgentX 1.0RC1:

 

--- org/snmp4j/agent/agentx/subagent/AgentXSharedMOTableSupport.java
Fri Nov 24 01:22:34 2006

+++ org/snmp4j/agent/agentx/subagent/AgentXSharedMOTableSupport.java
Tue Feb 06 11:07:40 2007

@@ -162,6 +162,7 @@

       if (oid == null) {

         throw new IllegalArgumentException("Sub-index "+i+" has no OID");

       }

+      vbs[i] = new VariableBinding();

       vbs[i].setOid(oid);

       vbs[i].setVariable(indexValues[i]);

     }

@@ -169,6 +170,7 @@

     if (indexAllocationMode != 0) {

       pdu.addFlag(indexAllocationMode);

     }

+    pdu.setSessionAttributes(session);

     try {

       AgentXResponseEvent response =

           agentX.send(pdu, session.createAgentXTarget(),

@@ -176,8 +178,9 @@

       if (response.getResponse() != null) {

         AgentXResponsePDU resp = response.getResponse();

         if (resp.getErrorStatus() == AgentXProtocol.AGENTX_SUCCESS) {

-          OID index = indexDef.getIndexOID(getVariables(vbs));

+            OID index =
indexDef.getIndexOID(getVariables(resp.getVariableBindings()));

           allocatedIndex.setValue(index.getValue());

+          return AgentXProtocol.AGENTX_SUCCESS;

         }

         else {

           return resp.getErrorStatus();

@@ -250,6 +253,7 @@

                               (byte)(table.getOID().size()+1),

                               table.getColumn(table.getColumnCount()-1).

                               getColumnID());

+    pdu.setSessionAttributes(session);

     try {

       AgentXResponseEvent resp =

           agentX.send(pdu, session.createAgentXTarget(),

--- org/snmp4j/agent/agentx/subagent/AgentXSubagent.java       Fri Feb 02
00:42:04 2007

+++ org/snmp4j/agent/agentx/subagent/AgentXSubagent.java    Tue Feb 06
10:59:34 2007

@@ -388,6 +388,7 @@

         new AgentXUnregisterPDU(context, region.getLowerBound(), t,

                                 region.getRangeSubID(),

                                 region.getUpperBoundSubID());

+    pdu.setSessionAttributes(session);

     AgentXResponseEvent event =

         agentX.send(pdu, new AgentXTarget(session.getPeer().getAddress(),

                                           this.timeout),




More information about the SNMP4J mailing list