[jboss-cvs] JBossAS SVN: r109673 - 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
Thu Dec 2 17:16:21 EST 2010


Author: thauser at redhat.com
Date: 2010-12-02 17:16:20 -0500 (Thu, 02 Dec 2010)
New Revision: 109673

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/RequestHandlerSupport.java
   branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentRequestHandler.java
   branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java
Log:
add snmpReceivedGetBulk method to interfaces and implementation. Add this method to be called when a PDU of type GETBULK is received by the Agent. Rudimentary PDU errors implemented. 

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-02 22:15:03 UTC (rev 109672)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java	2010-12-02 22:16:20 UTC (rev 109673)
@@ -148,24 +148,32 @@
     * <P>
     * This method handles SNMP GetBulk requests recieved in this session. Request
     * is already validated. Builds a response and passes it back.
+    * A GetBulk request has two additional fields: 
+    * nonRepeaters: the amount of scalar objects in the PDU
+    * maxRepetitions: the number of getNext requests to be done on the scalar objects.
+    * The parameter PDU is interpreted as follows: 
+    * The first nonRepeaters elements in the VariableBinding list are retrieved with a simple GET snmp call.
+    * The remaining (size - nonRepeaters) elements in the VariableBinding list have maxRepetitions GETNEXT calls
+    * upon them. All of these VariableBindings are added into the response. 
     * </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
+    * 		an Integer > 0 indicating the number of non-repeaters (set with PDU.setNonRepeaters())
+    * 		an Integer >= 0 indicating the number of repetitions   (set with PDU.setMaxRepetitions())
     * @return a PDU filled with the appropriate values.
     * 
     */
    
    // this method is a work in progress.
-   	public PDU snmpRecievedGetBulk(PDU pdu){
+   	public PDU snmpReceivedGetBulk(PDU pdu){
    		PDU response;
    		
 		if (pdu instanceof ScopedPDU){
 			response = DefaultPDUFactory.createPDU(SnmpConstants.version3);
 		} else if (pdu instanceof PDUv1){
-			response = DefaultPDUFactory.createPDU(SnmpConstants.version1);
+			log.debug("snmp-adaptor: cannot getBulk with V1 PDU.");
+			return null;
 		} else {
 			response = new PDU();
 		} 
@@ -178,39 +186,57 @@
 					+ pdu.size());
 		}
 		if (pdu != null){
-			
+			int nonRepeaters = pdu.getNonRepeaters();
+			int maxRepetitions = pdu.getMaxRepetitions();
 			Vector it = pdu.getVariableBindings();
-			VariableBinding newVB;
 			VariableBinding vb;
 			Variable var;
 			
-			for (int i=0;i<pdu.getNonRepeaters();i++){
+			// for the first nonRepeater Bindings, we simply get their value. if nonRepeaters is 0, 
+			// we do a GET on every element, and ignore the next loop.
+			for (int i=0; i < Math.min(nonRepeaters, it.size());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++){
+				OID oid = vb.getOid();
+					
+					if (oid == null){
+						log.debug("Attempt to GETBULK on non-existent scalar OID.");
+						response.setErrorStatus(PDU.noSuchName);
+						response.setErrorIndex(i);
+						return response;
+						// TODO: should we fail out here?
+					}
+					var = getValueFor(oid);
+					response.add(new VariableBinding(oid,var));
+				}
+			
+			// for the remaining it.size() bindings, we perform maxRepetitions successive getNext calls
+			for (int i = nonRepeaters; i < it.size(); i++){
 				vb = (VariableBinding)it.get(i);
 				OID noid = getNextOid(vb.getOid(),true);
-				for (int j=0;i<pdu.getMaxRepetitions();j++){
+				
+				//FIXME: returns null when maxReptitions goes into OIDs that don't exist. 
+				for (int j = 0; j < maxRepetitions; j++){
 					var = getValueFor(noid);
-					newVB = new VariableBinding(noid,var);
-					response.add(newVB);
+					
+					if (noid == null){
+						log.debug("Attempt to GETBULK on non-existent non-scalar OID.");
+						response.setErrorStatus(PDU.noSuchName);
+						response.setErrorIndex(i);
+						// TODO: should we fail out here?
+						return response;
+					}
+					
+					response.add(new VariableBinding(noid,var));
 					noid = getNextOid(noid,true);
-					if (noid == null)
-						break;
 				}
 			}
 				
-			}
+		}	
 		return response;
    	}
+   	
    
