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 File: SnmpRequestHandler.java    From jdk8u-jdk 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 #2
Source File: SnmpRequestHandler.java    From JDKSourceCode1.8 with 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 #3
Source File: SnmpRequestHandler.java    From dragonwell8_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 #4
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 #5
Source File: SnmpRequestHandler.java    From openjdk-8 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 #6
Source File: SnmpRequestHandler.java    From openjdk-jdk8u 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 #7
Source File: SnmpRequestHandler.java    From TencentKona-8 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 #8
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 #9
Source File: SnmpRequestHandler.java    From openjdk-jdk8u-backup 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 #10
Source File: SnmpRequestHandler.java    From jdk8u60 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 #11
Source File: SnmpRequestHandler.java    From dragonwell8_jdk 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 #12
Source File: SnmpRequestHandler.java    From jdk1.8-source-analysis with 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 #13
Source File: SnmpRequestHandler.java    From jdk8u-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 #14
Source File: SnmpRequestHandler.java    From jdk8u-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 #15
Source File: SnmpRequestHandler.java    From hottub with 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 #16
Source File: SnmpAdaptorServer.java    From hottub with 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 #17
Source File: SnmpRequestHandler.java    From jdk8u-dev-jdk with 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 #18
Source File: SnmpRequestHandler.java    From openjdk-jdk8u-backup with 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 File: SnmpRequestHandler.java    From openjdk-jdk8u with 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 #20
Source File: SnmpRequestHandler.java    From JDKSourceCode1.8 with 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 #21
Source File: SnmpAdaptorServer.java    From openjdk-8 with 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 #22
Source File: SnmpRequestHandler.java    From jdk8u60 with 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 #23
Source File: SnmpRequestHandler.java    From openjdk-jdk8u-backup with 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 #24
Source File: SnmpRequestHandler.java    From jdk8u-dev-jdk with 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 #25
Source File: SnmpRequestHandler.java    From openjdk-jdk8u-backup with 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 #26
Source File: SnmpAdaptorServer.java    From jdk8u-dev-jdk with 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 #27
Source File: SnmpRequestHandler.java    From jdk8u_jdk with 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 #28
Source File: SnmpRequestHandler.java    From openjdk-8 with 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 #29
Source File: SnmpRequestHandler.java    From jdk8u60 with 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 #30
Source File: SnmpRequestHandler.java    From jdk1.8-source-analysis with 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);
}