HOME

com.ireasoning.protocol.snmp
Class SnmpBaseAgent

java.lang.Object
  extended bycom.ireasoning.core.jmx.BaseAgent
      extended bycom.ireasoning.protocol.snmp.SnmpBaseAgent
All Implemented Interfaces:
Cloneable, com.ireasoning.core.network.DataHandler, EventListener, NotificationListener, Serializable
Direct Known Subclasses:
SnmpAgentX

public abstract class SnmpBaseAgent
extends BaseAgent
implements com.ireasoning.core.network.DataHandler, NotificationListener

This class is the base class for Snmp Agent implementation. It implements many of agent's functionality, such as processing SNMP requests, sending traps, etc.

See Also:
Serialized Form

Field Summary
protected  String _configFileName
          Agent's configuration file name
protected  int _port
          server port number, default value is 161
protected  OIDTreeNode _root
          MIB tree's root node, its value is initially set in sub class' setOIDTree() method
protected  boolean _shouldExit
          Sets true to stop agent
protected  SnmpAdaptorServer _snmpAdaptorServer
          SnmpAdaptorServer instance
static int AUTHENTICATION_FAILURE_TRAP
          SnmpV1 trap type: authenticationFailure
static SnmpOID AUTHENTICATION_FAILURE_TRAP_OID
          SNMPv2c warmStart trap oid: authenticationFailure
static int COLD_START_TRAP
          SnmpV1 trap type: coldStart
static SnmpOID COLD_START_TRAP_OID
          SNMPv2c coldStart trap oid
static SnmpOID EGPNEIGHBOR_LOSS_OID
          SNMPv2c warmStart trap oid: egpNeighborLoss
static int EGPNEIGHBOR_LOSS_TRAP
          SnmpV1 trap type: egpNeighborLoss
static int LINK_DOWN_TRAP
          SnmpV1 trap type: linkDown
static SnmpOID LINK_DOWN_TRAP_OID
          SNMPv2c warmStart trap oid: linkDown
static int LINK_UP_TRAP
          SnmpV1 trap type: linkUp
static SnmpOID LINK_UP_TRAP_OID
          SNMPv2c warmStart trap oid: linkUp
static SnmpOID SNMP_TRAP_OID
          Snmpv2 trap oid value (".1.3.6.1.6.3.1.1.4.1.0")
static SnmpOID SYS_UP_TIME_OID
          sysUpTime SnmpOID value (".1.3.6.1.2.1.1.3.0")
static int WARM_START_TRAP
          SnmpV1 trap type: warmStart
static SnmpOID WARM_START_TRAP_OID
          SNMPv2c warmStart trap oid: warmStart
 
Fields inherited from class com.ireasoning.core.jmx.BaseAgent
_mbeanServer
 
Constructor Summary
protected SnmpBaseAgent(DefaultAgentConfig config)
          Constructor.
protected SnmpBaseAgent(int port, Object configFileNameOrInputStream)
          Constructor.
protected SnmpBaseAgent(MBeanServer server, DefaultAgentConfig config)
          Constructor.
protected SnmpBaseAgent(MBeanServer server, int port, DefaultAgentConfig config)
          Constructor.
protected SnmpBaseAgent(MBeanServer server, int port, DefaultAgentConfig config, boolean startAgentAutomatically)
          Constructor.
protected SnmpBaseAgent(MBeanServer server, int port, Object configFileNameOrInputStream)
          Constructor.
protected SnmpBaseAgent(MBeanServer server, int port, Object configFileNameOrInputStream, boolean startAgentAutomatically)
          Constructor.
protected SnmpBaseAgent(MBeanServer server, Object configFileNameOrInputStream)
          Constructor.
protected SnmpBaseAgent(Object configFileNameOrInputStream)
          Constructor.
 
Method Summary
 void addAgentEventListener(Listener listener)
          This method allows the registration of event listeners.
protected  SnmpError checkPdu(SnmpPdu pdu)
          This method will be invoked in handleData(...) method, just after packet is deocoded into a SnmpPdu object, and before this pdu is processed.
protected  SnmpError checkPdu(SnmpPdu pdu, UsmUser user)
          This method will be invoked in handleData(...) method, just after packet is deocoded into a SnmpPdu object, and before this pdu is processed.
 void cleanup()
          Gets called automatically when socket is about to close.
 com.ireasoning.core.network.DataHandler copy()
          Overrides super class's abstract method, for internal use only.
