com.sun.jmx.snmp.SnmpVarBind Java Examples

The following examples show how to use com.sun.jmx.snmp.SnmpVarBind. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SnmpSubNextRequestHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The method updates the varbind list of the subrequest.
 */
protected  void updateRequest(SnmpVarBind var, int pos) {
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
            "updateRequest", "Copy :" + var);
    }
    int size= varBind.size();
    translation[size]= pos;
    final SnmpVarBind newVarBind =
        new SnmpVarBind(var.oid, var.value);
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
            "updateRequest", "Copied :" + newVarBind);
    }

    varBind.addElement(newVarBind);
}
 
Example #2
Source File: SnmpSubRequestHandler.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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) {

    if (result == null) return;
    final int max=varBind.size();
    final int len=result.length;
    for(int i= 0; i< max ; i++) {
        // bugId 4641694: must check position in order to avoid
        //       ArrayIndexOutOfBoundException
        final int pos=translation[i];
        if (pos < len) {
            result[pos] =
                (SnmpVarBind)((NonSyncVector)varBind).elementAtNonSync(i);
        } else {
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
                    "updateResult","Position `"+pos+"' is out of bound...");
            }
        }
    }
}
 
Example #3
Source File: SnmpErrorHandlerAgent.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Processes a <CODE>get</CODE> operation. It will throw an exception for V1 requests or it will set exceptions within the list for V2 requests.
 *
 * @param inRequest The SnmpMibRequest object holding the list of variable to be retrieved.
 *
 * @exception SnmpStatusException An error occurred during the operation.
 */

@Override
public void get(SnmpMibRequest inRequest) throws SnmpStatusException {

    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST,
            SnmpErrorHandlerAgent.class.getName(),
            "get", "Get in Exception");

    if(inRequest.getVersion() == SnmpDefinitions.snmpVersionOne)
        throw new SnmpStatusException(SnmpStatusException.noSuchName);

    Enumeration<SnmpVarBind> l = inRequest.getElements();
    while(l.hasMoreElements()) {
        SnmpVarBind varbind = l.nextElement();
        varbind.setNoSuchObject();
    }
}
 
Example #4
Source File: SnmpSubRequestHandler.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * SNMP V1/V2 . To be called with updateRequest.
 */
protected SnmpSubRequestHandler(SnmpMibAgent agent, SnmpPdu req) {
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
            "constructor", "creating instance for request " + String.valueOf(req.requestId));
    }

    version= req.version;
    type= req.type;
    this.agent= agent;

    // We get a ref on the pdu in order to pass it to SnmpMibRequest.
    reqPdu = req;

    //Pre-allocate room for storing varbindlist and translation table.
    //
    int length= req.varBindList.length;
    translation= new int[length];
    varBind= new NonSyncVector<SnmpVarBind>(length);
}
 
Example #5
Source File: SnmpMibAgent.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This is a factory method for creating new SnmpMibRequest objects.
 * @param engine The local engine.
 * @param reqPdu The received pdu.
 * @param vblist The vector of SnmpVarBind objects in which the
 *        MIB concerned by this request is involved.
 * @param version The protocol version of the SNMP request.
 * @param userData User allocated contextual data.
 *
 * @return A new SnmpMibRequest object.
 *
 * @since 1.5
 **/
public static SnmpMibRequest newMibRequest(SnmpEngine engine,
                                           SnmpPdu reqPdu,
                                           Vector<SnmpVarBind> vblist,
                                           int version,
                                           Object userData,
                                           String principal,
                                           int securityLevel,
                                           int securityModel,
                                           byte[] contextName,
                                           byte[] accessContextName) {
    return new SnmpMibRequestImpl(engine,
                                  reqPdu,
                                  vblist,
                                  version,
                                  userData,
                                  principal,
                                  securityLevel,
                                  securityModel,
                                  contextName,
                                  accessContextName);
}
 
Example #6
Source File: SnmpRequestHandler.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Make a response pdu with the specified error status and index.
 * NOTE: the response pdu share its varBindList with the request pdu.
 */
