[SNMP4j] getTable Issues [a] version1 vs version2c [b] null pointer

Mystery Guest fw58959 at hotmail.com
Mon Dec 5 06:40:04 CET 2005


Thank you for your response.

With respect to B I added code to check for a null value
and that got me past the null pointer exception.

     for ( int i = 0; i<tableEvent.getColumns().length; i++) {
       if (tableEvent.getColumns()[i] == null) {
	  System.out.print("NULL");
       }
       else {
          ... code from CVSTableListener to print a TableEvent ...
       }
       ...

I wonder if it would be a good idea to update the sample
SNMP4J console that comes bundled with SNMP4J to add the same check
in the CVSTableListener method?  Is it not susceptible
to the same problem?


In my TableEvent dump of each member of the list I also
discovered a couple of interesting things.

a. For a given index value the columnar values could be
spread across multiple TableEvent instances.

19,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,949021697
20, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,430111941
19,"FastEthernet0/23",6,1500,100000000,"00:0d:ed:75:8f:97",1,1,17 days, 
10:03:44 .71,1556074672,NULL
20,"FastEthernet0/24",6,1500,100000000,"00:0d:ed:75:8f:98",1,1,0:00:44.78,194266036,NULL

In the above example indices 19 and 20 are repeated with the first
instances having null values for all columns except the last one
and the second instances having valid values for all columns
except the last one.  Combine them and you get the true table
result.  I guess I was expecting getTable to return this as
just one TableEvent.

b.  There was a set of instances similar to the above where
there was null values for all columns except the last one but
there was no corresponding mate to combine it with.  A snoop
shows the missing bits coming across so I have to do some more
digging to determine why my program is not getting it.

25,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0
26,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0
27,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0
28,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,2074860
29,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,28369966
30,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,3186430

The values missing are for two GigabitEthernet interfaces, some
Vlans and a Null interface.

Interesting.

Thanks again for your help.



>From: Frank Fock <fock at agentpp.com>
>To: Mystery Guest <fw58959 at hotmail.com>
>CC: snmp4j at agentpp.org
>Subject: Re: [SNMP4j] getTable Issues [a] version1 vs version2c [b] null 
>pointer
>Date: Fri, 02 Dec 2005 20:28:50 +0100
>
>Colin,
>
>A: This issue is most likely related to your agent. Please check the
>response PDU received from the agent for correct version and
>request ID.
>
>B: The agent probably does not implement lexicographic ordering
>correctly or it does not implement all columns for all rows. You will
>have to check the Variable returned for each column if it is null or
>not in order to avoid the NullPointerException.
>
>Best regards,
>Frank
>
>Mystery Guest wrote:
>
>>Hello,
>>
>>I am relatively new to Java but have some experience with networking.
>>I have written some sample Java programs using SNMP4J that do both
>>synchronous and asynchronous GET requests and these have worked well.
>>I am now trying my hand at a synchronous table get and I have run
>>into a couple of problems.  The first problem I managed to solve but
>>the second one has me stumped at the moment and I am hoping that
>>someone could point me in the right direction to resolve it.
>>
>>OS:  Solaris 10 as a VMWare guest
>>Java: Java(TM) 2 Runtime Environment, Standard Edition (build 
>>1.5.0_01-b08)
>>SNMP4J:  1.6b
>>
>>A. The first issue was that my getTable call was returning a status code
>>which implied a timeout.  A snoop of the interface showed the
>>request going out and a response coming back.  It was then that I noticed
>>I had set my version to 1 [ target.setVersion(SnmpConstants.version1); ]
>>If I changed the version to 2c then I started getting results I expected.
>>Could anyone explain why this would be so?
>>
>>B. Now my getTable call is working and I am printing out the data from
>>each TableEvent.  However, at the 19th TableEvent I am getting a
>>null pointer exception.  The table event status code is 0 and a snoop
>>shows the data being returned so I am at a bit of a loss to figure out
>>where I have gone wrong.  I think my code is OK otherwise I would have
>>expected a problem on the first iteration.  If anyone has any hints
>>I would greatly appreciate it.
>>
>>Output:
>>
>>sol10a-colin[4]% ./runit SnmpTestTable
>>
>>----- Start of Table Event -----
>>Table event status = 0
>>Index = 1
>>Number of columns = 11
>>1,"FastEthernet0/1",6,1500,100000000,"00:0d:ed:75:8f:81",1,1,0:00:45.76,2561384523,9262716
>>
>>----- End of Table Event -----
>>
>>----- Start of Table Event -----
>>Table event status = 0
>>Index = 2
>>Number of columns = 11
>>2,"FastEthernet0/2",6,1500,100000000,"00:0d:ed:75:8f:82",1,1,0:00:44.68,4046297721,1826102036
>>
>>----- End of Table Event -----
>>
>>        .... snip ....
>>
>>----- Start of Table Event -----
>>Table event status = 0
>>Index = 18
>>Number of columns = 11
>>18,"FastEthernet0/22",6,1500,100000000,"00:0d:ed:75:8f:96",1,1,0:00:44.78,1125561467,105822311
>>
>>----- End of Table Event -----
>>
>>----- Start of Table Event -----
>>Table event status = 0
>>Index = 19
>>Number of columns = 11
>>Exception in thread "main" java.lang.NullPointerException
>>        at SnmpTestTable.main(SnmpTestTable.java:77)
>>
>>Code Snippet:
>>
>>   // send request
>>
>>   List tableEventList = tableUtils.getTable(target, oidIfTable, null, 
>>null);
>>
>>   // dump what we have received
>>
>>   Iterator tableEventIter = tableEventList.iterator();
>>   while (tableEventIter.hasNext()) {
>>
>>     TableEvent tableEvent = (TableEvent)tableEventIter.next();
>>
>>     System.out.println(" ");
>>     System.out.println("----- Start of Table Event -----");
>>     System.out.println("Table event status = "+tableEvent.getStatus());
>>     System.out.println("Index = "+tableEvent.getIndex());
>>     System.out.println("Number of columns = " + 
>>tableEvent.getColumns().length);
>>
>>     for ( int i = 0; i<tableEvent.getColumns().length; i++) {
>>       Variable v = tableEvent.getColumns()[i].getVariable();    <== Fails 
>>here
>>       String value = v.toString();
>>       switch (v.getSyntax()) {
>>           .... the rest of this code comes from the...
>>        .... SNMP4J sample console code in the method ...
>>        .... CVSTableListener ....
>>
>>I hope this isn't too long and that I have provided enough information.
>>
>>Many thanks in advance.
>>
>>./Colin
>>
>>
>>_______________________________________________
>>SNMP4J mailing list
>>SNMP4J at agentpp.org
>>http://lists.agentpp.org/mailman/listinfo/snmp4j
>>
>>
>
>
>--
>AGENT++
>http://www.agentpp.com
>http://www.mibexplorer.com
>http://www.mibdesigner.com
>
>





More information about the SNMP4J mailing list