protected  void finalize()
          Cleanup resources, gets called by JVM garbage collector
 AgentStats getAgentStats()
          Return AgentStats object which contains statistics info of this agent
 AgentUsmStats getAgentUsmStats()
          Return AgentUsmStats object which contains USM statistics info of this agent
 DefaultAgentConfig getConfig()
          Returns the config file of this agent as a DefaultAgentConfig object
 String getConfigFileName()
          Returns the config file name
static DefaultAgentConfig getDefaultConfig()
          Returns the first loaded config file object.
 SnmpAdaptorServer getSnmpAdaptorServer()
          Returns the SnmpAdaptorServer contained in this agent
static long getSysUpTime()
          Gets the system up time in hundredth of a second.
 boolean getUseSnmpDataType()
           
 int handleData(SocketServer server, Object sockData, TransportData data)
          Callback method which gets called when a new UDP packet is received.
 int handleNewConnection(SocketServer server, Object sock)
          Overrides super class's abstract method, not applicable to this class.
 void handleNotification(Notification notif, Object handback)
          Callback method, gets called when config file changed.
 void initialize()
          Gets called when this agent is (re)started
protected  void preSendPdu(SnmpPdu pdu, UsmUser user)
          This method will be invoked before agent sends back response.
protected abstract  void registerMBeans()
          Registers MBeans.
 void removeAgentEventListener(Listener listener)
          This method allows the removal of event listeners from the event target.
static void sendV1AuthenticationFailureTrap()
          Sends SNMPV1 authenticationFailure trap to all trapsinks
static void sendV1ColdStartTrap()
          Sends SNMPV1 coldStart trap to all trapsinks
static void sendV1EgpNeighborLossTrap(String ipAddress)
          Sends SNMPV1 egpNeighborLoss trap to all trapsinks
static void sendV1LinkDownTrap(int ifIndex)
          Sends SNMPV1 linkDown trap to all trapsinks
static void sendV1LinkUpTrap(int ifIndex)
          Sends SNMPV1 linkUp trap to all trapsinks
static void sendV1Trap(int generic, int specific, SnmpVarBind[] varbinds)
          Sends out SNMPV1 trap to all the trap sinks specified in the default config file.
static void sendV1Trap(int generic, int specific, SnmpVarBind[] varbinds, DefaultAgentConfig config)
          Sends out SNMPV1 trap to all the trap sinks specified in the config file.
static void sendV1Trap(SnmpV1Trap trap)
          Sends out SNMPv1 trap to all the trap sinks specified in the default config file.
static void sendV1Trap(SnmpV1Trap trap, DefaultAgentConfig config)
          Sends out SNMPv1 trap to all the trap sinks specified in the config file.
static void sendV1WarmStartTrap()
          Sends SNMPV1 warmStart trap to all trapsinks
static void sendV2AuthenticationFailureTrap()
          Sends out SNMPV2 authenticationFailure trap to all trapsinks
static void sendV2ColdStartTrap()
          Sends SNMPV2 coldStart trap to all trapsinks specified in the default config file
static void sendV2LinkDownTrap(int ifIndex, int ifAdminStatus, int ifOperStatus)
          Sends out SNMPV2 linkDown trap to all trapsinks
static void sendV2LinkUpTrap(int ifIndex, int ifAdminStatus, int ifOperStatus)
          Sends out SNMPV2 linkUp trap to all trapsinks
static void sendV2Trap(SnmpOID snmpTrapOid, SnmpVarBind[] varbinds)
          Sends out Snmpv2 trap to all the trap sinks specified in the default config file.
static void sendV2Trap(SnmpOID snmpTrapOid, SnmpVarBind[] varbinds, DefaultAgentConfig config)
          Sends out Snmpv2 trap to all the trap sinks specified in the config file.
static void sendV2Trap(SnmpOID snmpTrapOid, SnmpVarBind[] varbinds, DefaultAgentConfig config, DatagramSocket socket)
          Sends out Snmpv2 trap to all the trap sinks specified in the config file.
static void sendV2Trap(SnmpTrap trap)
          Sends out SNMPv2 or SNMPv3 trap to all the trap sinks specified in the default config file.
static void sendV2Trap(SnmpTrap trap, DefaultAgentConfig config)
          Sends out SNMPv2 or SNMPv3 trap to all the trap sinks specified in the config file.
