FileDocCategorySizeDatePackage
SnmpAdaptorServer.javaAPI DocJava SE 5 API84283Fri Aug 26 14:55:06 BST 2005com.sun.jmx.snmp.daemon

SnmpAdaptorServer

public class SnmpAdaptorServer extends CommunicatorServer implements com.sun.jmx.snmp.agent.SnmpMibHandler, SnmpAdaptorServerMBean, com.sun.jmx.snmp.SnmpDefinitions, MBeanRegistration
Implements an adaptor on top of the SNMP protocol.

When this SNMP protocol adaptor is started it creates a datagram socket and is able to receive requests and send traps or inform requests. When it is stopped, the socket is closed and neither requests and nor traps/inform request are processed.

The default port number of the socket is 161. This default value can be changed by specifying a port number:

  • in the object constructor
  • using the {@link com.sun.jmx.snmp.daemon.CommunicatorServer#setPort setPort} method before starting the adaptor
The default object name is defined by {@link com.sun.jmx.snmp.ServiceName#DOMAIN com.sun.jmx.snmp.ServiceName.DOMAIN} and {@link com.sun.jmx.snmp.ServiceName#SNMP_ADAPTOR_SERVER com.sun.jmx.snmp.ServiceName.SNMP_ADAPTOR_SERVER}.

The SNMP protocol adaptor supports versions 1 and 2 of the SNMP protocol in a stateless way: when it receives a v1 request, it replies with a v1 response, when it receives a v2 request it replies with a v2 response.
The method {@link #snmpV1Trap snmpV1Trap} sends traps using SNMP v1 format. The method {@link #snmpV2Trap snmpV2Trap} sends traps using SNMP v2 format. The method {@link #snmpInformRequest snmpInformRequest} sends inform requests using SNMP v2 format.

To receive data packets, the SNMP protocol adaptor uses a buffer which size can be configured using the property bufferSize (default value is 1024). Packets which do not fit into the buffer are rejected. Increasing bufferSize allows the exchange of bigger packets. However, the underlying networking system may impose a limit on the size of UDP packets. Packets which size exceed this limit will be rejected, no matter what the value of bufferSize actually is.

An SNMP protocol adaptor may serve several managers concurrently. The number of concurrent managers can be limited using the property maxActiveClientCount.

The SNMP protocol adaptor specifies a default value (10) for the maxActiveClientCount property. When the adaptor is stopped, the active requests are interrupted and an error result is sent to the managers.

This API is a Sun Microsystems internal API and is subject to change without notice.

Fields Summary
private int
trapPort
Port number for sending SNMP traps.
The default value is 162.
private int
informPort
Port number for sending SNMP inform requests.
The default value is 162.
InetAddress
address
The InetAddress used when creating the datagram socket.
It is specified when creating the SNMP protocol adaptor. If not specified, the local host machine is used.
private Object
ipacl
The IP address based ACL used by this SNMP protocol adaptor.
private com.sun.jmx.snmp.SnmpPduFactory
pduFactory
The factory object.
private com.sun.jmx.snmp.agent.SnmpUserDataFactory
userDataFactory
The user-data factory object.
private boolean
authRespEnabled
Indicates if the SNMP protocol adaptor sends a response in case of authentication failure
private boolean
authTrapEnabled
Indicates if authentication traps are enabled.
private com.sun.jmx.snmp.SnmpOid
enterpriseOid
The enterprise OID.
The default value is "1.3.6.1.4.1.42".
int
bufferSize
The buffer size of the SNMP protocol adaptor. This buffer size is used for both incoming request and outgoing inform requests.
The default value is 1024.
private transient long
startUpTime
private transient DatagramSocket
socket
transient DatagramSocket
trapSocket
private transient SnmpSession
informSession
private transient DatagramPacket
packet
transient Vector
mibs
private transient SnmpMibTree
root
private transient boolean
useAcl
Whether ACL must be used.
private int
maxTries
Number of times to try an inform request before giving up. The default number is 3.
private int
timeout
The amount of time to wait for an inform response from the manager. The default amount of time is 3000 millisec.
int
snmpOutTraps
The snmpOutTraps value defined in MIB-II.
private int
snmpOutGetResponses
The snmpOutGetResponses value defined in MIB-II.
private int
snmpOutGenErrs
The snmpOutGenErrs value defined in MIB-II.
private int
snmpOutBadValues
The snmpOutBadValues value defined in MIB-II.
private int
snmpOutNoSuchNames
The snmpOutNoSuchNames value defined in MIB-II.
private int
snmpOutTooBigs
The snmpOutTooBigs value defined in MIB-II.
int
snmpOutPkts
The snmpOutPkts value defined in MIB-II.
private int
snmpInASNParseErrs
The snmpInASNParseErrs value defined in MIB-II.
private int
snmpInBadCommunityUses
The snmpInBadCommunityUses value defined in MIB-II.
private int
snmpInBadCommunityNames
The snmpInBadCommunityNames value defined in MIB-II.
private int
snmpInBadVersions
The snmpInBadVersions value defined in MIB-II.
private int
snmpInGetRequests
The snmpInGetRequests value defined in MIB-II.
private int
snmpInGetNexts
The snmpInGetNexts value defined in MIB-II.
private int
snmpInSetRequests
The snmpInSetRequests value defined in MIB-II.
private int
snmpInPkts
The snmpInPkts value defined in MIB-II.
private int
snmpInTotalReqVars
The snmpInTotalReqVars value defined in MIB-II.
private int
snmpInTotalSetVars
The snmpInTotalSetVars value defined in MIB-II.
private int
snmpSilentDrops
The snmpInTotalSetVars value defined in rfc 1907 MIB-II.
private static final String
InterruptSysCallMsg
static final com.sun.jmx.snmp.SnmpOid
sysUpTimeOid
static final com.sun.jmx.snmp.SnmpOid
snmpTrapOidOid
private com.sun.jmx.snmp.tasks.ThreadService
threadService
private static int
threadNumber
Constructors Summary
public SnmpAdaptorServer()
Initializes this SNMP protocol adaptor using the default port (161). Use the {@link com.sun.jmx.snmp.IPAcl.SnmpAcl} default implementation of the InetAddressAcl interface.


     
	String s = System.getProperty("com.sun.jmx.snmp.threadnumber");

	if (s != null) {
	    try {
		threadNumber = Integer.parseInt(System.getProperty(s));
	    } catch (Exception e) {
		// ???
		System.err.println("Got wrong value for " +
				   "com.sun.jmx.snmp.threadnumber: "+s);
		System.err.println("Use the default value: "+threadNumber);
	    }
	}
    
        this(true, null, com.sun.jmx.snmp.ServiceName.SNMP_ADAPTOR_PORT, 
	     null) ;
    
private SnmpAdaptorServer(boolean forceAcl, com.sun.jmx.snmp.InetAddressAcl acl, int port, InetAddress addr)

        super(CommunicatorServer.SNMP_TYPE) ;
	
        
        // Initialize the ACL implementation.
        //
        if (acl == null && forceAcl) {
            try {
                acl = (InetAddressAcl) 
		    new SnmpAcl("SNMP protocol adaptor IP ACL");
            } catch (UnknownHostException e) {
                if (isDebugOn()) {
                    debug("constructor", 
			  "UnknowHostException when creating ACL");
                    debug("constructor", e);
                }
            }
        } else {
	    this.useAcl = (acl!=null) || forceAcl;
	}

        init(acl, port, addr) ;
    
public SnmpAdaptorServer(int port)
Initializes this SNMP protocol adaptor using the specified port. Use the {@link com.sun.jmx.snmp.IPAcl.SnmpAcl} default implementation of the InetAddressAcl interface.

param
port The port number for sending SNMP responses.

        this(true, null, port, null) ;
    
public SnmpAdaptorServer(com.sun.jmx.snmp.InetAddressAcl acl)
Initializes this SNMP protocol adaptor using the default port (161) and the specified IP address based ACL implementation.

param
acl The InetAddressAcl implementation. null means no ACL - everybody is authorized.
since
1.5

        this(false, acl, com.sun.jmx.snmp.ServiceName.SNMP_ADAPTOR_PORT, 
	     null) ;
    
public SnmpAdaptorServer(InetAddress addr)
Initializes this SNMP protocol adaptor using the default port (161) and the specified InetAddress. Use the {@link com.sun.jmx.snmp.IPAcl.SnmpAcl} default implementation of the InetAddressAcl interface.

param
addr The IP address to bind.

        this(true, null, com.sun.jmx.snmp.ServiceName.SNMP_ADAPTOR_PORT, 
	     addr) ;
    
public SnmpAdaptorServer(com.sun.jmx.snmp.InetAddressAcl acl, int port)
Initializes this SNMP protocol adaptor using the specified port and the specified IP address based ACL implementation.

param
acl The InetAddressAcl implementation. null means no ACL - everybody is authorized.
param
port The port number for sending SNMP responses.
since
1.5

        this(false, acl, port, null) ;
    
public SnmpAdaptorServer(int port, InetAddress addr)
Initializes this SNMP protocol adaptor using the specified port and the specified InetAddress. Use the {@link com.sun.jmx.snmp.IPAcl.SnmpAcl} default implementation of the InetAddressAcl interface.

param
port The port number for sending SNMP responses.
param
addr The IP address to bind.

        this(true, null, port, addr) ;
    
public SnmpAdaptorServer(com.sun.jmx.snmp.InetAddressAcl acl, InetAddress addr)
Initializes this SNMP protocol adaptor using the specified IP address based ACL implementation and the specified InetAddress.

param
acl The InetAddressAcl implementation.
param
addr The IP address to bind.
since
1.5

        this(false, acl, com.sun.jmx.snmp.ServiceName.SNMP_ADAPTOR_PORT,
	     addr) ;
    
public SnmpAdaptorServer(com.sun.jmx.snmp.InetAddressAcl acl, int port, InetAddress addr)
Initializes this SNMP protocol adaptor using the specified port, the specified address based ACL implementation and the specified InetAddress.

param
acl The InetAddressAcl implementation.
param
port The port number for sending SNMP responses.
param
addr The IP address to bind.
since
1.5

        this(false, acl, port, addr);
    
public SnmpAdaptorServer(boolean useAcl, int port, InetAddress addr)
Initializes this SNMP protocol adaptor using the specified port and the specified InetAddress. This constructor allows to initialize an SNMP adaptor without using the ACL mechanism (by setting the useAcl parameter to false).
This constructor must be used in particular with a platform that does not support the java.security.acl package like pJava.

param
useAcl Specifies if this new SNMP adaptor uses the ACL mechanism. If the specified parameter is set to true, this constructor is equivalent to SnmpAdaptorServer((int)port,(InetAddress)addr).
param
port The port number for sending SNMP responses.
param
addr The IP address to bind.

	this(useAcl,null,port,addr);
    
Methods Summary
public com.sun.jmx.snmp.agent.SnmpMibHandleraddMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib)
Adds a new MIB in the SNMP MIB handler.

param
mib The MIB to add.
return
A reference to the SNMP MIB handler.
exception
IllegalArgumentException If the parameter is null.

        if (mib == null) {
            throw new IllegalArgumentException() ;
        }
	
	if(!mibs.contains(mib))
	    mibs.addElement(mib);

        root.register(mib);
    
        return this;
    
public com.sun.jmx.snmp.agent.SnmpMibHandleraddMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib, com.sun.jmx.snmp.SnmpOid[] oids)
Adds a new MIB in the SNMP MIB handler. This method is to be called to set a specific agent to a specific OID. This can be useful when dealing with MIB overlapping. Some OID can be implemented in more than one MIB. In this case, the OID nearer agent will be used on SNMP operations.

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

	if (mib == null) {
	    throw new IllegalArgumentException() ;
	}
	
	//If null oid array, just add it to the mib.
	if(oids == null) 
	    return addMib(mib);
	
	if(!mibs.contains(mib))
	    mibs.addElement(mib);
	
	for (int i = 0; i < oids.length; i++) {
	    root.register(mib, oids[i].longValue());
	}
	return this;
    
public com.sun.jmx.snmp.agent.SnmpMibHandleraddMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib, java.lang.String contextName)
Adds a new MIB in the SNMP MIB handler. In SNMP V1 and V2 the contextName is useless and this method is equivalent to addMib(SnmpMibAgent mib).