-   
-   
-	/**
+    /**
 	 * <P>
 	 * This method is defined to handle SNMP Get requests that are received by
 	 * the session. The request has already been validated by the system. This
@@ -218,7 +244,7 @@
 	 * </P>
 	 * 
 	 * @param pdu
-	 *            The SNMP pdu
+	 *            The SNMP pdu.           
 	 * 
 	 * @return a PDU filled in with the proper response, or null if
 	 *         cannot process NOTE: this might be changed to throw an exception.
@@ -251,17 +277,28 @@
 			while (it.hasNext()){
 				VariableBinding vb = (VariableBinding)it.next();
 				OID oid = vb.getOid();
+				
+				if (oid == null){
+					log.debug("Attempt to SNMP GET non-existent OID.");
+					response.setErrorStatus(PDU.noSuchName);
+					return response;
+				}
+				//TODO: find a way to properly index problematic PDU variablebindings.
 
 				if (pdu.getType()==PDU.GETNEXT){	
 					// we get the lexically next OID from the given one.
 					OID noid = getNextOid(oid,true);
+					// if noid is null, there is no OID > the one given. so we change response's errorStatus.
+					if (noid == null){
+						log.debug("SNMP GETNEXT operation returned null. No such OID.");
+						response.setErrorStatus(PDU.noSuchName);
+						return response;
+					}
 					newVB = new VariableBinding(noid);
 					var = getValueFor(noid);						
 				}
 				else {
 					newVB = new VariableBinding(oid);
-					//some errorchecking ....
-					//else is good and do:
 					var = getValueFor(oid);
 				}
 					newVB.setVariable(var);
@@ -406,7 +443,8 @@
 				}
 				catch (ReadOnlyException e){
 					log.debug("attempt to set a read-only attribute: " + newVB);
-					response = null;
+					response.setErrorStatus(pdu.readOnly);
+					//TODO: find a way to indicate the Varbind with setErrorIndex without using a local int variable 
 					return response;
 				}
 				
@@ -417,8 +455,10 @@
 				response.add(newVB);
 			}
 		}
+
+		return response;
+	}		
 			
-			
 		//return null;
 //		final boolean trace = log.isTraceEnabled();
 //		SnmpPduRequest response = null;
@@ -463,8 +503,6 @@
 //		response.setErrorStatus(errorStatus);
 //		response.setErrorIndex(errorIndex);
 //
-		return response;
-	}
 
 	/**
 	 * <P>
@@ -630,7 +668,7 @@
 	 * 
 	 * @param oid
 	 *            The oid we want a value for
-	 * @return SnmpNull if no value present
+	 * @return Null if no value present
 	 */
 	private Variable getValueFor(final OID oid) {
 
@@ -756,6 +794,8 @@
         }
         else if (val instanceof TimeTicks)
         {
+        	// the SNMP4J class TimeTicks default toString method is formatted horribly. This 
+        	// call emulates the joesnmp SnmpTimeTicks display.
         	result = new OctetString(((TimeTicks)val).toString("{0} d {1} h {2} m {3} s {4} hs"));
         }
         else if (val instanceof Counter32)

Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java	2010-12-02 22:15:03 UTC (rev 109672)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java	2010-12-02 22:16:20 UTC (rev 109673)
@@ -99,6 +99,9 @@
     * @return SnmpPduRequest filled in with the proper response, or null if cannot process
     * NOTE: this might be changed to throw an exception.
     */   
+   public PDU snmpReceivedGetBulk(PDU pdu){
+	   return null;
+   }
    public PDU snmpReceivedGet(PDU pdu)
    {return null;
 //      SnmpPduRequest response = null;

Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentRequestHandler.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentRequestHandler.java	2010-12-02 22:15:03 UTC (rev 109672)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentRequestHandler.java	2010-12-02 22:16:20 UTC (rev 109673)
@@ -43,12 +43,25 @@
 * @param getNext The agent is requesting the lexically NEXT item after each
 *                    item in the pdu. *** THIS IS NO LONGER REQUIRED. REMOVED.***
 *
-* @return PDU filled in with the proper response, or null if cannot process
+* @return PDU filled in with the proper response, or null if cannot process. PDU's
+* version is based on the @param pdu.
+*  		  
 * NOTE: this might be changed to throw an exception.
 */
 PDU snmpReceivedGet(PDU pdu);
 
 /**
+ * <P> This method handles SNMP Get Bulk requests received by the session
+ * Builds a response PDU and passes it back to the caller.
+ * </P
+ * 
+ * @param pdu The SNMP pdu
+ * @return PDU filled with the proper response. This PDU is either V2c or V3.
+ */
+
+PDU snmpReceivedGetBulk(PDU pdu);
+
+/**
 * <P>This method is defined to handle SNMP Set requests
 * that are received by the session. The request has already
 * been validated by the system.  This routine will build a

Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java	2010-12-02 22:15:03 UTC (rev 109672)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java	2010-12-02 22:16:20 UTC (rev 109673)
@@ -52,6 +52,7 @@
 			case PDU.GETBULK:
 				//TODO maybe make a method called snmpReceivedGetBulk in requesthandler 
 				// requestHandler.snmpReceivedGet(pdu);
+				response = requestHandler.snmpReceivedGetBulk(pdu);
 				break;
 			case PDU.SET:
 				response = requestHandler.snmpReceivedSet(pdu);



More information about the jboss-cvs-commits mailing list