static void sendV2Trap(SnmpTrap trap, DefaultAgentConfig config, DatagramSocket socket)
          Sends out SNMPv2 or SNMPv3 trap to all the trap sinks specified in the config file.
static void sendV2WarmStartTrap()
          Sends SNMPV2 warmStart trap to all trapsinks
 void setConfig(DefaultAgentConfig config)
          Sets a new config object
protected  void setDefaultMaxRepetions(int repetitions)
          Changes the max_repetions if maxRepetions field in the received GET_BULK request is 0.
protected abstract  void setOIDTree()
          Sets SnmpOID tree, which represents all available OIDs
 void setPort(int port)
          Sets a new port.
 void setUseSnmpDataType(boolean b)
           
 boolean shouldExit()
          Return true if agent should stop running.
 void start()
          Starts agent and register MBeans (registerMBeans method will be invoked).
 void stop()
          Stops agent.
protected  void unregisterMBeans()
          Unregister MBeans.
 
Methods inherited from class com.ireasoning.core.jmx.BaseAgent
getMBeanServer, registerHelperMBeans, startAdaptorServer, startAdaptorServer, stopAdaptorServer, stopAdaptorServer, unregisterHelperMBeans
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SYS_UP_TIME_OID

public static final SnmpOID SYS_UP_TIME_OID
sysUpTime SnmpOID value (".1.3.6.1.2.1.1.3.0")


SNMP_TRAP_OID

public static final SnmpOID SNMP_TRAP_OID
Snmpv2 trap oid value (".1.3.6.1.6.3.1.1.4.1.0")


COLD_START_TRAP

public static final int COLD_START_TRAP
SnmpV1 trap type: coldStart

See Also:
Constant Field Values

WARM_START_TRAP

public static final int WARM_START_TRAP
SnmpV1 trap type: warmStart

See Also:
Constant Field Values

LINK_DOWN_TRAP

public static final int LINK_DOWN_TRAP
SnmpV1 trap type: linkDown

See Also:
Constant Field Values

LINK_UP_TRAP

public static final int LINK_UP_TRAP
SnmpV1 trap type: linkUp

See Also:
Constant Field Values

AUTHENTICATION_FAILURE_TRAP

public static final int AUTHENTICATION_FAILURE_TRAP
SnmpV1 trap type: authenticationFailure

See Also:
Constant Field Values

EGPNEIGHBOR_LOSS_TRAP

public static final int EGPNEIGHBOR_LOSS_TRAP
SnmpV1 trap type: egpNeighborLoss

See Also:
Constant Field Values

COLD_START_TRAP_OID

public static final SnmpOID COLD_START_TRAP_OID
SNMPv2c coldStart trap oid


WARM_START_TRAP_OID

public static final SnmpOID WARM_START_TRAP_OID
SNMPv2c warmStart trap oid: warmStart


LINK_DOWN_TRAP_OID

public static final SnmpOID LINK_DOWN_TRAP_OID
SNMPv2c warmStart trap oid: linkDown


LINK_UP_TRAP_OID

public static final SnmpOID LINK_UP_TRAP_OID
SNMPv2c warmStart trap oid: linkUp


AUTHENTICATION_FAILURE_TRAP_OID

public static final SnmpOID AUTHENTICATION_FAILURE_TRAP_OID
SNMPv2c warmStart trap oid: authenticationFailure


EGPNEIGHBOR_LOSS_OID

public static final SnmpOID EGPNEIGHBOR_LOSS_OID
SNMPv2c warmStart trap oid: egpNeighborLoss


_configFileName

protected String _configFileName
Agent's configuration file name


_shouldExit

protected boolean _shouldExit
Sets true to stop agent


_root

protected OIDTreeNode _root
MIB tree's root node, its value is initially set in sub class' setOIDTree() method


_port

protected int _port
server port number, default value is 161


_snmpAdaptorServer

protected SnmpAdaptorServer _snmpAdaptorServer
SnmpAdaptorServer instance

Constructor Detail

SnmpBaseAgent

protected SnmpBaseAgent(Object configFileNameOrInputStream)
                 throws Exception
Constructor. Uses the port number specified in the config file, and registers necessary MBeans by calling registerMBeans() method.

