[jboss-cvs] JBossAS SVN: r110204 - branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Dec 23 17:00:54 EST 2010


Author: thauser at redhat.com
Date: 2010-12-23 17:00:54 -0500 (Thu, 23 Dec 2010)
New Revision: 110204

Modified:
   branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/Test.java
Log:
start implementation of snmpwalk test.

Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/Test.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/Test.java	2010-12-23 21:35:12 UTC (rev 110203)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/Test.java	2010-12-23 22:00:54 UTC (rev 110204)
@@ -36,6 +36,9 @@
 		else if (args[0].equals("testnullpdu")){
 			testnull();
 		}
+		else if (args[0].equals("snmpwalk"));{
+			snmpwalk(args);
+		}
 		else 
 		{
 			System.out.println("Arg1: "+ args[1]);
@@ -45,6 +48,69 @@
 			//improper action
 		}
 }	
+		public static void snmpwalk(String [] args){
+			PDU pdu = new PDU();
+			OID currentOID = new OID(args[1]);
+			OID endOID = new OID(args[2]);
+			
+			if (currentOID.compareTo(endOID) > 0){
+				// invalid start / end OIDs.
+				return; 
+			}
+			pdu.add(new VariableBinding(currentOID));
+			pdu.setType(PDU.GETNEXT);
+			
+			while (currentOID.compareTo(endOID)<=0){
+				
+				
+			}
+			
+			
+			CommunityTarget target = new CommunityTarget();
+			OctetString community = new OctetString("public");
+			target.setCommunity(community);
+			target.setVersion(SnmpConstants.version2c);
+			Address targetAddress = GenericAddress.parse("udp:127.0.0.1/1161");
+			target.setAddress(targetAddress);
+			target.setRetries(0);
+			target.setTimeout(2000);
+			
+			try {
+				DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping();
+				transport.listen();
+				System.out.println("READY: "+System.currentTimeMillis());
+				Snmp snmp = new Snmp(transport);
+				long t1 = System.currentTimeMillis();
+				System.out.println("SENDING: "+t1);
+				System.out.println("PDU: "+pdu);
+				ResponseEvent responseEvent = snmp.send(pdu, target);
+				long t2=System.currentTimeMillis();
+				System.out.println("SENT: "+t2);
+				System.out.println("ELAPSED: "+(t2-t1));
+				System.out.println("response " + responseEvent.toString());
+
+				PDU responsePDU = responseEvent.getResponse();
+				if (responsePDU == null){
+					System.out.println("Request timed out");
+				}
+				else{
+					System.out.println("Received response "+responsePDU);
+				}
+					System.out.println("Peer Address: "+responseEvent.getPeerAddress());
+			} catch (UnknownHostException e1) {
+				// TODO Auto-generated catch block
+				e1.printStackTrace();
+			} catch (IOException e1) {
+				// TODO Auto-generated catch block
+				e1.printStackTrace();
+			} catch (Exception e) {
+				System.out.println("Some Other exception!!");
+			}
+			
+		}
+	
+	
+	
 	   public static void getbulk(){
 			PDU pdu = new PDU();
 			pdu.setType(PDU.GETBULK);



More information about the jboss-cvs-commits mailing list