com.sun.jmx.snmp.SnmpPduBulk Java Examples

The following examples show how to use com.sun.jmx.snmp.SnmpPduBulk. 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
/**
 * The method takes the incoming get bulk requests and split it into
 * subrequests.
 */
private void splitBulkRequest(SnmpPduBulk req,
                              int nonRepeaters,
                              int maxRepetitions,
                              int R) {
    // Send the getBulk to all agents
    //
    for(Enumeration<SnmpMibAgent> e= mibs.elements(); e.hasMoreElements(); ) {
        final SnmpMibAgent agent = e.nextElement();

        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
               "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters
               + " " + maxRepetitions + " " + R);
        }

        subs.put(agent,
                 new SnmpSubBulkRequestHandler(adaptor,
                                               agent,
                                               req,
                                               nonRepeaters,
                                               maxRepetitions,
                                               R));
    }
}
 
Example #2
Source Project: dragonwell8_jdk   Author: alibaba   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * The method takes the incoming get bulk requests and split it into
 * subrequests.
 */
private void splitBulkRequest(SnmpPduBulk req,
                              int nonRepeaters,
                              int maxRepetitions,
                              int R) {
    // Send the getBulk to all agents
    //
    for(Enumeration<SnmpMibAgent> e= mibs.elements(); e.hasMoreElements(); ) {
        final SnmpMibAgent agent = e.nextElement();

        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
               "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters
               + " " + maxRepetitions + " " + R);
        }

        subs.put(agent,
                 new SnmpSubBulkRequestHandler(adaptor,
                                               agent,
                                               req,
                                               nonRepeaters,
                                               maxRepetitions,
                                               R));
    }
}
 
Example #3
Source Project: TencentKona-8   Author: Tencent   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * The method takes the incoming get bulk requests and split it into
 * subrequests.
 */
private void splitBulkRequest(SnmpPduBulk req,
                              int nonRepeaters,
                              int maxRepetitions,
                              int R) {
    // Send the getBulk to all agents
    //
    for(Enumeration<SnmpMibAgent> e= mibs.elements(); e.hasMoreElements(); ) {
        final SnmpMibAgent agent = e.nextElement();

        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
               "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters
               + " " + maxRepetitions + " " + R);
        }

        subs.put(agent,
                 new SnmpSubBulkRequestHandler(adaptor,
                                               agent,
                                               req,
                                               nonRepeaters,
                                               maxRepetitions,
                                               R));
    }
}
 
Example #4
Source Project: jdk8u60   Author: chenghanpeng   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * The method takes the incoming get bulk requests and split it into
 * subrequests.
 */
private void splitBulkRequest(SnmpPduBulk req,
                              int nonRepeaters,
                              int maxRepetitions,
                              int R) {
    // Send the getBulk to all agents
    //
    for(Enumeration<SnmpMibAgent> e= mibs.elements(); e.hasMoreElements(); ) {
        final SnmpMibAgent agent = e.nextElement();

        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
               "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters
               + " " + maxRepetitions + " " + R);
        }

        subs.put(agent,
                 new SnmpSubBulkRequestHandler(adaptor,
                                               agent,
                                               req,
                                               nonRepeaters,
                                               maxRepetitions,
                                               R));
    }
}
 
Example #5
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: SnmpRequestHandler.java    License: MIT License 6 votes vote down vote up
/**
 * The method takes the incoming get bulk requests and split it into
 * subrequests.
 */
private void splitBulkRequest(SnmpPduBulk req,
                              int nonRepeaters,
                              int maxRepetitions,
                              int R) {
    // Send the getBulk to all agents
    //
    for(Enumeration<SnmpMibAgent> e= mibs.elements(); e.hasMoreElements(); ) {
        final SnmpMibAgent agent = e.nextElement();

        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
               "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters
               + " " + maxRepetitions + " " + R);
        }

        subs.put(agent,
                 new SnmpSubBulkRequestHandler(adaptor,
                                               agent,
                                               req,
                                               nonRepeaters,
                                               maxRepetitions,
                                               R));
    }
}
 
