HOME

com.ireasoning.protocol.snmp
Class SnmpTrapdSession

java.lang.Object
  extended bycom.ireasoning.protocol.ListenerManager
      extended bycom.ireasoning.protocol.Session
          extended bycom.ireasoning.protocol.snmp.SnmpBaseSession
              extended bycom.ireasoning.protocol.snmp.SnmpTrapdSession
All Implemented Interfaces:
Serializable, State

public class SnmpTrapdSession
extends SnmpBaseSession

Trap receiver class, a daemon session collecting SNMPv1, v2 and v3 trap and SNMPv2/v3 inform messages. For a class to process trap, it needs to register a Listener by calling addListener method.
Note:
Community name is not verified for each trap (SNMPv1/v2c). So even if commnity name is not correct, it's still considered as a valid trap. However, this verification can be added in user's code fairly easily.

See Also:
snmptrapd.java example, Serialized Form

Field Summary
protected static int _engineBoots
          number of enginer boots
 
Fields inherited from class com.ireasoning.protocol.Session
_localAddr, _localPort, _state, _target, _thread, _timeout, _transportLayer, _tries, DEFAULT_TIME_OUT, TCP, UDP
 
Fields inherited from class com.ireasoning.protocol.ListenerManager
_listeners
 
Fields inherited from interface com.ireasoning.core.jmx.State
STARTED, STARTING, STATES, STOPPED, STOPPING, UNINITIALIZED
 
Constructor Summary
SnmpTrapdSession()
          Constructs a trapd session, using the default port 162.
SnmpTrapdSession(int port)
          Constructs a trapd session.
SnmpTrapdSession(int port, InetAddress laddr)
          Constructs a trapd session
SnmpTrapdSession(int port, InetAddress laddr, int threadCount)
          Constructs a trapd session
SnmpTrapdSession(int port, InetAddress laddr, EDU.oswego.cs.dl.util.concurrent.PooledExecutor executor)
          Constructs a trapd session
 
Method Summary
 void addV3Params(String userName, String authProtocol, byte[] authKey, int privProtocol, byte[] privKey, byte[] engineID)
          Adds SNMPV3 trap receiver's properties if you know localized authentication and privacy keys.
 void addV3Params(String userName, String authProtocol, String authPassword, int privProtocol, String privPassword, byte[] engineID)
          Adds SNMPV3 trap receiver's properties.
 void addV3Params(String userName, String authProtocol, String authPassword, String privPassword, byte[] engineID)
          Adds SNMPV3 trap receiver's properties.
 void close()
          Closes session and stops waiting for traps
 SnmpDataType decode(byte[] bytes, int length)
           
static int getEngineBoots()
           
 byte[] getEngineID()
          Returns the engine ID of this trap daemon.
Note: only applies to SnmpV3 InformRequest
protected static int getEngineTime()
          snmpEngineTime, which is the number of seconds since the snmpEngineBoots counter was last incremented.
 int getReceiveBufferSize()
          Returns the receiver's buffer size
 DatagramSocket getSocket()
          Returns the DatagramPacket object used internally for receiving UDP packets.
 SnmpDataType process(byte[] _bytes, int _length, InetAddress _address, int _port, PacketSender sender)
           
static void setEngineBoots(int boots)
          Sets new engineBoots value
 void setEngineID(byte[] engineID)
          Sets the engine ID of this trap daemon
 void setReceiveBufferSize(int size)
          Sets the size of receiver's buffer.
 void waitForTrap()
          Blocks and waits for SnmpV1 ,V2c, v3 trap or SNMPv2c/v3 InformRequest.
 
Methods inherited from class com.ireasoning.protocol.snmp.SnmpBaseSession
addEngine, addEngine, lookupEngine, lookupEngine, lookupEngine, lookupUsmUser, receiveObject, removeEngine, removeEngine, removeEngine, removeEngine, removeUsmUser
 
Methods inherited from class com.ireasoning.protocol.Session
finalize, getRetries, getState, getStateString, getTarget, getTimeout, getTransportLayer, getTransportLayer, open, open, open, reopen, setRetries, setTarget, setTimeout, setTransportLayer, setTransportLayer, startThread
 
Methods inherited from class com.ireasoning.protocol.ListenerManager
addListener, listenerExists, notifyListeners, notifyListeners, removeListener
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_engineBoots

protected static int _engineBoots
number of enginer boots

Constructor Detail

SnmpTrapdSession

public SnmpTrapdSession()
                 throws SocketException
Constructs a trapd session, using the default port 162. The underlying datagram socket will be bound to the wildcard address, an IP address chosen by the kernel.


SnmpTrapdSession

public SnmpTrapdSession(int port)
                 throws SocketException
Constructs a trapd session. The underlying datagram socket will be bound to the wildcard address, an IP address chosen by the kernel.

Parameters:
port - the UDP port used for collecting traps

SnmpTrapdSession

public SnmpTrapdSession(int port,
                        InetAddress laddr)
                 throws SocketException
Constructs a trapd session

Parameters:
port - the UDP port used for collecting traps
laddr - local address to bind

SnmpTrapdSession

public SnmpTrapdSession(int port,
                        InetAddress laddr,
                        int threadCount)
                 throws SocketException