private SnmpPduRequest newValidResponsePdu(SnmpPduPacket reqPdu,
                                           SnmpVarBind[] varBindList) {
    SnmpPduRequest result = new SnmpPduRequest() ;

    result.address = reqPdu.address ;
    result.port = reqPdu.port ;
    result.version = reqPdu.version ;
    result.community = reqPdu.community ;
    result.type = SnmpPduRequest.pduGetResponsePdu ;
    result.requestId = reqPdu.requestId ;
    result.errorStatus = SnmpDefinitions.snmpRspNoError ;
    result.errorIndex = 0 ;
    result.varBindList = varBindList ;

    ((SnmpAdaptorServer)adaptorServer).
        updateErrorCounters(result.errorStatus) ;

    return result ;
}
 
Example #7
Source File: SnmpRequestHandler.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
SnmpPduPacket makeErrorVarbindPdu(SnmpPduPacket req, int statusTag) {

        final SnmpVarBind[] vblist = req.varBindList;
        final int length = vblist.length;

        switch (statusTag) {
        case SnmpDataTypeEnums.errEndOfMibViewTag:
            for (int i=0 ; i<length ; i++)
                vblist[i].value = SnmpVarBind.endOfMibView;
            break;
        case SnmpDataTypeEnums.errNoSuchObjectTag:
            for (int i=0 ; i<length ; i++)
                vblist[i].value = SnmpVarBind.noSuchObject;
            break;
        case SnmpDataTypeEnums.errNoSuchInstanceTag:
            for (int i=0 ; i<length ; i++)
                vblist[i].value = SnmpVarBind.noSuchInstance;
            break;
        default:
            return newErrorResponsePdu(req,snmpRspGenErr,1);
        }
        return newValidResponsePdu(req,vblist);
    }
 
Example #8
Source File: SnmpMibAgent.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * This method creates a new Vector which does not contain the first
 * element up to the specified limit.
 *
 * @param original The original vector.
 * @param limit The limit.
 */
private Vector<SnmpVarBind> splitFrom(Vector<SnmpVarBind> original, int limit) {

    int max= original.size();
    Vector<SnmpVarBind> result= new Vector<>(max - limit);
    int i= limit;

    // Ok the loop looks a bit strange. But in order to improve the
    // perf, we try to avoid reference to the limit variable from
    // within the loop ...
    //
    for(Enumeration<SnmpVarBind> e= original.elements(); e.hasMoreElements(); --i) {
        SnmpVarBind var= e.nextElement();
        if (i >0)
            continue;
        result.addElement(new SnmpVarBind(var.oid, var.value));
    }
    return result;
}
 
Example #9
Source File: SnmpRequestTree.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void registerCheckException(SnmpVarBind var,
                                   SnmpStatusException exception)
    throws SnmpStatusException {
    // The index in the exception must correspond to
    // the SNMP index ...
    //
    // We throw the exception in order to abort the SET operation
    // in an atomic way.
    final int errorCode = exception.getStatus();
    final int mappedErrorCode = mapSetException(errorCode,
                                                version);

    if (errorCode != mappedErrorCode)
        throw new
            SnmpStatusException(mappedErrorCode, getVarIndex(var)+1);
    else
        throw new SnmpStatusException(exception, getVarIndex(var)+1);
}
 
Example #10
Source File: SnmpSubRequestHandler.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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) {

    if (result == null) return;
    final int max=varBind.size();
    final int len=result.length;
    for(int i= 0; i< max ; i++) {
        // bugId 4641694: must check position in order to avoid
        //       ArrayIndexOutOfBoundException
        final int pos=translation[i];
        if (pos < len) {
            result[pos] =
                (SnmpVarBind)((NonSyncVector)varBind).elementAtNonSync(i);
        } else {
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
                    "updateResult","Position `"+pos+"' is out of bound...");
            }
        }
    }
}
 