Example #6
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * The method takes the incoming get bulk requests and split it into
 * subrequests.
 */
private void splitBulkRequest(SnmpPduBulk req,
                              int nonRepeaters,
                              int maxRepetitions,
                              int R) {
    // Send the getBulk to all agents
    //
    for(Enumeration<SnmpMibAgent> e= mibs.elements(); e.hasMoreElements(); ) {
        final SnmpMibAgent agent = e.nextElement();

        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
               "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters
               + " " + maxRepetitions + " " + R);
        }

        subs.put(agent,
                 new SnmpSubBulkRequestHandler(adaptor,
                                               agent,
                                               req,
                                               nonRepeaters,
                                               maxRepetitions,
                                               R));
    }
}
 
Example #7
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * The method takes the incoming get bulk requests and split it into
 * subrequests.
 */
private void splitBulkRequest(SnmpPduBulk req,
                              int nonRepeaters,
                              int maxRepetitions,
                              int R) {
    // Send the getBulk to all agents
    //
    for(Enumeration<SnmpMibAgent> e= mibs.elements(); e.hasMoreElements(); ) {
        final SnmpMibAgent agent = e.nextElement();

        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
               "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters
               + " " + maxRepetitions + " " + R);
        }

        subs.put(agent,
                 new SnmpSubBulkRequestHandler(adaptor,
                                               agent,
                                               req,
                                               nonRepeaters,
                                               maxRepetitions,
                                               R));
    }
}
 
Example #8
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * The method takes the incoming get bulk requests and split it into
 * subrequests.
 */
private void splitBulkRequest(SnmpPduBulk req,
                              int nonRepeaters,
                              int maxRepetitions,
                              int R) {
    // Send the getBulk to all agents
    //
    for(Enumeration<SnmpMibAgent> e= mibs.elements(); e.hasMoreElements(); ) {
        final SnmpMibAgent agent = e.nextElement();

        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
               "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters
               + " " + maxRepetitions + " " + R);
        }

        subs.put(agent,
                 new SnmpSubBulkRequestHandler(adaptor,
                                               agent,
                                               req,
                                               nonRepeaters,
                                               maxRepetitions,
                                               R));
    }
}
 
Example #9
Source Project: hottub   Author: dsrg-uoft   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * The method takes the incoming get bulk requests and split it into
 * subrequests.
 */
private void splitBulkRequest(SnmpPduBulk req,
                              int nonRepeaters,
                              int maxRepetitions,
                              int R) {
    // Send the getBulk to all agents
    //
    for(Enumeration<SnmpMibAgent> e= mibs.elements(); e.hasMoreElements(); ) {
        final SnmpMibAgent agent = e.nextElement();

        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
               "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters
               + " " + maxRepetitions + " " + R);
        }

        subs.put(agent,
                 new SnmpSubBulkRequestHandler(adaptor,
                                               agent,
                                               req,
                                               nonRepeaters,
                                               maxRepetitions,
                                               R));
    }
}
 
Example #10
Source Project: openjdk-8-source   Author: keerath   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * The method takes the incoming get bulk requests and split it into
 * subrequests.
 */
private void splitBulkRequest(SnmpPduBulk req,
                              int nonRepeaters,
                              int maxRepetitions,
                              int R) {
    // Send the getBulk to all agents
    //
    for(Enumeration<SnmpMibAgent> e= mibs.elements(); e.hasMoreElements(); ) {
        final SnmpMibAgent agent = e.nextElement();

        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
               "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters
               + " " + maxRepetitions + " " + R);
        }

        subs.put(agent,
                 new SnmpSubBulkRequestHandler(adaptor,
                                               agent,
                                               req,
                                               nonRepeaters,
                                               maxRepetitions,
                                               R));
    }
}
 
