feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,133 @@
/*
* Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jmx.snmp.daemon;
// java import
//
import java.io.*;
import java.util.logging.Level;
// jmx import
//
import javax.management.MBeanServer;
import javax.management.ObjectName;
// jmx RI import
//
import static com.sun.jmx.defaults.JmxProperties.SNMP_ADAPTOR_LOGGER;
/**
* The <CODE>ClientHandler</CODE> class is the base class of each
* adaptor.<p>
*/
abstract class ClientHandler implements Runnable {
public ClientHandler(CommunicatorServer server, int id, MBeanServer f, ObjectName n) {
adaptorServer = server ;
requestId = id ;
mbs = f ;
objectName = n ;
interruptCalled = false ;
dbgTag = makeDebugTag() ;
//if (mbs == null ){
//thread = new Thread (this) ;
thread = createThread(this);
//} else {
//thread = mbs.getThreadAllocatorSrvIf().obtainThread(objectName,this) ;
//}
// Note: the thread will be started by the subclass.
}
// thread service
Thread createThread(Runnable r) {
return new Thread(this);
}
public void interrupt() {
SNMP_ADAPTOR_LOGGER.entering(dbgTag, "interrupt");
interruptCalled = true ;
if (thread != null) {
thread.interrupt() ;
}
SNMP_ADAPTOR_LOGGER.exiting(dbgTag, "interrupt");
}
public void join() {
if (thread != null) {
try {
thread.join() ;
}
catch(InterruptedException x) {
}
}
}
public void run() {
try {
//
// Notify the server we are now active
//
adaptorServer.notifyClientHandlerCreated(this) ;
//
// Call protocol specific sequence
//
doRun() ;
}
finally {
//
// Now notify the adaptor server that the handler is terminating.
// This is important because the server may be blocked waiting for
// a handler to terminate.
//
adaptorServer.notifyClientHandlerDeleted(this) ;
}
}
//
// The protocol-dependent part of the request
//
public abstract void doRun() ;
protected CommunicatorServer adaptorServer = null ;
protected int requestId = -1 ;
protected MBeanServer mbs = null ;
protected ObjectName objectName = null ;
protected Thread thread = null ;
protected boolean interruptCalled = false ;
protected String dbgTag = null ;
protected String makeDebugTag() {
return "ClientHandler[" + adaptorServer.getProtocol() + ":" + adaptorServer.getPort() + "][" + requestId + "]";
}
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jmx.snmp.daemon;
// java import
//
import java.io.PrintStream;
import java.io.PrintWriter;
/**
* Represents exceptions raised due to communications problems,
* for example when a managed object server is out of reach.<p>
*
* <p><b>This API is a Sun Microsystems internal API and is subject
* to change without notice.</b></p>
*/
public class CommunicationException extends javax.management.JMRuntimeException {
/* Serial version */
private static final long serialVersionUID = -2499186113233316177L;
/**
* Constructs a CommunicationException with a target exception.
*/
public CommunicationException(Throwable target) {
super(target.getMessage());
initCause(target);
}
/**
* Constructs a CommunicationException with a target exception
* and a detail message.
*/
public CommunicationException(Throwable target, String msg) {
super(msg);
initCause(target);
}
/**
* Constructs a CommunicationException with a detail message.
*/
public CommunicationException(String msg) {
super(msg);
}
/**
* Get the thrown target exception.
*/
public Throwable getTargetException() {
return getCause();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,171 @@
/*
* Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jmx.snmp.daemon;
/**
* Defines generic behaviour for the server
* part of a connector or an adaptor. Most connectors or adaptors extend <CODE>CommunicatorServer</CODE>
* and inherit this behaviour. Connectors or adaptors that do not fit into this model do not extend
* <CODE>CommunicatorServer</CODE>.
* <p>
* An <CODE>CommunicatorServer</CODE> is an active object, it listens for client requests
* and processes them in its own thread. When necessary, a <CODE>CommunicatorServer</CODE>
* creates other threads to process multiple requests concurrently.
* <p>
* A <CODE>CommunicatorServer</CODE> object can be stopped by calling the <CODE>stop</CODE>
* method. When it is stopped, the <CODE>CommunicatorServer</CODE> no longer listens to client
* requests and no longer holds any thread or communication resources.
* It can be started again by calling the <CODE>start</CODE> method.
* <p>
* A <CODE>CommunicatorServer</CODE> has a <CODE>state</CODE> property which reflects its
* activity.
* <p>
* <TABLE>
* <TR><TH>CommunicatorServer</TH> <TH>State</TH></TR>
* <TR><TD><CODE>stopped</CODE></TD> <TD><CODE>OFFLINE</CODE></TD></TR>
* <TR><TD><CODE>starting</CODE></TD> <TD><CODE>STARTING</CODE></TD></TR>
* <TR><TD><CODE>running</CODE></TD> <TD><CODE>ONLINE</CODE></TD></TR>
* <TR><TD><CODE>stopping</CODE></TD> <TD><CODE>STOPPING</CODE></TD></TR>
* </TABLE>
* <p>
* The <CODE>STARTING</CODE> state marks the transition from <CODE>OFFLINE</CODE> to
* <CODE>ONLINE</CODE>.
* <p>
* The <CODE>STOPPING</CODE> state marks the transition from <CODE>ONLINE</CODE> to
* <CODE>OFFLINE</CODE>. This occurs when the <CODE>CommunicatorServer</CODE> is
* finishing or interrupting active requests.
* <p>
* A <CODE>CommunicatorServer</CODE> may serve several clients concurrently. The
* number of concurrent clients can be limited using the property
* <CODE>maxActiveClientCount</CODE>. The default value of this property is
* defined by the subclasses.
* <p>
* When a <CODE>CommunicatorServer</CODE> is unregistered from the MBeanServer,
* it is stopped automatically.
*
* <p><b>This API is a Sun Microsystems internal API and is subject
* to change without notice.</b></p>
*/
public interface CommunicatorServerMBean {
/**
* Starts this <CODE>CommunicatorServer</CODE>.
* <p>
* Has no effect if this <CODE>CommunicatorServer</CODE> is <CODE>ONLINE</CODE> or
* <CODE>STOPPING</CODE>.
*/
public void start() ;
/**
* Stops this <CODE>CommunicatorServer</CODE>.
* <p>
* Has no effect if this <CODE>CommunicatorServer</CODE> is <CODE>OFFLINE</CODE> or
* <CODE>STOPPING</CODE>.
*/
public void stop() ;
/**
* Tests if the <CODE>CommunicatorServer</CODE> is active.
*
* @return True if connector is <CODE>ONLINE</CODE>; false otherwise.
*/
public boolean isActive() ;
/**
* Waits untill either the State attribute of this MBean equals the specified <VAR>state</VAR> parameter,
* or the specified <VAR>timeOut</VAR> has elapsed. The method <CODE>waitState</CODE> returns with a boolean value indicating whether
* the specified <VAR>state</VAR> parameter equals the value of this MBean's State attribute at the time the method terminates.
*
* Two special cases for the <VAR>timeOut</VAR> parameter value are:
* <UL><LI> if <VAR>timeOut</VAR> is negative then <CODE>waitState</CODE> returns immediately (i.e. does not wait at all),</LI>
* <LI> if <VAR>timeOut</VAR> equals zero then <CODE>waitState</CODE> waits untill the value of this MBean's State attribute
* is the same as the <VAR>state</VAR> parameter (i.e. will wait indefinitely if this condition is never met).</LI></UL>
*
* @param state The value of this MBean's State attribute
* to wait for. <VAR>state</VAR> can be one of:
* <ul>
* <li><CODE>CommunicatorServer.OFFLINE</CODE>,</li>
* <li><CODE>CommunicatorServer.ONLINE</CODE>,</li>
* <li><CODE>CommunicatorServer.STARTING</CODE>,</li>
* <li><CODE>CommunicatorServer.STOPPING</CODE>.</li>
* </ul>
* @param timeOut The maximum time to wait for, in
* milliseconds, if positive.
* Infinite time out if 0, or no waiting at all if negative.
*
* @return true if the value of this MBean's State attribute is the
* same as the <VAR>state</VAR> parameter; false otherwise.
*/
public boolean waitState(int state , long timeOut) ;
/**
* Gets the state of this <CODE>CommunicatorServer</CODE> as an integer.
*
* @return <CODE>ONLINE</CODE>, <CODE>OFFLINE</CODE>, <CODE>STARTING</CODE> or <CODE>STOPPING</CODE>.
*/
public int getState() ;
/**
* Gets the state of this <CODE>CommunicatorServer</CODE> as a string.
*
* @return One of the strings "ONLINE", "OFFLINE", "STARTING" or "STOPPING".
*/
public String getStateString() ;
/**
* Gets the host name used by this <CODE>CommunicatorServer</CODE>.
*
* @return The host name used by this <CODE>CommunicatorServer</CODE>.
*/
public String getHost() ;
/**
* Gets the port number used by this <CODE>CommunicatorServer</CODE>.
*
* @return The port number used by this <CODE>CommunicatorServer</CODE>.
*/
public int getPort() ;
/**
* Sets the port number used by this <CODE>CommunicatorServer</CODE>.
*
* @param port The port number used by this <CODE>CommunicatorServer</CODE>.
*
* @exception java.lang.IllegalStateException This method has been invoked
* while the communicator was ONLINE or STARTING.
*/
public void setPort(int port) throws java.lang.IllegalStateException ;
/**
* Gets the protocol being used by this <CODE>CommunicatorServer</CODE>.
* @return The protocol as a string.
*/
public abstract String getProtocol() ;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,702 @@
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jmx.snmp.daemon;
// java import
import java.util.Vector;
import java.io.IOException;
import java.net.InetAddress;
// jmx imports
//
import com.sun.jmx.snmp.SnmpPduFactory;
import com.sun.jmx.snmp.SnmpStatusException;
import com.sun.jmx.snmp.SnmpVarBindList;
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpTimeticks;
import com.sun.jmx.snmp.SnmpIpAddress;
import com.sun.jmx.snmp.SnmpPduPacket;
import com.sun.jmx.snmp.InetAddressAcl;
import com.sun.jmx.snmp.SnmpPeer;
// SNMP Runtime imports
//
import com.sun.jmx.snmp.agent.SnmpMibAgent;
import com.sun.jmx.snmp.agent.SnmpMibHandler;
import com.sun.jmx.snmp.agent.SnmpUserDataFactory;
/**
* Exposes the remote management interface of the {@link SnmpAdaptorServer} MBean.
* <p><b>This API is a Sun Microsystems internal API and is subject
* to change without notice.</b></p>
*/
public interface SnmpAdaptorServerMBean extends CommunicatorServerMBean {
// GETTERS AND SETTERS
//--------------------
/**
* Returns the Ip address based ACL used by this SNMP protocol adaptor.
* @return The <CODE>InetAddressAcl</CODE> implementation.
*
* @since 1.5
*/
public InetAddressAcl getInetAddressAcl();
/**
* Returns the port used by this SNMP protocol adaptor for sending traps.
* By default, port 162 is used.
*
* @return The port number for sending SNMP traps.
*/
public Integer getTrapPort();
/**
* Sets the port used by this SNMP protocol adaptor for sending traps.
*
* @param port The port number for sending SNMP traps.
*/
public void setTrapPort(Integer port);
/**
* Returns the port used by this SNMP protocol adaptor for sending inform requests.
* By default, port 162 is used.
*
* @return The port number for sending SNMP inform requests.
*/
public int getInformPort();
/**
* Sets the port used by this SNMP protocol adaptor for sending inform requests.
*
* @param port The port number for sending SNMP inform requests.
*/
public void setInformPort(int port);
/**
* Gets the number of managers that have been processed by this SNMP protocol adaptor
* since its creation.
*
* @return The number of managers handled by this SNMP protocol adaptor
* since its creation. This counter is not reset by the <CODE>stop</CODE> method.
*/
public int getServedClientCount();
/**
* Gets the number of managers currently being processed by this
* SNMP protocol adaptor.
*
* @return The number of managers currently being processed by this
* SNMP protocol adaptor.
*/
public int getActiveClientCount();
/**
* Gets the maximum number of managers that this SNMP protocol adaptor can
* process concurrently.
*
* @return The maximum number of managers that this SNMP protocol adaptor can
* process concurrently.
*/
public int getMaxActiveClientCount();
/**
* Sets the maximum number of managers this SNMP protocol adaptor can
* process concurrently.
*
* @param c The number of managers.
*
* @exception java.lang.IllegalStateException This method has been invoked
* while the communicator was <CODE>ONLINE</CODE> or <CODE>STARTING</CODE>.
*/
public void setMaxActiveClientCount(int c) throws java.lang.IllegalStateException;
/**
* Returns the protocol of this SNMP protocol adaptor.
*
* @return The string "snmp".
*/
@Override
public String getProtocol();
/**
* Returns the buffer size of this SNMP protocol adaptor.
* By default, buffer size 1024 is used.
*
* @return The buffer size.
*/
public Integer getBufferSize();
/**
* Sets the buffer size of this SNMP protocol adaptor.
*
* @param s The buffer size.
*
* @exception java.lang.IllegalStateException This method has been invoked
* while the communicator was <CODE>ONLINE</CODE> or <CODE>STARTING</CODE>.
*/
public void setBufferSize(Integer s) throws java.lang.IllegalStateException;
/**
* Gets the number of times to try sending an inform request before giving up.
* @return The maximun number of tries.
*/
public int getMaxTries();
/**
* Changes the maximun number of times to try sending an inform request before giving up.
* @param newMaxTries The maximun number of tries.
*/
public void setMaxTries(int newMaxTries);
/**
* Gets the timeout to wait for an inform response from the manager.
* @return The value of the timeout property.
*/
public int getTimeout();
/**
* Changes the timeout to wait for an inform response from the manager.
* @param newTimeout The timeout (in milliseconds).
*/
public void setTimeout(int newTimeout);
/**
* Returns the message factory of this SNMP protocol adaptor.
*
* @return The factory object.
*/
public SnmpPduFactory getPduFactory();
/**
* Sets the message factory of this SNMP protocol adaptor.
*
* @param factory The factory object (null means the default factory).
*/
public void setPduFactory(SnmpPduFactory factory);
/**
* Set the user-data factory of this SNMP protocol adaptor.
*
* @param factory The factory object (null means no factory).
* @see com.sun.jmx.snmp.agent.SnmpUserDataFactory
*/
public void setUserDataFactory(SnmpUserDataFactory factory);
/**
* Get the user-data factory associated with this SNMP protocol adaptor.
*
* @return The factory object (null means no factory).
* @see com.sun.jmx.snmp.agent.SnmpUserDataFactory
*/
public SnmpUserDataFactory getUserDataFactory();
/**
* Returns <CODE>true</CODE> if authentication traps are enabled.
* <P>
* When this feature is enabled, the SNMP protocol adaptor sends
* an <CODE>authenticationFailure</CODE> trap each time an authentication fails.
* <P>
* The default behaviour is to send authentication traps.
*
* @return <CODE>true</CODE> if authentication traps are enabled, <CODE>false</CODE> otherwise.
*/
public boolean getAuthTrapEnabled();
/**
* Sets the flag indicating if traps need to be sent in case of authentication failure.
*
* @param enabled Flag indicating if traps need to be sent.
*/
public void setAuthTrapEnabled(boolean enabled);
/**
* Returns <code>true</code> if this SNMP protocol adaptor sends a response in case
* of authentication failure.
* <P>
* When this feature is enabled, the SNMP protocol adaptor sends a response with <CODE>noSuchName</CODE>
* or <CODE>readOnly</CODE> when the authentication failed. If the flag is disabled, the
* SNMP protocol adaptor trashes the PDU silently.
* <P>
* The default behavior is to send responses.
*
* @return <code>true</code> if responses are sent.
*/
public boolean getAuthRespEnabled();
/**
* Sets the flag indicating if responses need to be sent in case of authentication failure.
*
* @param enabled Flag indicating if responses need to be sent.
*/
public void setAuthRespEnabled(boolean enabled);
/**
* Returns the enterprise OID. It is used by {@link #snmpV1Trap snmpV1Trap} to fill
* the 'enterprise' field of the trap request.
*
* @return The OID in string format "x.x.x.x".
*/
public String getEnterpriseOid();
/**
* Sets the enterprise OID.
*
* @param oid The OID in string format "x.x.x.x".
*
* @exception IllegalArgumentException The string format is incorrect
*/
public void setEnterpriseOid(String oid) throws IllegalArgumentException;
/**
* Returns the names of the MIBs available in this SNMP protocol adaptor.
*
* @return An array of MIB names.
*/
public String[] getMibs();
// GETTERS FOR SNMP GROUP (MIBII)
//-------------------------------
/**
* Returns the <CODE>snmpOutTraps</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpOutTraps</CODE> value.
*/
public Long getSnmpOutTraps();
/**
* Returns the <CODE>snmpOutGetResponses</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpOutGetResponses</CODE> value.
*/
public Long getSnmpOutGetResponses();
/**
* Returns the <CODE>snmpOutGenErrs</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpOutGenErrs</CODE> value.
*/
public Long getSnmpOutGenErrs();
/**
* Returns the <CODE>snmpOutBadValues</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpOutBadValues</CODE> value.
*/
public Long getSnmpOutBadValues();
/**
* Returns the <CODE>snmpOutNoSuchNames</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpOutNoSuchNames</CODE> value.
*/
public Long getSnmpOutNoSuchNames();
/**
* Returns the <CODE>snmpOutTooBigs</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpOutTooBigs</CODE> value.
*/
public Long getSnmpOutTooBigs();
/**
* Returns the <CODE>snmpInASNParseErrs</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpInASNParseErrs</CODE> value.
*/
public Long getSnmpInASNParseErrs();
/**
* Returns the <CODE>snmpInBadCommunityUses</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpInBadCommunityUses</CODE> value.
*/
public Long getSnmpInBadCommunityUses();
/**
* Returns the <CODE>snmpInBadCommunityNames</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpInBadCommunityNames</CODE> value.
*/
public Long getSnmpInBadCommunityNames();
/**
* Returns the <CODE>snmpInBadVersions</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpInBadVersions</CODE> value.
*/
public Long getSnmpInBadVersions();
/**
* Returns the <CODE>snmpOutPkts</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpOutPkts</CODE> value.
*/
public Long getSnmpOutPkts();
/**
* Returns the <CODE>snmpInPkts</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpInPkts</CODE> value.
*/
public Long getSnmpInPkts();
/**
* Returns the <CODE>snmpInGetRequests</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpInGetRequests</CODE> value.
*/
public Long getSnmpInGetRequests();
/**
* Returns the <CODE>snmpInGetNexts</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpInGetNexts</CODE> value.
*/
public Long getSnmpInGetNexts();
/**
* Returns the <CODE>snmpInSetRequests</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpInSetRequests</CODE> value.
*/
public Long getSnmpInSetRequests();
/**
* Returns the <CODE>snmpInTotalSetVars</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpInTotalSetVars</CODE> value.
*/
public Long getSnmpInTotalSetVars();
/**
* Returns the <CODE>snmpInTotalReqVars</CODE> value defined in MIB-II.
*
* @return The <CODE>snmpInTotalReqVars</CODE> value.
*/
public Long getSnmpInTotalReqVars();
/**
* Returns the <CODE>snmpSilentDrops</CODE> value defined in rfc 1907 NMPv2-MIB .
*
* @return The <CODE>snmpSilentDrops</CODE> value.
*
* @since 1.5
*/
public Long getSnmpSilentDrops();
/**
* Returns the <CODE>snmpProxyDrops</CODE> value defined in rfc 1907 NMPv2-MIB .
*
* @return The <CODE>snmpProxyDrops</CODE> value.
*
* @since 1.5
*/
public Long getSnmpProxyDrops();
// PUBLIC METHODS
//---------------
/**
* Adds a new MIB in the SNMP MIB handler.
* This method is called automatically by {@link com.sun.jmx.snmp.agent.SnmpMibAgent#setSnmpAdaptor(SnmpMibHandler)}
* and {@link com.sun.jmx.snmp.agent.SnmpMibAgent#setSnmpAdaptorName(ObjectName)}
* and should not be called directly.
*
* @param mib The MIB to add.
*
* @return A reference to the SNMP MIB handler.
*
* @exception IllegalArgumentException If the parameter is null.
*/
public SnmpMibHandler addMib(SnmpMibAgent mib) throws IllegalArgumentException;
/**
* Adds a new MIB in the SNMP MIB handler.
*
* @param mib The MIB to add.
* @param oids The set of OIDs this agent implements.
*
* @return A reference to the SNMP MIB handler.
*
* @exception IllegalArgumentException If the parameter is null.
*
* @since 1.5
*/
public SnmpMibHandler addMib(SnmpMibAgent mib, SnmpOid[] oids) throws IllegalArgumentException;
/**
* Removes the specified MIB from the SNMP protocol adaptor.
* This method is called automatically by {@link com.sun.jmx.snmp.agent.SnmpMibAgent#setSnmpAdaptor(SnmpMibHandler)}
* and {@link com.sun.jmx.snmp.agent.SnmpMibAgent#setSnmpAdaptorName(ObjectName)}
* and should not be called directly.
*
* @param mib The MIB to be removed.
*
* @return <code>true</code> if the specified <CODE>mib</CODE> was a MIB included in the SNMP MIB handler,
* <code>false</code> otherwise.
*/
public boolean removeMib(SnmpMibAgent mib);
/**
* Sends a trap using SNMP V1 trap format.
* <BR>The trap is sent to each destination defined in the ACL file (if available).
* If no ACL file or no destinations are available, the trap is sent to the local host.
*
* @param generic The generic number of the trap.
* @param specific The specific number of the trap.
* @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
*
* @exception IOException An I/O error occurred while sending the trap.
* @exception SnmpStatusException If the trap exceeds the limit defined by <CODE>bufferSize</CODE>.
*/
public void snmpV1Trap(int generic, int specific, SnmpVarBindList varBindList) throws IOException, SnmpStatusException;
/**
* Sends a trap using SNMP V1 trap format.
* <BR>The trap is sent to the specified <CODE>InetAddress</CODE> destination
* using the specified community string (and the ACL file is not used).
*
* @param address The <CODE>InetAddress</CODE> destination of the trap.
* @param cs The community string to be used for the trap.
* @param generic The generic number of the trap.
* @param specific The specific number of the trap.
* @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
*
* @exception IOException An I/O error occurred while sending the trap.
* @exception SnmpStatusException If the trap exceeds the limit defined by <CODE>bufferSize</CODE>.
*/
public void snmpV1Trap(InetAddress address, String cs, int generic, int specific, SnmpVarBindList varBindList)
throws IOException, SnmpStatusException;
/**
* Sends a trap using SNMP V1 trap format.
* <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
* The community string used is the one located in the <CODE>SnmpPeer</CODE> parameters (<CODE>SnmpParameters.getRdCommunity() </CODE>).
*
* @param peer The <CODE>SnmpPeer</CODE> destination of the trap.
* @param agentAddr The agent address to be used for the trap.
* @param enterpOid The enterprise OID to be used for the trap.
* @param generic The generic number of the trap.
* @param specific The specific number of the trap.
* @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
* @param time The time stamp (overwrite the current time).
*
* @exception IOException An I/O error occurred while sending the trap.
* @exception SnmpStatusException If the trap exceeds the limit defined by <CODE>bufferSize</CODE>.
*
* @since 1.5
*/
public void snmpV1Trap(SnmpPeer peer,
SnmpIpAddress agentAddr,
SnmpOid enterpOid,
int generic,
int specific,
SnmpVarBindList varBindList,
SnmpTimeticks time) throws IOException, SnmpStatusException;
/**
* Sends a trap using SNMP V2 trap format.
* <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
* <BR>The community string used is the one located in the <CODE>SnmpPeer</CODE> parameters (<CODE>SnmpParameters.getRdCommunity() </CODE>).
* <BR>The variable list included in the outgoing trap is composed of the following items:
* <UL>
* <LI><CODE>sysUpTime.0</CODE> with the value specified by <CODE>time</CODE>
* <LI><CODE>snmpTrapOid.0</CODE> with the value specified by <CODE>trapOid</CODE>
* <LI><CODE>all the (oid,values)</CODE> from the specified <CODE>varBindList</CODE>
* </UL>
*
* @param peer The <CODE>SnmpPeer</CODE> destination of the trap.
* @param trapOid The OID identifying the trap.
* @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
* @param time The time stamp (overwrite the current time).
*
* @exception IOException An I/O error occurred while sending the trap.
* @exception SnmpStatusException If the trap exceeds the limit defined by <CODE>bufferSize</CODE>.
*
* @since 1.5
*/
public void snmpV2Trap(SnmpPeer peer,
SnmpOid trapOid,
SnmpVarBindList varBindList,
SnmpTimeticks time) throws IOException, SnmpStatusException;
/**
* Sends a trap using SNMP V2 trap format.
* <BR>The trap is sent to each destination defined in the ACL file (if available).
* If no ACL file or no destinations are available, the trap is sent to the local host.
* <BR>The variable list included in the outgoing trap is composed of the following items:
* <UL>
* <LI><CODE>sysUpTime.0</CODE> with its current value
* <LI><CODE>snmpTrapOid.0</CODE> with the value specified by <CODE>trapOid</CODE>
* <LI><CODE>all the (oid,values)</CODE> from the specified <CODE>varBindList</CODE>
* </UL>
*
* @param trapOid The OID identifying the trap.
* @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
*
* @exception IOException An I/O error occurred while sending the trap.
* @exception SnmpStatusException If the trap exceeds the limit defined by <CODE>bufferSize</CODE>.
*/
public void snmpV2Trap(SnmpOid trapOid, SnmpVarBindList varBindList) throws IOException, SnmpStatusException;
/**
* Sends a trap using SNMP V2 trap format.
* <BR>The trap is sent to the specified <CODE>InetAddress</CODE> destination
* using the specified community string (and the ACL file is not used).
* <BR>The variable list included in the outgoing trap is composed of the following items:
* <UL>
* <LI><CODE>sysUpTime.0</CODE> with its current value
* <LI><CODE>snmpTrapOid.0</CODE> with the value specified by <CODE>trapOid</CODE>
* <LI><CODE>all the (oid,values)</CODE> from the specified <CODE>varBindList</CODE>
* </UL>
*
* @param address The <CODE>InetAddress</CODE> destination of the trap.
* @param cs The community string to be used for the trap.
* @param trapOid The OID identifying the trap.
* @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
*
* @exception IOException An I/O error occurred while sending the trap.
* @exception SnmpStatusException If the trap exceeds the limit defined by <CODE>bufferSize</CODE>.
*/
public void snmpV2Trap(InetAddress address, String cs, SnmpOid trapOid, SnmpVarBindList varBindList)
throws IOException, SnmpStatusException;
/**
* Send the specified trap PDU to the passed <CODE>InetAddress</CODE>.
* @param address The destination address.
* @param pdu The pdu to send.
* @exception IOException An I/O error occurred while sending the trap.
* @exception SnmpStatusException If the trap exceeds the limit defined by <CODE>bufferSize</CODE>.
*
* @since 1.5
*/
public void snmpPduTrap(InetAddress address, SnmpPduPacket pdu)
throws IOException, SnmpStatusException;
/**
* Send the specified trap PDU to the passed <CODE>SnmpPeer</CODE>.
* @param peer The destination peer. The Read community string is used of <CODE>SnmpParameters</CODE> is used as the trap community string.
* @param pdu The pdu to send.
* @exception IOException An I/O error occurred while sending the trap.
* @exception SnmpStatusException If the trap exceeds the limit defined by <CODE>bufferSize</CODE>.
* @since 1.5
*/
public void snmpPduTrap(SnmpPeer peer,
SnmpPduPacket pdu)
throws IOException, SnmpStatusException;
/**
* Sends an inform using SNMP V2 inform request format.
* <BR>The inform request is sent to each destination defined in the ACL file (if available).
* If no ACL file or no destinations are available, the inform request is sent to the local host.
* <BR>The variable list included in the outgoing inform request is composed of the following items:
* <UL>
* <LI><CODE>sysUpTime.0</CODE> with its current value
* <LI><CODE>snmpTrapOid.0</CODE> with the value specified by <CODE>trapOid</CODE>
* <LI><CODE>all the (oid,values)</CODE> from the specified <CODE>varBindList</CODE>
* </UL>
* To send an inform request, the SNMP adaptor server must be active.
*
* @param cb The callback that is invoked when a request is complete.
* @param trapOid The OID identifying the trap.
* @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
*
* @return A vector of {@link com.sun.jmx.snmp.daemon.SnmpInformRequest} objects.
* <P>If there is no destination host for this inform request, the returned vector will be empty.
*
* @exception IllegalStateException This method has been invoked while the SNMP adaptor server was not active.
* @exception IOException An I/O error occurred while sending the inform request.
* @exception SnmpStatusException If the inform request exceeds the limit defined by <CODE>bufferSize</CODE>.
*/
public Vector<?> snmpInformRequest(SnmpInformHandler cb, SnmpOid trapOid,
SnmpVarBindList varBindList)
throws IllegalStateException, IOException, SnmpStatusException;
/**
* Sends an inform using SNMP V2 inform request format.
* <BR>The inform is sent to the specified <CODE>InetAddress</CODE> destination
* using the specified community string.
* <BR>The variable list included in the outgoing inform request is composed of the following items:
* <UL>
* <LI><CODE>sysUpTime.0</CODE> with its current value
* <LI><CODE>snmpTrapOid.0</CODE> with the value specified by <CODE>trapOid</CODE>
* <LI><CODE>all the (oid,values)</CODE> from the specified <CODE>varBindList</CODE>
* </UL>
* To send an inform request, the SNMP adaptor server must be active.
*
* @param address The <CODE>InetAddress</CODE> destination for this inform request.
* @param cs The community string to be used for the inform request.
* @param cb The callback that is invoked when a request is complete.
* @param trapOid The OID identifying the trap.
* @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
*
* @return The inform request object.
*
* @exception IllegalStateException This method has been invoked while the SNMP adaptor server was not active.
* @exception IOException An I/O error occurred while sending the inform request.
* @exception SnmpStatusException If the inform request exceeds the limit defined by <CODE>bufferSize</CODE>.
*/
public SnmpInformRequest snmpInformRequest(InetAddress address, String cs, SnmpInformHandler cb,
SnmpOid trapOid, SnmpVarBindList varBindList)
throws IllegalStateException, IOException, SnmpStatusException;
/**
* Sends an inform using SNMP V2 inform request format.
* <BR>The inform is sent to the specified <CODE>SnmpPeer</CODE> destination.
* <BR> The community string used is the one located in the <CODE>SnmpPeer</CODE> parameters (<CODE>SnmpParameters.getInformCommunity() </CODE>).
* <BR>The variable list included in the outgoing inform is composed of the following items:
* <UL>
* <LI><CODE>sysUpTime.0</CODE> with its current value
* <LI><CODE>snmpTrapOid.0</CODE> with the value specified by <CODE>trapOid</CODE>
* <LI><CODE>all the (oid,values)</CODE> from the specified <CODE>varBindList</CODE>
* </UL>
* To send an inform request, the SNMP adaptor server must be active.
*
* @param peer The <CODE>SnmpPeer</CODE> destination for this inform request.
* @param cb The callback that is invoked when a request is complete.
* @param trapOid The OID identifying the trap.
* @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
*
* @return The inform request object.
*
* @exception IllegalStateException This method has been invoked while the SNMP adaptor server was not active.
* @exception IOException An I/O error occurred while sending the inform request.
* @exception SnmpStatusException If the inform request exceeds the limit defined by <CODE>bufferSize</CODE>.
*
* @since 1.5
*/
public SnmpInformRequest snmpInformRequest(SnmpPeer peer,
SnmpInformHandler cb,
SnmpOid trapOid,
SnmpVarBindList varBindList) throws IllegalStateException, IOException, SnmpStatusException;
}

View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jmx.snmp.daemon;
// JMX imports
//
import com.sun.jmx.snmp.SnmpDefinitions;
import com.sun.jmx.snmp.SnmpVarBindList;
/**
* Provides the callback methods that are required to be implemented by the application
* when an inform response is received by the agent.
* <P>
* Each inform request can be provided with an object that implements this callback
* interface. An application then uses the SNMP adaptor to start an SNMP inform request,
* which marks the request as active. The methods in this callback interface
* get invoked when any of the following happens:
* <P>
* <UL>
* <LI> The agent receives the SNMP inform response.
* <LI> The agent does not receive any response within a specified time and the number of tries
* have exceeded the limit (timeout condition).
* <LI> An internal error occurs while processing or parsing the inform request.
* </UL>
* <p><b>This API is a Sun Microsystems internal API and is subject
* to change without notice.</b></p>
*/
public interface SnmpInformHandler extends SnmpDefinitions {
/**
* This callback is invoked when a manager responds to an SNMP inform request.
* The callback should check the error status of the inform request to determine
* the kind of response.
*
* @param request The <CODE>SnmpInformRequest</CODE> associated with this callback.
* @param errStatus The status of the request.
* @param errIndex The index in the list that caused the error.
* @param vblist The <CODE>Response varBind</CODE> list for the successful request.
*/
public abstract void processSnmpPollData(SnmpInformRequest request, int errStatus, int errIndex, SnmpVarBindList vblist);
/**
* This callback is invoked when a manager does not respond within the
* specified timeout value to the SNMP inform request. The number of tries have also
* been exhausted.
* @param request The <CODE>SnmpInformRequest</CODE> associated with this callback.
*/
public abstract void processSnmpPollTimeout(SnmpInformRequest request);
/**
* This callback is invoked when any form of internal error occurs.
* @param request The <CODE>SnmpInformRequest</CODE> associated with this callback.
* @param errmsg The <CODE>String</CODE> describing the internal error.
*/
public abstract void processSnmpInternalError(SnmpInformRequest request, String errmsg);
}

View File

@@ -0,0 +1,269 @@
/*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jmx.snmp.daemon;
// java imports
//
import java.util.Vector;
import java.util.Enumeration;
// jmx imports
//
import com.sun.jmx.snmp.SnmpOid;
// SNMP Runtime imports
//
import com.sun.jmx.snmp.agent.SnmpMibAgent;
/**
* The class is used for building a tree representation of the different
* root oids of the supported MIBs. Each node is associated to a specific MIB.
*/
final class SnmpMibTree {
public SnmpMibTree() {
defaultAgent= null;
root= new TreeNode(-1, null, null);
}
public void setDefaultAgent(SnmpMibAgent def) {
defaultAgent= def;
root.agent= def;
}
public SnmpMibAgent getDefaultAgent() {
return defaultAgent;
}
public void register(SnmpMibAgent agent) {
root.registerNode(agent);
}
public void register(SnmpMibAgent agent, long[] oid) {
root.registerNode(oid, 0, agent);
}
public SnmpMibAgent getAgentMib(SnmpOid oid) {
TreeNode node= root.retrieveMatchingBranch(oid.longValue(), 0);
if (node == null)
return defaultAgent;
else
if(node.getAgentMib() == null)
return defaultAgent;
else
return node.getAgentMib();
}
public void unregister(SnmpMibAgent agent, SnmpOid[] oids) {
for(int i = 0; i < oids.length; i++) {
long[] oid = oids[i].longValue();
TreeNode node = root.retrieveMatchingBranch(oid, 0);
if (node == null)
continue;
node.removeAgent(agent);
}
}
public void unregister(SnmpMibAgent agent) {
root.removeAgentFully(agent);
}
/*
public void unregister(SnmpMibAgent agent) {
long[] oid= agent.getRootOid();
TreeNode node= root.retrieveMatchingBranch(oid, 0);
if (node == null)
return;
node.removeAgent(agent);
}
*/
public void printTree() {
root.printTree(">");
}
private SnmpMibAgent defaultAgent;
private TreeNode root;
// A SnmpMibTree object is a tree of TreeNode
//
final class TreeNode {
void registerNode(SnmpMibAgent agent) {
long[] oid= agent.getRootOid();
registerNode(oid, 0, agent);
}
TreeNode retrieveMatchingBranch(long[] oid, int cursor) {
TreeNode node= retrieveChild(oid, cursor);
if (node == null)
return this;
if (children.isEmpty()) {
// In this case, the node does not have any children. So no point to
// continue the search ...
return node;
}
if( cursor + 1 == oid.length) {
// In this case, the oid does not have any more element. So the search
// is over.
return node;
}
TreeNode n = node.retrieveMatchingBranch(oid, cursor + 1);
//If the returned node got a null agent, we have to replace it by
//the current one (in case it is not null)
//
return n.agent == null ? this : n;
}
SnmpMibAgent getAgentMib() {
return agent;
}
public void printTree(String ident) {
StringBuilder buff= new StringBuilder();
if (agents == null) {
return;
}
for(Enumeration<SnmpMibAgent> e= agents.elements(); e.hasMoreElements(); ) {
SnmpMibAgent mib= e.nextElement();
if (mib == null)
buff.append("empty ");
else
buff.append(mib.getMibName()).append(" ");
}
ident+= " ";
if (children == null) {
return;
}
for(Enumeration<TreeNode> e= children.elements(); e.hasMoreElements(); ) {
TreeNode node= e.nextElement();
node.printTree(ident);
}
}
// PRIVATE STUFF
//--------------
/**
* Only the treeNode class can create an instance of treeNode.
* The creation occurs when registering a new oid.
*/
private TreeNode(long nodeValue, SnmpMibAgent agent, TreeNode sup) {
this.nodeValue= nodeValue;
this.parent= sup;
agents.addElement(agent);
}
private void removeAgentFully(SnmpMibAgent agent) {
Vector<TreeNode> v = new Vector<>();
for(Enumeration<TreeNode> e= children.elements();
e.hasMoreElements(); ) {
TreeNode node= e.nextElement();
node.removeAgentFully(agent);
if(node.agents.isEmpty())
v.add(node);
}
for(Enumeration<TreeNode> e= v.elements(); e.hasMoreElements(); ) {
children.removeElement(e.nextElement());
}
removeAgent(agent);
}
private void removeAgent(SnmpMibAgent mib) {
if (!agents.contains(mib))
return;
agents.removeElement(mib);
if (!agents.isEmpty())
agent= agents.firstElement();
}
private void setAgent(SnmpMibAgent agent) {
this.agent = agent;
}
private void registerNode(long[] oid, int cursor, SnmpMibAgent agent) {
if (cursor >= oid.length)
//That's it !
//
return;
TreeNode child = retrieveChild(oid, cursor);
if (child == null) {
// Create a child and register it !
//
long theValue= oid[cursor];
child= new TreeNode(theValue, agent, this);
children.addElement(child);
}
else
if (agents.contains(agent) == false) {
agents.addElement(agent);
}
// We have to set the agent attribute
//
if(cursor == (oid.length - 1)) {
child.setAgent(agent);
}
else
child.registerNode(oid, cursor+1, agent);
}
private TreeNode retrieveChild(long[] oid, int current) {
long theValue= oid[current];
for(Enumeration<TreeNode> e= children.elements(); e.hasMoreElements(); ) {
TreeNode node= e.nextElement();
if (node.match(theValue))
return node;
}
return null;
}
private boolean match(long value) {
return (nodeValue == value) ? true : false;
}
private Vector<TreeNode> children= new Vector<>();
private Vector<SnmpMibAgent> agents= new Vector<>();
private long nodeValue;
private SnmpMibAgent agent;
private TreeNode parent;
}; // end of class TreeNode
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,343 @@
/*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jmx.snmp.daemon;
// java import
//
import java.util.Enumeration;
import java.util.logging.Level;
// jmx imports
//
import com.sun.jmx.snmp.SnmpPdu;
import com.sun.jmx.snmp.SnmpVarBind;
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpValue;
import com.sun.jmx.snmp.SnmpDefinitions;
import com.sun.jmx.snmp.SnmpStatusException;
import com.sun.jmx.snmp.SnmpEngine;
// SNMP Runtime import
//
import static com.sun.jmx.defaults.JmxProperties.SNMP_ADAPTOR_LOGGER;
import com.sun.jmx.snmp.agent.SnmpMibAgent;
import com.sun.jmx.snmp.internal.SnmpIncomingRequest;
import com.sun.jmx.snmp.ThreadContext;
class SnmpSubBulkRequestHandler extends SnmpSubRequestHandler {
private SnmpAdaptorServer server = null;
/**
* The constructor initialize the subrequest with the whole varbind list contained
* in the original request.
*/
protected SnmpSubBulkRequestHandler(SnmpEngine engine,
SnmpAdaptorServer server,
SnmpIncomingRequest incRequest,
SnmpMibAgent agent,
SnmpPdu req,
int nonRepeat,
int maxRepeat,
int R) {
super(engine, incRequest, agent, req);
init(server, req, nonRepeat, maxRepeat, R);
}
/**
* The constructor initialize the subrequest with the whole varbind list contained
* in the original request.
*/
protected SnmpSubBulkRequestHandler(SnmpAdaptorServer server,
SnmpMibAgent agent,
SnmpPdu req,
int nonRepeat,
int maxRepeat,
int R) {
super(agent, req);
init(server, req, nonRepeat, maxRepeat, R);
}
@Override
public void run() {
size= varBind.size();
try {
// Invoke a getBulk operation
//
/* NPCTE fix for bugId 4492741, esc 0, 16-August-2001 */
final ThreadContext oldContext =
ThreadContext.push("SnmpUserData",data);
try {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() +
"]:getBulk operation on " + agent.getMibName());
}
agent.getBulk(createMibRequest(varBind,version,data),
nonRepeat, maxRepeat);
} finally {
ThreadContext.restore(oldContext);
}
/* end of NPCTE fix for bugId 4492741 */
} catch(SnmpStatusException x) {
errorStatus = x.getStatus() ;
errorIndex= x.getErrorIndex();
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() +
"]:an Snmp error occurred during the operation", x);
}
}
catch(Exception x) {
errorStatus = SnmpDefinitions.snmpRspGenErr ;
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() +
"]:a generic error occurred during the operation", x);
}
}
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() +
"]:operation completed");
}
}
private void init(SnmpAdaptorServer server,
SnmpPdu req,
int nonRepeat,
int maxRepeat,
int R) {
this.server = server;
this.nonRepeat= nonRepeat;
this.maxRepeat= maxRepeat;
this.globalR= R;
final int max= translation.length;
final SnmpVarBind[] list= req.varBindList;
final NonSyncVector<SnmpVarBind> nonSyncVarBind =
((NonSyncVector<SnmpVarBind>)varBind);
for(int i=0; i < max; i++) {
translation[i]= i;
// we need to allocate a new SnmpVarBind. Otherwise the first
// sub request will modify the list...
//
final SnmpVarBind newVarBind =
new SnmpVarBind(list[i].oid, list[i].value);
nonSyncVarBind.addNonSyncElement(newVarBind);
}
}
/**
* The method updates find out which element to use at update time. Handle oid overlapping as well
*/
private SnmpVarBind findVarBind(SnmpVarBind element,
SnmpVarBind result) {
if (element == null) return null;
if (result.oid == null) {
return element;
}
if (element.value == SnmpVarBind.endOfMibView) return result;
if (result.value == SnmpVarBind.endOfMibView) return element;
final SnmpValue val = result.value;
int comp = element.oid.compareTo(result.oid);
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"findVarBind","Comparing OID element : " + element.oid +
" with result : " + result.oid);
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"findVarBind","Values element : " + element.value +
" result : " + result.value);
}
if (comp < 0) {
// Take the smallest (lexicographically)
//
return element;
}
else {
if(comp == 0) {
// Must compare agent used for reply
// Take the deeper within the reply
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"findVarBind"," oid overlapping. Oid : " +
element.oid + "value :" + element.value);
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"findVarBind","Already present varBind : " +
result);
}
SnmpOid oid = result.oid;
SnmpMibAgent deeperAgent = server.getAgentMib(oid);
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"findVarBind","Deeper agent : " + deeperAgent);
}
if(deeperAgent == agent) {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"findVarBind","The current agent is the deeper one. Update the value with the current one");
}
return element;
} else {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"findVarBind","The current agent is not the deeper one. return the previous one.");
}
return result;
}
/*
Vector v = new Vector();
SnmpMibRequest getReq = createMibRequest(v,
version,
null);
SnmpVarBind realValue = new SnmpVarBind(oid);
getReq.addVarBind(realValue);
try {
deeperAgent.get(getReq);
} catch(SnmpStatusException e) {
e.printStackTrace();
}
if(isDebugOn())
trace("findVarBind", "Biggest priority value is : " +
realValue.value);
return realValue;
*/
}
else {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"findVarBind","The right varBind is the already present one");
}
return result;
}
}
}
/**
* The method updates a given var bind list with the result of a
* previsouly invoked operation.
* Prior to calling the method, one must make sure that the operation was
* successful. As such the method getErrorIndex or getErrorStatus should be
* called.
*/
@Override
protected void updateResult(SnmpVarBind[] result) {
// we can assume that the run method is over ...
//
final Enumeration<SnmpVarBind> e= varBind.elements();
final int max= result.length;
// First go through all the values once ...
for(int i=0; i < size; i++) {
// May be we should control the position ...
//
if (e.hasMoreElements() == false)
return;
// bugId 4641694: must check position in order to avoid
// ArrayIndexOutOfBoundException
final int pos=translation[i];
if (pos >= max) {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
"updateResult","Position '"+pos+"' is out of bound...");
}
continue;
}
final SnmpVarBind element= e.nextElement();
if (element == null) continue;
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"updateResult","Non repeaters Current element : " +
element + " from agent : " + agent);
}
final SnmpVarBind res = findVarBind(element,result[pos]);
if(res == null) continue;
result[pos] = res;
}
// Now update the values which have been repeated
// more than once.
int localR= size - nonRepeat;
for (int i = 2 ; i <= maxRepeat ; i++) {
for (int r = 0 ; r < localR ; r++) {
final int pos = (i-1)* globalR + translation[nonRepeat + r] ;
if (pos >= max)
return;
if (e.hasMoreElements() ==false)
return;
final SnmpVarBind element= e.nextElement();
if (element == null) continue;
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"updateResult","Repeaters Current element : " +
element + " from agent : " + agent);
}
final SnmpVarBind res = findVarBind(element, result[pos]);
if(res == null) continue;
result[pos] = res;
}
}
}
// PROTECTED VARIABLES
//------------------
/**
* Specific to the sub request
*/
protected int nonRepeat=0;
protected int maxRepeat=0;
/**
* R as defined in RCF 1902 for the global request the sub-request is associated to.
*/
protected int globalR=0;
protected int size=0;
}