Constructs a trapd session

Parameters:
port - the UDP port used for collecting traps
laddr - local address to bind
threadCount - max number of threads in the thread pool, which is used to process received traps.

SnmpTrapdSession

public SnmpTrapdSession(int port,
                        InetAddress laddr,
                        EDU.oswego.cs.dl.util.concurrent.PooledExecutor executor)
                 throws SocketException
Constructs a trapd session

Parameters:
port - the UDP port used for collecting traps
laddr - local address to bind
Method Detail

waitForTrap

public void waitForTrap()
Blocks and waits for SnmpV1 ,V2c, v3 trap or SNMPv2c/v3 InformRequest.


close

public void close()
Closes session and stops waiting for traps

Overrides:
close in class Session

addV3Params

public void addV3Params(String userName,
                        String authProtocol,
                        String authPassword,
                        String privPassword,
                        byte[] engineID)
Adds SNMPV3 trap receiver's properties. This method can be invoked multiple times for a trap receiver.

Security level is determined by the passed authPassword and privPassword, if both of them are null or empty strings, security level is noAuthNoPriv. If privPassword is null or empty string, security level is authNoPriv. If both of them are non-empty strings, security level is authPriv.

Parameters:
userName - user name
authProtocol - authentication protocol, one of {SnmpConst.MD5, SnmpConst.SHA, SnmpConst.SHA224, SnmpConst.SHA256, SnmpConst.SHA384, SnmpConst.SHA512}
authPassword - authentication password. It will be used to generate localized authentication key.
privPassword - privacy protocol password. It will be used to generate localized privacy key.
engineID - engine ID of the authoritive snmp entity (trap sender). If trap sender's engineID can be ignored, null value can be used.
Since:
SnmpV3

addV3Params

public void addV3Params(String userName,
                        String authProtocol,
                        String authPassword,
                        int privProtocol,
                        String privPassword,
                        byte[] engineID)
Adds SNMPV3 trap receiver's properties.

Security level is determined by the passed authPassword and privPassword, if both of them are null or empty strings, security level is noAuthNoPriv. If privPassword is null or empty string, security level is authNoPriv. If both of them are non-empty strings, security level is authPriv.

Parameters:
userName - user name
authProtocol - authentication protocol, one of {SnmpConst.MD5, SnmpConst.SHA, SnmpConst.SHA224, SnmpConst.SHA256, SnmpConst.SHA384, SnmpConst.SHA512}
authPassword - authentication password. It will be used to generate localized authentication key.
privProtocol - privacy protocol. One of {SnmpConst.DES, SnmpConst.AES, SnmpConst.AES192, SnmpConst.AES256}. Default value is SnmpConst.DES
privPassword - privacy protocol password. It will be used to generate localized privacy key.
engineID - engine ID of the authoritive snmp entity (trap sender). If trap sender's engineID can be ignored, null value can be used.
Since:
SnmpV3

addV3Params

public void addV3Params(String userName,
                        String authProtocol,
                        byte[] authKey,
                        int privProtocol,
                        byte[] privKey,
                        byte[] engineID)
Adds SNMPV3 trap receiver's properties if you know localized authentication and privacy keys.

Security level is determined by the passed authPassword and privPassword, if both of them are null or empty strings, security level is noAuthNoPriv. If privPassword is null or empty string, security level is authNoPriv. If both of them are non-empty strings, security level is authPriv.

Parameters:
userName - user name
authProtocol - authentication protocol, one of {SnmpConst.MD5, SnmpConst.SHA, SnmpConst.SHA224, SnmpConst.SHA256, SnmpConst.SHA384, SnmpConst.SHA512}
privProtocol - privacy protocol. One of {SnmpConst.DES, SnmpConst.AES, SnmpConst.AES192, SnmpConst.AES256}. Default value is SnmpConst.DES
authKey - localized authentication key
privKey - localized privacy key
engineID - engine ID of the authoritive snmp entity (trap sender). If trap sender's engineID can be ignored, null value can be used.
Since:
SnmpV3

getEngineTime

protected static int getEngineTime()
snmpEngineTime, which is the number of seconds since the snmpEngineBoots counter was last incremented.


getEngineBoots

public static int getEngineBoots()
Returns:
the engineBoots value

setEngineBoots

public static void setEngineBoots(int boots)
Sets new engineBoots value


getEngineID

public byte[] getEngineID()
Returns the engine ID of this trap daemon.
Note: only applies to SnmpV3 InformRequest


setEngineID

public void setEngineID(byte[] engineID)
Sets the engine ID of this trap daemon


setReceiveBufferSize

public void setReceiveBufferSize(int size)
Sets the size of receiver's buffer.


getReceiveBufferSize

public int getReceiveBufferSize()
Returns the receiver's buffer size


getSocket

public DatagramSocket getSocket()
Returns the DatagramPacket object used internally for receiving UDP packets. You can customized its properties to suit your needs.


decode

public SnmpDataType decode(byte[] bytes,
                           int length)

process

public SnmpDataType process(byte[] _bytes,
                            int _length,
                            InetAddress _address,
                            int _port,
                            PacketSender sender)

HOME

Copyright © 2002 iReasoning Inc. All Rights Reserved.