Example #11
Source Project: openjdk-8   Author: bpupadhyaya   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * The method takes the incoming get bulk requests and split it into
 * subrequests.
 */
private void splitBulkRequest(SnmpPduBulk req,
                              int nonRepeaters,
                              int maxRepetitions,
                              int R) {
    // Send the getBulk to all agents
    //
    for(Enumeration<SnmpMibAgent> e= mibs.elements(); e.hasMoreElements(); ) {
        final SnmpMibAgent agent = e.nextElement();

        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
               "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters
               + " " + maxRepetitions + " " + R);
        }

        subs.put(agent,
                 new SnmpSubBulkRequestHandler(adaptor,
                                               agent,
                                               req,
                                               nonRepeaters,
                                               maxRepetitions,
                                               R));
    }
}
 
Example #12
Source Project: jdk8u_jdk   Author: JetBrains   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * The method takes the incoming get bulk requests and split it into
 * subrequests.
 */
private void splitBulkRequest(SnmpPduBulk req,
                              int nonRepeaters,
                              int maxRepetitions,
                              int R) {
    // Send the getBulk to all agents
    //
    for(Enumeration<SnmpMibAgent> e= mibs.elements(); e.hasMoreElements(); ) {
        final SnmpMibAgent agent = e.nextElement();

        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
               "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters
               + " " + maxRepetitions + " " + R);
        }

        subs.put(agent,
                 new SnmpSubBulkRequestHandler(adaptor,
                                               agent,
                                               req,
                                               nonRepeaters,
                                               maxRepetitions,
                                               R));
    }
}
 
Example #13
Source Project: jdk8u-jdk   Author: frohoff   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * The method takes the incoming get bulk requests and split it into
 * subrequests.
 */
private void splitBulkRequest(SnmpPduBulk req,
                              int nonRepeaters,
                              int maxRepetitions,
                              int R) {
    // Send the getBulk to all agents
    //
    for(Enumeration<SnmpMibAgent> e= mibs.elements(); e.hasMoreElements(); ) {
        final SnmpMibAgent agent = e.nextElement();

        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
               "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters
               + " " + maxRepetitions + " " + R);
        }

        subs.put(agent,
                 new SnmpSubBulkRequestHandler(adaptor,
                                               agent,
                                               req,
                                               nonRepeaters,
                                               maxRepetitions,
                                               R));
    }
}
 
Example #14
Source Project: jdk8u-dev-jdk   Author: frohoff   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * The method takes the incoming get bulk requests and split it into
 * subrequests.
 */
private void splitBulkRequest(SnmpPduBulk req,
                              int nonRepeaters,
                              int maxRepetitions,
                              int R) {
    // Send the getBulk to all agents
    //
    for(Enumeration<SnmpMibAgent> e= mibs.elements(); e.hasMoreElements(); ) {
        final SnmpMibAgent agent = e.nextElement();

        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
               "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters
               + " " + maxRepetitions + " " + R);
        }

        subs.put(agent,
                 new SnmpSubBulkRequestHandler(adaptor,
                                               agent,
                                               req,
                                               nonRepeaters,
                                               maxRepetitions,
                                               R));
    }
}
 
Example #15
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: SnmpRequestHandler.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
 
Example #16
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: SnmpRequestHandler.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Here we make the response pdu for a bulk request.
 * At this level, the result is never null.
 */