Example #11
Source File: SnmpRequestHandler.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
SnmpPduPacket makeErrorVarbindPdu(SnmpPduPacket req, int statusTag) {

        final SnmpVarBind[] vblist = req.varBindList;
        final int length = vblist.length;

        switch (statusTag) {
        case SnmpDataTypeEnums.errEndOfMibViewTag:
            for (int i=0 ; i<length ; i++)
                vblist[i].value = SnmpVarBind.endOfMibView;
            break;
        case SnmpDataTypeEnums.errNoSuchObjectTag:
            for (int i=0 ; i<length ; i++)
                vblist[i].value = SnmpVarBind.noSuchObject;
            break;
        case SnmpDataTypeEnums.errNoSuchInstanceTag:
            for (int i=0 ; i<length ; i++)
                vblist[i].value = SnmpVarBind.noSuchInstance;
            break;
        default:
            return newErrorResponsePdu(req,snmpRspGenErr,1);
        }
        return newValidResponsePdu(req,vblist);
    }
 
Example #12
Source File: SnmpSubRequestHandler.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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) {

    if (result == null) return;
    final int max=varBind.size();
    final int len=result.length;
    for(int i= 0; i< max ; i++) {
        // bugId 4641694: must check position in order to avoid
        //       ArrayIndexOutOfBoundException
        final int pos=translation[i];
        if (pos < len) {
            result[pos] =
                (SnmpVarBind)((NonSyncVector)varBind).elementAtNonSync(i);
        } else {
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
                    "updateResult","Position `"+pos+"' is out of bound...");
            }
        }
    }
}
 
Example #13
Source File: SnmpSubNextRequestHandler.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The method updates the varbind list of the subrequest.
 */
protected  void updateRequest(SnmpVarBind var, int pos) {
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
            "updateRequest", "Copy :" + var);
    }
    int size= varBind.size();
    translation[size]= pos;
    final SnmpVarBind newVarBind =
        new SnmpVarBind(var.oid, var.value);
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
            "updateRequest", "Copied :" + newVarBind);
    }

    varBind.addElement(newVarBind);
}
 
Example #14
Source File: SnmpErrorHandlerAgent.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Processes a <CODE>getNext</CODE> operation. It will throw an exception for V1 requests or it will set exceptions within the list for V2 requests..
 *
 * @param inRequest The SnmpMibRequest object holding the list of variables to be retrieved.
 *
 * @exception SnmpStatusException An error occurred during the operation.
 */

@Override
public void getNext(SnmpMibRequest inRequest) throws SnmpStatusException {

    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST,
            SnmpErrorHandlerAgent.class.getName(),
            "getNext", "GetNext in Exception");

    if(inRequest.getVersion() == SnmpDefinitions.snmpVersionOne)
        throw new SnmpStatusException(SnmpStatusException.noSuchName);

    Enumeration<SnmpVarBind> l = inRequest.getElements();
    while(l.hasMoreElements()) {
        SnmpVarBind varbind = l.nextElement();
        varbind.setEndOfMibView();
    }
}
 
Example #15
Source File: SnmpMibAgent.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This is a factory method for creating new SnmpMibRequest objects.
 * @param engine The local engine.
 * @param reqPdu The received pdu.
 * @param vblist The vector of SnmpVarBind objects in which the
 *        MIB concerned by this request is involved.
 * @param version The protocol version of the SNMP request.
 * @param userData User allocated contextual data.
 *
 * @return A new SnmpMibRequest object.
 *
 * @since 1.5
 **/
public static SnmpMibRequest newMibRequest(SnmpEngine engine,
                                           SnmpPdu reqPdu,
                                           Vector<SnmpVarBind> vblist,
                                           int version,
                                           Object userData,
                                           String principal,
                                           int securityLevel,
                                           int securityModel,
                                           byte[] contextName,
                                           byte[] accessContextName) {
    return new SnmpMibRequestImpl(engine,
                                  reqPdu,
                                  vblist,
                                  version,
                                  userData,
                                  principal,
                                  securityLevel,
                                  securityModel,
                                  contextName,
                                  accessContextName);
}
 
