Java Code Examples for com.sun.jmx.snmp.SnmpVarBind

The following examples show how to use com.sun.jmx.snmp.SnmpVarBind. These examples are extracted from open source projects. 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 Project: JDKSourceCode1.8   Source File: SnmpMibAgent.java    License: 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 2
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 3
/**
 * 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 4
Source Project: hottub   Source File: SnmpSubRequestHandler.java    License: 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 5
/**
 * 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 6
Source Project: dragonwell8_jdk   Source File: SnmpMibAgent.java    License: 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 7
/**
 * 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 8
Source Project: jdk1.8-source-analysis   Source File: SnmpRequestTree.java    License: 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 9
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 10
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 11
Source Project: jdk1.8-source-analysis   Source File: SnmpMibRequestImpl.java    License: 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 12
/**
 * 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 13
Source Project: hottub   Source File: SnmpRequestHandler.java    License: 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 14
/**
 * 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 15
/**
 * 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 16
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 17
/**
 * 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 18
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
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 20
/**
 * 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 21
/**
 * 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 22
/**
 * 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 23
/**
 * 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 24
/**
 * 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 25
Source Project: jdk8u-jdk   Source File: SnmpRequestHandler.java    License: 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 26
/**
 * 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 27
@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 28
/**
 * 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 Project: jdk8u-jdk   Source File: SnmpAdaptorServer.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sends a trap using SNMP V2 trap format.
 * <BR>The trap is sent to each destination defined in the ACL file
 * (if available). If no ACL file or no destinations are available,
 * the trap is sent to the local host.
 * <BR>The variable list included in the outgoing trap is composed of
 * the following items:
 * <UL>
 * <LI><CODE>sysUpTime.0</CODE> with its current value</LI>
 * <LI><CODE>snmpTrapOid.0</CODE> with the value specified by
 *     <CODE>trapOid</CODE></LI>
 * <LI><CODE>all the (oid,values)</CODE> from the specified
 *     <CODE>varBindList</CODE></LI>
 * </UL>
 *
 * @param trapOid The OID identifying the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 */
@Override
public void snmpV2Trap(SnmpOid trapOid, SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV2Trap", "trapOid=" + trapOid);
    }

    // First, make an SNMP V2 trap pdu
    // We clone varBindList and insert sysUpTime and snmpTrapOid
    //
    SnmpPduRequest pdu = new SnmpPduRequest() ;
    pdu.address = null ;
    pdu.port = trapPort ;
    pdu.type = pduV2TrapPdu ;
    pdu.version = snmpVersionTwo ;
    pdu.community = null ;

    SnmpVarBindList fullVbl ;
    if (varBindList != null)
        fullVbl = varBindList.clone() ;
    else
        fullVbl = new SnmpVarBindList(2) ;
    SnmpTimeticks sysUpTimeValue = new SnmpTimeticks(getSysUpTime()) ;
    fullVbl.insertElementAt(new SnmpVarBind(snmpTrapOidOid, trapOid), 0) ;
    fullVbl.insertElementAt(new SnmpVarBind(sysUpTimeOid, sysUpTimeValue),
                            0);
    pdu.varBindList = new SnmpVarBind[fullVbl.size()] ;
    fullVbl.copyInto(pdu.varBindList) ;

    // Next, send the pdu to all destinations defined in ACL
    //
    sendTrapPdu(pdu) ;
}
 
Example 30
Source Project: jdk8u-dev-jdk   Source File: SnmpMibAgent.java    License: 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));
    }
}