private SnmpPduPacket makeGetBulkResponsePdu(SnmpPduBulk req,
                                             Object userData) {

    SnmpVarBind[] respVarBindList;

    // RFC 1905, Section 4.2.3, p14
    int L = req.varBindList.length ;
    int N = Math.max(Math.min(req.nonRepeaters, L), 0) ;
    int M = Math.max(req.maxRepetitions, 0) ;
    int R = L - N ;

    if (req.varBindList == null) {
        // Good ! Let's make a full response pdu.
        //
        return newValidResponsePdu(req, null) ;
    }

    // Split the request into subrequests.
    //
    splitBulkRequest(req, N, M, R);
    SnmpPduPacket result= executeSubRequest(req,userData);
    if (result != null)
        return result;

    respVarBindList= mergeBulkResponses(N + (M * R));

    // Now we remove useless trailing endOfMibView.
    //
    int m2 ; // respVarBindList[m2] item and next are going to be removed
    int t = respVarBindList.length ;
    while ((t > N) && (respVarBindList[t-1].
                       value.equals(SnmpVarBind.endOfMibView))) {
        t-- ;
    }
    if (t == N)
        m2 = N + R ;
    else
        m2 = N + ((t -1 -N) / R + 2) * R ; // Trivial, of course...
    if (m2 < respVarBindList.length) {
        SnmpVarBind[] truncatedList = new SnmpVarBind[m2] ;
        for (int i = 0 ; i < m2 ; i++) {
            truncatedList[i] = respVarBindList[i] ;
        }
        respVarBindList = truncatedList ;
    }

    // Good ! Let's make a full response pdu.
    //
    return newValidResponsePdu(req, respVarBindList) ;
}
 
Example #17
Source Project: dragonwell8_jdk   Author: alibaba   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
 
Example #18
Source Project: dragonwell8_jdk   Author: alibaba   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Here we make the response pdu for a bulk request.
 * At this level, the result is never null.
 */
private SnmpPduPacket makeGetBulkResponsePdu(SnmpPduBulk req,
                                             Object userData) {

    SnmpVarBind[] respVarBindList;

    // RFC 1905, Section 4.2.3, p14
    int L = req.varBindList.length ;
    int N = Math.max(Math.min(req.nonRepeaters, L), 0) ;
    int M = Math.max(req.maxRepetitions, 0) ;
    int R = L - N ;

    if (req.varBindList == null) {
        // Good ! Let's make a full response pdu.
        //
        return newValidResponsePdu(req, null) ;
    }

    // Split the request into subrequests.
    //
    splitBulkRequest(req, N, M, R);
    SnmpPduPacket result= executeSubRequest(req,userData);
    if (result != null)
        return result;

    respVarBindList= mergeBulkResponses(N + (M * R));

    // Now we remove useless trailing endOfMibView.
    //
    int m2 ; // respVarBindList[m2] item and next are going to be removed
    int t = respVarBindList.length ;
    while ((t > N) && (respVarBindList[t-1].
                       value.equals(SnmpVarBind.endOfMibView))) {
        t-- ;
    }
    if (t == N)
        m2 = N + R ;
    else
        m2 = N + ((t -1 -N) / R + 2) * R ; // Trivial, of course...
    if (m2 < respVarBindList.length) {
        SnmpVarBind[] truncatedList = new SnmpVarBind[m2] ;
        for (int i = 0 ; i < m2 ; i++) {
            truncatedList[i] = respVarBindList[i] ;
        }
        respVarBindList = truncatedList ;
    }

    // Good ! Let's make a full response pdu.
    //
    return newValidResponsePdu(req, respVarBindList) ;
}
 
Example #19
Source Project: TencentKona-8   Author: Tencent   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
 
Example #20
Source Project: TencentKona-8   Author: Tencent   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Here we make the response pdu for a bulk request.
 * At this level, the result is never null.
 */