For example:

      class Agent extends SnmpBaseAgent
      {
          public Agent(Object configFileNameOrInputStream)
          {
              super(configFileNameOrInputStream);
          }
          public static void main(String[] args)
          {
              //loading from a config file:
              Agent agent = new Agent("c:\\agent\\SnmpAgent.xml");
              ...

              // Or loading config from resource:
              InputStream istream = Agent.class.getResourceAsStream("/SnmpAgent.xml");
              Agent agent = new Agent(istream);
              ...
          }
      }
 

Parameters:
configFileNameOrInputStream - config file name or InputStream object. If it's a file name and the file does not exist, code'll try locating it at ./config/ directory. If it's an instance of InputStream, it'll be closed when config is loaded.

SnmpBaseAgent

protected SnmpBaseAgent(int port,
                        Object configFileNameOrInputStream)
                 throws Exception
Constructor. Constructs an agent listening on passed port, and registers necessary MBeans by calling registerMBeans() method.

Parameters:
port - Agent's UDP port number
configFileNameOrInputStream - config file name or InputStream object. If it's a file name and the file does not exist, code'll try locating it at ./config/ directory. If it's an instance of InputStream, it'll be closed when config is loaded.

SnmpBaseAgent

protected SnmpBaseAgent(MBeanServer server,
                        Object configFileNameOrInputStream)
                 throws Exception
Constructor. Constructs and starts an agent listening on port specified in config file, and registers necessary MBeans by calling registerMBeans() method.

Parameters:
server - the MBeanServer object which is to be used to create/register MBeans. If the passed server is null, an MBeanServer instance will be created.
configFileNameOrInputStream - config file name or InputStream object. If it's a file name and the file does not exist, code'll try locating it at ./config/ directory. If it's an instance of InputStream, it'll be closed when config is loaded.

SnmpBaseAgent

protected SnmpBaseAgent(DefaultAgentConfig config)
                 throws Exception
Constructor. Constructs and starts an agent listening on passed port, and registers necessary MBeans by calling registerMBeans() method.

Parameters:
config - the config Object for this agent

SnmpBaseAgent

protected SnmpBaseAgent(MBeanServer server,
                        DefaultAgentConfig config)
                 throws Exception
Constructor. Constructs and starts an agent listening on passed port, and registers necessary MBeans by calling registerMBeans() method.

Parameters:
server - the MBeanServer object which is to be used to create/register MBeans. If the passed server is null, an MBeanServer instance will be created.
config - the config Object for this agent

SnmpBaseAgent

protected SnmpBaseAgent(MBeanServer server,
                        int port,
                        DefaultAgentConfig config)
                 throws Exception
Constructor. Constructs and starts an agent listening on passed port, and registers necessary MBeans by calling registerMBeans() method.

Parameters:
server - the MBeanServer object which is to be used to create/register MBeans. If the passed server is null, an MBeanServer instance will be created.
port - Agent's UDP port number
config - the config Object for this agent

SnmpBaseAgent

protected SnmpBaseAgent(MBeanServer server,
                        int port,
                        Object configFileNameOrInputStream)
                 throws Exception
Constructor. Constructs and starts an agent listening on passed port, and registers necessary MBeans by calling registerMBeans() method.

Parameters:
server - the MBeanServer object which is to be used to create/register MBeans. If the passed server is null, an MBeanServer instance will be created.
port - Agent's UDP port number. If it's -1, port number is taken from config settings.
configFileNameOrInputStream - config file name or InputStream object. If it's a file name and the file does not exist, code'll try locating it at ./config/ directory. If it's an instance of InputStream, it'll be closed when config is loaded.

SnmpBaseAgent

protected SnmpBaseAgent(MBeanServer server,
                        int port,
                        DefaultAgentConfig config,
                        boolean startAgentAutomatically)
                 throws Exception
Constructor. Constructs an agent. Agent will not be started if the passed startAgentAutomatically is false.

Parameters:
server - the MBeanServer object which is to be used to create/register MBeans. If the passed server is null, an MBeanServer instance will be created.
port - Agent's UDP port number. If it's -1, port number is taken from config settings.
config - the config Object for this agent
startAgentAutomatically - if true, start() doesn't need to be called, this constructor will call it automatically. Otherwise you need to call that method after instanticating this class to start agent.

SnmpBaseAgent

