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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Dec 1 17:48:45 EST 2010


Author: thauser at redhat.com
Date: 2010-12-01 17:48:43 -0500 (Wed, 01 Dec 2010)
New Revision: 109635

Modified:
   branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
Log:
starting implementation of GETBULK requests

Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java	2010-12-01 18:47:31 UTC (rev 109634)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java	2010-12-01 22:48:43 UTC (rev 109635)
@@ -144,6 +144,86 @@
    
 	// SnmpAgentHandler Implementation -------------------------------
 
+   /** 
+    * <P>
+    * This method handles SNMP GetBulk requests recieved in this session. Request
+    * is already validated. Builds a response and passes it back.
+    * </P>
+    * @param pdu
+    * 		contains the following:
+    * 		a list of OIDs 
+    * 		an Integer indicating the number of non-repeaters
+    * 		an Integer indicating the number of repititions
+    * @return a PDU filled with the appropriate values.
+    * 
+    */
+   	public PDU snmpRecievedGetBulk(PDU pdu){
+   		PDU response;
+   		
+		if (pdu instanceof ScopedPDU){
+			response = DefaultPDUFactory.createPDU(SnmpConstants.version3);
+		} else if (pdu instanceof PDUv1){
+			response = DefaultPDUFactory.createPDU(SnmpConstants.version1);
+		} else {
+			response = new PDU();
+		} 
+		response.setType(PDU.RESPONSE);
+		
+		final boolean trace = log.isTraceEnabled();
+			
+		if (trace) {
+			log.trace("requestID=" + pdu.getRequestID() + ", elementCount="
+					+ pdu.size());
+		}
+		if (pdu != null){
+			
+			Vector it = pdu.getVariableBindings();
+			VariableBinding newVB;
+			VariableBinding vb;
+			Variable var;
+			
+			for (int i=0;i<pdu.getNonRepeaters();i++){
+				vb = (VariableBinding)it.get(i);
+				OID oid = getNextOid(vb.getOid(), true);
+				var = getValueFor(oid);
+				newVB = new VariableBinding(oid,var);
+				response.add(newVB);			
+			}
+			for (int i=pdu.getNonRepeaters();i<it.size();i++){
+				vb = (VariableBinding)it.get(i);
+				OID noid = getNextOid(vb.getOid(),true);
+				for (int j=0;i<pdu.getMaxRepetitions();j++){
+					var = getValueFor(noid);
+					newVB = new VariableBinding(noid,var);
+					response.add(newVB);
+					noid = getNextOid(noid,true);
+					if (noid == null)
+						break;
+				}
+			}
+				
+			}
+			
+			
+			
+			
+/*			while (it.hasNext()){
+				VariableBinding vb = (VariableBinding)it.next();
+				OID oid = vb.getOid();
+				
+				newVB = new VariableBinding(oid);
+				//some errorchecking ....
+				//else is good and do:
+				var = getValueFor(oid);
+				
+					newVB.setVariable(var);
+					response.add(newVB);
+					}*/
+		return response;
+   	}
+   
+   
+   
 	/**
 	 * <P>
 	 * This method is defined to handle SNMP Get requests that are received by
@@ -153,11 +233,8 @@
 	 * 
 	 * @param pdu
 	 *            The SNMP pdu
-	 * @param getNext
-	 *            The agent is requesting the lexically NEXT item after each
-	 *            item in the pdu.
 	 * 
-	 * @return SnmpPduRequest filled in with the proper response, or null if
+	 * @return a PDU filled in with the proper response, or null if
 	 *         cannot process NOTE: this might be changed to throw an exception.
 	 */
 	public PDU snmpReceivedGet(PDU pdu)
@@ -180,35 +257,36 @@
 						+ pdu.size());
 			}
 		
-			if (pdu != null){
+		if (pdu != null){
 				
-				Iterator it = pdu.getVariableBindings().iterator();
-				VariableBinding newVB;
-				Variable var;
-				while (it.hasNext()){
-					VariableBinding vb = (VariableBinding)it.next();
-					OID oid = vb.getOid();
-					if (pdu.getType()==PDU.GETNEXT){	
-						OID noid = getNextOid(oid,true);
-						newVB = new VariableBinding(noid);
-						var = getValueFor(noid);						
-					}
+			Iterator it = pdu.getVariableBindings().iterator();
+			VariableBinding newVB;
+			Variable var;
+			
+			while (it.hasNext()){
+				VariableBinding vb = (VariableBinding)it.next();
+				OID oid = vb.getOid();
+
+				if (pdu.getType()==PDU.GETNEXT){	
+					// we get the lexically next OID from the given one.
+					OID noid = getNextOid(oid,true);
+					newVB = new VariableBinding(noid);
+					var = getValueFor(noid);						
+				}
 				else {
-						newVB = new VariableBinding(oid);
+					newVB = new VariableBinding(oid);
 					//some errorchecking ....
 					//else is good and do:
 					var = getValueFor(oid);
 				}
 					newVB.setVariable(var);
 					response.add(newVB);
-					}
-				//}
-			}
-		//END IF MINE
-
+		 	}
+			
+		}
 		return response;
+	}	
 		
-		
 //		try
 //		{
 //			SnmpPduRequest response = null;
@@ -290,7 +368,6 @@
 //			e.printStackTrace();
 //			return null;
 //		}
-	}
 
 	/**
 	 * <P>
@@ -676,6 +753,7 @@
 	
 	private Variable prepForPdu(final Object val){
 		Variable result = null;
+		//TODO: all types managed by the PDU 
 		if (val instanceof Long)
         {
 			result = new Counter32((Long)val);
@@ -739,10 +817,6 @@
 		
 	}
 	
-	
-	
-	
-	
 //	/**
 //	 * Set a jmx attribute
 //	 * @param oid The oid to set. This is translated into a mbean / attribute pair



More information about the jboss-cvs-commits mailing list