private SnmpPduPacket makeGetBulkResponsePdu(SnmpPduBulk req,
                                             Object userData) {

    SnmpVarBind[] respVarBindList;

    // RFC 1905, Section 4.2.3, p14
    int L = req.varBindList.length ;
    int N = Math.max(Math.min(req.nonRepeaters, L), 0) ;
    int M = Math.max(req.maxRepetitions, 0) ;
    int R = L - N ;

    if (req.varBindList == null) {
        // Good ! Let's make a full response pdu.
        //
        return newValidResponsePdu(req, null) ;
    }

    // Split the request into subrequests.
    //
    splitBulkRequest(req, N, M, R);
    SnmpPduPacket result= executeSubRequest(req,userData);
    if (result != null)
        return result;

    respVarBindList= mergeBulkResponses(N + (M * R));

    // Now we remove useless trailing endOfMibView.
    //
    int m2 ; // respVarBindList[m2] item and next are going to be removed
    int t = respVarBindList.length ;
    while ((t > N) && (respVarBindList[t-1].
                       value.equals(SnmpVarBind.endOfMibView))) {
        t-- ;
    }
    if (t == N)
        m2 = N + R ;
    else
        m2 = N + ((t -1 -N) / R + 2) * R ; // Trivial, of course...
    if (m2 < respVarBindList.length) {
        SnmpVarBind[] truncatedList = new SnmpVarBind[m2] ;
        for (int i = 0 ; i < m2 ; i++) {
            truncatedList[i] = respVarBindList[i] ;
        }
        respVarBindList = truncatedList ;
    }

    // Good ! Let's make a full response pdu.
    //
    return newValidResponsePdu(req, respVarBindList) ;
}
 
Example #21
Source Project: jdk8u60   Author: chenghanpeng   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
 
Example #22
Source Project: jdk8u60   Author: chenghanpeng   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Here we make the response pdu for a bulk request.
 * At this level, the result is never null.
 */
private SnmpPduPacket makeGetBulkResponsePdu(SnmpPduBulk req,
                                             Object userData) {

    SnmpVarBind[] respVarBindList;

    // RFC 1905, Section 4.2.3, p14
    int L = req.varBindList.length ;
    int N = Math.max(Math.min(req.nonRepeaters, L), 0) ;
    int M = Math.max(req.maxRepetitions, 0) ;
    int R = L - N ;

    if (req.varBindList == null) {
        // Good ! Let's make a full response pdu.
        //
        return newValidResponsePdu(req, null) ;
    }

    // Split the request into subrequests.
    //
    splitBulkRequest(req, N, M, R);
    SnmpPduPacket result= executeSubRequest(req,userData);
    if (result != null)
        return result;

    respVarBindList= mergeBulkResponses(N + (M * R));

    // Now we remove useless trailing endOfMibView.
    //
    int m2 ; // respVarBindList[m2] item and next are going to be removed
    int t = respVarBindList.length ;
    while ((t > N) && (respVarBindList[t-1].
                       value.equals(SnmpVarBind.endOfMibView))) {
        t-- ;
    }
    if (t == N)
        m2 = N + R ;
    else
        m2 = N + ((t -1 -N) / R + 2) * R ; // Trivial, of course...
    if (m2 < respVarBindList.length) {
        SnmpVarBind[] truncatedList = new SnmpVarBind[m2] ;
        for (int i = 0 ; i < m2 ; i++) {
            truncatedList[i] = respVarBindList[i] ;
        }
        respVarBindList = truncatedList ;
    }

    // Good ! Let's make a full response pdu.
    //
    return newValidResponsePdu(req, respVarBindList) ;
}
 
Example #23
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: SnmpRequestHandler.java    License: MIT License 4 votes vote down vote up
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
 
Example #24
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: SnmpRequestHandler.java    License: MIT License 4 votes vote down vote up
/**
 * Here we make the response pdu for a bulk request.
 * At this level, the result is never null.
 */
