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 com.ireasoning.protocol.snmp.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
_state, _target, _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
 
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, EDU.oswego.cs.dl.util.concurrent.PooledExecutor executor)
          Constructs a trapd session
 
Method Summary
 void addEngine(byte[] engineID)
          Adds a new SnmpEngine
 void addEngine(SnmpEngine engine)
          Adds a new SnmpEngine
 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
 byte[] getEngineID()
          Returns the engine ID of this trap daemon.
Note: only apply 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.
 SnmpEngine lookupEngine(byte[] engineID)
          Looks up SnmpEngine instance based on engineID
 SnmpEngine lookupEngine(String host, int port)
          Looks up SnmpEngine instance based on host name and port
 SnmpEngine lookupEngine(Target target)
          Looks up SnmpEngine instance based on host name and port
protected  UsmUser lookupUsmUser(String userName, byte[] engineID, InetAddress address)
          Looks up USM user based on passed user name and engineID.
protected  Object receiveObject()
          Not applicable for this class
 SnmpEngine removeEngine(byte[] engineID)
          Removes SnmpEngine from engine table
 SnmpEngine removeEngine(SnmpEngine engine)
          Removes SnmpEngine from engine table
 SnmpEngine removeEngine(String host, int port)
          Removes SnmpEngine from engine table
 SnmpEngine removeEngine(Target target)
          Removes SnmpEngine from engine table
 void removeUsmUser(String userName, byte[] engineID)
          Removes a UserUser instance from internal map.
 void setEngineID(byte[] engineID)
          Sets the engine ID of this trap daemon
Note: only apply to SnmpV3 InformRequest
 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.Session
finalize, getRetries, getState, getStateString, getTarget, getTimeout, getTransportLayer, open, open, reopen, setRetries, setTarget, setTimeout, 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,
                        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.

Note: One of JVM's security property files, java.security, will be modified to add required security provider if it's not already installed.

Parameters:
userName - user name
authProtocol - authentication protocol, one of {SnmpConst.MD5, SnmpConst.SHA}
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)
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.

Note: One of JVM's security property files, java.security, will be modified to add required security provider if it's not already installed.

Parameters:
userName - user name
authProtocol - authentication protocol, one of {SnmpConst.MD5, SnmpConst.SHA}
authPassword - authentication password. It will be used to generate localized authentication key.
privProtocol - privacy protocol, either SnmpConst.DES (DES algorithm) or SnmpConst.AES (128-bit AES algorithm). 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)
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.

Note: One of JVM's security property files, java.security, will be modified to add required security provider if it's not already installed.

Parameters:
userName - user name
authProtocol - authentication protocol, one of {SnmpConst.MD5, SnmpConst.SHA}
privProtocol - privacy protocol, either SnmpConst.DES (DES algorithm) or SnmpConst.AES (128-bit AES algorithm). Default value is SnmpConst.DES
authKey - localized authentication key
privKey - localized privacy key
engineID - engine ID of the authoritive snmp entity (trap sender)
Since:
SnmpV3

getEngineID

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


getEngineTime

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


setEngineID

public void setEngineID(byte[] engineID)
Sets the engine ID of this trap daemon
Note: only apply to SnmpV3 InformRequest


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.


lookupEngine

public SnmpEngine lookupEngine(String host,
                               int port)
Looks up SnmpEngine instance based on host name and port

Returns:
SnmpEngine instance if found, null otherwise.
Since:
SnmpV3

lookupEngine

public SnmpEngine lookupEngine(Target target)
Looks up SnmpEngine instance based on host name and port

Returns:
SnmpEngine instance if found, null otherwise.
Since:
SnmpV3

lookupEngine

public SnmpEngine lookupEngine(byte[] engineID)
Looks up SnmpEngine instance based on engineID

Returns:
SnmpEngine instance if found, null otherwise.
Since:
SnmpV3

addEngine

public void addEngine(SnmpEngine engine)
Adds a new SnmpEngine

Parameters:
engine - a instance of SnmpEngine to be added
Since:
SnmpV3

addEngine

public void addEngine(byte[] engineID)
Adds a new SnmpEngine

Parameters:
engineID - engine ID of the SnmpEngine to be added

removeEngine

public SnmpEngine removeEngine(byte[] engineID)
Removes SnmpEngine from engine table

Parameters:
engineID - the engine ID of the engine to be removed
Returns:
the SnmpEngine object removed, null if engine not found.

removeEngine

public SnmpEngine removeEngine(Target target)
Removes SnmpEngine from engine table

Parameters:
target - the target object of the engine to be removed
Returns:
the SnmpEngine object removed, null if engine not found.

removeEngine

public SnmpEngine removeEngine(String host,
                               int port)
Removes SnmpEngine from engine table

Parameters:
host - the host name of the engine to be removed
port - the port number of the engine to be removed
Returns:
the SnmpEngine object removed, null if engine not found.

removeEngine

public SnmpEngine removeEngine(SnmpEngine engine)
Removes SnmpEngine from engine table

Parameters:
engine - the engine to be removed
Returns:
the SnmpEngine object removed, null if engine not found.

removeUsmUser

public void removeUsmUser(String userName,
                          byte[] engineID)
Removes a UserUser instance from internal map.


lookupUsmUser

protected UsmUser lookupUsmUser(String userName,
                                byte[] engineID,
                                InetAddress address)
Looks up USM user based on passed user name and engineID. This method is invoked for SNMPv3 packets only, and before decoder starts to decode SNMPv3 PDU.

Parameters:
userName - USM user name contained in the PDU
engineID - SNMPv3 engine ID
address - sender's IP address

receiveObject

protected Object receiveObject()
                        throws IOException
Not applicable for this class

Specified by:
receiveObject in class Session
Throws:
IOException

HOME

Copyright © 2002 iReasoning Inc. All Rights Reserved.