param
mib The MIB to add.
param
contextName The MIB context name.
return
A reference on the SNMP MIB handler.
exception
IllegalArgumentException If the parameter is null.
since
1.5

	return addMib(mib);
    
public com.sun.jmx.snmp.agent.SnmpMibHandleraddMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib, java.lang.String contextName, com.sun.jmx.snmp.SnmpOid[] oids)
Adds a new MIB in the SNMP MIB handler. In SNMP V1 and V2 the contextName is useless and this method is equivalent to addMib(SnmpMibAgent mib, SnmpOid[] oids).

param
mib The MIB to add.
param
contextName The MIB context. If null is passed, will be registered in the default context.
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

	return addMib(mib, oids);
    
synchronized voidcloseInformSocketIfNeeded()
Close informSocket if the SNMP protocol adaptor is not ONLINE.

        if ((informSession != null) && (state != ONLINE)) {
            informSession.destroySession() ;
            informSession = null ;
        }
    
synchronized voidcloseTrapSocketIfNeeded()
Close trapSocket if the SNMP protocol adaptor is not ONLINE.

        if ((trapSocket != null) && (state != ONLINE)) {
            trapSocket.close() ;
            trapSocket = null ;
        }
    
protected java.lang.ThreadcreateMainThread()

	final Thread t = super.createMainThread();
	t.setDaemon(true);
	return t;
    
voidcreateSnmpRequestHandler(com.sun.jmx.snmp.daemon.SnmpAdaptorServer server, int id, java.net.DatagramSocket s, java.net.DatagramPacket p, SnmpMibTree tree, java.util.Vector m, java.lang.Object a, com.sun.jmx.snmp.SnmpPduFactory factory, com.sun.jmx.snmp.agent.SnmpUserDataFactory dataFactory, javax.management.MBeanServer f, javax.management.ObjectName n)

	final SnmpRequestHandler handler = 
	    new SnmpRequestHandler(this, id, s, p, tree, m, a, factory,
				   dataFactory, f, n);
	threadService.submitTask(handler);
    
protected voiddoBind()
Creates the datagram socket.


        try {
	    synchronized (this) {
		socket = new DatagramSocket(port, address) ;
	    }
	    dbgTag = makeDebugTag();
        } catch (SocketException e) {
            if (e.getMessage().equals(InterruptSysCallMsg))
                throw new InterruptedException(e.toString()) ;
            else {
                if (isDebugOn()) {
                    debug("doBind", "cannot bind on port " + port);
                }
                throw new CommunicationException(e) ;
            }
        }
    
protected voiddoError(java.lang.Exception e)

        return;
    
