[jboss-cvs] JBossAS SVN: r109499 - 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
Fri Nov 26 15:50:50 EST 2010


Author: thauser at redhat.com
Date: 2010-11-26 15:50:50 -0500 (Fri, 26 Nov 2010)
New Revision: 109499

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:
implemented GETNEXT functionality with SNMP4J. 

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-11-26 20:17:44 UTC (rev 109498)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java	2010-11-26 20:50:50 UTC (rev 109499)
@@ -160,7 +160,7 @@
 	 * @return SnmpPduRequest 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, boolean getNext)
+	public PDU snmpReceivedGet(PDU pdu)
 	{
 		PDU response;
 		//later on should be able to get rid of getNext because pdu.getType() should have it
@@ -180,29 +180,32 @@
 		
 			if (trace) {
 				log.trace("requestID=" + pdu.getRequestID() + ", elementCount="
-						+ pdu.size() + ", getNext=" + getNext);
+						+ pdu.size());
 			}
 		
 			if (pdu != null){
 				
-				if (getNext){
-					//TODO do the GETNEXT case
-				}
-				
 				Iterator it = pdu.getVariableBindings().iterator();
-				
+				VariableBinding newVB;
+				Variable var;
 				while (it.hasNext()){
 					VariableBinding vb = (VariableBinding)it.next();
 					OID oid = vb.getOid();
-					//setup the new variable binding to put into the response pdu
-					VariableBinding newVB = new VariableBinding(oid);
-					
+					if (pdu.getType()==PDU.GETNEXT){	
+						OID noid = getNextOid(oid,true);
+						newVB = new VariableBinding(noid);
+						var = getValueFor(noid);						
+					}
+				else {
+						newVB = new VariableBinding(oid);
 					//some errorchecking ....
 					//else is good and do:
-					Variable var = getValueFor(oid);
+					var = getValueFor(oid);
+				}
 					newVB.setVariable(var);
 					response.add(newVB);
-				}
+					}
+				//}
 			}
 		//END IF MINE
 
@@ -341,10 +344,10 @@
 				try{
 				var = setValueFor(oid,newVal);
 				}
-				catch (ReadOnlyException e){log.debug("ReadOnlyException in RequestHandlerImpl");}
+				catch (ReadOnlyException e){log.debug("attempt to set a read-only attribute: " + newVB);}
 				
 				if (var != null){
-					log.debug("set operation failed to set attribute, returned non-null result");
+					log.debug("attempt to set value resulted in a null PDU being returned.");
 					response = null;
 				}
 				//null on success. change this;
@@ -599,10 +602,11 @@
 				}
 				
 				//not sure about how to handle this case yet
-//           else if (val instanceof SnmpObjectId)
-//           {
-//					ssy = (SnmpObjectId)val;
-//				}
+/*           else if (val instanceof SnmpObjectId)     
+           {
+        	   		int[] oid = val.getValue;
+					ssy = new OID(oid);
+           }*/
            else if (val instanceof TimeTicks)
            {
               ssy = (TimeTicks)val;
@@ -711,6 +715,7 @@
 		else{
 			result = null;
 		}
+		// TODO do more mumbo jumbo for type casting / changing
 		return result;
 		
 	}
