[jboss-cvs] JBossAS SVN: r110220 - in branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp: test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Dec 24 15:58:56 EST 2010
Author: thauser at redhat.com
Date: 2010-12-24 15:58:56 -0500 (Fri, 24 Dec 2010)
New Revision: 110220
Modified:
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/EndOfMibViewException.java
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
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/Test.java
Log:
modifying the way errors are indicated in the Responses to manager queries.
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/EndOfMibViewException.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/EndOfMibViewException.java 2010-12-24 20:11:41 UTC (rev 110219)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/EndOfMibViewException.java 2010-12-24 20:58:56 UTC (rev 110220)
@@ -1,10 +1,7 @@
package org.jboss.jmx.adaptor.snmp.agent;
/** This exception is thrown when a GETNEXT or GETBULK operation
- * attempts to read out of the Tree it is in.
- * Example: 4 OID MIB with 1.2.3.4.1, 1.2.3.4.2, 1.2.3.4.3, and 1.3.7.1.1
- * This exception will be thrown when the GETNEXT(1.2.3.4.3) is called, because 1.3.7.1.1
- * is part of a different tree.
+ * attempts to get an OID that is not in the MIB
*
* @author Thomas Hauser <a href="mailto:thauser at redhat.com"></a>
*
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-24 20:11:41 UTC (rev 110219)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java 2010-12-24 20:58:56 UTC (rev 110220)
@@ -234,7 +234,7 @@
vb = (VariableBinding)it.get(i);
OID noid = null;
try {
- noid = getNextOid(vb.getOid(),true);
+ noid = getNextOid(vb.getOid());
}
catch (NoSuchOidException e) {
// if this OID didn't exist, the GETNEXT surely does not exist. try the next one.
@@ -273,7 +273,7 @@
response.add(new VariableBinding(noid,var));
try {
- noid = getNextOid(noid,true);
+ noid = getNextOid(noid);
}
catch (NoSuchOidException e) {
// error. break out and try the next one
@@ -305,7 +305,7 @@
* error indications. Both the error type (ErrorStatus) and error index (the binding in the
* PDU being processed that caused the error are returned.)
*/
- public PDU snmpReceivedGet(PDU pdu)
+ public PDU snmpReceivedGet (PDU pdu) throws NoSuchOidException, EndOfMibViewException
{
PDU response;
// this counts the number of VariableBindings and indicates which one caused a problem, if any
@@ -341,19 +341,21 @@
if (pdu.getType()==PDU.GETNEXT){
// we get the lexically next OID from the given one.
try{
- noid = getNextOid(oid,true);
- // if noid is null, there is no OID > the one given. so we change response's errorStatus.
- // we also abort here.
+ noid = getNextOid(oid);
+
}
catch(NoSuchOidException e){
log.debug("snmpReceivedGet: GETNEXT operation couldn't find given oid.");
- makeErrorPdu(noid,PDU.noSuchName,counter,response);
- return response;
+ throw e;
+/* makeErrorPdu(noid,PDU.noSuchName,counter,response);
+ return response;*/
}
+ // if this OID is the last one possible, we throw this exception.
catch(EndOfMibViewException e){
log.debug("snmpReceivedGet: GETNEXT operation left the OID subtree");
- //TODO: need to take an action here so we don't just return an empty VB.
- continue;
+ throw e;
+ /*response.add(new VariableBinding(noid,Null.endOfMibView));
+ continue;*/
}
/* if (noid == null){
// this reaction should be factored out.
@@ -369,11 +371,13 @@
}
catch (NoSuchOidException e) {
log.debug("snmpReceivedGet: GETNEXT operation returned null. No such OID.");
+ throw e;/*
makeErrorPdu(noid, PDU.noSuchName, counter,response);
- return response;
+ return response;*/
}
catch (VariableTypeException e) {
log.debug("snmpReceivedGet: GETNEXT operation could not convert the returned value for " + noid + " into an appropriate type.");
+ // throw e;
makeErrorPdu(noid,PDU.badValue, counter,response);
return response;
@@ -389,11 +393,12 @@
}
catch (NoSuchOidException e) {
log.debug("snmpReceivedGet: GET operation returned null. No such OID.");
+ throw e;
//response.setErrorIndex(counter);
//response.setErrorStatus(PDU.noSuchName);
//response.add(new VariableBinding(oid,Null.noSuchObject));
- makeErrorPdu(oid, PDU.noSuchName, counter, response);
- return response;
+ /*makeErrorPdu(oid, PDU.noSuchName, counter, response);
+ return response;*/
//return makeErrorPdu(oid, PDU.noSuchName, counter);
}
catch (VariableTypeException e) {
@@ -435,7 +440,7 @@
* or a PDU with an empty VB List and an error status indicating why the operation failed,
* and which PDU was problematic.
*/
- public PDU snmpReceivedSet(PDU pdu)
+ public PDU snmpReceivedSet(PDU pdu) throws NoSuchOidException, VariableTypeException
{
PDU response;
// the modified OID entries so far.
@@ -484,15 +489,17 @@
catch (NoSuchOidException e){
log.debug("snmpReceivedSet: attempt to set a non-existent OID " + oid);
undoSets(modified);
- makeErrorPdu(oid, PDU.noSuchName,counter,response);
- return response;
+ throw e;
+/* makeErrorPdu(oid, PDU.noSuchName,counter,response);
+ return response;*/
//maybe factor out later: pdu = makeErrorPdu(oid, errorIndex, errorStatus, vb);
}
catch (VariableTypeException e){
log.debug("snmpReceievedSet: could not convert the given value into an appropriate type: " +newVal);
undoSets(modified);
- makeErrorPdu(oid, PDU.badValue, counter, response);
- return response;
+ throw e;
+ /*makeErrorPdu(oid, PDU.badValue, counter, response);
+ return response;*/
}
catch (ReadOnlyException e){
// this reaction needs to be turned into an exception in all cases.
@@ -994,8 +1001,10 @@
* @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.
+ * @throws NoSuchOidException if request is given an OID that doesn't exist in the first place
+ * @throws EndOfMibViewException if there is no greater OID than the given, valid, oid.
*/
- private OID getNextOid(final OID oid, boolean stayInSubtree) throws NoSuchOidException, EndOfMibViewException {
+ private OID getNextOid(final OID oid) throws NoSuchOidException, EndOfMibViewException {
OID coid = new OID(oid);
@@ -1041,9 +1050,9 @@
}
}
- // * Check if still in subtree if requested to stay within
+ // Check if still in subtree if requested to stay within
- if (stayInSubtree && roid != null)
+/* if (stayInSubtree && roid != null)
{
//OID parent = coid.removeLast();
// this emulates the functionality of the "isRoot" in SnmpObjectId from joesnmp
@@ -1051,7 +1060,7 @@
log.debug("getNextOid: Placeholder. The traversal has left the subtree.");
throw new EndOfMibViewException();
}
- }
+ }*/
return roid;
}
@@ -1072,6 +1081,8 @@
response.setErrorStatus(errNo);
response.setErrorIndex(errInd);
switch (errNo){
+ case PDU.noError:
+ break;
case PDU.noSuchName:
response.add(new VariableBinding(retOID, Null.noSuchObject));
break;
@@ -1080,7 +1091,6 @@
response.add(new VariableBinding(retOID, Null.noSuchInstance));
break;
case PDU.readOnly:
- case PDU.noError:
case PDU.tooBig:
case PDU.genErr:
case PDU.noAccess:
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-24 20:11:41 UTC (rev 110219)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java 2010-12-24 20:58:56 UTC (rev 110220)
@@ -102,7 +102,7 @@
public PDU snmpReceivedGetBulk(PDU pdu){
return null;
}
- public PDU snmpReceivedGet(PDU pdu)
+ public PDU snmpReceivedGet(PDU pdu) throws NoSuchOidException, EndOfMibViewException
{return null;
// SnmpPduRequest response = null;
// int pduLength = pdu.getLength();
@@ -163,7 +163,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 snmpReceivedSet(PDU pdu)
+ public PDU snmpReceivedSet(PDU pdu) throws NoSuchOidException, VariableTypeException
{
return 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-24 20:11:41 UTC (rev 110219)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentRequestHandler.java 2010-12-24 20:58:56 UTC (rev 110220)
@@ -48,7 +48,7 @@
*
* NOTE: this might be changed to throw an exception.
*/
-PDU snmpReceivedGet(PDU pdu);
+PDU snmpReceivedGet(PDU pdu) throws NoSuchOidException, EndOfMibViewException;
/**
* <P> This method handles SNMP Get Bulk requests received by the session
@@ -57,6 +57,8 @@
*
* @param pdu The SNMP pdu
* @return PDU filled with the proper response. This PDU is either V2c or V3.
+ * this PDU will always try to ignore errors and fill with as much info
+ * as possible.
*/
PDU snmpReceivedGetBulk(PDU pdu);
@@ -72,7 +74,7 @@
* @return PDU filled in with the proper response, or null if cannot process
* NOTE: this might be changed to throw an exception.
*/
-PDU snmpReceivedSet(PDU pdu);
+PDU snmpReceivedSet(PDU pdu) throws NoSuchOidException, VariableTypeException;
//ResponseEvent maybe
///**
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-24 20:11:41 UTC (rev 110219)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java 2010-12-24 20:58:56 UTC (rev 110220)
@@ -31,7 +31,8 @@
}
@Override
- public void processPdu(CommandResponderEvent event) {
+ //TODO: catch thrown exceptions properly and decide what to do with them.
+ public void processPdu(CommandResponderEvent event){
PDU pdu = event.getPDU();
if (pdu == null) {
@@ -46,14 +47,15 @@
//switch based on pdu.getType() == ___
switch (type) {
case PDU.GET:
+ // TODO: this needs to catch NoSuchOidException, VariableTypeException, and EndOfMibViewException
case PDU.GETNEXT:
response = requestHandler.snmpReceivedGet(pdu);
break;
case PDU.GETBULK:
- //TODO maybe make a method called snmpReceivedGetBulk in requesthandler
response = requestHandler.snmpReceivedGetBulk(pdu);
break;
case PDU.SET:
+ // TODO: this needs to catch NoSuchOidException, and VariableTypeException
response = requestHandler.snmpReceivedSet(pdu);
break;
default:
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-24 20:11:41 UTC (rev 110219)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/Test.java 2010-12-24 20:58:56 UTC (rev 110220)
@@ -1,6 +1,7 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.util.Vector;
import org.snmp4j.CommandResponder;
import org.snmp4j.CommandResponderEvent;
@@ -36,7 +37,7 @@
else if (args[0].equals("testnullpdu")){
testnull();
}
- else if (args[0].equals("snmpwalk"));{
+ else if (args[0].equals("snmpwalk")){
snmpwalk(args);
}
else
@@ -50,22 +51,10 @@
}
public static void snmpwalk(String [] args){
PDU pdu = new PDU();
+ OID treeOID = new OID (args[1]);
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);
@@ -75,39 +64,68 @@
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());
+ if (currentOID.compareTo(endOID) > 0){
+ // invalid start / end OIDs.
+ System.out.println("invalid oid range.");
+ return;
+ }
+
+ pdu.setType(PDU.GETNEXT);
- PDU responsePDU = responseEvent.getResponse();
- if (responsePDU == null){
- System.out.println("Request timed out");
+ while (currentOID.compareTo(endOID)<0){
+ pdu.add(new VariableBinding(currentOID));
+ try {
+ DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping();
+ transport.listen();
+ Snmp snmp = new Snmp(transport);
+
+ System.out.println("Sending PDU: "+pdu);
+ ResponseEvent responseEvent = snmp.send(pdu, target);
+ System.out.println("response " + responseEvent.toString());
+ PDU responsePDU = responseEvent.getResponse();
+ if (responsePDU == null){
+ System.out.println("Request timed out");
+ }
+ else{
+ if (responsePDU.getErrorStatus()!= 0){
+ System.out.println("Received error response: " + responsePDU);
+ pdu.clear();
+ return;
+ }
+
+ System.out.println("Received response "+responsePDU);
+ }
+ System.out.println("Peer Address: "+responseEvent.getPeerAddress());
+ Vector<VariableBinding> vbs = responsePDU.getVariableBindings();
+
+ Variable retvar = vbs.get(0).getVariable();
+ if (retvar == Null.endOfMibView){
+ System.out.print("end of mib.");
+ pdu.clear();
+ return;
}
- else{
- System.out.println("Received response "+responsePDU);
+ currentOID = vbs.get(0).getOid();
+ if (currentOID == )
+ responsePDU = null;
+ pdu.clear();
+ } 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!!");
+ System.out.println(e);
}
- 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!!");
+
+
}
- }
+
+
+ }
More information about the jboss-cvs-commits
mailing list