Search in sources :

Example 1 with SnmpValue

use of com.sun.jmx.snmp.SnmpValue in project jdk8u_jdk by JetBrains.

the class SnmpMibTable method endRowAction.

/**
     * This method takes care of final RowStatus handling during the
     * set() phase of a SET request.
     *
     * In particular it will:
     *     <ul><li>either call <code>setRowStatus(<i>active</i>)</code>
     *         (<code> rowAction = <i>createAndGo</i> or <i>active</i>
     *         </code>),</li>
     *     <li>or call <code>setRowStatus(<i>notInService</i> or <i>
     *         notReady</i>)</code> depending on the result of <code>
     *         isRowReady()</code> (<code>rowAction = <i>createAndWait</i>
     *         </code>),</li>
     *     <li>or call <code>setRowStatus(<i>notInService</i>)</code>
     *         (<code> rowAction = <i>notInService</i></code>),
     *     <li>or call <code>removeTableRow()</code> (<code>
     *         rowAction = <i>destroy</i></code>),</li>
     *     <li>or generate a SnmpStatusException if the passed <code>
     *         rowAction</code> is not correct. This should be avoided
     *         since it would break SET request atomicity</li>
     *     </ul>
     * <p>
     * In principle, you should not need to redefine this method.
     * <p>
     * <code>endRowAction()</code> is called during the set() phase
     * of a SET request, after the actual set() on the varbind list
     * has been performed. The varbind containing the control variable
     * is updated with the value returned by setRowStatus() (if it is
     * not <code>null</code>).
     *
     * <p>
     * @param req    The sub-request that must be handled by this node.
     *
     * @param rowOid The <CODE>SnmpOid</CODE> identifying the table
     *               row involved in the operation.
     *
     * @param depth  The depth reached in the OID tree.
     *
     * @param rowAction The requested action as returned by <code>
     *        getRowAction()</code>: one of the RowStatus codes defined in
     *        {@link com.sun.jmx.snmp.EnumRowStatus}. These codes
     *        correspond to RowStatus codes as defined in RFC 2579,
     *        plus the <i>unspecified</i> value which is SNMP Runtime specific.
     *
     * @exception SnmpStatusException if the specified <code>rowAction</code>
     *            is not valid.
     *
     * @see com.sun.jmx.snmp.EnumRowStatus
     **/
protected void endRowAction(SnmpMibSubRequest req, SnmpOid rowOid, int depth, int rowAction) throws SnmpStatusException {
    final boolean isnew = req.isNewEntry();
    final SnmpOid oid = rowOid;
    final int action = rowAction;
    final Object data = req.getUserData();
    SnmpValue value = null;
    switch(action) {
        case EnumRowStatus.unspecified:
            break;
        case EnumRowStatus.createAndGo:
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Setting RowStatus to 'active' " + "for row[" + rowOid + "] : requested RowStatus = " + "createAndGo");
            }
            value = setRowStatus(oid, EnumRowStatus.active, data);
            break;
        case EnumRowStatus.createAndWait:
            if (isRowReady(oid, data)) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Setting RowStatus to 'notInService' for row[" + rowOid + "] : requested RowStatus = createAndWait");
                }
                value = setRowStatus(oid, EnumRowStatus.notInService, data);
            } else {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Setting RowStatus to 'notReady' " + "for row[" + rowOid + "] : requested RowStatus = " + "createAndWait");
                }
                value = setRowStatus(oid, EnumRowStatus.notReady, data);
            }
            break;
        case EnumRowStatus.destroy:
            if (isnew) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Warning: requested RowStatus = destroy, " + "but row[" + rowOid + "] does not exist");
                }
            } else {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Destroying row[" + rowOid + "] : requested RowStatus = destroy");
                }
            }
            removeTableRow(req, oid, depth);
            break;
        case EnumRowStatus.active:
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Setting RowStatus to 'active' for row[" + rowOid + "] : requested RowStatus = active");
            }
            value = setRowStatus(oid, EnumRowStatus.active, data);
            break;
        case EnumRowStatus.notInService:
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Setting RowStatus to 'notInService' for row[" + rowOid + "] : requested RowStatus = notInService");
            }
            value = setRowStatus(oid, EnumRowStatus.notInService, data);
            break;
        case EnumRowStatus.notReady:
        default:
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Invalid RowStatus value for row[" + rowOid + "] : specified RowStatus = " + action);
            }
            setRowStatusFail(req, SnmpStatusException.snmpRspInconsistentValue);
    }
    if (value != null) {
        final SnmpVarBind vb = req.getRowStatusVarBind();
        if (vb != null)
            vb.value = value;
    }
}
Also used : SnmpOid(com.sun.jmx.snmp.SnmpOid) SnmpValue(com.sun.jmx.snmp.SnmpValue) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 2 with SnmpValue