View File

@@ -0,0 +1,272 @@
/*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jmx.snmp.daemon;
// java imports
//
import java.util.logging.Level;
import java.util.Vector;
// jmx imports
//
import com.sun.jmx.snmp.SnmpEngine;
import com.sun.jmx.snmp.SnmpPdu;
import com.sun.jmx.snmp.SnmpValue;
import com.sun.jmx.snmp.SnmpVarBind;
import com.sun.jmx.snmp.SnmpVarBindList;
import com.sun.jmx.snmp.SnmpOid;
import com.sun.jmx.snmp.SnmpDefinitions;
import com.sun.jmx.snmp.SnmpStatusException;
// SNMP Runtime import
//
import static com.sun.jmx.defaults.JmxProperties.SNMP_ADAPTOR_LOGGER;
import com.sun.jmx.snmp.agent.SnmpMibAgent;
import com.sun.jmx.snmp.agent.SnmpMibRequest;
import com.sun.jmx.snmp.daemon.SnmpAdaptorServer;
import com.sun.jmx.snmp.internal.SnmpIncomingRequest;
/* NPCTE fix for bugId 4492741, esc 0 */
import com.sun.jmx.snmp.ThreadContext;
/* end of NPCTE fix for bugId 4492741 */
class SnmpSubNextRequestHandler extends SnmpSubRequestHandler {
private SnmpAdaptorServer server = null;
/**
* The constructor initialize the subrequest with the whole varbind
* list contained in the original request.
*/
protected SnmpSubNextRequestHandler(SnmpAdaptorServer server,
SnmpMibAgent agent,
SnmpPdu req) {
super(agent,req);
init(req, server);
}
protected SnmpSubNextRequestHandler(SnmpEngine engine,
SnmpAdaptorServer server,
SnmpIncomingRequest incRequest,
SnmpMibAgent agent,
SnmpPdu req) {
super(engine, incRequest, agent, req);
init(req, server);
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubNextRequestHandler.class.getName(),
"SnmpSubNextRequestHandler", "Constructor : " + this);
}
}
private void init(SnmpPdu req, SnmpAdaptorServer server) {
this.server = server;
// The translation table is easy in this case ...
//
final int max= translation.length;
final SnmpVarBind[] list= req.varBindList;
final NonSyncVector<SnmpVarBind> nonSyncVarBind =
((NonSyncVector<SnmpVarBind>)varBind);
for(int i=0; i < max; i++) {
translation[i]= i;
// we need to allocate a new SnmpVarBind. Otherwise the first
// sub request will modify the list...
//
final SnmpVarBind newVarBind =
new SnmpVarBind(list[i].oid, list[i].value);
nonSyncVarBind.addNonSyncElement(newVarBind);
}
}
public void run() {
try {
/* NPCTE fix for bugId 4492741, esc 0, 16-August-2001 */
final ThreadContext oldContext =
ThreadContext.push("SnmpUserData",data);
try {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() +
"]:getNext operation on " + agent.getMibName());
}
// Always call with V2. So the merge of the responses will
// be easier.
//
agent.getNext(createMibRequest(varBind, snmpVersionTwo, data));
} finally {
ThreadContext.restore(oldContext);
}
/* end of NPCTE fix for bugId 4492741 */
} catch(SnmpStatusException x) {
errorStatus = x.getStatus() ;
errorIndex= x.getErrorIndex();
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() +
"]:an Snmp error occurred during the operation", x);
}
}
catch(Exception x) {
errorStatus = SnmpDefinitions.snmpRspGenErr ;
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() +
"]:a generic error occurred during the operation", x);
}
}
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() + "]:operation completed");
}
}
/**
* The method updates the varbind list of the subrequest.
*/
protected void updateRequest(SnmpVarBind var, int pos) {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
"updateRequest", "Copy :" + var);
}
int size= varBind.size();
translation[size]= pos;
final SnmpVarBind newVarBind =
new SnmpVarBind(var.oid, var.value);
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
"updateRequest", "Copied :" + newVarBind);
}
varBind.addElement(newVarBind);
}
/**
* The method updates a given var bind list with the result of a
* previsouly invoked operation.
* Prior to calling the method, one must make sure that the operation was
* successful. As such the method getErrorIndex or getErrorStatus should be
* called.
*/
protected void updateResult(SnmpVarBind[] result) {
final int max=varBind.size();
for(int i= 0; i< max ; i++) {
// May be we should control the position ...
//
final int index= translation[i];
final SnmpVarBind elmt=
(SnmpVarBind)((NonSyncVector)varBind).elementAtNonSync(i);
final SnmpVarBind vb= result[index];
if (vb == null) {
result[index]= elmt;
/* NPCTE fix for bugid 4381195 esc 0. <J.C.> < 17-Oct-2000> */
// if ((elmt != null) && (elmt.value == null) &&
// (version == snmpVersionTwo))
// elmt.value = SnmpVarBind.endOfMibView;
/* end of NPCTE fix for bugid 4381195 */
continue;
}
final SnmpValue val= vb.value;
if ((val == null)|| (val == SnmpVarBind.endOfMibView)){
/* NPCTE fix for bugid 4381195 esc 0. <J.C.> < 17-Oct-2000> */
if ((elmt != null) &&
(elmt.value != SnmpVarBind.endOfMibView))
result[index]= elmt;
// else if ((val == null) && (version == snmpVersionTwo))
// vb.value = SnmpVarBind.endOfMibView;
continue;
/* end of NPCTE fix for bugid 4381195 */
}
/* NPCTE fix for bugid 4381195 esc 0. <J.C.> < 17-Oct-2000> */
if (elmt == null) continue;
/* end of NPCTE fix for bugid 4381195 */
if (elmt.value == SnmpVarBind.endOfMibView) continue;
// Now we need to take the smallest oid ...
//
int comp = elmt.oid.compareTo(vb.oid);
if (comp < 0) {
// Take the smallest (lexicographically)
//
result[index]= elmt;
}
else {
if(comp == 0) {
// Must compare agent used for reply
// Take the deeper within the reply
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"updateResult"," oid overlapping. Oid : " +
elmt.oid + "value :" + elmt.value);
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"updateResult","Already present varBind : " +
vb);
}
SnmpOid oid = vb.oid;
SnmpMibAgent deeperAgent = server.getAgentMib(oid);
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"updateResult","Deeper agent : " + deeperAgent);
}
if(deeperAgent == agent) {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"updateResult","The current agent is the deeper one. Update the value with the current one");
}
result[index].value = elmt.value;
}
/*
Vector v = new Vector();
SnmpMibRequest getReq = createMibRequest(v,
version,
null);
SnmpVarBind realValue = new SnmpVarBind(oid);
getReq.addVarBind(realValue);
try {
deeperAgent.get(getReq);
} catch(SnmpStatusException e) {
e.printStackTrace();
}
if(isDebugOn())
trace("updateResult", "Biggest priority value is : " +
realValue.value);
result[index].value = realValue.value;
*/
}
}
}
}
}