protected voiddoProcess()
Not used in this context.

    
protected voiddoReceive()
Reads a packet from the datagram socket and creates a request handler which decodes and processes the request.


        // Let's wait for something to be received.
        //
        try {
            packet = new DatagramPacket(new byte[bufferSize], bufferSize) ;
            socket.receive(packet);
	    int state = getState();
	    
	    if(state != ONLINE) {
		if (isTraceOn()) {
		    trace("doReceive", 
		       "received a message but state not online, returning.");
		}
		return;
	    }
	    
	    createSnmpRequestHandler(this, servedClientCount, socket, 
				     packet, root, mibs, ipacl, pduFactory,
				     userDataFactory, topMBS, objectName);
        } catch (SocketException e) {
            // Let's check if we have been interrupted by stop().
            //
            if (e.getMessage().equals(InterruptSysCallMsg))
                throw new InterruptedException(e.toString()) ;
            else
                throw new CommunicationException(e) ;
        } catch (InterruptedIOException e) {
            throw new InterruptedException(e.toString()) ;
        } catch (CommunicationException e) {
            throw e ;
        } catch (Exception e) {
            throw new CommunicationException(e) ;
        }
        if (isTraceOn()) {
            trace("doReceive", "received a message");
        }
    
protected voiddoUnbind()
Closes the datagram socket.

        if (isTraceOn()) {
            trace("doUnbind","Finally close the socket");
        }
	synchronized (this) {
	    if (socket != null) {
		socket.close() ;
		socket = null ; 
		// Important to inform finalize() that the socket is closed...
	    }
	}
        closeTrapSocketIfNeeded() ;
        closeInformSocketIfNeeded() ;
    
protected voidfinalize()
Finalizer of the SNMP protocol adaptor objects. This method is called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

Closes the datagram socket associated to this SNMP protocol adaptor.

	try {
	    if (socket != null) {
		socket.close() ;
		socket = null ;
	    }

	    threadService.terminate();
	} catch (Exception e) {
	    trace("finalize","Exception in finalizer: " +e);
	}
    
public intgetActiveClientCount()
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.

        return super.getActiveClientCount();
    
java.net.InetAddressgetAddress()
Gets the IP address to bind. This getter is used to initialize the DatagramSocket in the SnmpSocket object created for the inform request stuff.

        return address;
    
com.sun.jmx.snmp.agent.SnmpMibAgentgetAgentMib(com.sun.jmx.snmp.SnmpOid oid)

	return root.getAgentMib(oid);
    
public booleangetAuthRespEnabled()
Returns true if this SNMP protocol adaptor sends a response in case of authentication failure.

When this feature is enabled, the SNMP protocol adaptor sends a response with noSuchName or readOnly when the authentication failed. If the flag is disabled, the SNMP protocol adaptor trashes the PDU silently.

The default behavior is to send responses.

return
true if responses are sent.

        return authRespEnabled ;
    
public booleangetAuthTrapEnabled()
Returns true if authentication traps are enabled.

When this feature is enabled, the SNMP protocol adaptor sends an authenticationFailure trap each time an authentication fails.

The default behaviour is to send authentication traps.

return
true if authentication traps are enabled, false otherwise.

        return authTrapEnabled ;
    
protected intgetBindTries()
The number of times the communicator server will attempt to bind before giving up. We attempt only once...

return
1

	return 1;
    
public java.lang.IntegergetBufferSize()
Returns the buffer size of this SNMP protocol adaptor. This buffer size is used for both incoming request and outgoing inform requests. By default, buffer size 1024 is used.

return
The buffer size.

        return new Integer(bufferSize) ;
    
public java.lang.StringgetEnterpriseOid()
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".

        return enterpriseOid.toString() ;
    
public com.sun.jmx.snmp.InetAddressAclgetInetAddressAcl()
Returns the Ip address based ACL used by this SNMP protocol adaptor.

return
The InetAddressAcl implementation.
since
1.5

	return (InetAddressAcl)ipacl;	
    
public intgetInformPort()
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.

        return informPort;
    
public intgetMaxActiveClientCount()
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.

        return super.getMaxActiveClientCount();
    
public final intgetMaxTries()
Gets the number of times to try sending an inform request before giving up. By default, a maximum of 3 tries is used.

return
The maximun number of tries.

        return maxTries;
    
public java.lang.String[]getMibs()
Returns the names of the MIBs available in this SNMP protocol adaptor.

return
An array of MIB names.

        String[] result = new String[mibs.size()] ;
        int i = 0 ;
        for (Enumeration e = mibs.elements() ; e.hasMoreElements() ;) {
            SnmpMibAgent mib = (SnmpMibAgent)e.nextElement() ;
            result[i++] = mib.getMibName();
        }
        return result ;
    
public com.sun.jmx.snmp.SnmpPduFactorygetPduFactory()
Returns the message factory of this SNMP protocol adaptor.

return
The factory object.

        return pduFactory ;
    
public intgetPort()
Return the actual port to which the adaptor is bound. Can be different from the port given at construction time if that port number was 0.

return
the actual port to which the adaptor is bound.

	synchronized (this) {
	    if (socket != null) return socket.getLocalPort();
	}
	return super.getPort();
    
public java.lang.StringgetProtocol()
Returns the protocol of this SNMP protocol adaptor.

return
The string "snmp".

        return "snmp";
    
public intgetServedClientCount()
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 stop method.

        return super.getServedClientCount();
    
public java.lang.LonggetSnmpInASNParseErrs()
Returns the snmpInASNParseErrs value defined in MIB-II.

return
The snmpInASNParseErrs value.

        return new Long(snmpInASNParseErrs);
    
public java.lang.LonggetSnmpInBadCommunityNames()
Returns the snmpInBadCommunityNames value defined in MIB-II.

return
The snmpInBadCommunityNames value.

        return new Long(snmpInBadCommunityNames);
    
public java.lang.LonggetSnmpInBadCommunityUses()
Returns the snmpInBadCommunityUses value defined in MIB-II.

return
The snmpInBadCommunityUses value.

        return new Long(snmpInBadCommunityUses);
    
public java.lang.LonggetSnmpInBadVersions()
Returns the snmpInBadVersions value defined in MIB-II.

return
The snmpInBadVersions value.

        return new Long(snmpInBadVersions);
    
public java.lang.LonggetSnmpInGetNexts()
Returns the snmpInGetNexts value defined in MIB-II.

return
The snmpInGetNexts value.

        return new Long(snmpInGetNexts);
    
public java.lang.LonggetSnmpInGetRequests()
Returns the snmpInGetRequests value defined in MIB-II.

return
The snmpInGetRequests value.

        return new Long(snmpInGetRequests);
    
public java.lang.LonggetSnmpInPkts()
Returns the snmpInPkts value defined in MIB-II.

return
The snmpInPkts value.

        return new Long(snmpInPkts);
    
public java.lang.LonggetSnmpInSetRequests()
Returns the snmpInSetRequests value defined in MIB-II.

return
The snmpInSetRequests value.

        return new Long(snmpInSetRequests);
    
public java.lang.LonggetSnmpInTotalReqVars()
Returns the snmpInTotalReqVars value defined in MIB-II.

return
The snmpInTotalReqVars value.

        return new Long(snmpInTotalReqVars);
    
public java.lang.LonggetSnmpInTotalSetVars()
Returns the snmpInTotalSetVars value defined in MIB-II.

return
The snmpInTotalSetVars value.

        return new Long(snmpInTotalSetVars);
    
public java.lang.LonggetSnmpOutBadValues()
Returns the snmpOutBadValues value defined in MIB-II.

return
The snmpOutBadValues value.

        return new Long(snmpOutBadValues);
    
public java.lang.LonggetSnmpOutGenErrs()
Returns the snmpOutGenErrs value defined in MIB-II.

return
The snmpOutGenErrs value.

        return new Long(snmpOutGenErrs);
    
public java.lang.LonggetSnmpOutGetResponses()
Returns the snmpOutGetResponses value defined in MIB-II.

return
The snmpOutGetResponses value.

        return new Long(snmpOutGetResponses);
    
public java.lang.LonggetSnmpOutNoSuchNames()
Returns the snmpOutNoSuchNames value defined in MIB-II.

return
The snmpOutNoSuchNames value.

        return new Long(snmpOutNoSuchNames);
    
