jdk/src/share/classes/com/sun/jmx/snmp/daemon/SnmpRequestHandler.java
author sherman
Tue, 30 Aug 2011 11:53:11 -0700
changeset 10419 12c063b39232
parent 5506 202f599c92aa
child 14342 8435a30053c1
permissions -rw-r--r--
7084245: Update usages of InternalError to use exception chaining Summary: to use new InternalError constructor with cause chainning Reviewed-by: alanb, ksrini, xuelei, neugens Contributed-by: sebastian.sickelmann@gmx.de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package com.sun.jmx.snmp.daemon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
// java import
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.logging.Level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.InterruptedIOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.net.DatagramSocket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.net.DatagramPacket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.net.SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
// jmx imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import com.sun.jmx.snmp.SnmpMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import com.sun.jmx.snmp.SnmpPduFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import com.sun.jmx.snmp.SnmpPduBulk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import com.sun.jmx.snmp.SnmpPduPacket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import com.sun.jmx.snmp.SnmpPduRequest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import com.sun.jmx.snmp.SnmpPduTrap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import com.sun.jmx.snmp.SnmpValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import com.sun.jmx.snmp.SnmpVarBind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import com.sun.jmx.snmp.SnmpVarBindList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import com.sun.jmx.snmp.SnmpDefinitions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import com.sun.jmx.snmp.SnmpStatusException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import com.sun.jmx.snmp.SnmpTooBigException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import com.sun.jmx.snmp.SnmpDataTypeEnums;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
// RI imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import static com.sun.jmx.defaults.JmxProperties.SNMP_ADAPTOR_LOGGER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
// SNMP runtime import
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import com.sun.jmx.snmp.agent.SnmpMibAgent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import com.sun.jmx.snmp.agent.SnmpUserDataFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
//import com.sun.jmx.snmp.IPAcl.IPAcl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import com.sun.jmx.snmp.InetAddressAcl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private transient DatagramSocket      socket = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private transient DatagramPacket      packet = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private transient Vector              mibs = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Contains the list of sub-requests associated to the current request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private transient Hashtable<SnmpMibAgent, SnmpSubRequestHandler> subs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Reference on the MIBS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private transient SnmpMibTree root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private transient Object              ipacl = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private transient SnmpPduFactory      pduFactory = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private transient SnmpUserDataFactory userDataFactory = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private transient SnmpAdaptorServer adaptor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Full constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public SnmpRequestHandler(SnmpAdaptorServer server, int id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                              DatagramSocket s, DatagramPacket p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                              SnmpMibTree tree, Vector m, Object a,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                              SnmpPduFactory factory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                              SnmpUserDataFactory dataFactory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                              MBeanServer f, ObjectName n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        super(server, id, f, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        // Need a reference on SnmpAdaptorServer for getNext & getBulk,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // in case of oid equality (mib overlapping).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        adaptor = server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        socket = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        packet = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        root= tree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        mibs = (Vector) m.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        subs= new Hashtable<SnmpMibAgent, SnmpSubRequestHandler>(mibs.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        ipacl = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        pduFactory = factory ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        userDataFactory = dataFactory ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        //thread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Treat the request available in 'packet' and send the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * back to the client.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Note: we overwrite 'packet' with the response bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public void doRun() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        // Trace the input packet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    "doRun","Packet received:\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    SnmpMessage.dumpHexBuffer(packet.getData(), 0, packet.getLength()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // Let's build the response packet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        DatagramPacket respPacket = makeResponsePacket(packet) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // Trace the output packet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if ((SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) && (respPacket != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    "doRun","Packet to be sent:\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    SnmpMessage.dumpHexBuffer(respPacket.getData(), 0, respPacket.getLength()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        // Send the response packet if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if (respPacket != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                socket.send(respPacket) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            } catch (SocketException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    if (e.getMessage().equals(InterruptSysCallMsg)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                            "doRun", "interrupted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                      SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                            "doRun", "I/O exception", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            } catch(InterruptedIOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                        "doRun", "interrupted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            } catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                        "doRun", "failure when sending response", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Here we make a response packet from a request packet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * We return null if there no response packet to sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    private DatagramPacket makeResponsePacket(DatagramPacket reqPacket) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        DatagramPacket respPacket = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        // Transform the request packet into a request SnmpMessage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        SnmpMessage reqMsg = new SnmpMessage() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            reqMsg.decodeMessage(reqPacket.getData(), reqPacket.getLength()) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            reqMsg.address = reqPacket.getAddress() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            reqMsg.port = reqPacket.getPort() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        catch(SnmpStatusException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    "makeResponsePacket", "packet decoding failed", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            reqMsg = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            ((SnmpAdaptorServer)adaptorServer).incSnmpInASNParseErrs(1) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        // Make the response SnmpMessage if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        SnmpMessage respMsg = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (reqMsg != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            respMsg = makeResponseMessage(reqMsg) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        // Try to transform the response SnmpMessage into response packet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        // NOTE: we overwrite the request packet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (respMsg != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                reqPacket.setLength(respMsg.encodeMessage(reqPacket.getData())) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                respPacket = reqPacket ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            catch(SnmpTooBigException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        "makeResponsePacket", "response message is too big");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    respMsg = newTooBigMessage(reqMsg) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    reqPacket.setLength(respMsg.encodeMessage(reqPacket.getData())) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    respPacket = reqPacket ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                catch(SnmpTooBigException xx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                            "makeResponsePacket", "'too big' is 'too big' !!!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    adaptor.incSnmpSilentDrops(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return respPacket ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Here we make a response message from a request message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * We return null if there is no message to reply.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    private SnmpMessage makeResponseMessage(SnmpMessage reqMsg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        SnmpMessage respMsg = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        // Transform the request message into a request pdu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        SnmpPduPacket reqPdu = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        Object userData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            reqPdu = (SnmpPduPacket)pduFactory.decodeSnmpPdu(reqMsg) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            if (reqPdu != null && userDataFactory != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                userData = userDataFactory.allocateUserData(reqPdu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        catch(SnmpStatusException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            reqPdu = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            snmpServer.incSnmpInASNParseErrs(1) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            if (x.getStatus()== SnmpDefinitions.snmpWrongSnmpVersion)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                snmpServer.incSnmpInBadVersions(1) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    "makeResponseMessage", "message decoding failed", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        // Make the response pdu if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        SnmpPduPacket respPdu = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if (reqPdu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            respPdu = makeResponsePdu(reqPdu,userData) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                if (userDataFactory != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    userDataFactory.releaseUserData(userData,respPdu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            } catch (SnmpStatusException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                respPdu = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        // Try to transform the response pdu into a response message if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (respPdu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                respMsg = (SnmpMessage)pduFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    encodeSnmpPdu(respPdu, packet.getData().length) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            catch(SnmpStatusException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                respMsg = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                        "makeResponseMessage", "failure when encoding the response message", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            catch(SnmpTooBigException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                        "makeResponseMessage", "response message is too big");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                    // if the PDU is too small, why should we try to do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    // recovery ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                    if (packet.getData().length <=32)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                        throw x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    int pos= x.getVarBindCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                            "makeResponseMessage", "fail on element" + pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    int old= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                            respPdu = reduceResponsePdu(reqPdu, respPdu, pos) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                            respMsg = (SnmpMessage)pduFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                                encodeSnmpPdu(respPdu,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                                              packet.getData().length -32) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                        } catch (SnmpTooBigException xx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                                    "makeResponseMessage", "response message is still too big");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                            old= pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                            pos= xx.getVarBindCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                                    "makeResponseMessage","fail on element" + pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                            if (pos == old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                                // we can not go any further in trying to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                                // reduce the message !
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                                throw xx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    }// end of loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                } catch(SnmpStatusException xx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    respMsg = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                           "makeResponseMessage", "failure when encoding the response message", xx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                catch(SnmpTooBigException xx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                        respPdu = newTooBigPdu(reqPdu) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                        respMsg = (SnmpMessage)pduFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                            encodeSnmpPdu(respPdu, packet.getData().length) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    catch(SnmpTooBigException xxx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                        respMsg = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                            SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                               "makeResponseMessage", "'too big' is 'too big' !!!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                        adaptor.incSnmpSilentDrops(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    catch(Exception xxx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                            SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                               "makeResponseMessage", "Got unexpected exception", xxx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                        respMsg = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                catch(Exception xx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                           "makeResponseMessage", "Got unexpected exception", xx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    respMsg = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return respMsg ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Here we make a response pdu from a request pdu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * We return null if there is no pdu to reply.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                                          Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        SnmpPduPacket respPdu = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        snmpServer.updateRequestCounters(reqPdu.type) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        if (reqPdu.varBindList != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            snmpServer.updateVarCounters(reqPdu.type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                                         reqPdu.varBindList.length) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (checkPduType(reqPdu)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            respPdu = checkAcl(reqPdu) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            if (respPdu == null) { // reqPdu is accepted by ACLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                if (mibs.size() < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                           "makeResponsePdu", "Request " + reqPdu.requestId +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                           " received but no MIB registered.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    return makeNoMibErrorPdu((SnmpPduRequest)reqPdu, userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                switch(reqPdu.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                case SnmpPduPacket.pduGetRequestPdu:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                case SnmpPduPacket.pduGetNextRequestPdu:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                case SnmpPduPacket.pduSetRequestPdu:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                    respPdu = makeGetSetResponsePdu((SnmpPduRequest)reqPdu,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                                                    userData) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    break ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                case SnmpPduPacket.pduGetBulkRequestPdu:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    respPdu = makeGetBulkResponsePdu((SnmpPduBulk)reqPdu,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                                                     userData) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    break ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            else { // reqPdu is rejected by ACLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                // respPdu contains the error response to be sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                // We send this response only if authResEnabled is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                if (!snmpServer.getAuthRespEnabled()) { // No response should be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    respPdu = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                if (snmpServer.getAuthTrapEnabled()) { // A trap must be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                        snmpServer.snmpV1Trap(SnmpPduTrap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                              trapAuthenticationFailure, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                              new SnmpVarBindList()) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                    catch(Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                            SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                               "makeResponsePdu", "Failure when sending authentication trap", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        return respPdu ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    // Generates a response packet, filling the values in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    // varbindlist with one of endOfMibView, noSuchObject, noSuchInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    // according to the value of <code>status</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    // @param statusTag should be one of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    //        <li>SnmpDataTypeEnums.errEndOfMibViewTag</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    //        <li>SnmpDataTypeEnums.errNoSuchObjectTag</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    //        <li>SnmpDataTypeEnums.errNoSuchInstanceTag</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    SnmpPduPacket makeErrorVarbindPdu(SnmpPduPacket req, int statusTag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        final SnmpVarBind[] vblist = req.varBindList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        final int length = vblist.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        switch (statusTag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        case SnmpDataTypeEnums.errEndOfMibViewTag:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            for (int i=0 ; i<length ; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                vblist[i].value = SnmpVarBind.endOfMibView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        case SnmpDataTypeEnums.errNoSuchObjectTag:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            for (int i=0 ; i<length ; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                vblist[i].value = SnmpVarBind.noSuchObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        case SnmpDataTypeEnums.errNoSuchInstanceTag:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            for (int i=0 ; i<length ; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                vblist[i].value = SnmpVarBind.noSuchInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            return newErrorResponsePdu(req,snmpRspGenErr,1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        return newValidResponsePdu(req,vblist);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    // Generates an appropriate response when no mib is registered in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    // the adaptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    // <li>If the version is V1:</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    // <ul><li>Generates a NoSuchName error V1 response PDU</li></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    // <li>If the version is V2:</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    // <ul><li>If the request is a GET, fills the varbind list with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    //         NoSuchObject's</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    //     <li>If the request is a GET-NEXT/GET-BULK, fills the varbind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    //         list with EndOfMibView's</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    //     <li>If the request is a SET, generates a NoAccess error V2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    //          response PDU</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    // </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    SnmpPduPacket makeNoMibErrorPdu(SnmpPduRequest req, Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        // There is no agent registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        if (req.version == SnmpDefinitions.snmpVersionOne) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            // Version 1: => NoSuchName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                newErrorResponsePdu(req,snmpRspNoSuchName,1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        } else if (req.version == SnmpDefinitions.snmpVersionTwo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            // Version 2: => depends on PDU type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            switch (req.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            case pduSetRequestPdu :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            case pduWalkRequest :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                // SET request => NoAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                    newErrorResponsePdu(req,snmpRspNoAccess,1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            case pduGetRequestPdu :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                // GET request => NoSuchObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    makeErrorVarbindPdu(req,SnmpDataTypeEnums.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                                        errNoSuchObjectTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            case pduGetNextRequestPdu :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            case pduGetBulkRequestPdu :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                // GET-NEXT or GET-BULK => EndOfMibView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    makeErrorVarbindPdu(req,SnmpDataTypeEnums.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                                        errEndOfMibViewTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        // Something wrong here: => snmpRspGenErr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        return newErrorResponsePdu(req,snmpRspGenErr,1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * Here we make the response pdu from a get/set request pdu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * At this level, the result is never null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    private SnmpPduPacket makeGetSetResponsePdu(SnmpPduRequest req,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                                                Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        // Create the trhead group specific for handling sub-requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        // associated to the current request. Use the invoke id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        // Nice idea to use a thread group on a request basis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        // However the impact on performance is terrible !
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        // theGroup= new ThreadGroup(thread.getThreadGroup(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        //                "request " + String.valueOf(req.requestId));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        // Let's build the varBindList for the response pdu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        if (req.varBindList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            // Good ! Let's make a full response pdu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            return newValidResponsePdu(req, null) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        // First we need to split the request into subrequests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        splitRequest(req);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        int nbSubRequest= subs.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        if (nbSubRequest == 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            return turboProcessingGetSet(req,userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        // Execute all the subrequests resulting from the split of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        // varbind list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        SnmpPduPacket result= executeSubRequest(req,userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        if (result != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            // It means that an error occured. The error is already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            // formatted by the executeSubRequest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            // method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        // So far so good. So we need to concatenate all the answers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
               "makeGetSetResponsePdu",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
               "Build the unified response for request " + req.requestId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        return mergeResponses(req);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * The method runs all the sub-requests associated to the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * instance of SnmpRequestHandler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    private SnmpPduPacket executeSubRequest(SnmpPduPacket req,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                                            Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        int errorStatus = SnmpDefinitions.snmpRspNoError ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        int nbSubRequest= subs.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        int i=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        // If it's a set request, we must first check any varBind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        if (req.type == pduSetRequestPdu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            i=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            for(Enumeration e= subs.elements(); e.hasMoreElements() ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                // Indicate to the sub request that a check must be invoked ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                // OK we should have defined out own tag for that !
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                SnmpSubRequestHandler sub= (SnmpSubRequestHandler)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                    e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                sub.setUserData(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                sub.type= pduWalkRequest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                sub.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                sub.type= pduSetRequestPdu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                if (sub.getErrorStatus() != SnmpDefinitions.snmpRspNoError) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                    // No point to go any further.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                           "executeSubRequest", "an error occurs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                    return newErrorResponsePdu(req, errorStatus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                                               sub.getErrorIndex() + 1) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        }// end processing check operation for a set PDU.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        // Let's start the sub-requests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        i=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        for(Enumeration e= subs.elements(); e.hasMoreElements() ;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            SnmpSubRequestHandler sub= (SnmpSubRequestHandler) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        /* NPCTE fix for bugId 4492741, esc 0, 16-August 2001 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            sub.setUserData(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        /* end of NPCTE fix for bugId 4492741 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            sub.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            if (sub.getErrorStatus() != SnmpDefinitions.snmpRspNoError) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                // No point to go any further.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                       "executeSubRequest", "an error occurs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                return newErrorResponsePdu(req, errorStatus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                                           sub.getErrorIndex() + 1) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        // everything is ok
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * Optimize when there is only one sub request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    private SnmpPduPacket turboProcessingGetSet(SnmpPduRequest req,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                                                Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        int errorStatus = SnmpDefinitions.snmpRspNoError ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        SnmpSubRequestHandler sub = subs.elements().nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        sub.setUserData(userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        // Indicate to the sub request that a check must be invoked ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        // OK we should have defined out own tag for that !
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        if (req.type == SnmpDefinitions.pduSetRequestPdu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            sub.type= pduWalkRequest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            sub.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            sub.type= pduSetRequestPdu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            // Check the error status.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            errorStatus= sub.getErrorStatus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            if (errorStatus != SnmpDefinitions.snmpRspNoError) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                // No point to go any further.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                return newErrorResponsePdu(req, errorStatus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                                           sub.getErrorIndex() + 1) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        // process the operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        sub.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        errorStatus= sub.getErrorStatus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        if (errorStatus != SnmpDefinitions.snmpRspNoError) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            // No point to go any further.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                   "turboProcessingGetSet", "an error occurs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            int realIndex= sub.getErrorIndex() + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            return newErrorResponsePdu(req, errorStatus, realIndex) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        // So far so good. So we need to concatenate all the answers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
               "turboProcessingGetSet",  "build the unified response for request "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                + req.requestId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        return mergeResponses(req);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * Here we make the response pdu for a bulk request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * At this level, the result is never null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    private SnmpPduPacket makeGetBulkResponsePdu(SnmpPduBulk req,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                                                 Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        SnmpVarBind[] respVarBindList = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        // RFC 1905, Section 4.2.3, p14
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        int L = req.varBindList.length ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        int N = Math.max(Math.min(req.nonRepeaters, L), 0) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        int M = Math.max(req.maxRepetitions, 0) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        int R = L - N ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        if (req.varBindList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            // Good ! Let's make a full response pdu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            return newValidResponsePdu(req, null) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        // Split the request into subrequests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        splitBulkRequest(req, N, M, R);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        SnmpPduPacket result= executeSubRequest(req,userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        if (result != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        respVarBindList= mergeBulkResponses(N + (M * R));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        // Now we remove useless trailing endOfMibView.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        int m2 ; // respVarBindList[m2] item and next are going to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        int t = respVarBindList.length ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        while ((t > N) && (respVarBindList[t-1].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                           value.equals(SnmpVarBind.endOfMibView))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            t-- ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        if (t == N)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            m2 = N + R ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            m2 = N + ((t -1 -N) / R + 2) * R ; // Trivial, of course...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        if (m2 < respVarBindList.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            SnmpVarBind[] truncatedList = new SnmpVarBind[m2] ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            for (int i = 0 ; i < m2 ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                truncatedList[i] = respVarBindList[i] ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            respVarBindList = truncatedList ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        // Good ! Let's make a full response pdu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        return newValidResponsePdu(req, respVarBindList) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * Check the type of the pdu: only the get/set/bulk request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * are accepted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    private boolean checkPduType(SnmpPduPacket pdu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        boolean result = true ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        switch(pdu.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        case SnmpDefinitions.pduGetRequestPdu:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        case SnmpDefinitions.pduGetNextRequestPdu:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        case SnmpDefinitions.pduSetRequestPdu:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        case SnmpDefinitions.pduGetBulkRequestPdu:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            result = true ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                   "checkPduType", "cannot respond to this kind of PDU");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            result = false ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        return result ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * Check if the specified pdu is conform to the ACL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * This method returns null if the pdu is ok. If not, it returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * the response pdu to be replied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    private SnmpPduPacket checkAcl(SnmpPduPacket pdu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        SnmpPduPacket response = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        String community = new String(pdu.community) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        // We check the pdu type and create an error response if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        // the check failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        if (ipacl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            if (pdu.type == SnmpDefinitions.pduSetRequestPdu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                if (!((InetAddressAcl)ipacl).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                    checkWritePermission(pdu.address, community)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                           "checkAcl", "sender is " + pdu.address +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                              " with " + community +". Sender has no write permission");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                    int err = SnmpSubRequestHandler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                        mapErrorStatus(SnmpDefinitions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                                       snmpRspAuthorizationError,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                                       pdu.version, pdu.type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                    response = newErrorResponsePdu(pdu, err, 0) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                           "checkAcl", "sender is " + pdu.address +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                              " with " + community +". Sender has write permission");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                if (!((InetAddressAcl)ipacl).checkReadPermission(pdu.address, community)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                           "checkAcl", "sender is " + pdu.address +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                              " with " + community +". Sender has no read permission");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                    int err = SnmpSubRequestHandler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                        mapErrorStatus(SnmpDefinitions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                                       snmpRspAuthorizationError,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                                       pdu.version, pdu.type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                    response = newErrorResponsePdu(pdu,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                                                   err,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                                                   0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                    SnmpAdaptorServer snmpServer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                        (SnmpAdaptorServer)adaptorServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                    snmpServer.updateErrorCounters(SnmpDefinitions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                                                   snmpRspNoSuchName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                           "checkAcl", "sender is " + pdu.address +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                              " with " + community +". Sender has read permission");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        // If the response is not null, this means the pdu is rejected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        // So let's update the statistics.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        if (response != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            snmpServer.incSnmpInBadCommunityUses(1) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            if (((InetAddressAcl)ipacl).checkCommunity(community) == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                snmpServer.incSnmpInBadCommunityNames(1) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        return response ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * Make a response pdu with the specified error status and index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * NOTE: the response pdu share its varBindList with the request pdu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    private SnmpPduRequest newValidResponsePdu(SnmpPduPacket reqPdu,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                                               SnmpVarBind[] varBindList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        SnmpPduRequest result = new SnmpPduRequest() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        result.address = reqPdu.address ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        result.port = reqPdu.port ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        result.version = reqPdu.version ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        result.community = reqPdu.community ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        result.type = result.pduGetResponsePdu ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        result.requestId = reqPdu.requestId ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        result.errorStatus = SnmpDefinitions.snmpRspNoError ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        result.errorIndex = 0 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        result.varBindList = varBindList ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        ((SnmpAdaptorServer)adaptorServer).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            updateErrorCounters(result.errorStatus) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        return result ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * Make a response pdu with the specified error status and index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * NOTE: the response pdu share its varBindList with the request pdu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    private SnmpPduRequest newErrorResponsePdu(SnmpPduPacket req,int s,int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        SnmpPduRequest result = newValidResponsePdu(req, null) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        result.errorStatus = s ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        result.errorIndex = i ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        result.varBindList = req.varBindList ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        ((SnmpAdaptorServer)adaptorServer).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            updateErrorCounters(result.errorStatus) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        return result ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    private SnmpMessage newTooBigMessage(SnmpMessage reqMsg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        throws SnmpTooBigException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        SnmpMessage result = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        SnmpPduPacket reqPdu = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            reqPdu = (SnmpPduPacket)pduFactory.decodeSnmpPdu(reqMsg) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            if (reqPdu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                SnmpPduPacket respPdu = newTooBigPdu(reqPdu) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                result = (SnmpMessage)pduFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                    encodeSnmpPdu(respPdu, packet.getData().length) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        catch(SnmpStatusException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            // This should not occur because decodeIncomingRequest has normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            // been successfully called before.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                   "newTooBigMessage", "Internal error", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            }
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   924
            throw new InternalError(x) ;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        return result ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    private SnmpPduPacket newTooBigPdu(SnmpPduPacket req) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        SnmpPduRequest result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            newErrorResponsePdu(req, SnmpDefinitions.snmpRspTooBig, 0) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        result.varBindList = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        return result ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    private SnmpPduPacket reduceResponsePdu(SnmpPduPacket req,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                                            SnmpPduPacket resp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                                            int acceptedVbCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        throws SnmpTooBigException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        // Reduction can be attempted only on bulk response
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        if (req.type != req.pduGetBulkRequestPdu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                   "reduceResponsePdu", "cannot remove anything");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            throw new SnmpTooBigException(acceptedVbCount) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        // We're going to reduce the varbind list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        // First determine which items should be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        // Next duplicate and replace the existing list by the reduced one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        // acceptedVbCount is the number of varbind which have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        // successfully encoded before reaching bufferSize:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        //   * when it is >= 2, we split the varbindlist at this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        //     position (-1 to be safe),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        //   * when it is 1, we only put one (big?) item in the varbindlist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        //   * when it is 0 (in fact, acceptedVbCount is not available),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        //     we split the varbindlist by 2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        int vbCount = resp.varBindList.length ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        if (acceptedVbCount >= 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            vbCount = Math.min(acceptedVbCount - 1, resp.varBindList.length) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        else if (acceptedVbCount == 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            vbCount = 1 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        else // acceptedCount == 0 ie it is unknown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            vbCount = resp.varBindList.length / 2 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        if (vbCount < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                   "reduceResponsePdu", "cannot remove anything");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            throw new SnmpTooBigException(acceptedVbCount) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            SnmpVarBind[] newVbList = new SnmpVarBind[vbCount] ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            for (int i = 0 ; i < vbCount ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                newVbList[i] = resp.varBindList[i] ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                   "reduceResponsePdu", (resp.varBindList.length - newVbList.length) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                    " items have been removed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            resp.varBindList = newVbList ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        return resp ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * The method takes the incoming requests and split it into subrequests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    private void splitRequest(SnmpPduRequest req) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        int nbAgents= mibs.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        SnmpMibAgent agent= (SnmpMibAgent) mibs.firstElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        if (nbAgents == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            // Take all the oids contained in the request and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            subs.put(agent, new SnmpSubRequestHandler(agent, req, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        // For the get next operation we are going to send the varbind list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        // to all agents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        if (req.type == pduGetNextRequestPdu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            for(Enumeration e= mibs.elements(); e.hasMoreElements(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                SnmpMibAgent ag= (SnmpMibAgent) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                subs.put(ag, new SnmpSubNextRequestHandler(adaptor, ag, req));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        int nbReqs= req.varBindList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        SnmpVarBind[] vars= req.varBindList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        SnmpSubRequestHandler sub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        for(int i=0; i < nbReqs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            agent= root.getAgentMib(vars[i].oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            sub= subs.get(agent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            if (sub == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                // We need to create the sub request handler and update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                // the hashtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                sub= new SnmpSubRequestHandler(agent, req);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                subs.put(agent, sub);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            // Update the translation table within the subrequest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            sub.updateRequest(vars[i], i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * The method takes the incoming get bulk requests and split it into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * subrequests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    private void splitBulkRequest(SnmpPduBulk req,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                                  int nonRepeaters,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                                  int maxRepetitions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                                  int R) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        // Send the getBulk to all agents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        for(Enumeration e= mibs.elements(); e.hasMoreElements(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            SnmpMibAgent agent = (SnmpMibAgent) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                   "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                   + " " + maxRepetitions + " " + R);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            subs.put(agent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                     new SnmpSubBulkRequestHandler(adaptor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                                                   agent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                                                   req,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                                                   nonRepeaters,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                                                   maxRepetitions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                                                   R));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    private SnmpPduPacket mergeResponses(SnmpPduRequest req) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        if (req.type == pduGetNextRequestPdu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            return mergeNextResponses(req);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        SnmpVarBind[] result= req.varBindList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        // Go through the list of subrequests and concatenate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        // Hopefully, by now all the sub-requests should be finished
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        for(Enumeration e= subs.elements(); e.hasMoreElements();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            SnmpSubRequestHandler sub= (SnmpSubRequestHandler) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            sub.updateResult(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        return newValidResponsePdu(req,result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    private SnmpPduPacket mergeNextResponses(SnmpPduRequest req) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        int max= req.varBindList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        SnmpVarBind[] result= new SnmpVarBind[max];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        // Go through the list of subrequests and concatenate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        // Hopefully, by now all the sub-requests should be finished
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        for(Enumeration e= subs.elements(); e.hasMoreElements();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            SnmpSubRequestHandler sub= (SnmpSubRequestHandler) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            sub.updateResult(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        if (req.version == snmpVersionTwo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            return newValidResponsePdu(req,result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        // In v1 make sure there is no endOfMibView ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        for(int i=0; i < max; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            SnmpValue val= result[i].value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            if (val == SnmpVarBind.endOfMibView)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                return newErrorResponsePdu(req,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                                   SnmpDefinitions.snmpRspNoSuchName, i+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        // So far so good ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        return newValidResponsePdu(req,result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    private SnmpVarBind[] mergeBulkResponses(int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        // Let's allocate the array for storing the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        SnmpVarBind[] result= new SnmpVarBind[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        for(int i= size-1; i >=0; --i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            result[i]= new SnmpVarBind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            result[i].value= SnmpVarBind.endOfMibView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        // Go through the list of subrequests and concatenate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        // Hopefully, by now all the sub-requests should be finished
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        for(Enumeration e= subs.elements(); e.hasMoreElements();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            SnmpSubRequestHandler sub= (SnmpSubRequestHandler) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            sub.updateResult(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
    protected String makeDebugTag() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        return "SnmpRequestHandler[" + adaptorServer.getProtocol() + ":" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            adaptorServer.getPort() + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
    Thread createThread(Runnable r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    static final private String InterruptSysCallMsg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        "Interrupted system call";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    static final private SnmpStatusException noSuchNameException =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        new SnmpStatusException(SnmpDefinitions.snmpRspNoSuchName) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
}