use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMibGroup method findNextHandlingNode.
// -------------------------------------------------------------------
// See comments in SnmpMibNode.
// -------------------------------------------------------------------
@Override
long[] findNextHandlingNode(SnmpVarBind varbind, long[] oid, int pos, int depth, SnmpRequestTree handlers, AcmChecker checker) throws SnmpStatusException {
int length = oid.length;
SnmpMibNode node = null;
if (handlers == null) {
//
throw new SnmpStatusException(SnmpStatusException.noSuchObject);
}
final Object data = handlers.getUserData();
final int pduVersion = handlers.getRequestPduVersion();
// arc to -1 would work too.
if (pos >= length)
return super.findNextHandlingNode(varbind, oid, pos, depth, handlers, checker);
// Ok, we've got the arc.
long arc = oid[pos];
long[] result = null;
// We have a recursive logic. Should we have a loop instead?
try {
if (isTable(arc)) {
// If the arc identifies a table, then we need to forward
// the search to the table.
// Gets the table identified by `arc'
SnmpMibTable table = getTable(arc);
// Forward to the table
checker.add(depth, arc);
try {
result = table.findNextHandlingNode(varbind, oid, pos + 1, depth + 1, handlers, checker);
} catch (SnmpStatusException ex) {
throw new SnmpStatusException(SnmpStatusException.noSuchObject);
} finally {
checker.remove(depth);
}
// Build up the leaf OID
result[depth] = arc;
return result;
} else if (isReadable(arc)) {
if (pos == (length - 1)) {
// The end of the OID is reached, so we return the leaf
// corresponding to the variable identified by `arc'
// Build up the OID
// result = new SnmpOid(0);
// result.insert((int)arc);
result = new long[depth + 2];
result[depth + 1] = 0L;
result[depth] = arc;
checker.add(depth, result, depth, 2);
try {
checker.checkCurrentOid();
} catch (SnmpStatusException e) {
throw new SnmpStatusException(SnmpStatusException.noSuchObject);
} finally {
checker.remove(depth, 2);
}
// Registers this node
handlers.add(this, depth, varbind);
return result;
}
// The end of the OID is not yet reached, so we must return
// the next leaf following the variable identified by `arc'.
// We cannot return the variable because whatever follows in
// the OID will be greater or equals to 0, and 0 identifies
// the variable itself - so we have indeed to return the
// next object.
// So we do nothing, because this case is handled at the
// end of the if ... else if ... else ... block.
} else if (isNestedArc(arc)) {
// Now if the arc leads to a subgroup, we delegate the
// search to the child, just as done in SnmpMibNode.
//
// get the child ( = nested arc node).
//
final SnmpMibNode child = getChild(arc);
if (child != null) {
checker.add(depth, arc);
try {
result = child.findNextHandlingNode(varbind, oid, pos + 1, depth + 1, handlers, checker);
result[depth] = arc;
return result;
} finally {
checker.remove(depth);
}
}
}
//
throw new SnmpStatusException(SnmpStatusException.noSuchObject);
} catch (SnmpStatusException e) {
// We didn't find anything at the given arc, so we're going
// to try with the next valid arc
//
long[] newOid = new long[1];
newOid[0] = getNextVarId(arc, data, pduVersion);
return findNextHandlingNode(varbind, newOid, 0, depth, handlers, checker);
}
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMibOid method check.
/**
* Generic handling of the <CODE>check</CODE> operation.
*
* <p> This method should be overridden in subclasses.
* <p>
*
* @param req The sub-request that must be handled by this node.
*
* @param depth The depth reached in the OID tree.
*
* @exception SnmpStatusException The default implementation (if not
* overridden) is to generate a SnmpStatusException.
*/
@Override
public void check(SnmpMibSubRequest req, int depth) throws SnmpStatusException {
for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
SnmpVarBind var = e.nextElement();
SnmpStatusException x = new SnmpStatusException(SnmpStatusException.noAccess);
req.registerCheckException(var, x);
}
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMibTable method findHandlingNode.
// ---------------------------------------------------------------------
//
// Implements the method defined in SnmpMibNode.
//
// ---------------------------------------------------------------------
@Override
final synchronized void findHandlingNode(SnmpVarBind varbind, long[] oid, int depth, SnmpRequestTree handlers) throws SnmpStatusException {
final int length = oid.length;
if (handlers == null)
throw new SnmpStatusException(SnmpStatusException.snmpRspGenErr);
if (depth >= length)
throw new SnmpStatusException(SnmpStatusException.noAccess);
if (oid[depth] != nodeId)
throw new SnmpStatusException(SnmpStatusException.noAccess);
if (depth + 2 >= length)
throw new SnmpStatusException(SnmpStatusException.noAccess);
// Checks that the oid is valid
// validateOid(oid,depth);
// Gets the part of the OID that identifies the entry
final SnmpOid entryoid = new SnmpEntryOid(oid, depth + 2);
// Finds the entry: false means that the entry does not exists
final Object data = handlers.getUserData();
final boolean hasEntry = contains(entryoid, data);
// We know that the entry does not exists if (isentry == false).
if (!hasEntry) {
if (!handlers.isCreationAllowed()) {
// we're not doing a set
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
} else if (!isCreationEnabled())
// we're doing a set but creation is disabled.
throw new SnmpStatusException(SnmpStatusException.snmpRspNoAccess);
}
final long var = oid[depth + 1];
// Validate the entry id
if (hasEntry) {
// The entry already exists - validate the id
validateVarEntryId(entryoid, var, data);
}
//
if (handlers.isSetRequest() && isRowStatus(entryoid, var, data))
// We only try to identify the RowStatus for SET operations
//
handlers.add(this, depth, entryoid, varbind, (!hasEntry), varbind);
else
handlers.add(this, depth, entryoid, varbind, (!hasEntry));
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpStandardObjectServer method check.
/**
* Generic handling of the <CODE>check</CODE> operation.
* <p> The default implementation of this method is to loop over the
* varbind list associated with the sub-request and to call
* <CODE>check(var.value, var.oid.getOidArc(depth), data);</CODE>
* <pre>
* public void check(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
* int depth)
* throws SnmpStatusException {
*
* final Object data = req.getUserData();
*
* for (Enumeration e= req.getElements(); e.hasMoreElements();) {
*
* final SnmpVarBind var= (SnmpVarBind) e.nextElement();
*
* try {
* // This method will generate a SnmpStatusException
* // if `depth' is out of bounds.
* //
* final long id = var.oid.getOidArc(depth);
* meta.check(var.value, id, data);
* } catch(SnmpStatusException x) {
* req.registerCheckException(var,x);
* }
* }
* }
* </pre>
* <p> You can override this method if you need to implement some
* specific policies for minimizing the accesses made to some remote
* underlying resources, or if you need to implement some consistency
* checks between the different values provided in the varbind list.
* <p>
*
* @param meta A pointer to the generated meta-data object which
* implements the <code>SnmpStandardMetaServer</code>
* interface.
*
* @param req The sub-request that must be handled by this node.
*
* @param depth The depth reached in the OID tree.
*
* @exception SnmpStatusException An error occurred while accessing
* the MIB node.
*/
public void check(SnmpStandardMetaServer meta, SnmpMibSubRequest req, int depth) throws SnmpStatusException {
final Object data = req.getUserData();
for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
final SnmpVarBind var = e.nextElement();
try {
// This method will generate a SnmpStatusException
// if `depth' is out of bounds.
//
final long id = var.oid.getOidArc(depth);
meta.check(var.value, id, data);
} catch (SnmpStatusException x) {
req.registerCheckException(var, x);
}
}
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMib method getHandlers.
// --------------------------------------------------------------------
// PRIVATE METHODS
//---------------------------------------------------------------------
/**
* This method builds the temporary request-tree that will be used to
* perform the SNMP request associated with the given vector of varbinds
* `list'.
*
* @param req The SnmpMibRequest object holding the varbind list
* concerning this MIB.
* @param createflag Indicates whether the operation allow for creation
* of new instances (ie: it is a SET).
* @param atomic Indicates whether the operation is atomic or not.
* @param type Request type (from SnmpDefinitions).
*
* @return The request-tree where the original varbind list has been
* dispatched to the appropriate nodes.
*/
private SnmpRequestTree getHandlers(SnmpMibRequest req, boolean createflag, boolean atomic, int type) throws SnmpStatusException {
// Build an empty request tree
SnmpRequestTree handlers = new SnmpRequestTree(req, createflag, type);
int index = 0;
SnmpVarBind var;
final int ver = req.getVersion();
// For each varbind in the list finds its handling node.
for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); index++) {
var = e.nextElement();
try {
// Find the handling node for this varbind.
root.findHandlingNode(var, var.oid.longValue(false), 0, handlers);
} catch (SnmpStatusException x) {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getHandlers", "Couldn't find a handling node for " + var.oid.toString());
}
//
if (ver == SnmpDefinitions.snmpVersionOne) {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getHandlers", "\tV1: Throwing exception");
}
// The index in the exception must correspond to the
// SNMP index ...
//
final SnmpStatusException sse = new SnmpStatusException(x, index + 1);
sse.initCause(x);
throw sse;
} else if ((type == SnmpDefinitions.pduWalkRequest) || (type == SnmpDefinitions.pduSetRequestPdu)) {
final int status = SnmpRequestTree.mapSetException(x.getStatus(), ver);
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getHandlers", "\tSET: Throwing exception");
}
final SnmpStatusException sse = new SnmpStatusException(status, index + 1);
sse.initCause(x);
throw sse;
} else if (atomic) {
// Should never come here...
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getHandlers", "\tATOMIC: Throwing exception");
}
final SnmpStatusException sse = new SnmpStatusException(x, index + 1);
sse.initCause(x);
throw sse;
}
final int status = SnmpRequestTree.mapGetException(x.getStatus(), ver);
if (status == SnmpStatusException.noSuchInstance) {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getHandlers", "\tGET: Registering noSuchInstance");
}
var.value = SnmpVarBind.noSuchInstance;
} else if (status == SnmpStatusException.noSuchObject) {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getHandlers", "\tGET: Registering noSuchObject");
}
var.value = SnmpVarBind.noSuchObject;
} else {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getHandlers", "\tGET: Registering global error: " + status);
}
final SnmpStatusException sse = new SnmpStatusException(status, index + 1);
sse.initCause(x);
throw sse;
}
}
}
return handlers;
}
Aggregations