public java.lang.LonggetSnmpOutPkts()
Returns the snmpOutPkts value defined in MIB-II.

return
The snmpOutPkts value.

        return new Long(snmpOutPkts);
    
public java.lang.LonggetSnmpOutTooBigs()
Returns the snmpOutTooBigs value defined in MIB-II.

return
The snmpOutTooBigs value.

        return new Long(snmpOutTooBigs);
    
public java.lang.LonggetSnmpOutTraps()
Returns the snmpOutTraps value defined in MIB-II.

return
The snmpOutTraps value.

        return new Long(snmpOutTraps);
    
public java.lang.LonggetSnmpProxyDrops()
Returns the snmpProxyDrops value defined in RFC 1907 NMPv2-MIB .

return
The snmpProxyDrops value.
since
1.5

        return new Long(0);
    
public java.lang.LonggetSnmpSilentDrops()
Returns the snmpSilentDrops value defined in RFC 1907 NMPv2-MIB .

return
The snmpSilentDrops value.
since
1.5

        return new Long(snmpSilentDrops);
    
longgetSysUpTime()
Returns the time (in hundreths of second) elapsed since the SNMP protocol adaptor startup.

        return (System.currentTimeMillis() - startUpTime) / 10 ;
    
public final intgetTimeout()
Gets the timeout to wait for an inform response from the manager. By default, a timeout of 3 seconds is used.

return
The value of the timeout property.

        return timeout;
    
public java.lang.IntegergetTrapPort()
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.

        return new Integer(trapPort) ;
    
public com.sun.jmx.snmp.agent.SnmpUserDataFactorygetUserDataFactory()
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

	return userDataFactory;
    
private com.sun.jmx.snmp.SnmpIpAddresshandleMultipleIpVersion(byte[] address)

	if(address.length == 4)
	  return new SnmpIpAddress(address);
	else {
	    if(isDebugOn())
		debug("handleMultipleIPVersion", 
		      "Not an IPv4 address, return null");
	    return null;
	}
    
voidincSnmpInASNParseErrs(int n)

        snmpInASNParseErrs += n ;
    
voidincSnmpInBadCommunityNames(int n)

        snmpInBadCommunityNames += n ;
    
voidincSnmpInBadCommunityUses(int n)

        snmpInBadCommunityUses += n ;
    
voidincSnmpInBadVersions(int n)

        snmpInBadVersions += n ;
    
voidincSnmpSilentDrops(int n)

        snmpSilentDrops += n ;
    
private voidinit(java.lang.Object acl, int p, java.net.InetAddress a)
Common initializations.

  
        root= new SnmpMibTree();

	// The default Agent is initialized with a SnmpErrorHandlerAgent agent.
	root.setDefaultAgent(new SnmpErrorHandlerAgent());

        // For the trap time, use the time the agent started ...
        //
        startUpTime= java.lang.System.currentTimeMillis();
        maxActiveClientCount = 10;
    
        // Create the default message factory
        pduFactory = new SnmpPduFactoryBER() ;

        port = p ;
        ipacl = acl ;
        address = a ;
    
        if ((ipacl == null) && (useAcl == true))
            throw new IllegalArgumentException("ACL object cannot be null") ;

	threadService = new ThreadService(threadNumber);
    
java.lang.StringmakeDebugTag()
Returns the string used in debug traces.

        return "SnmpAdaptorServer["+ getProtocol() + ":" + getPort() + "]";    
    
public static final intmapErrorStatus(int errorStatus, int protocolVersion, int reqPduType)
Method that maps an SNMP error status in the passed protocolVersion according to the provided pdu type.

param
errorStatus The error status to convert.
param
protocolVersion The protocol version.
param
reqPduType The pdu type.

	return SnmpSubRequestHandler.mapErrorStatus(errorStatus,
						    protocolVersion,
						    reqPduType);
    
synchronized voidopenInformSocketIfNeeded()
Open informSocket if it's not already done.

        if (informSession == null) {
            informSession = new SnmpSession(this) ;
            if (isTraceOn()) {
                trace("openInformSocketIfNeeded", 
		      "to send inform requests and receive inform responses");
            }
        }
    
synchronized voidopenTrapSocketIfNeeded()
Open trapSocket if it's not already done.

        if (trapSocket == null) {
            trapSocket = new DatagramSocket(0, address) ;
            if (isTraceOn()) {
                trace("openTrapSocketIfNeeded", "using port " + 
		      trapSocket.getLocalPort() + " to send traps");
            }
        }
    
public voidpostDeregister()
Not used in this context.

        super.postDeregister();
    
public voidpostRegister(java.lang.Boolean registrationDone)
Not used in this context.

        super.postRegister(registrationDone);
    
public voidpreDeregister()
Not used in this context.

        super.preDeregister();
    
public javax.management.ObjectNamepreRegister(javax.management.MBeanServer server, javax.management.ObjectName name)
Allows the MBean to perform any operations it needs before being registered in the MBean server. If the name of the SNMP protocol adaptor MBean is not specified, it is initialized with the default value: {@link com.sun.jmx.snmp.ServiceName#DOMAIN com.sun.jmx.snmp.ServiceName.DOMAIN}:{@link com.sun.jmx.snmp.ServiceName#SNMP_ADAPTOR_SERVER com.sun.jmx.snmp.ServiceName.SNMP_ADAPTOR_SERVER}. If any exception is raised, the SNMP protocol adaptor MBean will not be registered in the MBean server.

param
server The MBean server to register the service with.
param
name The object name.
return
The name of the SNMP protocol adaptor registered.
exception
java.lang.Exception


        if (name == null) {
            name = new ObjectName(server.getDefaultDomain() + ":" + 
			     com.sun.jmx.snmp.ServiceName.SNMP_ADAPTOR_SERVER);
        }
        return (super.preRegister(server, name));
    
private voidreadObject(java.io.ObjectInputStream stream)
Control the way the SnmpAdaptorServer service is deserialized.

      
        // Call the default deserialization of the object.
        //
        stream.defaultReadObject();
      
        // Call the specific initialization for the SnmpAdaptorServer service.
        // This is for transient structures to be initialized to specific 
	// default values.
        //
        mibs      = new Vector() ;
    
public booleanremoveMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib, java.lang.String contextName)
Removes the specified MIB from the SNMP protocol adaptor. In SNMP V1 and V2 the contextName is useless and this method is equivalent to removeMib(SnmpMibAgent mib).

param
mib The MIB to be removed.
param
contextName The context name used at registration time.
return
true if the specified mib was a MIB included in the SNMP MIB handler, false otherwise.
since
1.5

	return removeMib(mib);
    
public booleanremoveMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib)
Removes the specified MIB from the SNMP protocol adaptor.

param
mib The MIB to be removed.
return
true if the specified mib was a MIB included in the SNMP MIB handler, false otherwise.

        root.unregister(mib);
        return (mibs.removeElement(mib)) ;
    
public booleanremoveMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib, com.sun.jmx.snmp.SnmpOid[] oids)
Removes the specified MIB from the SNMP protocol adaptor.

param
mib The MIB to be removed.
param
oids The oid the MIB was previously registered for.
return
true if the specified mib was a MIB included in the SNMP MIB handler, false otherwise.
since
1.5

	root.unregister(mib, oids);
	return (mibs.removeElement(mib)) ;
    
public booleanremoveMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib, java.lang.String contextName, com.sun.jmx.snmp.SnmpOid[] oids)
Removes the specified MIB from the SNMP protocol adaptor.

param
mib The MIB to be removed.
param
contextName The context name used at registration time.
param
oids The oid the MIB was previously registered for.
return
true if the specified mib was a MIB included in the SNMP MIB handler, false otherwise.
since
1.5

	return removeMib(mib, oids);
    