protected SnmpBaseAgent(MBeanServer server,
                        int port,
                        Object configFileNameOrInputStream,
                        boolean startAgentAutomatically)
                 throws Exception
Constructor. Constructs an agent. Agent will not be started if the passed startAgentAutomatically is false.

Parameters:
server - the MBeanServer object which is to be used to create/register MBeans. If the passed server is null, an MBeanServer instance will be created.
port - Agent's UDP port number. If it's -1, port number is taken from config settings.
configFileNameOrInputStream - config file name or InputStream object. If it's a file name and the file does not exist, code'll try locating it at ./config/ directory. If it's an instance of InputStream, it'll be closed when config is loaded.
startAgentAutomatically - if true, start() doesn't need to be called, this constructor will call it automatically. Otherwise you need to call that method after instanticating this class to start agent.
Method Detail

getConfig

public DefaultAgentConfig getConfig()
Returns the config file of this agent as a DefaultAgentConfig object

See Also:
getDefaultConfig()

setConfig

public void setConfig(DefaultAgentConfig config)
Sets a new config object


getDefaultConfig

public static DefaultAgentConfig getDefaultConfig()
Returns the first loaded config file object. When there're multiple snmp agents running in a JVM and they use different config files, the default config is the one loaded first.
If you have only one agent in a JVM, this method has the same effect as getConfig() method.

See Also:
getConfig()

getAgentStats

public AgentStats getAgentStats()
Return AgentStats object which contains statistics info of this agent


getAgentUsmStats

public AgentUsmStats getAgentUsmStats()
Return AgentUsmStats object which contains USM statistics info of this agent


handleData

public int handleData(SocketServer server,
                      Object sockData,
                      TransportData data)
Callback method which gets called when a new UDP packet is received. It processes received packet and sends back response. This method can be overridden in sub classes if more logic needs to be added before/after processing packet. Or you can override checkPdu method, in which you have a SnmpPdu object instead of byte array in this method.

Specified by:
handleData in interface com.ireasoning.core.network.DataHandler
Parameters:
sockData - an instance of UdpSocketData, which contains info of just received UDP packet, such as client's IP address and port, etc.
data - received UDP packet data
server - SocketServer object
Returns:
return value does not matter here
See Also:
checkPdu(com.ireasoning.protocol.snmp.SnmpPdu)

checkPdu

protected SnmpError checkPdu(SnmpPdu pdu)
This method will be invoked in handleData(...) method, just after packet is deocoded into a SnmpPdu object, and before this pdu is processed.

This method can be overridden to stop further process for certain PDUs.

Parameters:
pdu - received PDU object
Returns:
SnmpError.NO_ERROR if the PDU is Ok; SnmpError.REJECT_PACKET if this packet is to be rejected and no response will be returned to SNMP manager; Or set SnmpError's errorStatus or errorIndex so that a response will be sent back to indicate SNMP error.
Throws:
SnmpException - raised to return a response with errorStatus code contained in the SnmpException object
See Also:
handleData(com.ireasoning.core.network.SocketServer, java.lang.Object, com.ireasoning.core.network.TransportData)

checkPdu

protected SnmpError checkPdu(SnmpPdu pdu,
                             UsmUser user)
This method will be invoked in handleData(...) method, just after packet is deocoded into a SnmpPdu object, and before this pdu is processed.

This method can be overridden to stop further process for certain PDUs.

Parameters:
pdu - received PDU object
user - SNMPv3 USM user info contained in the received SNMP PDU object
Returns:
SnmpError.NO_ERROR if the PDU is Ok; SnmpError.REJECT_PACKET if this packet is to be rejected and no response will be returned to SNMP manager; Or set SnmpError's errorStatus or errorIndex so that a response will be sent back to indicate SNMP error.
Throws:
SnmpException - raised to return a response with errorStatus code contained in the SnmpException object
See Also:
handleData(com.ireasoning.core.network.SocketServer, java.lang.Object, com.ireasoning.core.network.TransportData)

preSendPdu

protected void preSendPdu(SnmpPdu pdu,
                          UsmUser user)
This method will be invoked before agent sends back response. You can override this method and check or modify pdu object.

Parameters:
pdu - SNMP PDU object to be sent out
user - SNMPv3 USM user info contained in the received SNMP PDU object

start

public void start()
           throws Exception
Starts agent and register MBeans (registerMBeans method will be invoked). It has no effect when server is already started.