Example #16
Source File: SnmpRequestHandler.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private SnmpPduPacket mergeResponses(SnmpPduRequest req) {

        if (req.type == pduGetNextRequestPdu) {
            return mergeNextResponses(req);
        }

        SnmpVarBind[] result= req.varBindList;

        // Go through the list of subrequests and concatenate.
        // Hopefully, by now all the sub-requests should be finished
        //
        for(Enumeration<SnmpSubRequestHandler> e= subs.elements(); e.hasMoreElements();) {
            SnmpSubRequestHandler sub= e.nextElement();
            sub.updateResult(result);
        }
        return newValidResponsePdu(req,result);
    }
 
Example #17
Source File: SnmpErrorHandlerAgent.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Processes a <CODE>get</CODE> operation. It will throw an exception for V1 requests or it will set exceptions within the list for V2 requests.
 *
 * @param inRequest The SnmpMibRequest object holding the list of variable to be retrieved.
 *
 * @exception SnmpStatusException An error occurred during the operation.
 */

@Override
public void get(SnmpMibRequest inRequest) throws SnmpStatusException {

    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST,
            SnmpErrorHandlerAgent.class.getName(),
            "get", "Get in Exception");

    if(inRequest.getVersion() == SnmpDefinitions.snmpVersionOne)
        throw new SnmpStatusException(SnmpStatusException.noSuchName);

    Enumeration<SnmpVarBind> l = inRequest.getElements();
    while(l.hasMoreElements()) {
        SnmpVarBind varbind = l.nextElement();
        varbind.setNoSuchObject();
    }
}
 
Example #18
Source File: SnmpSubBulkRequestHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void init(SnmpAdaptorServer server,
                  SnmpPdu req,
                  int nonRepeat,
                  int maxRepeat,
                  int R) {
    this.server = server;
    this.nonRepeat= nonRepeat;
    this.maxRepeat= maxRepeat;
    this.globalR= R;

    final int max= translation.length;
    final SnmpVarBind[] list= req.varBindList;
    final NonSyncVector<SnmpVarBind> nonSyncVarBind =
            ((NonSyncVector<SnmpVarBind>)varBind);
    for(int i=0; i < max; i++) {
        translation[i]= i;
        // we need to allocate a new SnmpVarBind. Otherwise the first
        // sub request will modify the list...
        //
        final SnmpVarBind newVarBind =
            new SnmpVarBind(list[i].oid, list[i].value);
        nonSyncVarBind.addNonSyncElement(newVarBind);
    }
}
 
Example #19
Source File: SnmpRequestTree.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
@Override
public void registerCheckException(SnmpVarBind var,
                                   SnmpStatusException exception)
    throws SnmpStatusException {
    // The index in the exception must correspond to
    // the SNMP index ...
    //
    // We throw the exception in order to abort the SET operation
    // in an atomic way.
    final int errorCode = exception.getStatus();
    final int mappedErrorCode = mapSetException(errorCode,
                                                version);

    if (errorCode != mappedErrorCode)
        throw new
            SnmpStatusException(mappedErrorCode, getVarIndex(var)+1);
    else
        throw new SnmpStatusException(exception, getVarIndex(var)+1);
}
 
Example #20
Source File: SnmpSubNextRequestHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void init(SnmpPdu req, SnmpAdaptorServer server) {
    this.server = server;

    // The translation table is easy in this case ...
    //
    final int max= translation.length;
    final SnmpVarBind[] list= req.varBindList;
    final NonSyncVector<SnmpVarBind> nonSyncVarBind =
            ((NonSyncVector<SnmpVarBind>)varBind);
    for(int i=0; i < max; i++) {
        translation[i]= i;
        // we need to allocate a new SnmpVarBind. Otherwise the first
        // sub request will modify the list...
        //
        final SnmpVarBind newVarBind =
            new SnmpVarBind(list[i].oid, list[i].value);
        nonSyncVarBind.addNonSyncElement(newVarBind);
    }
}
 