private voidsendTrapMessage(com.sun.jmx.snmp.SnmpMessage msg)
Send the specified message on trapSocket.

        byte[] buffer = new byte[bufferSize] ;
        DatagramPacket packet = new DatagramPacket(buffer, buffer.length) ;
        int encodingLength = msg.encodeMessage(buffer) ;
        packet.setLength(encodingLength) ;
        packet.setAddress(msg.address) ;
        packet.setPort(msg.port) ;
        if (isTraceOn()) {
            trace("sendTrapMessage", "sending trap to " + msg.address + ":" +
		  msg.port);
        }
        trapSocket.send(packet) ;
        if (isTraceOn()) {
            trace("sendTrapMessage", "sent to " + msg.address + ":" + 
		  msg.port);
        }
        snmpOutTraps++;
        snmpOutPkts++;
    
private voidsendTrapPdu(com.sun.jmx.snmp.SnmpPduPacket pdu)
Send the specified trap PDU to every destinations from the ACL file.

  
        // Make an SNMP message from the pdu
        //
        SnmpMessage msg = null ;
        try {
            msg = (SnmpMessage)pduFactory.encodeSnmpPdu(pdu, bufferSize) ;
            if (msg == null) {
                throw new SnmpStatusException(
			  SnmpDefinitions.snmpRspAuthorizationError) ;
            }
        }
        catch (SnmpTooBigException x) {
            if (isDebugOn()) {
                debug("sendTrapPdu", "trap pdu is too big");
                debug("sendTrapPdu", "trap hasn't been sent to anyone");
            }
            throw new SnmpStatusException(SnmpDefinitions.snmpRspTooBig) ;
            // FIXME: is the right exception to throw ?
            // We could simply forward SnmpTooBigException ?
        }
    
        // Now send the SNMP message to each destination
        //
        int sendingCount = 0 ;
        openTrapSocketIfNeeded() ;
        if (ipacl != null) {
            Enumeration ed = ((InetAddressAcl)ipacl).getTrapDestinations() ;
            while (ed.hasMoreElements()) {
                msg.address = (InetAddress)ed.nextElement() ;
                Enumeration ec = ((InetAddressAcl)ipacl).
		    getTrapCommunities(msg.address) ;
                while (ec.hasMoreElements()) {
                    msg.community = ((String)ec.nextElement()).getBytes() ;
                    try {
                        sendTrapMessage(msg) ;
                        sendingCount++ ;
                    }
                    catch (SnmpTooBigException x) {
                        if (isDebugOn()) {
                            debug("sendTrapPdu", "trap pdu is too big");
                            debug("sendTrapPdu", "trap hasn't been sent to "+
				  msg.address);
                        }
                    }
                }
            }
        }
    
        // If there is no destination defined or if everything has failed
        // we tried to send the trap to the local host (as suggested by
        // mister Olivier Reisacher).
        //
        if (sendingCount == 0) {
            try {
                msg.address = InetAddress.getLocalHost() ;
                sendTrapMessage(msg) ;
            } catch (SnmpTooBigException x) {
                if (isDebugOn()) {
                    debug("sendTrapPdu", "trap pdu is too big");
                    debug("sendTrapPdu", "trap hasn't been sent");
                }
            } catch (UnknownHostException e) {
                if (isDebugOn()) {
                    debug("sendTrapPdu", "cannot get the local host");
                    debug("sendTrapPdu", "trap hasn't been sent");
                }
            }
        }
    
        closeTrapSocketIfNeeded() ;
    
private voidsendTrapPdu(java.net.InetAddress addr, com.sun.jmx.snmp.SnmpPduPacket pdu)
Send the specified trap PDU to the specified destination.

  
        // Make an SNMP message from the pdu
        //
        SnmpMessage msg = null ;
        try {
            msg = (SnmpMessage)pduFactory.encodeSnmpPdu(pdu, bufferSize) ;
            if (msg == null) {
                throw new SnmpStatusException(
                          SnmpDefinitions.snmpRspAuthorizationError) ;
            }
        } catch (SnmpTooBigException x) {
            if (isDebugOn()) {
                debug("sendTrapPdu", "trap pdu is too big");
                debug("sendTrapPdu", 
		      "trap hasn't been sent to the specified host");
            }
            throw new SnmpStatusException(SnmpDefinitions.snmpRspTooBig) ;
            // FIXME: is the right exception to throw ?
            // We could simply forward SnmpTooBigException ?
        }
    
        // Now send the SNMP message to specified destination
        //
        openTrapSocketIfNeeded() ;
        if (addr != null) {
            msg.address = addr;
            try {
                sendTrapMessage(msg) ;
            } catch (SnmpTooBigException x) {
                if (isDebugOn()) {
                    debug("sendTrapPdu", "trap pdu is too big");
                    debug("sendTrapPdu", "trap hasn't been sent to " + 
			  msg.address);
                }
            }
        }
    
        closeTrapSocketIfNeeded() ;
    
public voidsetAuthRespEnabled(boolean enabled)
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.

        authRespEnabled = enabled ;
    
public voidsetAuthTrapEnabled(boolean enabled)
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.

        authTrapEnabled = enabled ;
    
public voidsetBufferSize(java.lang.Integer s)
Sets the buffer size of this SNMP protocol adaptor. This buffer size is used for both incoming request and outgoing inform requests.

param
s The buffer size.
exception
java.lang.IllegalStateException This method has been invoked while the communicator was ONLINE or STARTING.

        if ((state == ONLINE) || (state == STARTING)) {
            throw new IllegalStateException("Stop server before carrying out"+
					    " this operation");
        }
        bufferSize = s.intValue() ;
    
public voidsetEnterpriseOid(java.lang.String oid)
Sets the enterprise OID.

param
oid The OID in string format "x.x.x.x".
exception
IllegalArgumentException The string format is incorrect

        enterpriseOid = new SnmpOid(oid) ;
    
public voidsetInformPort(int port)
Sets the port used by this SNMP protocol adaptor for sending inform requests.

param
port The port number for sending SNMP inform requests.

        if (port < 0)
            throw new IllegalArgumentException("Inform request port "+
					       "cannot be a negative value");
        informPort= port ;
    
public voidsetMaxActiveClientCount(int c)
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 ONLINE or STARTING.

	super.setMaxActiveClientCount(c);
    
public final synchronized voidsetMaxTries(int newMaxTries)
Changes the maximun number of times to try sending an inform request before giving up.

param
newMaxTries The maximun number of tries.

        if (newMaxTries < 0)
            throw new IllegalArgumentException();
        maxTries = newMaxTries;
    
public voidsetPduFactory(com.sun.jmx.snmp.SnmpPduFactory factory)
Sets the message factory of this SNMP protocol adaptor.

param
factory The factory object (null means the default factory).

        if (factory == null)
            pduFactory = new SnmpPduFactoryBER() ;
        else
            pduFactory = factory ;
    
public final synchronized voidsetTimeout(int newTimeout)
Changes the timeout to wait for an inform response from the manager.

param
newTimeout The timeout (in milliseconds).

        if (newTimeout < 0)
            throw new IllegalArgumentException();
        timeout= newTimeout;
    
public voidsetTrapPort(java.lang.Integer port)
Sets the port used by this SNMP protocol adaptor for sending traps.

param
port The port number for sending SNMP traps.

        setTrapPort(port.intValue());
    
public voidsetTrapPort(int port)
Sets the port used by this SNMP protocol adaptor for sending traps.

param
port The port number for sending SNMP traps.

        int val= port ;
        if (val < 0) throw new 
            IllegalArgumentException("Trap port cannot be a negative value");
        trapPort= val ;
    