If this agent is a subagent only, this method won't connect it to the master agent, it onlys registers necessary MBeans.

Throws:
Exception

stop

public void stop()
Stops agent. Release resources.

If it's a subagent, this method does not close the connection with master agents if any. You need to invoke SubAgentSession.close() to close the master agent connection.


getSnmpAdaptorServer

public SnmpAdaptorServer getSnmpAdaptorServer()
Returns the SnmpAdaptorServer contained in this agent


getSysUpTime

public static long getSysUpTime()
Gets the system up time in hundredth of a second.


setPort

public void setPort(int port)
Sets a new port. If the server is running, it'll be restarted.


handleNotification

public void handleNotification(Notification notif,
                               Object handback)
Callback method, gets called when config file changed. Config file will be reloaded if this method is invoked.

Specified by:
handleNotification in interface NotificationListener

getConfigFileName

public String getConfigFileName()
Returns the config file name


initialize

public void initialize()
Gets called when this agent is (re)started

Specified by:
initialize in interface com.ireasoning.core.network.DataHandler

shouldExit

public boolean shouldExit()
Return true if agent should stop running. Sub classes can set _shouldExit to "true" if wanting to stop agent.

Specified by:
shouldExit in interface com.ireasoning.core.network.DataHandler
Returns:
true if agent should stop running.

cleanup

public void cleanup()
Gets called automatically when socket is about to close. It's not supposed to be explicitly called by user.

Specified by:
cleanup in interface com.ireasoning.core.network.DataHandler

sendV2Trap

public static void sendV2Trap(SnmpTrap trap)
Sends out SNMPv2 or SNMPv3 trap to all the trap sinks specified in the default config file. If trap sink's version property's value is 1, the passed v2 trap will be converted to v1 trap then sent out.

You also can use SnmpTrapSender class to send out traps, then the trap sinks in config file will be ignored.


Note:
If a subagent calls this method, trap will be sent directly to the remote trap receivers intead of going through master agent. Subagent can use SubAgentSession.sendTrap to pass trap on to master agent.

Parameters:
trap - trap to be sent

sendV2Trap

public static void sendV2Trap(SnmpTrap trap,
                              DefaultAgentConfig config)
Sends out SNMPv2 or SNMPv3 trap to all the trap sinks specified in the config file. If trap sink's version property's value is 1, the passed v2 trap will be converted to v1 trap then sent out.

You also can use SnmpTrapSender class to send out traps, then the trap sinks in config file will be ignored.


Note:
If a subagent calls this method, trap will be sent directly to the remote trap receivers intead of going through master agent. Subagent can use SubAgentSession.sendTrap to pass trap on to master agent.

Parameters:
trap - trap to be sent
config - Snmp agent config, trap will be sent to the trap sinks specified in this object

sendV2Trap

public static void sendV2Trap(SnmpTrap trap,
                              DefaultAgentConfig config,
                              DatagramSocket socket)
Sends out SNMPv2 or SNMPv3 trap to all the trap sinks specified in the config file. If trap sink's version property's value is 1, the passed v2 trap will be converted to v1 trap then sent out.

You also can use SnmpTrapSender class to send out traps, then the trap sinks in config file will be ignored.


Note:
If a subagent calls this method, trap will be sent directly to the remote trap receivers intead of going through master agent. Subagent can use SubAgentSession.sendTrap to pass trap on to master agent.

Parameters:
trap - trap to be sent
config - Snmp agent config, trap will be sent to the trap sinks specified in this object
socket - A DatagramSocket instance which is used to send out UDP packet
See Also:
SnmpTrapSender

sendV2Trap

public static void sendV2Trap(SnmpOID snmpTrapOid,
                              SnmpVarBind[] varbinds)
Sends out Snmpv2 trap to all the trap sinks specified in the default config file. If trap sink's version property's value is 1, the passed v2 trap will be converted to v1 trap then sent out.

You also can use SnmpTrapSender class to send out traps, then the trap sinks in config file will be ignored.


Note:
If a subagent calls this method, trap will be sent directly to the remote trap receivers intead of going through master agent. Subagent can use SubAgentSession.sendTrap to pass trap on to master agent.

Parameters:
varbinds - variable bindings, sysUpTime is automatically added as the first varbind, snmpTrapOid will be the second varbind.
snmpTrapOid - the trap oid object, usually it's the second varbind in a snmpv2 trap

