com.sun.jmx.snmp.SnmpPduRequest Java Examples

The following examples show how to use com.sun.jmx.snmp.SnmpPduRequest. 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: jdk1.8-source-analysis   Author: raysonfang   File: SnmpRequestHandler.java    License: Apache License 2.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 #2
Source Project: dragonwell8_jdk   Author: alibaba   File: SnmpRequestHandler.java    License: 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 #3
Source Project: dragonwell8_jdk   Author: alibaba   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 #4
Source Project: TencentKona-8   Author: Tencent   File: SnmpRequestHandler.java    License: 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 #5
Source Project: hottub   Author: dsrg-uoft   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 #6
Source Project: jdk8u60   Author: chenghanpeng   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 #7
Source Project: openjdk-8   Author: bpupadhyaya   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 #8
Source Project: openjdk-8-source   Author: keerath   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 #9
Source Project: jdk8u-jdk   Author: frohoff   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 #10
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: SnmpRequestHandler.java    License: MIT License 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 #11
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   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 #12
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: SnmpRequestHandler.java    License: 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 #13
Source Project: jdk8u-jdk   Author: frohoff   File: SnmpRequestHandler.java    License: 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 #14
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: SnmpRequestHandler.java    License: 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 #15
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: SnmpRequestHandler.java    License: Apache License 2.0 5 votes vote down vote up
SnmpPduPacket makeNoMibErrorPdu(SnmpPduRequest req, Object userData) {
    // There is no agent registered
    //
    if (req.version == SnmpDefinitions.snmpVersionOne) {
        // Version 1: => NoSuchName
        return
            newErrorResponsePdu(req,snmpRspNoSuchName,1);
    } else if (req.version == SnmpDefinitions.snmpVersionTwo) {
        // Version 2: => depends on PDU type
        switch (req.type) {
        case pduSetRequestPdu :
        case pduWalkRequest :
            // SET request => NoAccess
            return
                newErrorResponsePdu(req,snmpRspNoAccess,1);
        case pduGetRequestPdu :
            // GET request => NoSuchObject
            return
                makeErrorVarbindPdu(req,SnmpDataTypeEnums.
                                    errNoSuchObjectTag);
        case pduGetNextRequestPdu :
        case pduGetBulkRequestPdu :
            // GET-NEXT or GET-BULK => EndOfMibView
            return
                makeErrorVarbindPdu(req,SnmpDataTypeEnums.
                                    errEndOfMibViewTag);
        default:
        }
    }
    // Something wrong here: => snmpRspGenErr
    return newErrorResponsePdu(req,snmpRspGenErr,1);
}
 
Example #16
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: SnmpRequestHandler.java    License: Apache License 2.0 5 votes vote down vote up
private SnmpPduPacket mergeNextResponses(SnmpPduRequest req) {
    int max= req.varBindList.length;
    SnmpVarBind[] result= new SnmpVarBind[max];

    // 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);
    }

    if (req.version == snmpVersionTwo) {
        return newValidResponsePdu(req,result);
    }

    // In v1 make sure there is no endOfMibView ...
    //
    for(int i=0; i < max; i++) {
        SnmpValue val= result[i].value;
        if (val == SnmpVarBind.endOfMibView)
            return newErrorResponsePdu(req,
                               SnmpDefinitions.snmpRspNoSuchName, i+1);
    }

    // So far so good ...
    //
    return newValidResponsePdu(req,result);
}
 