public voidsetUserDataFactory(com.sun.jmx.snmp.agent.SnmpUserDataFactory 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

	userDataFactory = factory ;
    
private SnmpInformRequestsnmpInformRequest(java.net.InetAddress addr, int port, java.lang.String cs, SnmpInformHandler cb, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList)

	if (!isActive()) {
            throw new IllegalStateException(
	      "Start SNMP adaptor server before carrying out this operation");
        }
        if (isTraceOn()) {
            trace("snmpInformRequest", "trapOid=" + trapOid);
        }
        
        // First, make an SNMP inform pdu:
        // We clone varBindList and insert sysUpTime and snmpTrapOid variables.
        //
        SnmpVarBindList fullVbl ;    
        if (varBindList != null)
            fullVbl = (SnmpVarBindList)varBindList.clone() ;
        else
            fullVbl = new SnmpVarBindList(2) ;
        SnmpTimeticks sysUpTimeValue = new SnmpTimeticks(getSysUpTime()) ;
        fullVbl.insertElementAt(new SnmpVarBind(snmpTrapOidOid, trapOid), 0) ;
        fullVbl.insertElementAt(new SnmpVarBind(sysUpTimeOid, sysUpTimeValue),
				0);
                
        // Next, send the pdu to the specified destination
        //
        openInformSocketIfNeeded() ;
        return informSession.makeAsyncRequest(addr, cs, cb, fullVbl, port) ;
    
public java.util.VectorsnmpInformRequest(SnmpInformHandler cb, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList)
Sends an inform using SNMP V2 inform request format.
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.
The variable list included in the outgoing inform is composed of the following items:
  • sysUpTime.0 with its current value
  • snmpTrapOid.0 with the value specified by trapOid
  • all the (oid,values) from the specified varBindList
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 SnmpVarBind instances or null.
return
A vector of {@link com.sun.jmx.snmp.daemon.SnmpInformRequest} objects.

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 bufferSize.

	
        if (!isActive()) {
            throw new IllegalStateException(
               "Start SNMP adaptor server before carrying out this operation");
        }
        if (isTraceOn()) {
            trace("snmpInformRequest", "trapOid=" + trapOid);
        }
        
        // First, make an SNMP inform pdu:
        // We clone varBindList and insert sysUpTime and snmpTrapOid variables.
        //
        SnmpVarBindList fullVbl ;    
        if (varBindList != null)
            fullVbl = (SnmpVarBindList)varBindList.clone() ;
        else
            fullVbl = new SnmpVarBindList(2) ;
        SnmpTimeticks sysUpTimeValue = new SnmpTimeticks(getSysUpTime()) ;
        fullVbl.insertElementAt(new SnmpVarBind(snmpTrapOidOid, trapOid), 0) ;
        fullVbl.insertElementAt(new SnmpVarBind(sysUpTimeOid, sysUpTimeValue),
				0);
        
        // Next, send the pdu to the specified destination
        //
        openInformSocketIfNeeded() ;
        
        // Now send the SNMP message to each destination
        //
        Vector informReqList = new Vector();
        InetAddress addr = null;
        String cs = null;
        if (ipacl != null) {
            Enumeration ed = ((InetAddressAcl)ipacl).getInformDestinations() ;
            while (ed.hasMoreElements()) {
                addr = (InetAddress)ed.nextElement() ;
                Enumeration ec = ((InetAddressAcl)ipacl).
		    getInformCommunities(addr) ;
                while (ec.hasMoreElements()) {
                    cs = (String)ec.nextElement() ;
                    informReqList.addElement(
		       informSession.makeAsyncRequest(addr, cs, cb, 
					      fullVbl,getInformPort())) ;
                }
            }
        }
	
        return informReqList ;
    
public SnmpInformRequestsnmpInformRequest(java.net.InetAddress addr, java.lang.String cs, SnmpInformHandler cb, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList)
Sends an inform using SNMP V2 inform request format.
The inform is sent to the specified InetAddress destination using the specified community string.
The variable list included in the outgoing inform is composed of the following items:
  • sysUpTime.0 with its current value
  • snmpTrapOid.0 with the value specified by trapOid
  • all the (oid,values) from the specified varBindList
To send an inform request, the SNMP adaptor server must be active.

param
addr The InetAddress 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 SnmpVarBind 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 bufferSize.

	
	return snmpInformRequest(addr, 
				 getInformPort(), 
				 cs,
				 cb,
				 trapOid,
				 varBindList);
    
public SnmpInformRequestsnmpInformRequest(com.sun.jmx.snmp.SnmpPeer peer, SnmpInformHandler cb, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList)
Sends an inform using SNMP V2 inform request format.
The inform is sent to the specified SnmpPeer destination.
The community string used is the one located in the SnmpPeer parameters (SnmpParameters.getInformCommunity() ).
The variable list included in the outgoing inform is composed of the following items:
  • sysUpTime.0 with its current value
  • snmpTrapOid.0 with the value specified by trapOid
  • all the (oid,values) from the specified varBindList
To send an inform request, the SNMP adaptor server must be active.

param
peer The SnmpPeer 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 SnmpVarBind 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 bufferSize.
since
1.5

	SnmpParameters p = (SnmpParameters) peer.getParams();
	return snmpInformRequest(peer.getDestAddr(), 
				 peer.getDestPort(), 
				 p.getInformCommunity(),
				 cb,
				 trapOid,
				 varBindList);
    
public voidsnmpPduTrap(java.net.InetAddress address, com.sun.jmx.snmp.SnmpPduPacket pdu)
Send the specified trap PDU to the passed InetAddress.

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 bufferSize.
since
1.5


        if(address != null)
            sendTrapPdu(address, pdu);
        else
            sendTrapPdu(pdu);
    
public voidsnmpPduTrap(com.sun.jmx.snmp.SnmpPeer peer, com.sun.jmx.snmp.SnmpPduPacket pdu)
Send the specified trap PDU to the passed SnmpPeer.

param
peer The destination peer. The Read community string is used of SnmpParameters 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 bufferSize.
since
1.5

	if(peer != null) {
	    pdu.port = peer.getDestPort();
	    sendTrapPdu(peer.getDestAddr(), pdu);
	}
	else {
	    pdu.port = getTrapPort().intValue();
	    sendTrapPdu(pdu);   
	}
    
public voidsnmpV1Trap(int generic, int specific, com.sun.jmx.snmp.SnmpVarBindList varBindList)
Sends a trap using SNMP V1 trap format.
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 SnmpVarBind instances or null.
exception
IOException An I/O error occurred while sending the trap.
exception
SnmpStatusException If the trap exceeds the limit defined by bufferSize.


        if (isTraceOn()) {
            trace("snmpV1Trap", "generic=" + generic + 
		  ", specific=" + specific);
        }
        
        // First, make an SNMP V1 trap pdu
        //
        SnmpPduTrap pdu = new SnmpPduTrap() ;
        pdu.address = null ;
        pdu.port = trapPort ;
        pdu.type = pduV1TrapPdu ;
        pdu.version = snmpVersionOne ;
        pdu.community = null ;
        pdu.enterprise = enterpriseOid ;
        pdu.genericTrap = generic ;
        pdu.specificTrap = specific ;
        pdu.timeStamp = getSysUpTime();
    
        if (varBindList != null) {
            pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
            varBindList.copyInto(pdu.varBindList);
        }
        else
            pdu.varBindList = null ;
      
        // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
        try {
            if (address != null)
                pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
            else pdu.agentAddr = 
              handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
        } catch (UnknownHostException e) {
	    byte[] zeroedAddr = new byte[4];
            pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
        }
    
        // Next, send the pdu to all destinations defined in ACL
        //
        sendTrapPdu(pdu) ;
    
public voidsnmpV1Trap(java.net.InetAddress addr, java.lang.String cs, int generic, int specific, com.sun.jmx.snmp.SnmpVarBindList varBindList)
Sends a trap using SNMP V1 trap format.
The trap is sent to the specified InetAddress destination using the specified community string (and the ACL file is not used).

param
addr The InetAddress 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 SnmpVarBind instances or null.
exception
IOException An I/O error occurred while sending the trap.
exception
SnmpStatusException If the trap exceeds the limit defined by bufferSize.

	
        if (isTraceOn()) {
            trace("snmpV1Trap", "generic=" + generic + ", specific=" + 
		  specific);
        }
        
        // First, make an SNMP V1 trap pdu
        //
        SnmpPduTrap pdu = new SnmpPduTrap() ;
        pdu.address = null ;
        pdu.port = trapPort ;
        pdu.type = pduV1TrapPdu ;
        pdu.version = snmpVersionOne ;
	
	if(cs != null)
	    pdu.community = cs.getBytes();
	else
	    pdu.community = null ;
	
        pdu.enterprise = enterpriseOid ;
        pdu.genericTrap = generic ;
        pdu.specificTrap = specific ;
        pdu.timeStamp = getSysUpTime();
    
        if (varBindList != null) {
            pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
            varBindList.copyInto(pdu.varBindList);
        }
        else
            pdu.varBindList = null ;
      
        // If the local host cannot be determined, we put 0.0.0.0 in agentAddr
        try {
            if (address != null)
                pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
            else pdu.agentAddr = 
	      handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
        } catch (UnknownHostException e) {
	    byte[] zeroedAddr = new byte[4];
            pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
        }
	
        // Next, send the pdu to the specified destination
        //
	if(addr != null)
	    sendTrapPdu(addr, pdu) ;
	else
	    sendTrapPdu(pdu);
    
public voidsnmpV1Trap(java.net.InetAddress addr, com.sun.jmx.snmp.SnmpIpAddress agentAddr, java.lang.String cs, com.sun.jmx.snmp.SnmpOid enterpOid, int generic, int specific, com.sun.jmx.snmp.SnmpVarBindList varBindList, com.sun.jmx.snmp.SnmpTimeticks time)
Sends a trap using SNMP V1 trap format.
The trap is sent to the specified InetAddress destination using the specified parameters (and the ACL file is not used). Note that if the specified InetAddress destination is null, then the ACL file mechanism is used.

param
addr The InetAddress destination of the trap.
param
agentAddr The agent address to be used for the trap.
param
cs The community string 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 SnmpVarBind 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 bufferSize.
since
1.5

	snmpV1Trap(addr, 
		   trapPort,
		   agentAddr,
		   cs,
		   enterpOid,
		   generic,
		   specific,
		   varBindList,
		   time);
    
public voidsnmpV1Trap(com.sun.jmx.snmp.SnmpPeer peer, com.sun.jmx.snmp.SnmpIpAddress agentAddr, com.sun.jmx.snmp.SnmpOid enterpOid, int generic, int specific, com.sun.jmx.snmp.SnmpVarBindList varBindList, com.sun.jmx.snmp.SnmpTimeticks time)
Sends a trap using SNMP V1 trap format.
The trap is sent to the specified SnmpPeer destination. The community string used is the one located in the SnmpPeer parameters (SnmpParameters.getRdCommunity() ).

param
peer The SnmpPeer 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 SnmpVarBind 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 bufferSize.
since
1.5

	SnmpParameters p = (SnmpParameters) peer.getParams();
	snmpV1Trap(peer.getDestAddr(), 
		   peer.getDestPort(),
		   agentAddr,
		   p.getRdCommunity(),
		   enterpOid,
		   generic,
		   specific,
		   varBindList,
		   time);
    
private voidsnmpV1Trap(java.net.InetAddress addr, int port, com.sun.jmx.snmp.SnmpIpAddress agentAddr, java.lang.String cs, com.sun.jmx.snmp.SnmpOid enterpOid, int generic, int specific, com.sun.jmx.snmp.SnmpVarBindList varBindList, com.sun.jmx.snmp.SnmpTimeticks time)

	
	if (isTraceOn()) {
            trace("snmpV1Trap", "generic=" + generic + ", specific=" + 
		  specific);
        }
        
        // First, make an SNMP V1 trap pdu
        //
        SnmpPduTrap pdu = new SnmpPduTrap() ;
        pdu.address = null ;
        pdu.port = port ;
        pdu.type = pduV1TrapPdu ;
        pdu.version = snmpVersionOne ;
	
        //Diff start
        if(cs != null) 
            pdu.community = cs.getBytes();
        else
            pdu.community = null ;
        //Diff end

        // Diff start
        if(enterpOid != null)
            pdu.enterprise = enterpOid;
        else
            pdu.enterprise = enterpriseOid ;
        //Diff end
        pdu.genericTrap = generic ;
        pdu.specificTrap = specific ;
        //Diff start
        if(time != null)
            pdu.timeStamp = time.longValue();
        else
            pdu.timeStamp = getSysUpTime();
        //Diff end
    
        if (varBindList != null) {
            pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
            varBindList.copyInto(pdu.varBindList);
        }
        else
            pdu.varBindList = null ;
      
        if (agentAddr == null) {
            // If the local host cannot be determined, 
            // we put 0.0.0.0 in agentAddr
            try {
		final InetAddress inetAddr = 
		    (address!=null)?address:InetAddress.getLocalHost();
		agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
            }  catch (UnknownHostException e) {
		byte[] zeroedAddr = new byte[4];
		agentAddr = handleMultipleIpVersion(zeroedAddr);
            }
        }

	pdu.agentAddr = agentAddr;
	
        // Next, send the pdu to the specified destination
        //
        // Diff start
        if(addr != null)
            sendTrapPdu(addr, pdu) ;
        else
            sendTrapPdu(pdu);

        //End diff
    
public voidsnmpV2Trap(com.sun.jmx.snmp.SnmpPeer peer, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList, com.sun.jmx.snmp.SnmpTimeticks time)
Sends a trap using SNMP V2 trap format.
The trap is sent to the specified SnmpPeer destination.
The community string used is the one located in the SnmpPeer parameters (SnmpParameters.getRdCommunity() ).
The variable list included in the outgoing trap is composed of the following items:
  • sysUpTime.0 with the value specified by time
  • snmpTrapOid.0 with the value specified by trapOid
  • all the (oid,values) from the specified varBindList

param
peer The SnmpPeer destination of the trap.
param
trapOid The OID identifying the trap.
param
varBindList A list of SnmpVarBind 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 bufferSize.
since
1.5

	SnmpParameters p = (SnmpParameters) peer.getParams();
	snmpV2Trap(peer.getDestAddr(), 
		   peer.getDestPort(), 
		   p.getRdCommunity(),
		   trapOid,
		   varBindList,
		   time);
    
public voidsnmpV2Trap(com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList)
Sends a trap using SNMP V2 trap format.
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.
The variable list included in the outgoing trap is composed of the following items:
  • sysUpTime.0 with its current value
  • snmpTrapOid.0 with the value specified by trapOid
  • all the (oid,values) from the specified varBindList

param
trapOid The OID identifying the trap.
param
varBindList A list of SnmpVarBind instances or null.
exception
IOException An I/O error occurred while sending the trap.
exception
SnmpStatusException If the trap exceeds the limit defined by bufferSize.


        if (isTraceOn()) {
            trace("snmpV2Trap", "trapOid=" + trapOid);
        }
        
        // First, make an SNMP V2 trap pdu
        // We clone varBindList and insert sysUpTime and snmpTrapOid
        //
        SnmpPduRequest pdu = new SnmpPduRequest() ;
        pdu.address = null ;
        pdu.port = trapPort ;
        pdu.type = pduV2TrapPdu ;
        pdu.version = snmpVersionTwo ;
        pdu.community = null ;

        SnmpVarBindList fullVbl ;    
        if (varBindList != null)
            fullVbl = (SnmpVarBindList)varBindList.clone() ;
        else
            fullVbl = new SnmpVarBindList(2) ;
        SnmpTimeticks sysUpTimeValue = new SnmpTimeticks(getSysUpTime()) ;
        fullVbl.insertElementAt(new SnmpVarBind(snmpTrapOidOid, trapOid), 0) ;
        fullVbl.insertElementAt(new SnmpVarBind(sysUpTimeOid, sysUpTimeValue),
				0);
        pdu.varBindList = new SnmpVarBind[fullVbl.size()] ;
        fullVbl.copyInto(pdu.varBindList) ;
      
        // Next, send the pdu to all destinations defined in ACL
        //
        sendTrapPdu(pdu) ;
    
public voidsnmpV2Trap(java.net.InetAddress addr, java.lang.String cs, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList)
Sends a trap using SNMP V2 trap format.
The trap is sent to the specified InetAddress destination using the specified community string (and the ACL file is not used).
The variable list included in the outgoing trap is composed of the following items:
  • sysUpTime.0 with its current value
  • snmpTrapOid.0 with the value specified by trapOid
  • all the (oid,values) from the specified varBindList

param
addr The InetAddress 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 SnmpVarBind instances or null.
exception
IOException An I/O error occurred while sending the trap.
exception
SnmpStatusException If the trap exceeds the limit defined by bufferSize.

	
        if (isTraceOn()) {
            trace("snmpV2Trap", "trapOid=" + trapOid);
        }
        
        // First, make an SNMP V2 trap pdu
        // We clone varBindList and insert sysUpTime and snmpTrapOid
        //
        SnmpPduRequest pdu = new SnmpPduRequest() ;
        pdu.address = null ;
        pdu.port = trapPort ;
        pdu.type = pduV2TrapPdu ;
        pdu.version = snmpVersionTwo ;

	if(cs != null) 
            pdu.community = cs.getBytes();
        else
            pdu.community = null;
	
        SnmpVarBindList fullVbl ;    
        if (varBindList != null)
            fullVbl = (SnmpVarBindList)varBindList.clone() ;
        else
            fullVbl = new SnmpVarBindList(2) ;
        SnmpTimeticks sysUpTimeValue = new SnmpTimeticks(getSysUpTime()) ;
        fullVbl.insertElementAt(new SnmpVarBind(snmpTrapOidOid, trapOid), 0) ;
        fullVbl.insertElementAt(new SnmpVarBind(sysUpTimeOid, sysUpTimeValue),
				0);
        pdu.varBindList = new SnmpVarBind[fullVbl.size()] ;
        fullVbl.copyInto(pdu.varBindList) ;
      
        // Next, send the pdu to the specified destination
        //
	if(addr != null)
	    sendTrapPdu(addr, pdu);
	else
	    sendTrapPdu(pdu);
    
public voidsnmpV2Trap(java.net.InetAddress addr, java.lang.String cs, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList, com.sun.jmx.snmp.SnmpTimeticks time)
Sends a trap using SNMP V2 trap format.
The trap is sent to the specified InetAddress destination using the specified parameters (and the ACL file is not used). Note that if the specified InetAddress destination is null, then the ACL file mechanism is used.
The variable list included in the outgoing trap is composed of the following items:
  • sysUpTime.0 with the value specified by time
  • snmpTrapOid.0 with the value specified by trapOid
  • all the (oid,values) from the specified varBindList

param
addr The InetAddress 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 SnmpVarBind 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 bufferSize.
since
1.5

      
	snmpV2Trap(addr, 
		   trapPort, 
		   cs,
		   trapOid,
		   varBindList,
		   time);
    
private voidsnmpV2Trap(java.net.InetAddress addr, int port, java.lang.String cs, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList, com.sun.jmx.snmp.SnmpTimeticks time)

	
        if (isTraceOn()) {
            trace("snmpV2Trap", "trapOid=" + trapOid +
                  "\ncommunity=" + cs + "\naddr=" + addr +
                  "\nvarBindList=" + varBindList + "\ntime=" + time +
                  "\ntrapPort=" + port);
        }
        
        // First, make an SNMP V2 trap pdu
        // We clone varBindList and insert sysUpTime and snmpTrapOid
        //
        SnmpPduRequest pdu = new SnmpPduRequest() ;
        pdu.address = null ;
        pdu.port = port ;
        pdu.type = pduV2TrapPdu ;
        pdu.version = snmpVersionTwo ;
	
	if(cs != null) 
            pdu.community = cs.getBytes();
        else
            pdu.community = null;

        SnmpVarBindList fullVbl ;    
        if (varBindList != null)
            fullVbl = (SnmpVarBindList)varBindList.clone() ;
        else
            fullVbl = new SnmpVarBindList(2) ;

        // Only difference with other
        SnmpTimeticks sysUpTimeValue = null;
        if(time != null)
            sysUpTimeValue = time;
        else
            sysUpTimeValue = new SnmpTimeticks(getSysUpTime()) ;
        //End of diff

        fullVbl.insertElementAt(new SnmpVarBind(snmpTrapOidOid, trapOid), 0) ;
        fullVbl.insertElementAt(new SnmpVarBind(sysUpTimeOid, sysUpTimeValue),
				0);
        pdu.varBindList = new SnmpVarBind[fullVbl.size()] ;
        fullVbl.copyInto(pdu.varBindList) ;
      
        // Next, send the pdu to the specified destination
        //
        // Diff start
        if(addr != null)
            sendTrapPdu(addr, pdu) ;
        else
            sendTrapPdu(pdu);
        //End diff
    
public voidstop()
Stops this SNMP protocol adaptor. Closes the datagram socket.

Has no effect if this SNMP protocol adaptor is OFFLINE or STOPPING.

        
	final int port = getPort();
        if (isTraceOn()) {
            trace("stop", "Stopping: using port " + port);
        }
        if ((state == ONLINE) || (state == STARTING)){
            super.stop();
            try {
		DatagramSocket sn = new DatagramSocket(0);
		try {
		    byte[] ob = new byte[1];
		    
		    DatagramPacket pk;
		    if (address != null)
			pk = new DatagramPacket(ob , 1, address, port);
		    else
			pk = new DatagramPacket(ob , 1, 
				 java.net.InetAddress.getLocalHost(), port);
                                
		    if (isTraceOn()) {
			trace("stop", "Sending: using port " + port);
		    }
		    sn.send(pk);
		} finally {
		    sn.close();
		}
            } catch (Throwable e){
                if (isDebugOn()) {
                    debug("stop", e);
                }
            } 
        }
    
voidupdateErrorCounters(int errorStatus)

        switch(errorStatus) {
            
        case snmpRspNoError:
            snmpOutGetResponses++;
            break;
        case snmpRspGenErr:
            snmpOutGenErrs++;
            break;
        case snmpRspBadValue:
            snmpOutBadValues++;
            break;
        case snmpRspNoSuchName:
            snmpOutNoSuchNames++;
            break;
        case snmpRspTooBig:
            snmpOutTooBigs++;
            break;
        default:
            break;
        }
        snmpOutPkts++ ;
    
voidupdateRequestCounters(int pduType)

        switch(pduType)  {
            
        case pduGetRequestPdu:
            snmpInGetRequests++;
            break;
        case pduGetNextRequestPdu:
            snmpInGetNexts++;
            break;
        case pduSetRequestPdu:
            snmpInSetRequests++;
            break;
        default:
            break;
        }
        snmpInPkts++ ;
    
voidupdateVarCounters(int pduType, int n)

        switch(pduType) {
            
        case pduGetRequestPdu:
        case pduGetNextRequestPdu:
        case pduGetBulkRequestPdu:
            snmpInTotalReqVars += n ;
            break ;
        case pduSetRequestPdu:
            snmpInTotalSetVars += n ;
            break ;
        }