use of com.sun.jmx.snmp.SnmpValue in project jdk8u_jdk by JetBrains.

the class SnmpSubBulkRequestHandler method findVarBind.

/**
     * The method updates find out which element to use at update time. Handle oid overlapping as well
     */
private SnmpVarBind findVarBind(SnmpVarBind element, SnmpVarBind result) {
    if (element == null)
        return null;
    if (result.oid == null) {
        return element;
    }
    if (element.value == SnmpVarBind.endOfMibView)
        return result;
    if (result.value == SnmpVarBind.endOfMibView)
        return element;
    final SnmpValue val = result.value;
    int comp = element.oid.compareTo(result.oid);
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", "Comparing OID element : " + element.oid + " with result : " + result.oid);
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", "Values element : " + element.value + " result : " + result.value);
    }
    if (comp < 0) {
        //
        return element;
    } else {
        if (comp == 0) {
            // Take the deeper within the reply
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", " oid overlapping. Oid : " + element.oid + "value :" + element.value);
                SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", "Already present varBind : " + result);
            }
            SnmpOid oid = result.oid;
            SnmpMibAgent deeperAgent = server.getAgentMib(oid);
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", "Deeper agent : " + deeperAgent);
            }
            if (deeperAgent == agent) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", "The current agent is the deeper one. Update the value with the current one");
                }
                return element;
            } else {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", "The current agent is not the deeper one. return the previous one.");
                }
                return result;
            }
        /*
                   Vector v = new Vector();
                   SnmpMibRequest getReq = createMibRequest(v,
                   version,
                   null);
                   SnmpVarBind realValue = new SnmpVarBind(oid);
                   getReq.addVarBind(realValue);
                   try {
                   deeperAgent.get(getReq);
                   } catch(SnmpStatusException e) {
                   e.printStackTrace();
                   }

                   if(isDebugOn())
                   trace("findVarBind", "Biggest priority value is : " +
                   realValue.value);

                   return realValue;
                */
        } else {
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", "The right varBind is the already present one");
            }
            return result;
        }
    }
}
Also used : SnmpOid(com.sun.jmx.snmp.SnmpOid) SnmpValue(com.sun.jmx.snmp.SnmpValue) SnmpMibAgent(com.sun.jmx.snmp.agent.SnmpMibAgent)

Example 3 with SnmpValue

use of com.sun.jmx.snmp.SnmpValue in project jdk8u_jdk by JetBrains.

the class SnmpSubNextRequestHandler method updateResult.

/**
     * The method updates a given var bind list with the result of a
     * previsouly invoked operation.
     * Prior to calling the method, one must make sure that the operation was
     * successful. As such the method getErrorIndex or getErrorStatus should be
     * called.
     */
