[SNMP4J] Determine if an agent supports SNMPv2c

PHIL BERGSTRESSER phil.bergstresser at adtran.com
Mon Mar 14 19:08:29 CET 2005


Rodolfo,
    I think your first approach is the correct one if the agents you are
accessing implement SNMP correctly. A simple get of sysDescr.0 with SNMP
version of 2 should yield no response if the agent does not support v2. You
don't have to experiment with trying getBulks etc. The agent either does or
does not support SNMPv2. Saying you know that your target does not support
SNMPv2 is curious if in fact it is responding with a v2 Response PDU. It
looks like it doesn't agree with you. Go with the evidence it is telling
you. If you find later that a getBulk doesn't work, then the agent is
defective, and there could be all kinds of other problems too.
    You could enhance your println to include the version field of the
response PDU. It h
    HTH,

Phil
Phil Bergstresser
Design Engineer
SNMP Network Management
ADTRAN, Inc.

 -----Original Message-----
From: 	Rodolfo Josÿffffe9 Castellanos Jaimes [mailto:rodolfojcj at yahoo.com] 
Sent:	Monday, March 14, 2005 8:26 AM
To:	snmp4j at agentpp.org
Subject:	[SNMP4J] Determine if an agent supports SNMPv2c

Hi friends. I hope all of you be very well.

I have a doubt about how to determine in a reliable
way if an agent supports SNMPv2c.

That I know is that for version 1 the agent implements
the MIB-II specified by RFC 1213 and has the PDUs
GetRequest, GetNextRequest, SetRequest, GetResponse
and Trap. In the case of v2c the RJC 1907 defines the
enhancements of MIB-II and the PUDs are GetRequest,
GetNextRequest, GetBulkRequest, SetRequest,
InformRequest, Response and SNMPv2-Trap. (Stallings,
1999)

Well, using SNMP4J, I've done a Java class that
determines if a given host supports v1. The code is
something like this:

///////////// test v1 support

 Address targetAddress = 
   GenericAddress.parse( targetHost + "/" + snmpPort
);
 TransportMapping transport = 
   new DefaultUdpTransportMapping();
 Snmp snmp = new Snmp( transport );
 transport.listen();

 // setting up target
 CommunityTarget target = new CommunityTarget();
 target.setCommunity( new OctetString( "public" ) );
 target.setAddress( targetAddress );
 target.setRetries( 2 );
 target.setTimeout( 350 );
 target.setVersion( SnmpConstants.version1 );

 // creating request PDU
 PDU requestPDU = new PDU();
 // request "sysName" variable, because its status is
 // "mandatory" then any Snmp agent must respond to
 // this request
 requestPDU.add( new VariableBinding( 
 new OID( new int[] {1,3,6,1,2,1,1,5,0} ) ) );
 requestPDU.setType( PDU.GET );

 // sending request
 PDU responsePDU = null;
 ResponseEvent responseEvent = null;

 responseEvent = snmp.send( requestPDU, target );
 if ( responseEvent != null )
   responsePDU = responseEvent.getResponse();
 snmp.close();
			
 if ( responsePDU != null) // there was a response
   System.out.println( "The device supports SNMPv1" );
 else
   System.out.println( "Device doesn't support SNMPv1"
);

/////////////

Next, I modified the code to test if a device supports
SNMPv2c. I wrote "target.setVersion(
SnmpConstants.version2c )" and sent the same PDU
(requesting 1.3.6.1.2.1.1.5.0) and, for a device that
I know that only has support for version 1, I'm
getting a response; and it wasn't that I
was expecting because I specified version2c
(SnmpConstants.version2c). Here is probably that I
have a misunderstanding about the fields
SnmpConstants.version1 and SnmpConstants.version2c.
But, that I undernstand about it is that I can specify
which message processing model are we using when
communicating with the target host.

Then, I'm thinking about request an OID that is only
present in RFC 1907 (for example sysORLastChange
1.3.6.1.2.1.1.8.0) or specify a PDU GetBulk because
any of them is only specified for version 2 of SNMP.
If I get a positive response, then the device supports
this last version.
But actually I'm not sure if applying this approach
I'll get a reliable diagnose.

What do you think about this ?
Which could be a better point of view to determine
which version of SNMP is an agent running (that, in
last case, is that I want to do) ?

Any comment, suggestion, help, etc. will be welcome.

Thanks in advance by your time and attention.
Rodolfo José Castellanos Jaimes.

_________________________________________________________
Do You Yahoo!?
Información de Estados Unidos y América Latina, en Yahoo! Noticias.
Visítanos en http://noticias.espanol.yahoo.com
_______________________________________________
SNMP4J mailing list
SNMP4J at agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j



More information about the SNMP4J mailing list