Example #17
Source Project: openjdk-8   Author: bpupadhyaya   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 5 votes vote down vote up
SnmpPduPacket makeNoMibErrorPdu(SnmpPduRequest req, Object userData) {
    // There is no agent registered
    //
    if (req.version == SnmpDefinitions.snmpVersionOne) {
        // Version 1: => NoSuchName
        return
            newErrorResponsePdu(req,snmpRspNoSuchName,1);
    } else if (req.version == SnmpDefinitions.snmpVersionTwo) {
        // Version 2: => depends on PDU type
        switch (req.type) {
        case pduSetRequestPdu :
        case pduWalkRequest :
            // SET request => NoAccess
            return
                newErrorResponsePdu(req,snmpRspNoAccess,1);
        case pduGetRequestPdu :
            // GET request => NoSuchObject
            return
                makeErrorVarbindPdu(req,SnmpDataTypeEnums.
                                    errNoSuchObjectTag);
        case pduGetNextRequestPdu :
        case pduGetBulkRequestPdu :
            // GET-NEXT or GET-BULK => EndOfMibView
            return
                makeErrorVarbindPdu(req,SnmpDataTypeEnums.
                                    errEndOfMibViewTag);
        default:
        }
    }
    // Something wrong here: => snmpRspGenErr
    return newErrorResponsePdu(req,snmpRspGenErr,1);
}
 
Example #18
Source Project: dragonwell8_jdk   Author: alibaba   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 5 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 newErrorResponsePdu(SnmpPduPacket req,int s,int i) {
    SnmpPduRequest result = newValidResponsePdu(req, null) ;
    result.errorStatus = s ;
    result.errorIndex = i ;
    result.varBindList = req.varBindList ;

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

    return result ;
}
 
Example #19
Source Project: dragonwell8_jdk   Author: alibaba   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 5 votes vote down vote up
private SnmpPduPacket mergeNextResponses(SnmpPduRequest req) {
    int max= req.varBindList.length;
    SnmpVarBind[] result= new SnmpVarBind[max];

    // 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);
    }

    if (req.version == snmpVersionTwo) {
        return newValidResponsePdu(req,result);
    }

    // In v1 make sure there is no endOfMibView ...
    //
    for(int i=0; i < max; i++) {
        SnmpValue val= result[i].value;
        if (val == SnmpVarBind.endOfMibView)
            return newErrorResponsePdu(req,
                               SnmpDefinitions.snmpRspNoSuchName, i+1);
    }

    // So far so good ...
    //
    return newValidResponsePdu(req,result);
}
 
Example #20
Source Project: jdk8u-dev-jdk   Author: frohoff   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 5 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 newErrorResponsePdu(SnmpPduPacket req,int s,int i) {
    SnmpPduRequest result = newValidResponsePdu(req, null) ;
    result.errorStatus = s ;
    result.errorIndex = i ;
    result.varBindList = req.varBindList ;

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

    return result ;
}
 
Example #21
Source Project: openjdk-8-source   Author: keerath   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 5 votes vote down vote up
private SnmpPduPacket mergeNextResponses(SnmpPduRequest req) {
    int max= req.varBindList.length;
    SnmpVarBind[] result= new SnmpVarBind[max];

    // 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);
    }

    if (req.version == snmpVersionTwo) {
        return newValidResponsePdu(req,result);
    }

    // In v1 make sure there is no endOfMibView ...
    //
    for(int i=0; i < max; i++) {
        SnmpValue val= result[i].value;
        if (val == SnmpVarBind.endOfMibView)
            return newErrorResponsePdu(req,
                               SnmpDefinitions.snmpRspNoSuchName, i+1);
    }

    // So far so good ...
    //
    return newValidResponsePdu(req,result);
}
 
Example #22
Source Project: TencentKona-8   Author: Tencent   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 5 votes vote down vote up
private SnmpPduPacket mergeNextResponses(SnmpPduRequest req) {
    int max= req.varBindList.length;
    SnmpVarBind[] result= new SnmpVarBind[max];

    // 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);
    }

    if (req.version == snmpVersionTwo) {
        return newValidResponsePdu(req,result);
    }

    // In v1 make sure there is no endOfMibView ...
    //
    for(int i=0; i < max; i++) {
        SnmpValue val= result[i].value;
        if (val == SnmpVarBind.endOfMibView)
            return newErrorResponsePdu(req,
                               SnmpDefinitions.snmpRspNoSuchName, i+1);
    }

    // So far so good ...
    //
    return newValidResponsePdu(req,result);
}
 