protected void updateResult(SnmpVarBind[] result) {
    final int max = varBind.size();
    for (int i = 0; i < max; i++) {
        // May be we should control the position ...
        //
        final int index = translation[i];
        final SnmpVarBind elmt = (SnmpVarBind) ((NonSyncVector) varBind).elementAtNonSync(i);
        final SnmpVarBind vb = result[index];
        if (vb == null) {
            result[index] = elmt;
            /* end of NPCTE fix for bugid 4381195 */
            continue;
        }
        final SnmpValue val = vb.value;
        if ((val == null) || (val == SnmpVarBind.endOfMibView)) {
            /* NPCTE fix for bugid 4381195 esc 0. <J.C.> < 17-Oct-2000> */
            if ((elmt != null) && (elmt.value != SnmpVarBind.endOfMibView))
                result[index] = elmt;
            //    vb.value = SnmpVarBind.endOfMibView;
            continue;
        /* end of NPCTE fix for bugid 4381195 */
        }
        /* NPCTE fix for bugid 4381195 esc 0. <J.C.> < 17-Oct-2000> */
        if (elmt == null)
            continue;
        if (elmt.value == SnmpVarBind.endOfMibView)
            continue;
        // Now we need to take the smallest oid ...
        //
        int comp = elmt.oid.compareTo(vb.oid);
        if (comp < 0) {
            // Take the smallest (lexicographically)
            //
            result[index] = elmt;
        } else {
            if (comp == 0) {
                // Take the deeper within the reply
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "updateResult", " oid overlapping. Oid : " + elmt.oid + "value :" + elmt.value);
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "updateResult", "Already present varBind : " + vb);
                }
                SnmpOid oid = vb.oid;
                SnmpMibAgent deeperAgent = server.getAgentMib(oid);
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "updateResult", "Deeper agent : " + deeperAgent);
                }
                if (deeperAgent == agent) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "updateResult", "The current agent is the deeper one. Update the value with the current one");
                    }
                    result[index].value = elmt.value;
                }
            /*
                      Vector v = new Vector();
                      SnmpMibRequest getReq = createMibRequest(v,
                      version,
                      null);
                      SnmpVarBind realValue = new SnmpVarBind(oid);
                      getReq.addVarBind(realValue);
                      try {
                      deeperAgent.get(getReq);
                      } catch(SnmpStatusException e) {
                      e.printStackTrace();
                      }

                      if(isDebugOn())
                      trace("updateResult", "Biggest priority value is : " +
                      realValue.value);

                      result[index].value = realValue.value;
                    */
            }
        }
    }
}
Also used : SnmpOid(com.sun.jmx.snmp.SnmpOid) SnmpValue(com.sun.jmx.snmp.SnmpValue) SnmpMibAgent(com.sun.jmx.snmp.agent.SnmpMibAgent) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 4 with SnmpValue

use of com.sun.jmx.snmp.SnmpValue in project jdk8u_jdk by JetBrains.

the class SnmpRequestHandler method mergeNextResponses.

private SnmpPduPacket mergeNextResponses(SnmpPduRequest req) {
    int max = req.varBindList.length;
    SnmpVarBind[] result = new SnmpVarBind[max];
    //
    for (Enumeration<SnmpSubRequestHandler> e = subs.elements(); e.hasMoreElements(); ) {
        SnmpSubRequestHandler sub = e.nextElement();
        sub.updateResult(result);
    }
    if (req.version == snmpVersionTwo) {
        return newValidResponsePdu(req, result);
    }
    //
    for (int i = 0; i < max; i++) {
        SnmpValue val = result[i].value;
        if (val == SnmpVarBind.endOfMibView)
            return newErrorResponsePdu(req, SnmpDefinitions.snmpRspNoSuchName, i + 1);
    }
    //
    return newValidResponsePdu(req, result);
}
Also used : SnmpValue(com.sun.jmx.snmp.SnmpValue) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Aggregations

SnmpValue (com.sun.jmx.snmp.SnmpValue)4 SnmpOid (com.sun.jmx.snmp.SnmpOid)3 SnmpVarBind (com.sun.jmx.snmp.SnmpVarBind)3 SnmpMibAgent (com.sun.jmx.snmp.agent.SnmpMibAgent)2