Example #21
Source File: SnmpErrorHandlerAgent.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Processes a <CODE>getBulk</CODE> operation. It will throw an exception if the request is a V1 one or it will set exceptions within the list for V2 ones.
 *
 * @param inRequest The SnmpMibRequest object holding the list of variable to be retrieved.
 *
 * @exception SnmpStatusException An error occurred during the operation.
 */

@Override
public void getBulk(SnmpMibRequest inRequest, int nonRepeat, int maxRepeat)
    throws SnmpStatusException {

    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST,
            SnmpErrorHandlerAgent.class.getName(),
            "getBulk", "GetBulk in Exception");

    if(inRequest.getVersion() == SnmpDefinitions.snmpVersionOne)
        throw new SnmpStatusException(SnmpDefinitions.snmpRspGenErr, 0);

    Enumeration<SnmpVarBind> l = inRequest.getElements();
    while(l.hasMoreElements()) {
        SnmpVarBind varbind = l.nextElement();
        varbind.setEndOfMibView();
    }
}
 
Example #22
Source File: SnmpSubBulkRequestHandler.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void init(SnmpAdaptorServer server,
                  SnmpPdu req,
                  int nonRepeat,
                  int maxRepeat,
                  int R) {
    this.server = server;
    this.nonRepeat= nonRepeat;
    this.maxRepeat= maxRepeat;
    this.globalR= R;

    final int max= translation.length;
    final SnmpVarBind[] list= req.varBindList;
    final NonSyncVector<SnmpVarBind> nonSyncVarBind =
            ((NonSyncVector<SnmpVarBind>)varBind);
    for(int i=0; i < max; i++) {
        translation[i]= i;
        // we need to allocate a new SnmpVarBind. Otherwise the first
        // sub request will modify the list...
        //
        final SnmpVarBind newVarBind =
            new SnmpVarBind(list[i].oid, list[i].value);
        nonSyncVarBind.addNonSyncElement(newVarBind);
    }
}
 
Example #23
Source File: SnmpSubNextRequestHandler.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private void init(SnmpPdu req, SnmpAdaptorServer server) {
    this.server = server;

    // The translation table is easy in this case ...
    //
    final int max= translation.length;
    final SnmpVarBind[] list= req.varBindList;
    final NonSyncVector<SnmpVarBind> nonSyncVarBind =
            ((NonSyncVector<SnmpVarBind>)varBind);
    for(int i=0; i < max; i++) {
        translation[i]= i;
        // we need to allocate a new SnmpVarBind. Otherwise the first
        // sub request will modify the list...
        //
        final SnmpVarBind newVarBind =
            new SnmpVarBind(list[i].oid, list[i].value);
        nonSyncVarBind.addNonSyncElement(newVarBind);
    }
}
 
Example #24
Source File: SnmpMibRequestImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * @param engine The local engine.
 * @param reqPdu The received pdu.
 * @param vblist The vector of SnmpVarBind objects in which the
 *        MIB concerned by this request is involved.
 * @param protocolVersion  The protocol version of the SNMP request.
 * @param userData     User allocated contextual data. This object must
 *        be allocated on a per SNMP request basis through the
 *        SnmpUserDataFactory registered with the SnmpAdaptorServer,
 *        and is handed back to the user through SnmpMibRequest objects.
 */
public SnmpMibRequestImpl(SnmpEngine engine,
                          SnmpPdu reqPdu,
                          Vector<SnmpVarBind> vblist,
                          int protocolVersion,
                          Object userData,
                          String principal,
                          int securityLevel,
                          int securityModel,
                          byte[] contextName,
                          byte[] accessContextName) {
    varbinds   = vblist;
    version    = protocolVersion;
    data       = userData;
    this.reqPdu = reqPdu;
    this.engine = engine;
    this.principal = principal;
    this.securityLevel = securityLevel;
    this.securityModel = securityModel;
    this.contextName = contextName;
    this.accessContextName = accessContextName;
}
 