private SnmpPduPacket makeGetBulkResponsePdu(SnmpPduBulk req,
                                             Object userData) {

    SnmpVarBind[] respVarBindList;

    // RFC 1905, Section 4.2.3, p14
    int L = req.varBindList.length ;
    int N = Math.max(Math.min(req.nonRepeaters, L), 0) ;
    int M = Math.max(req.maxRepetitions, 0) ;
    int R = L - N ;

    if (req.varBindList == null) {
        // Good ! Let's make a full response pdu.
        //
        return newValidResponsePdu(req, null) ;
    }

    // Split the request into subrequests.
    //
    splitBulkRequest(req, N, M, R);
    SnmpPduPacket result= executeSubRequest(req,userData);
    if (result != null)
        return result;

    respVarBindList= mergeBulkResponses(N + (M * R));

    // Now we remove useless trailing endOfMibView.
    //
    int m2 ; // respVarBindList[m2] item and next are going to be removed
    int t = respVarBindList.length ;
    while ((t > N) && (respVarBindList[t-1].
                       value.equals(SnmpVarBind.endOfMibView))) {
        t-- ;
    }
    if (t == N)
        m2 = N + R ;
    else
        m2 = N + ((t -1 -N) / R + 2) * R ; // Trivial, of course...
    if (m2 < respVarBindList.length) {
        SnmpVarBind[] truncatedList = new SnmpVarBind[m2] ;
        for (int i = 0 ; i < m2 ; i++) {
            truncatedList[i] = respVarBindList[i] ;
        }
        respVarBindList = truncatedList ;
    }

    // Good ! Let's make a full response pdu.
    //
    return newValidResponsePdu(req, respVarBindList) ;
}
 
Example #25
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
 
Example #26
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Here we make the response pdu for a bulk request.
 * At this level, the result is never null.
 */
private SnmpPduPacket makeGetBulkResponsePdu(SnmpPduBulk req,
                                             Object userData) {

    SnmpVarBind[] respVarBindList;

    // RFC 1905, Section 4.2.3, p14
    int L = req.varBindList.length ;
    int N = Math.max(Math.min(req.nonRepeaters, L), 0) ;
    int M = Math.max(req.maxRepetitions, 0) ;
    int R = L - N ;

    if (req.varBindList == null) {
        // Good ! Let's make a full response pdu.
        //
        return newValidResponsePdu(req, null) ;
    }

    // Split the request into subrequests.
    //
    splitBulkRequest(req, N, M, R);
    SnmpPduPacket result= executeSubRequest(req,userData);
    if (result != null)
        return result;

    respVarBindList= mergeBulkResponses(N + (M * R));

    // Now we remove useless trailing endOfMibView.
    //
    int m2 ; // respVarBindList[m2] item and next are going to be removed
    int t = respVarBindList.length ;
    while ((t > N) && (respVarBindList[t-1].
                       value.equals(SnmpVarBind.endOfMibView))) {
        t-- ;
    }
    if (t == N)
        m2 = N + R ;
    else
        m2 = N + ((t -1 -N) / R + 2) * R ; // Trivial, of course...
    if (m2 < respVarBindList.length) {
        SnmpVarBind[] truncatedList = new SnmpVarBind[m2] ;
        for (int i = 0 ; i < m2 ; i++) {
            truncatedList[i] = respVarBindList[i] ;
        }
        respVarBindList = truncatedList ;
    }

    // Good ! Let's make a full response pdu.
    //
    return newValidResponsePdu(req, respVarBindList) ;
}
 
Example #27
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
 
Example #28
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Here we make the response pdu for a bulk request.
 * At this level, the result is never null.
 */