Example #23
Source Project: jdk8u60   Author: chenghanpeng   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 5 votes vote down vote up
SnmpPduPacket makeNoMibErrorPdu(SnmpPduRequest req, Object userData) {
    // There is no agent registered
    //
    if (req.version == SnmpDefinitions.snmpVersionOne) {
        // Version 1: => NoSuchName
        return
            newErrorResponsePdu(req,snmpRspNoSuchName,1);
    } else if (req.version == SnmpDefinitions.snmpVersionTwo) {
        // Version 2: => depends on PDU type
        switch (req.type) {
        case pduSetRequestPdu :
        case pduWalkRequest :
            // SET request => NoAccess
            return
                newErrorResponsePdu(req,snmpRspNoAccess,1);
        case pduGetRequestPdu :
            // GET request => NoSuchObject
            return
                makeErrorVarbindPdu(req,SnmpDataTypeEnums.
                                    errNoSuchObjectTag);
        case pduGetNextRequestPdu :
        case pduGetBulkRequestPdu :
            // GET-NEXT or GET-BULK => EndOfMibView
            return
                makeErrorVarbindPdu(req,SnmpDataTypeEnums.
                                    errEndOfMibViewTag);
        default:
        }
    }
    // Something wrong here: => snmpRspGenErr
    return newErrorResponsePdu(req,snmpRspGenErr,1);
}
 
Example #24
Source Project: jdk8u60   Author: chenghanpeng   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 5 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 newErrorResponsePdu(SnmpPduPacket req,int s,int i) {
    SnmpPduRequest result = newValidResponsePdu(req, null) ;
    result.errorStatus = s ;
    result.errorIndex = i ;
    result.varBindList = req.varBindList ;

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

    return result ;
}
 
Example #25
Source Project: openjdk-8   Author: bpupadhyaya   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 5 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 newErrorResponsePdu(SnmpPduPacket req,int s,int i) {
    SnmpPduRequest result = newValidResponsePdu(req, null) ;
    result.errorStatus = s ;
    result.errorIndex = i ;
    result.varBindList = req.varBindList ;

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

    return result ;
}
 
Example #26
Source Project: jdk8u_jdk   Author: JetBrains   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 5 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 newErrorResponsePdu(SnmpPduPacket req,int s,int i) {
    SnmpPduRequest result = newValidResponsePdu(req, null) ;
    result.errorStatus = s ;
    result.errorIndex = i ;
    result.varBindList = req.varBindList ;

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

    return result ;
}
 
Example #27
Source Project: jdk8u-dev-jdk   Author: frohoff   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 #28
Source Project: jdk8u-dev-jdk   Author: frohoff   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 5 votes vote down vote up
private SnmpPduPacket mergeNextResponses(SnmpPduRequest req) {
    int max= req.varBindList.length;
    SnmpVarBind[] result= new SnmpVarBind[max];

    // 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);
    }

    if (req.version == snmpVersionTwo) {
        return newValidResponsePdu(req,result);
    }

    // In v1 make sure there is no endOfMibView ...
    //
    for(int i=0; i < max; i++) {
        SnmpValue val= result[i].value;
        if (val == SnmpVarBind.endOfMibView)
            return newErrorResponsePdu(req,
                               SnmpDefinitions.snmpRspNoSuchName, i+1);
    }

    // So far so good ...
    //
    return newValidResponsePdu(req,result);
}
 
Example #29
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: SnmpRequestHandler.java    License: MIT License 5 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 newErrorResponsePdu(SnmpPduPacket req,int s,int i) {
    SnmpPduRequest result = newValidResponsePdu(req, null) ;
    result.errorStatus = s ;
    result.errorIndex = i ;
    result.varBindList = req.varBindList ;

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

    return result ;
}
 
Example #30
Source Project: openjdk-8   Author: bpupadhyaya   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) ;
}