[jboss-cvs] JBossAS SVN: r109905 - 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
Tue Dec 14 14:24:16 EST 2010
Author: thauser at redhat.com
Date: 2010-12-14 14:24:15 -0500 (Tue, 14 Dec 2010)
New Revision: 109905
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/test/Test.java
Log:
change makeErrorPdu to a void method, to directly modify the input PDU.
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-14 17:31:01 UTC (rev 109904)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java 2010-12-14 19:24:15 UTC (rev 109905)
@@ -204,7 +204,8 @@
if (it.size() == 0){ // we were given an empty list in the PDU
log.debug("snmpReceivedGetBulk: No VariableBindings in received PDU");
- return makeErrorPdu(null, SnmpConstants.SNMP_ERROR_GENERAL_ERROR, 0);
+ makeErrorPdu(new OID(""), SnmpConstants.SNMP_ERROR_GENERAL_ERROR, 0, response);
+ return response;
}
// 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.
@@ -217,12 +218,12 @@
catch (NoSuchOidException e) {
// getBulk allows Null values and errors in it's return.
log.debug("snmpReceivedGetBulk: An OID didn't exist. Null substituted in it's place.");
- response.add(new VariableBinding(null, new Null()));
+ response.add(new VariableBinding(oid, Null.noSuchObject));
continue;
}
catch (VariableTypeException e){
log.debug("snmpReceivedGetBulk: Couldn't convert a Variable to a correct type. adding a null value instead.");
- response.add(new VariableBinding(oid, new Null()));
+ response.add(new VariableBinding(oid, Null.noSuchInstance));
continue;
}
response.add(new VariableBinding(oid,var));
@@ -238,7 +239,7 @@
catch (NoSuchOidException e) {
// if this OID didn't exist, the GETNEXT surely does not exist. try the next one.
log.debug("snmpReceivedGetBulk: An OID didn't exist. Null value given.");
- response.add(new VariableBinding(noid, Null.noSuchObject));
+ response.add(new VariableBinding(vb.getOid(), Null.noSuchObject));
continue;
}
catch (EndOfMibViewException e) {
@@ -346,10 +347,12 @@
}
catch(NoSuchOidException e){
log.debug("snmpReceivedGet: GETNEXT operation couldn't find given oid.");
- return makeErrorPdu(noid,PDU.noSuchName,counter);
+ makeErrorPdu(noid,PDU.noSuchName,counter,response);
+ return response;
}
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;
}
/* if (noid == null){
@@ -366,11 +369,13 @@
}
catch (NoSuchOidException e) {
log.debug("snmpReceivedGet: GETNEXT operation returned null. No such OID.");
- return makeErrorPdu(noid, PDU.noSuchName, counter);
+ makeErrorPdu(noid, PDU.noSuchName, counter,response);
+ return response;
}
catch (VariableTypeException e) {
log.debug("snmpReceivedGet: GETNEXT operation could not convert the returned value for " + noid + " into an appropriate type.");
- return makeErrorPdu(noid,PDU.badValue, counter);
+ makeErrorPdu(noid,PDU.badValue, counter,response);
+ return response;
}
@@ -384,11 +389,17 @@
}
catch (NoSuchOidException e) {
log.debug("snmpReceivedGet: GET operation returned null. No such OID.");
- return makeErrorPdu(oid, PDU.noSuchName, counter);
+ //response.setErrorIndex(counter);
+ //response.setErrorStatus(PDU.noSuchName);
+ //response.add(new VariableBinding(oid,Null.noSuchObject));
+ makeErrorPdu(oid, PDU.noSuchName, counter, response);
+ return response;
+ //return makeErrorPdu(oid, PDU.noSuchName, counter);
}
catch (VariableTypeException e) {
log.debug("snmpReceivedGet: GET operation could not convert the returned value for " + oid + " into an appropriate type.");
- return makeErrorPdu(oid, PDU.badValue, counter);
+ makeErrorPdu(oid, PDU.badValue, counter,response);
+ return response;
}
// the OID we are looking for has no BindEntry. Indicate this in the returned pdu.
// and abort immediately.
@@ -473,19 +484,22 @@
catch (NoSuchOidException e){
log.debug("snmpReceivedSet: attempt to set a non-existent OID " + oid);
undoSets(modified);
- return makeErrorPdu(oid, PDU.noSuchName,counter);
+ 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);
- return makeErrorPdu(oid, PDU.badValue, counter);
+ makeErrorPdu(oid, PDU.badValue, counter, response);
+ return response;
}
catch (ReadOnlyException e){
// this reaction needs to be turned into an exception in all cases.
log.debug("snmpReceivedSet: attempt to set a read-only attribute: " + newVB);
undoSets(modified);
- return makeErrorPdu(oid, PDU.readOnly, counter);
+ makeErrorPdu(oid, PDU.readOnly, counter, response);
+ return response;
}
//this can probably be removed entirely
@@ -1044,23 +1058,28 @@
/** This utility method is used to construct an error PDU. This code
* was repeated so many times it was prudent to give it it's own method.
+ * @param response
*
*/
- private PDU makeErrorPdu(OID oid, int errNo, int errInd){
- PDU retVal = new PDU();
- retVal.setErrorStatus(errNo);
- retVal.setErrorIndex(errInd);
+ private void makeErrorPdu(OID oid, int errNo, int errInd, PDU response){
+ OID retOID;
+ if (oid == null){
+ retOID=new OID("");
+ }
+ else{
+ retOID = oid;
+ }
+ response.setErrorStatus(errNo);
+ response.setErrorIndex(errInd);
switch (errNo){
case PDU.noSuchName:
- retVal.add(new VariableBinding(oid, Null.noSuchObject));
+ response.add(new VariableBinding(retOID, Null.noSuchObject));
break;
case PDU.badValue:
case PDU.wrongValue:
- retVal.add(new VariableBinding(oid, Null.noSuchInstance));
+ response.add(new VariableBinding(retOID, Null.noSuchInstance));
break;
case PDU.readOnly:
- retVal.add(new VariableBinding(oid, Null.instance));
- break;
case PDU.noError:
case PDU.tooBig:
case PDU.genErr:
@@ -1074,10 +1093,9 @@
case PDU.authorizationError:
case PDU.notWritable:
case PDU.inconsistentName:
- retVal.add(new VariableBinding(oid, Null.instance));
+ response.add(new VariableBinding(retOID, Null.instance));
break;
- }
- return retVal;
+ }
}
// Inner Class ---------------------------------------------------
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-14 17:31:01 UTC (rev 109904)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/Test.java 2010-12-14 19:24:15 UTC (rev 109905)
@@ -50,7 +50,7 @@
pdu.setType(PDU.GETBULK);
pdu.add(new VariableBinding(new OID("1.2.3.4.1.1")));
pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.0")));
- pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.0")));
+ pdu.add(new VariableBinding(new OID("1.3.1.1")));
pdu.setMaxRepetitions(7);
pdu.setNonRepeaters(1);
CommunityTarget target = new CommunityTarget();
@@ -59,7 +59,7 @@
target.setVersion(SnmpConstants.version2c);
Address targetAddress = GenericAddress.parse("udp:127.0.0.1/1161");
target.setAddress(targetAddress);
- target.setRetries(2);
+ target.setRetries(0);
target.setTimeout(2000);
try {
More information about the jboss-cvs-commits
mailing list