sendV2Trap

public static void sendV2Trap(SnmpOID snmpTrapOid,
                              SnmpVarBind[] varbinds,
                              DefaultAgentConfig config)
Sends out Snmpv2 trap to all the trap sinks specified in the config file. If trap sink's version property's value is 1, the passed v2 trap will be converted to v1 trap then sent out.

You also can use SnmpTrapSender class to send out traps, then the trap sinks in config file will be ignored.


Note:
If a subagent calls this method, trap will be sent directly to the remote trap receivers intead of going through master agent. Subagent can use SubAgentSession.sendTrap to pass trap on to master agent.

Parameters:
varbinds - variable bindings, sysUpTime is automatically added as the first varbind, snmpTrapOid will be the second varbind.
snmpTrapOid - the trap oid object, usually it's the second varbind in a snmpv2 trap
config - Snmp agent config, trap will be sent to the trap sinks specified in this object

sendV2Trap

public static void sendV2Trap(SnmpOID snmpTrapOid,
                              SnmpVarBind[] varbinds,
                              DefaultAgentConfig config,
                              DatagramSocket socket)
Sends out Snmpv2 trap to all the trap sinks specified in the config file. If trap sink's version property's value is 1, the passed v2 trap will be converted to v1 trap then sent out.

You also can use SnmpTrapSender class to send out traps, then the trap sinks in config file will be ignored.


Note:
If a subagent calls this method, trap will be sent directly to the remote trap receivers intead of going through master agent. Subagent can use SubAgentSession.sendTrap to pass trap on to master agent.

Parameters:
varbinds - variable bindings, sysUpTime is automatically added as the first varbind, snmpTrapOid will be the second varbind.
snmpTrapOid - the trap oid object, usually it's the second varbind in a snmpv2 trap
config - Snmp agent config, trap will be sent to the trap sinks specified in this object
socket - A DatagramSocket instance which is used to send out UDP packet

sendV1Trap

public static void sendV1Trap(SnmpV1Trap trap)
Sends out SNMPv1 trap to all the trap sinks specified in the default config file. If trap sink's version property's value is 2, the passed v1 trap will be converted to v2 trap then sent out.

You also can use SnmpTrapSender class to send out traps, then the trap sinks in config file will be ignored.


Note:
If a subagent calls this method, trap will be sent directly to the remote trap receivers intead of going through master agent. Subagent can use SubAgentSession.sendTrap to pass trap on to master agent.

Parameters:
trap - SNMPv1 trap to sent out

sendV1Trap

public static void sendV1Trap(SnmpV1Trap trap,
                              DefaultAgentConfig config)
Sends out SNMPv1 trap to all the trap sinks specified in the config file. If trap sink's version property's value is 2, the passed v1 trap will be converted to v2 trap then sent out.

You also can use SnmpTrapSender class to send out traps, then the trap sinks in config file will be ignored.


Note:
If a subagent calls this method, trap will be sent directly to the remote trap receivers intead of going through master agent. Subagent can use SubAgentSession.sendTrap to pass trap on to master agent.

Parameters:
trap - SNMPv1 trap to sent out
config - Snmp agent config, trap will be sent to the trap sinks specified in this object

sendV1Trap

public static void sendV1Trap(int generic,
                              int specific,
                              SnmpVarBind[] varbinds)
Sends out SNMPV1 trap to all the trap sinks specified in the default config file. If trap sink's version property's value is 2, the passed v1 trap will be converted to v2 trap then sent out.

Since enterprise OID is not specified, the "system.sysObjectID" value specified in the config file will be used as enterprise OID.

You also can use SnmpTrapSender class to send out traps, then the trap sinks in config file will be ignored.


Note:
If a subagent calls this method, trap will be sent directly to the remote trap receivers intead of going through master agent. Subagent can use SubAgentSession.sendTrap to pass trap on to master agent.

Parameters:
generic - the value of the generic field
specific - the value of the specific field,

sendV1Trap

public static void sendV1Trap(int generic,
                              int specific,
                              SnmpVarBind[] varbinds,
                              DefaultAgentConfig config)
Sends out SNMPV1 trap to all the trap sinks specified in the config file. If trap sink's version property's value is 2, the passed v1 trap will be converted to v2 trap then sent out.

You also can use SnmpTrapSender class to send out traps, then the trap sinks in config file will be ignored.