View File

@@ -0,0 +1,630 @@
/*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jmx.snmp.daemon;
// java import
//
import java.util.logging.Level;
import java.util.Vector;
// jmx imports
//
import static com.sun.jmx.defaults.JmxProperties.SNMP_ADAPTOR_LOGGER;
import com.sun.jmx.snmp.SnmpPdu;
import com.sun.jmx.snmp.SnmpVarBind;
import com.sun.jmx.snmp.SnmpDefinitions;
import com.sun.jmx.snmp.SnmpStatusException;
import com.sun.jmx.snmp.SnmpEngine;
// SNMP Runtime import
//
import com.sun.jmx.snmp.agent.SnmpMibAgent;
import com.sun.jmx.snmp.agent.SnmpMibRequest;
import com.sun.jmx.snmp.ThreadContext;
import com.sun.jmx.snmp.internal.SnmpIncomingRequest;
class SnmpSubRequestHandler implements SnmpDefinitions, Runnable {
protected SnmpIncomingRequest incRequest = null;
protected SnmpEngine engine = null;
/**
* V3 enabled Adaptor. Each Oid is added using updateRequest method.
*/
protected SnmpSubRequestHandler(SnmpEngine engine,
SnmpIncomingRequest incRequest,
SnmpMibAgent agent,
SnmpPdu req) {
this(agent, req);
init(engine, incRequest);
}
/**
* V3 enabled Adaptor.
*/
protected SnmpSubRequestHandler(SnmpEngine engine,
SnmpIncomingRequest incRequest,
SnmpMibAgent agent,
SnmpPdu req,
boolean nouse) {
this(agent, req, nouse);
init(engine, incRequest);
}
/**
* SNMP V1/V2 . To be called with updateRequest.
*/
protected SnmpSubRequestHandler(SnmpMibAgent agent, SnmpPdu req) {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"constructor", "creating instance for request " + String.valueOf(req.requestId));
}
version= req.version;
type= req.type;
this.agent= agent;
// We get a ref on the pdu in order to pass it to SnmpMibRequest.
reqPdu = req;
//Pre-allocate room for storing varbindlist and translation table.
//
int length= req.varBindList.length;
translation= new int[length];
varBind= new NonSyncVector<SnmpVarBind>(length);
}
/**
* SNMP V1/V2 The constructor initialize the subrequest with the whole varbind list contained
* in the original request.
*/
@SuppressWarnings("unchecked") // cast to NonSyncVector<SnmpVarBind>
protected SnmpSubRequestHandler(SnmpMibAgent agent,
SnmpPdu req,
boolean nouse) {
this(agent,req);
// The translation table is easy in this case ...
//
int max= translation.length;
SnmpVarBind[] list= req.varBindList;
for(int i=0; i < max; i++) {
translation[i]= i;
((NonSyncVector<SnmpVarBind>)varBind).addNonSyncElement(list[i]);
}
}
SnmpMibRequest createMibRequest(Vector<SnmpVarBind> vblist,
int protocolVersion,
Object userData) {
// This is an optimization:
// The SnmpMibRequest created in the check() phase is
// reused in the set() phase.
//
if (type == pduSetRequestPdu && mibRequest != null)
return mibRequest;
//This is a request comming from an SnmpV3AdaptorServer.
//Full power.
SnmpMibRequest result = null;
if(incRequest != null) {
result = SnmpMibAgent.newMibRequest(engine,
reqPdu,
vblist,
protocolVersion,
userData,
incRequest.getPrincipal(),
incRequest.getSecurityLevel(),
incRequest.getSecurityModel(),
incRequest.getContextName(),
incRequest.getAccessContext());
} else {
result = SnmpMibAgent.newMibRequest(reqPdu,
vblist,
protocolVersion,
userData);
}
// If we're doing the check() phase, we store the SnmpMibRequest
// so that we can reuse it in the set() phase.
//
if (type == pduWalkRequest)
mibRequest = result;
return result;
}
void setUserData(Object userData) {
data = userData;
}
public void run() {
try {
final ThreadContext oldContext =
ThreadContext.push("SnmpUserData",data);
try {
switch(type) {
case pduGetRequestPdu:
// Invoke a get operation
//
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() +
"]:get operation on " + agent.getMibName());
}
agent.get(createMibRequest(varBind,version,data));
break;
case pduGetNextRequestPdu:
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() +
"]:getNext operation on " + agent.getMibName());
}
//#ifdef DEBUG
agent.getNext(createMibRequest(varBind,version,data));
break;
case pduSetRequestPdu:
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() +
"]:set operation on " + agent.getMibName());
}
agent.set(createMibRequest(varBind,version,data));
break;
case pduWalkRequest:
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() +
"]:check operation on " + agent.getMibName());
}
agent.check(createMibRequest(varBind,version,data));
break;
default:
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() +
"]:unknown operation (" + type + ") on " +
agent.getMibName());
}
errorStatus= snmpRspGenErr;
errorIndex= 1;
break;
}// end of switch
} finally {
ThreadContext.restore(oldContext);
}
} catch(SnmpStatusException x) {
errorStatus = x.getStatus() ;
errorIndex= x.getErrorIndex();
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() +
"]:an Snmp error occurred during the operation", x);
}
}
catch(Exception x) {
errorStatus = SnmpDefinitions.snmpRspGenErr ;
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() +
"]:a generic error occurred during the operation", x);
}
}
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(),
"run", "[" + Thread.currentThread() + "]:operation completed");
}
}
// -------------------------------------------------------------
//
// This function does a best-effort to map global error status
// to SNMP v1 valid global error status.
//
// An SnmpStatusException can contain either:
// <li> v2 local error codes (that should be stored in the varbind)</li>
// <li> v2 global error codes </li>
// <li> v1 global error codes </li>
//
// v2 local error codes (noSuchInstance, noSuchObject) are
// transformed in a global v1 snmpRspNoSuchName error.
//
// v2 global error codes are transformed in the following way:
//
// If the request was a GET/GETNEXT then either
// snmpRspNoSuchName or snmpRspGenErr is returned.
//
// Otherwise:
// snmpRspNoAccess, snmpRspInconsistentName
// => snmpRspNoSuchName
// snmpRspAuthorizationError, snmpRspNotWritable, snmpRspNoCreation
// => snmpRspReadOnly (snmpRspNoSuchName for GET/GETNEXT)
// snmpRspWrong*
// => snmpRspBadValue (snmpRspNoSuchName for GET/GETNEXT)
// snmpRspResourceUnavailable, snmpRspRspCommitFailed,
// snmpRspUndoFailed
// => snmpRspGenErr
//
// -------------------------------------------------------------
//
static final int mapErrorStatusToV1(int errorStatus, int reqPduType) {
// Map v2 codes onto v1 codes
//
if (errorStatus == SnmpDefinitions.snmpRspNoError)
return SnmpDefinitions.snmpRspNoError;
if (errorStatus == SnmpDefinitions.snmpRspGenErr)
return SnmpDefinitions.snmpRspGenErr;
if (errorStatus == SnmpDefinitions.snmpRspNoSuchName)
return SnmpDefinitions.snmpRspNoSuchName;
if ((errorStatus == SnmpStatusException.noSuchInstance) ||
(errorStatus == SnmpStatusException.noSuchObject) ||
(errorStatus == SnmpDefinitions.snmpRspNoAccess) ||
(errorStatus == SnmpDefinitions.snmpRspInconsistentName) ||
(errorStatus == SnmpDefinitions.snmpRspAuthorizationError)){
return SnmpDefinitions.snmpRspNoSuchName;
} else if ((errorStatus ==
SnmpDefinitions.snmpRspAuthorizationError) ||
(errorStatus == SnmpDefinitions.snmpRspNotWritable)) {
if (reqPduType == SnmpDefinitions.pduWalkRequest)
return SnmpDefinitions.snmpRspReadOnly;
else
return SnmpDefinitions.snmpRspNoSuchName;
} else if ((errorStatus == SnmpDefinitions.snmpRspNoCreation)) {
return SnmpDefinitions.snmpRspNoSuchName;
} else if ((errorStatus == SnmpDefinitions.snmpRspWrongType) ||
(errorStatus == SnmpDefinitions.snmpRspWrongLength) ||
(errorStatus == SnmpDefinitions.snmpRspWrongEncoding) ||
(errorStatus == SnmpDefinitions.snmpRspWrongValue) ||
(errorStatus == SnmpDefinitions.snmpRspWrongLength) ||
(errorStatus ==
SnmpDefinitions.snmpRspInconsistentValue)) {
if ((reqPduType == SnmpDefinitions.pduSetRequestPdu) ||
(reqPduType == SnmpDefinitions.pduWalkRequest))
return SnmpDefinitions.snmpRspBadValue;
else
return SnmpDefinitions.snmpRspNoSuchName;
} else if ((errorStatus ==
SnmpDefinitions.snmpRspResourceUnavailable) ||
(errorStatus ==
SnmpDefinitions.snmpRspCommitFailed) ||
(errorStatus == SnmpDefinitions.snmpRspUndoFailed)) {
return SnmpDefinitions.snmpRspGenErr;
}
// At this point we should have a V1 error code
//
if (errorStatus == SnmpDefinitions.snmpRspTooBig)
return SnmpDefinitions.snmpRspTooBig;
if( (errorStatus == SnmpDefinitions.snmpRspBadValue) ||
(errorStatus == SnmpDefinitions.snmpRspReadOnly)) {
if ((reqPduType == SnmpDefinitions.pduSetRequestPdu) ||
(reqPduType == SnmpDefinitions.pduWalkRequest))
return errorStatus;
else
return SnmpDefinitions.snmpRspNoSuchName;
}
// We have a snmpRspGenErr, or something which is not defined
// in RFC1905 => return a snmpRspGenErr
//
return SnmpDefinitions.snmpRspGenErr;
}
// -------------------------------------------------------------
//
// This function does a best-effort to map global error status
// to SNMP v2 valid global error status.
//
// An SnmpStatusException can contain either:
// <li> v2 local error codes (that should be stored in the varbind)</li>
// <li> v2 global error codes </li>
// <li> v1 global error codes </li>
//
// v2 local error codes (noSuchInstance, noSuchObject)
// should not raise this level: they should have been stored in the
// varbind earlier. If they, do there is nothing much we can do except
// to transform them into:
// <li> a global snmpRspGenErr (if the request is a GET/GETNEXT) </li>
// <li> a global snmpRspNoSuchName otherwise. </li>
//
// v2 global error codes are transformed in the following way:
//
// If the request was a GET/GETNEXT then snmpRspGenErr is returned.
// (snmpRspGenErr is the only global error that is expected to be
// raised by a GET/GETNEXT request).
//
// Otherwise the v2 code itself is returned
//
// v1 global error codes are transformed in the following way:
//
// snmpRspNoSuchName
// => snmpRspNoAccess (snmpRspGenErr for GET/GETNEXT)
// snmpRspReadOnly
// => snmpRspNotWritable (snmpRspGenErr for GET/GETNEXT)
// snmpRspBadValue
// => snmpRspWrongValue (snmpRspGenErr for GET/GETNEXT)
//
// -------------------------------------------------------------
//
static final int mapErrorStatusToV2(int errorStatus, int reqPduType) {
// Map v1 codes onto v2 codes
//
if (errorStatus == SnmpDefinitions.snmpRspNoError)
return SnmpDefinitions.snmpRspNoError;
if (errorStatus == SnmpDefinitions.snmpRspGenErr)
return SnmpDefinitions.snmpRspGenErr;
if (errorStatus == SnmpDefinitions.snmpRspTooBig)
return SnmpDefinitions.snmpRspTooBig;
// For get / getNext / getBulk the only global error
// (PDU-level) possible is genErr.
//
if ((reqPduType != SnmpDefinitions.pduSetRequestPdu) &&
(reqPduType != SnmpDefinitions.pduWalkRequest)) {
if(errorStatus == SnmpDefinitions.snmpRspAuthorizationError)
return errorStatus;
else
return SnmpDefinitions.snmpRspGenErr;
}
// Map to noSuchName
// if ((errorStatus == SnmpDefinitions.snmpRspNoSuchName) ||
// (errorStatus == SnmpStatusException.noSuchInstance) ||
// (errorStatus == SnmpStatusException.noSuchObject))
// return SnmpDefinitions.snmpRspNoSuchName;
// SnmpStatusException.noSuchInstance and
// SnmpStatusException.noSuchObject can't happen...
if (errorStatus == SnmpDefinitions.snmpRspNoSuchName)
return SnmpDefinitions.snmpRspNoAccess;
// Map to notWritable
if (errorStatus == SnmpDefinitions.snmpRspReadOnly)
return SnmpDefinitions.snmpRspNotWritable;
// Map to wrongValue
if (errorStatus == SnmpDefinitions.snmpRspBadValue)
return SnmpDefinitions.snmpRspWrongValue;
// Other valid V2 codes
if ((errorStatus == SnmpDefinitions.snmpRspNoAccess) ||
(errorStatus == SnmpDefinitions.snmpRspInconsistentName) ||
(errorStatus == SnmpDefinitions.snmpRspAuthorizationError) ||
(errorStatus == SnmpDefinitions.snmpRspNotWritable) ||
(errorStatus == SnmpDefinitions.snmpRspNoCreation) ||
(errorStatus == SnmpDefinitions.snmpRspWrongType) ||
(errorStatus == SnmpDefinitions.snmpRspWrongLength) ||
(errorStatus == SnmpDefinitions.snmpRspWrongEncoding) ||
(errorStatus == SnmpDefinitions.snmpRspWrongValue) ||
(errorStatus == SnmpDefinitions.snmpRspWrongLength) ||
(errorStatus == SnmpDefinitions.snmpRspInconsistentValue) ||
(errorStatus == SnmpDefinitions.snmpRspResourceUnavailable) ||
(errorStatus == SnmpDefinitions.snmpRspCommitFailed) ||
(errorStatus == SnmpDefinitions.snmpRspUndoFailed))
return errorStatus;
// Ivalid V2 code => genErr
return SnmpDefinitions.snmpRspGenErr;
}
static final int mapErrorStatus(int errorStatus,
int protocolVersion,
int reqPduType) {
if (errorStatus == SnmpDefinitions.snmpRspNoError)
return SnmpDefinitions.snmpRspNoError;
// Too bad, an error occurs ... we need to translate it ...
//
if (protocolVersion == SnmpDefinitions.snmpVersionOne)
return mapErrorStatusToV1(errorStatus,reqPduType);
if (protocolVersion == SnmpDefinitions.snmpVersionTwo ||
protocolVersion == SnmpDefinitions.snmpVersionThree)
return mapErrorStatusToV2(errorStatus,reqPduType);
return SnmpDefinitions.snmpRspGenErr;
}
/**
* The method returns the error status of the operation.
* The method takes into account the protocol version.
*/
protected int getErrorStatus() {
if (errorStatus == snmpRspNoError)
return snmpRspNoError;
return mapErrorStatus(errorStatus,version,type);
}
/**
* The method returns the error index as a position in the var bind list.
* The value returned by the method corresponds to the index in the original
* var bind list as received by the SNMP protocol adaptor.
*/
protected int getErrorIndex() {
if (errorStatus == snmpRspNoError)
return -1;
// An error occurs. We need to be carefull because the index
// we are getting is a valid SNMP index (so range starts at 1).
// FIX ME: Shall we double-check the range here ?
// The response is : YES :
if ((errorIndex == 0) || (errorIndex == -1))
errorIndex = 1;
return translation[errorIndex -1];
}
/**
* The method updates the varbind list of the subrequest.
*/
protected void updateRequest(SnmpVarBind var, int pos) {
int size= varBind.size();
translation[size]= pos;
varBind.addElement(var);
}
/**
* The method updates a given var bind list with the result of a
* previsouly invoked operation.
* Prior to calling the method, one must make sure that the operation was
* successful. As such the method getErrorIndex or getErrorStatus should be
* called.
*/
protected void updateResult(SnmpVarBind[] result) {
if (result == null) return;
final int max=varBind.size();
final int len=result.length;
for(int i= 0; i< max ; i++) {
// bugId 4641694: must check position in order to avoid
// ArrayIndexOutOfBoundException
final int pos=translation[i];
if (pos < len) {
result[pos] =
(SnmpVarBind)((NonSyncVector)varBind).elementAtNonSync(i);
} else {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(),
"updateResult","Position `"+pos+"' is out of bound...");
}
}
}
}
private void init(SnmpEngine engine,
SnmpIncomingRequest incRequest) {
this.incRequest = incRequest;
this.engine = engine;
}
// PRIVATE VARIABLES
//------------------
/**
* Store the protocol version to handle
*/
protected int version= snmpVersionOne;
/**
* Store the operation type. Remember if the type is Walk, it means
* that we have to invoke the check method ...
*/
protected int type= 0;
/**
* Agent directly handled by the sub-request handler.
*/
protected SnmpMibAgent agent;
/**
* Error status.
*/
protected int errorStatus= snmpRspNoError;
/**
* Index of error.
* A value of -1 means no error.
*/
protected int errorIndex= -1;
/**
* The varbind list specific to the current sub request.
* The vector must contain object of type SnmpVarBind.
*/
protected Vector<SnmpVarBind> varBind;
/**
* The array giving the index translation between the content of
* <VAR>varBind</VAR> and the varbind list as specified in the request.
*/
protected int[] translation;
/**
* Contextual object allocated by the SnmpUserDataFactory.
**/
protected Object data;
/**
* The SnmpMibRequest that will be passed to the agent.
*
**/
private SnmpMibRequest mibRequest = null;
/**
* The SnmpPdu that will be passed to the request.
*
**/
private SnmpPdu reqPdu = null;
// All the methods of the Vector class are synchronized.
// Synchronization is a very expensive operation. In our case it is not always
// required...
//
@SuppressWarnings("serial") // we never serialize this
class NonSyncVector<E> extends Vector<E> {
public NonSyncVector(int size) {
super(size);
}
final void addNonSyncElement(E obj) {
ensureCapacity(elementCount + 1);
elementData[elementCount++] = obj;
}
@SuppressWarnings("unchecked") // cast to E
final E elementAtNonSync(int index) {
return (E) elementData[index];
}
};
}