@@ -751,28 +756,8 @@
 			try
          {		
 				
-			//	Object val = null;
-				Object val = convertValue(newVal);
-			/*	if (newVal instanceof OctetString)
-				{	
-					val = newVal.toString();
-				}
-				else if (newVal instanceof Integer32)
-				{
-					val = new Integer(((Integer32)newVal).getValue());
-				}
-				else if (newVal instanceof Counter32)
-				{
-					val = new Long(((Counter32)newVal).getValue());
-				}
-				else if (newVal instanceof Counter64)
-				{
-					val = new Long(((Counter64)newVal).getValue());
-				}*/
-				// TODO do more mumbo jumbo for type casting / changing
-				
-				
-				
+			Object val = convertValue(newVal);
+		
 				if (val != null)
             { 
 					Attribute at = new Attribute(be.attr.getName(), val);
@@ -803,7 +788,7 @@
 
 
 	/**
-	 * Lookup a BinEntry on the given oid. If the oid ends in .0,
+	 * Lookup a BindEntry on the given oid. If the oid ends in .0,
 	 * then the .0 will be stripped of before the search.
 	 * @param oid The oid look up.
 	 * @return a bind entry or null.
@@ -811,14 +796,14 @@
 	private BindEntry findBindEntryForOid(final OID oid) {
 		
 		//param probably not supposed to be OID type
-//		ComparableSnmpObjectId coid= new ComparableSnmpObjectId(oid.toString());
+		OID coid= new OID(oid);
 		
 		//add possible oid format checking
-//		if (coid.isLeaf())
-//		{
-//			coid = coid.removeLastPart();
-//		}
-		BindEntry be = (BindEntry)bindings.get(oid);
+		if (coid.last() == 0)
+		{
+			coid.removeLast();
+		}
+		BindEntry be = (BindEntry)bindings.get(coid);
 
 		return be;
 	}
@@ -842,68 +827,69 @@
 //		return be;
 //	}
 
-//	/**
-//	 * Return the next oid that is larger than ours.
-//	 * @param oid the starting oid
-//	 * @param stayInSubtree if true, the next oid will not have a different prefix than the one of oid.
-//	 * @return the next oid or null if none found.
-//	 */
-//	private ComparableSnmpObjectId getNextOid(final ComparableSnmpObjectId oid, boolean stayInSubtree) {
-//		ComparableSnmpObjectId coid = new ComparableSnmpObjectId(oid);
-//
-//
-//		if (coid.isLeaf())
-//			coid = coid.removeLastPart();
-//
-//		SortedSet ret;
-//		ret= oidKeys.tailSet(oid);  // get oids >= oid
-//		Iterator it = ret.iterator();
-//		ComparableSnmpObjectId roid=null;
-//		
-//		/*
-//		 * If there are elements in the tail set, then
-//		 * - get first one.
-//		 * - if first is input (which it is supposed to be according to the contract of
-//		 *   SortedSet.tailSet() , then get next, which is the 
-//		 *   one we look for.
-//		 */
-//		if (it.hasNext()) 
-//		{
-//			roid = (ComparableSnmpObjectId)it.next(); // oid
-//		}
-//		
-//		if (roid == null)
-//		{
-//			return null; // roid is null, 
-//		}
-//		
-//		if (roid.compareTo(coid)==0) // input elment
-//		{
-//			// if there is a next element, then it is ours.
-//			if (it.hasNext()) 
-//			{
-//				roid = (ComparableSnmpObjectId)it.next();
-//			}
-//			else
-//			{
-//				roid = null; // end of list
-//			}
-//		}
-//      
-//		/*
-//		 * Check if still in subtree if requested to stay within
-//		 */
-//		if (stayInSubtree && roid != null)
-//		{
-//			ComparableSnmpObjectId parent = coid.removeLastPart();
-//			if (!parent.isRootOf(roid))
-//				roid = null;
-//		}
-//
-//		return roid;
-//	}
+	/**
+	 * Return the next oid that is larger than ours.
+	 * @param oid the starting oid
+	 * @param stayInSubtree if true, the next oid will not have a different prefix than the one of oid.
+	 * @return the next oid or null if none found.
+	 */
+	private OID getNextOid(final OID oid, boolean stayInSubtree) {
+		OID coid = new OID(oid);
 
 
+		if (coid.last() == 0)
+			coid.removeLast();
+
+		SortedSet ret;
+		ret= oidKeys.tailSet(oid);  // get oids >= oid
+		Iterator it = ret.iterator();
+		OID roid=null;
+		
+		/*
+		 * If there are elements in the tail set, then
+		 * - get first one.
+		 * - if first is input (which it is supposed to be according to the contract of
+		 *   SortedSet.tailSet() , then get next, which is the 
+		 *   one we look for.
+		 */
+		if (it.hasNext()) 
+		{
+			roid = (OID)it.next(); // oid
+		}
+		
+		if (roid == null)
+		{
+			return null; // roid is null, 
+		}
+		
+		if (roid.compareTo(coid)==0) // input elment
+		{
+			// if there is a next element, then it is ours.
+			if (it.hasNext()) 
+			{
+				roid = (OID)it.next();
+			}
+			else
+			{
+				roid = null; // end of list
+			}
+		}
+      
+		
+		// * Check if still in subtree if requested to stay within
+		 
+		if (stayInSubtree && roid != null)
+		{
+			//OID parent = coid.removeLast();
+			// this emulates the functionality of the "isRoot" in SnmpObjectId from joesnmp
+			if (coid.leftMostCompare((coid.size()-1), roid) != 0)
+				roid = null;
+		}
+
+		return roid;
+	}
+
+
    // Inner Class ---------------------------------------------------
    
 	/**

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-11-26 20:17:44 UTC (rev 109498)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java	2010-11-26 20:50:50 UTC (rev 109499)
@@ -99,7 +99,7 @@
     * @return SnmpPduRequest 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, boolean getNext)
+   public PDU snmpReceivedGet(PDU pdu)
    {return null;
 //      SnmpPduRequest response = null;
 //      int pduLength = pdu.getLength();

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-11-26 20:17:44 UTC (rev 109498)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentRequestHandler.java	2010-11-26 20:50:50 UTC (rev 109499)
@@ -41,12 +41,12 @@
 *
 * @param pdu     The SNMP pdu
 * @param getNext The agent is requesting the lexically NEXT item after each
-*                    item in the pdu.
+*                    item in the pdu. *** THIS IS NO LONGER REQUIRED. REMOVED.***
 *
 * @return PDU filled in with the proper response, or null if cannot process
 * NOTE: this might be changed to throw an exception.
 */
-PDU snmpReceivedGet(PDU pdu, boolean getNext);
+PDU snmpReceivedGet(PDU pdu);
 
 /**
 * <P>This method is defined to handle SNMP Set requests

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-11-26 20:17:44 UTC (rev 109498)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java	2010-11-26 20:50:50 UTC (rev 109499)
@@ -46,15 +46,13 @@
 		//switch based on pdu.getType() == ___
 			switch (type) {
 			case PDU.GET:
-				response = requestHandler.snmpReceivedGet(pdu, false);
+			case PDU.GETNEXT:
+				response = requestHandler.snmpReceivedGet(pdu);
 				break;
 			case PDU.GETBULK:
 				//TODO maybe make a method called snmpReceivedGetBulk in requesthandler 
 				// requestHandler.snmpReceivedGet(pdu);
 				break;
-			case PDU.GETNEXT:
-				response = requestHandler.snmpReceivedGet(pdu, true);
-				break;
 			case PDU.SET:
 				response = requestHandler.snmpReceivedSet(pdu);
 				break;



More information about the jboss-cvs-commits mailing list