Note:
If a subagent calls this method, trap will be sent directly to the remote trap receivers intead of going through master agent. Subagent can use SubAgentSession.sendTrap to pass trap on to master agent.

Parameters:
generic - the value of the generic field
specific - the value of the specific field
config - Snmp agent config, trap will be sent to the trap sinks specified in this object

sendV2ColdStartTrap

public static void sendV2ColdStartTrap()
Sends SNMPV2 coldStart trap to all trapsinks specified in the default config file


sendV2WarmStartTrap

public static void sendV2WarmStartTrap()
Sends SNMPV2 warmStart trap to all trapsinks


sendV2LinkDownTrap

public static void sendV2LinkDownTrap(int ifIndex,
                                      int ifAdminStatus,
                                      int ifOperStatus)
Sends out SNMPV2 linkDown trap to all trapsinks


sendV2LinkUpTrap

public static void sendV2LinkUpTrap(int ifIndex,
                                    int ifAdminStatus,
                                    int ifOperStatus)
Sends out SNMPV2 linkUp trap to all trapsinks


sendV2AuthenticationFailureTrap

public static void sendV2AuthenticationFailureTrap()
Sends out SNMPV2 authenticationFailure trap to all trapsinks


sendV1ColdStartTrap

public static void sendV1ColdStartTrap()
Sends SNMPV1 coldStart trap to all trapsinks


sendV1WarmStartTrap

public static void sendV1WarmStartTrap()
Sends SNMPV1 warmStart trap to all trapsinks


sendV1LinkDownTrap

public static void sendV1LinkDownTrap(int ifIndex)
Sends SNMPV1 linkDown trap to all trapsinks


sendV1LinkUpTrap

public static void sendV1LinkUpTrap(int ifIndex)
Sends SNMPV1 linkUp trap to all trapsinks


sendV1AuthenticationFailureTrap

public static void sendV1AuthenticationFailureTrap()
Sends SNMPV1 authenticationFailure trap to all trapsinks


sendV1EgpNeighborLossTrap

public static void sendV1EgpNeighborLossTrap(String ipAddress)
Sends SNMPV1 egpNeighborLoss trap to all trapsinks


addAgentEventListener

public void addAgentEventListener(Listener listener)
This method allows the registration of event listeners. Listener.handleMsg(Session session, Msg msg) will get called if an agent event is raised

Parameters:
listener - an object which implements Listener interface
See Also:
Listener.handleMsg(java.lang.Object, com.ireasoning.protocol.Msg)

removeAgentEventListener

public void removeAgentEventListener(Listener listener)
This method allows the removal of event listeners from the event target. If an EventListener is removed from an EventTarget while it is processing an event, it will not be triggered by the current actions.

Parameters:
listener - an object which implements Listener interface

setDefaultMaxRepetions

protected void setDefaultMaxRepetions(int repetitions)
Changes the max_repetions if maxRepetions field in the received GET_BULK request is 0. The default value is 1.


finalize

protected void finalize()
                 throws Throwable
Cleanup resources, gets called by JVM garbage collector

Throws:
Throwable

setOIDTree

protected abstract void setOIDTree()
Sets SnmpOID tree, which represents all available OIDs


registerMBeans

protected abstract void registerMBeans()
                                throws SnmpException
Registers MBeans. This method is called in this class' constructor.

Throws:
SnmpException

unregisterMBeans

protected void unregisterMBeans()
Unregister MBeans. Subclass needs to override this method to unregister MBeans. It's an empty method in this class.


copy

public com.ireasoning.core.network.DataHandler copy()
Overrides super class's abstract method, for internal use only.

Specified by:
copy in interface com.ireasoning.core.network.DataHandler

handleNewConnection

public int handleNewConnection(SocketServer server,
                               Object sock)
Overrides super class's abstract method, not applicable to this class.

Specified by:
handleNewConnection in interface com.ireasoning.core.network.DataHandler
Returns:
-1 to terminate this new connection

setUseSnmpDataType

public void setUseSnmpDataType(boolean b)
Parameters:
b - if true, all table/group class members use subclasses of SnmpDataType; if false, use String for SnmpOctetString, and int for SnmpInt.

getUseSnmpDataType

public boolean getUseSnmpDataType()

HOME

Copyright © 2002 iReasoning Inc. All Rights Reserved.