[jboss-cvs] JBossAS SVN: r110458 - in branches/snmp4j-int/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
Wed Jan 26 14:46:30 EST 2011
Author: thauser at redhat.com
Date: 2011-01-26 14:46:30 -0500 (Wed, 26 Jan 2011)
New Revision: 110458
Modified:
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/Test.java
Log:
RFC-3416 behavior / fix Test class Get functionality testing
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java 2011-01-26 19:42:33 UTC (rev 110457)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java 2011-01-26 19:46:30 UTC (rev 110458)
@@ -427,8 +427,9 @@
* The SNMP pdu
*
* @return PDU filled with the new value of the given OID and an error of 0 on success,
- * or a PDU with an empty VB List and an error status indicating why the operation failed,
- * and which PDU was problematic.
+ * or a PDU with the same VB list as given and an error status indicating why the operation failed,
+ * and which VariableBinding caused the problem. Any changes that have completed before this problem occured
+ * will be undone, as per RFC-3416
*/
public PDU snmpReceivedSet(PDU pdu)
{
@@ -474,33 +475,41 @@
try{
oldVar = getValueFor(oid);
modified.add(new VariableBinding(oid, oldVar)); // keep a record of the old variable binding.
- var = setValueFor(oid,newVal);
+ if (checkObject(oid)){
+ var = setValueFor(oid,newVal);
}
+ else
+ log.debug("snmpReceivedSet: no object for setting");
+ undoSets(modified);
+ makeErrorPdu(response, pdu, counter, PDU.noAccess);
+ return response;
+
+ }
catch (NoSuchInstanceException e){
log.debug("snmpReceivedSet: attempt to set a non-existent OID " + oid);
undoSets(modified);
- makeErrorPdu(response, pdu, counter);
+ makeErrorPdu(response, pdu, counter, PDU.noCreation);
return response;
}
catch (VariableTypeException e){
log.debug("snmpReceievedSet: could not convert the given value into an appropriate type: " +newVal);
undoSets(modified);
- makeErrorPdu(response, pdu, counter);
+ makeErrorPdu(response, pdu, counter, PDU.wrongType);
return response;
}
catch (ReadOnlyException e){
log.debug("snmpReceivedSet: attempt to set a read-only attribute: " + newVB);
undoSets(modified);
- makeErrorPdu(response, pdu, counter);
+ makeErrorPdu(response, pdu, counter, PDU.notWritable);
return response;
}
+ catch (Exception e){
+ log.debug("snmpReceivedSet: catastrophe!!! General variable validation error.");
+ undoSets(modified);
+ makeErrorPdu(response, pdu, counter, PDU.genErr);
+ return response;
+ }
- //this can probably be removed entirely
-/* if (var != null){
- log.debug("snmpReceivedSet: attempt to set value resulted in a null PDU being returned");
- undoSets(modified);
- return makeErrorPdu(oid, PDU.noSuchName, counter);
- }*/
// if we get here, we modified the value successfully.
response.add(newVB);
counter++;
@@ -779,16 +788,12 @@
if (be != null)
{
if (log.isTraceEnabled())
- log.trace("getValueFor: Found entry " + be.toString() + " for oid " + oid);
+ log.debug("getValueFor: Found entry " + be.toString() + " for oid " + oid);
try
{
Object val = server.getAttribute(be.mbean, be.attr.getName());
ssy = prepForPdu(val);
-
- if (val == null){
- log.info("getValueFor: Unknown type for " + be);
- }
}
catch (VariableTypeException e){
log.debug("getValueFor: didn't find a suitable data type for the requested data");
@@ -1106,11 +1111,11 @@
* @param errNo The error number defined in the PDU class that indicates a given failure
* @param errInd the VariableBinding in the PDU that caused the error.
*/
- private void makeErrorPdu(PDU response, PDU pdu, int counter){
+ private void makeErrorPdu(PDU response, PDU pdu, int counter, int err){
response.clear();
response.addAll(pdu.toArray());
response.setErrorIndex(counter);
- response.setErrorStatus(PDU.genErr);
+ response.setErrorStatus(err);
}
// Inner Class ---------------------------------------------------
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/Test.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/Test.java 2011-01-26 19:42:33 UTC (rev 110457)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/Test.java 2011-01-26 19:46:30 UTC (rev 110458)
@@ -52,8 +52,6 @@
}
else
{
- System.out.println("Arg1: "+ args[1]);
- System.out.println("Arg2: "+ args[2]);
System.out.println("*Usage*\n" +
"<get/getnext> <oid>\n" +
"<set> <oid> <value>\n" +
@@ -297,20 +295,20 @@
*/
public static void get(String [] oids){
- PDU pdu = new ScopedPDU();
+ PDU pdu = new PDU();
pdu.setType(PDU.GET);
for (int i =1; i < oids.length; i++){
pdu.add(new VariableBinding(new OID(oids[i])));
}
- UserTarget target = new UserTarget();
- target.setVersion(SnmpConstants.version3);
+ CommunityTarget target = new CommunityTarget();
+ target.setCommunity(new OctetString("public"));
+ target.setVersion(SnmpConstants.version2c);
Address targetAddress = GenericAddress.parse("udp:127.0.0.1/1161");
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(2000);
- target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
- target.setSecurityName(new OctetString("MD5DES"));
+
try {
DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping();
More information about the jboss-cvs-commits
mailing list