Example #25
Source File: SnmpErrorHandlerAgent.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Processes a <CODE>getBulk</CODE> operation. It will throw an exception if the request is a V1 one or it will set exceptions within the list for V2 ones.
 *
 * @param inRequest The SnmpMibRequest object holding the list of variable to be retrieved.
 *
 * @exception SnmpStatusException An error occurred during the operation.
 */

@Override
public void getBulk(SnmpMibRequest inRequest, int nonRepeat, int maxRepeat)
    throws SnmpStatusException {

    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST,
            SnmpErrorHandlerAgent.class.getName(),
            "getBulk", "GetBulk in Exception");

    if(inRequest.getVersion() == SnmpDefinitions.snmpVersionOne)
        throw new SnmpStatusException(SnmpDefinitions.snmpRspGenErr, 0);

    Enumeration<SnmpVarBind> l = inRequest.getElements();
    while(l.hasMoreElements()) {
        SnmpVarBind varbind = l.nextElement();
        varbind.setEndOfMibView();
    }
}
 
Example #26
Source File: SnmpSubRequestHandler.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * SNMP V1/V2 The constructor initialize the subrequest with the whole varbind list contained
 * in the original request.
 */
@SuppressWarnings("unchecked")  // cast to NonSyncVector<SnmpVarBind>
protected SnmpSubRequestHandler(SnmpMibAgent agent,
                                SnmpPdu req,
                                boolean nouse) {
    this(agent,req);

    // The translation table is easy in this case ...
    //
    int max= translation.length;
    SnmpVarBind[] list= req.varBindList;
    for(int i=0; i < max; i++) {
        translation[i]= i;
        ((NonSyncVector<SnmpVarBind>)varBind).addNonSyncElement(list[i]);
    }
}
 
Example #27
Source File: SnmpRequestHandler.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private SnmpPduPacket mergeResponses(SnmpPduRequest req) {

        if (req.type == pduGetNextRequestPdu) {
            return mergeNextResponses(req);
        }

        SnmpVarBind[] result= req.varBindList;

        // Go through the list of subrequests and concatenate.
        // Hopefully, by now all the sub-requests should be finished
        //
        for(Enumeration<SnmpSubRequestHandler> e= subs.elements(); e.hasMoreElements();) {
            SnmpSubRequestHandler sub= e.nextElement();
            sub.updateResult(result);
        }
        return newValidResponsePdu(req,result);
    }
 
Example #28
Source File: SnmpSubRequestHandler.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * 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) {

    if (result == null) return;
    final int max=varBind.size();
    final int len=result.length;
    for(int i= 0; i< max ; i++) {
        // bugId 4641694: must check position in order to avoid
        //       ArrayIndexOutOfBoundException
        final int pos=translation[i];
        if (pos < len) {
            result[pos] =
                (SnmpVarBind)((NonSyncVector)varBind).elementAtNonSync(i);
        } else {
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
                    "updateResult","Position `"+pos+"' is out of bound...");
            }
        }
    }
}
 
Example #29
Source File: SnmpMibTable.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void setRowStatusFail(SnmpMibSubRequest req, int errorStatus)
    throws SnmpStatusException {

    final SnmpVarBind statusvb  = req.getRowStatusVarBind();
    final SnmpStatusException x = new SnmpStatusException(errorStatus);
    req.registerSetException(statusvb,x);
}
 
Example #30
Source File: SnmpMibAgent.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void concatVector(SnmpMibRequest req, Vector<SnmpVarBind> source) {
    for(Enumeration<SnmpVarBind> e= source.elements(); e.hasMoreElements(); ) {
        SnmpVarBind var= e.nextElement();
        // We need to duplicate the SnmpVarBind otherwise it is going
        // to be overloaded by the next get Next ...
        req.addVarBind(new SnmpVarBind(var.oid, var.value));
    }
}