private SnmpPduPacket makeGetBulkResponsePdu(SnmpPduBulk req,
                                             Object userData) {

    SnmpVarBind[] respVarBindList;

    // RFC 1905, Section 4.2.3, p14
    int L = req.varBindList.length ;
    int N = Math.max(Math.min(req.nonRepeaters, L), 0) ;
    int M = Math.max(req.maxRepetitions, 0) ;
    int R = L - N ;

    if (req.varBindList == null) {
        // Good ! Let's make a full response pdu.
        //
        return newValidResponsePdu(req, null) ;
    }

    // Split the request into subrequests.
    //
    splitBulkRequest(req, N, M, R);
    SnmpPduPacket result= executeSubRequest(req,userData);
    if (result != null)
        return result;

    respVarBindList= mergeBulkResponses(N + (M * R));

    // Now we remove useless trailing endOfMibView.
    //
    int m2 ; // respVarBindList[m2] item and next are going to be removed
    int t = respVarBindList.length ;
    while ((t > N) && (respVarBindList[t-1].
                       value.equals(SnmpVarBind.endOfMibView))) {
        t-- ;
    }
    if (t == N)
        m2 = N + R ;
    else
        m2 = N + ((t -1 -N) / R + 2) * R ; // Trivial, of course...
    if (m2 < respVarBindList.length) {
        SnmpVarBind[] truncatedList = new SnmpVarBind[m2] ;
        for (int i = 0 ; i < m2 ; i++) {
            truncatedList[i] = respVarBindList[i] ;
        }
        respVarBindList = truncatedList ;
    }

    // Good ! Let's make a full response pdu.
    //
    return newValidResponsePdu(req, respVarBindList) ;
}
 
Example #29
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Here we make a response pdu from a request pdu.
 * We return null if there is no pdu to reply.
 */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
                                      Object userData) {

    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
    SnmpPduPacket respPdu = null ;

    snmpServer.updateRequestCounters(reqPdu.type) ;
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type,
                                     reqPdu.varBindList.length) ;

    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu) ;
        if (respPdu == null) { // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
                       "makeResponsePdu", "Request " + reqPdu.requestId +
                       " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
            }
            switch(reqPdu.type) {
            case SnmpPduPacket.pduGetRequestPdu:
            case SnmpPduPacket.pduGetNextRequestPdu:
            case SnmpPduPacket.pduSetRequestPdu:
                respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
                                                userData) ;
                break ;

            case SnmpPduPacket.pduGetBulkRequestPdu:
                respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
                                                 userData) ;
                break ;
            }
        }
        else { // reqPdu is rejected by ACLs
            // respPdu contains the error response to be sent.
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
                respPdu = null ;
            }
            if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.
                                          trapAuthenticationFailure, 0,
                                          new SnmpVarBindList()) ;
                }
                catch(Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
                           "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu ;
}
 
Example #30
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: SnmpRequestHandler.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Here we make the response pdu for a bulk request.
 * At this level, the result is never null.
 */
private SnmpPduPacket makeGetBulkResponsePdu(SnmpPduBulk req,
                                             Object userData) {

    SnmpVarBind[] respVarBindList;

    // RFC 1905, Section 4.2.3, p14
    int L = req.varBindList.length ;
    int N = Math.max(Math.min(req.nonRepeaters, L), 0) ;
    int M = Math.max(req.maxRepetitions, 0) ;
    int R = L - N ;

    if (req.varBindList == null) {
        // Good ! Let's make a full response pdu.
        //
        return newValidResponsePdu(req, null) ;
    }

    // Split the request into subrequests.
    //
    splitBulkRequest(req, N, M, R);
    SnmpPduPacket result= executeSubRequest(req,userData);
    if (result != null)
        return result;

    respVarBindList= mergeBulkResponses(N + (M * R));

    // Now we remove useless trailing endOfMibView.
    //
    int m2 ; // respVarBindList[m2] item and next are going to be removed
    int t = respVarBindList.length ;
    while ((t > N) && (respVarBindList[t-1].
                       value.equals(SnmpVarBind.endOfMibView))) {
        t-- ;
    }
    if (t == N)
        m2 = N + R ;
    else
        m2 = N + ((t -1 -N) / R + 2) * R ; // Trivial, of course...
    if (m2 < respVarBindList.length) {
        SnmpVarBind[] truncatedList = new SnmpVarBind[m2] ;
        for (int i = 0 ; i < m2 ; i++) {
            truncatedList[i] = respVarBindList[i] ;
        }
        respVarBindList = truncatedList ;
    }

    // Good ! Let's make a full response pdu.
    //
    return newValidResponsePdu(req, respVarBindList) ;
}