HOME

com.ireasoning.protocol.snmp
Class SnmpAgentX

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

public abstract class SnmpAgentX
extends SnmpBaseAgent

This class provides support for AgentX protocol, a master/subagent architecture specified in RFC 2741. RFC 2741 defines a standardized framework for extensible SNMP agents, it defines processing entities called master agents and subagents, a protocol (AgentX) used to communicate between them, and the elements of procedure by which the extensible agent processes SNMP protocol messages.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.ireasoning.protocol.snmp.SnmpBaseAgent
_configFileName, _port, _root, _shouldExit, _snmpAdaptorServer, AUTHENTICATION_FAILURE_TRAP, AUTHENTICATION_FAILURE_TRAP_OID, COLD_START_TRAP, COLD_START_TRAP_OID, EGPNEIGHBOR_LOSS_OID, EGPNEIGHBOR_LOSS_TRAP, LINK_DOWN_TRAP, LINK_DOWN_TRAP_OID, LINK_UP_TRAP, LINK_UP_TRAP_OID, SNMP_TRAP_OID, SYS_UP_TIME_OID, WARM_START_TRAP, WARM_START_TRAP_OID
 
Fields inherited from class com.ireasoning.core.jmx.BaseAgent
_mbeanServer
 
Constructor Summary
protected SnmpAgentX()
          Creates subagent only SnmpAgentX instance, without any config file
protected SnmpAgentX(MBeanServer server)
          Creates subagent only SnmpAgentX instance, without any config file
protected SnmpAgentX(MBeanServer server, DefaultAgentConfig config, boolean noStandardSnmpAgent, boolean startAgentAutomatically)
          Constructor.
protected SnmpAgentX(MBeanServer server, int port, DefaultAgentConfig config, boolean startAgentAutomatically)
          Constructor.
protected SnmpAgentX(MBeanServer server, Object configFileNameOrInputStream, boolean noStandardSnmpAgent)
          Constructor.
protected SnmpAgentX(MBeanServer server, Object configFileNameOrInputStream, boolean noStandardSnmpAgent, boolean startAgentAutomatically)
          Constructor.
protected SnmpAgentX(Object configFileNameOrInputStream, boolean noStandardSnmpAgent)
          Constructor.
 
Method Summary
 void addSubagentEventListener(Listener listener)
          This method allows the registration of event listeners.
protected  SnmpError allocateTableIndices(SnmpVarBind[] vbs, boolean isNewIndex, boolean isAnyIndex)
          This method must be implemented to process agentx-IndexAllocate-PDU.
 SubAgentSession connect(String masterAgentHostName, int port)
          Connects this subagent to master agent.
protected  SnmpError deallocateTableIndices(SnmpVarBind[] vbs)
          This method must be implemented to process agentx-IndexDeallocate-PDU.
 long getMasterAgentSysUpTime()
          Returns the sysUptime of master agent, in hundredth of a second.
 List getRegisteredSubtrees()
           
 void removeSubagentEventListener(Listener listener)
          This method allows the removal of event listeners from the event target.
static boolean sendTrapToMasterAgents(SnmpTrap trap)
          Sends out trap to all connected master agents.
 void startMasterAgent()
          Starts master agent listening on port specified in the agent config file ( properties:masterAgentPort field )
 void startMasterAgent(int port)
          Starts master agent.
 void stopMasterAgent()
          Stops master agent whose port is specified in config file's masterAgentPort field
 void stopMasterAgent(int port)
          Stops master agent
 
Methods inherited from class com.ireasoning.protocol.snmp.SnmpBaseAgent
addAgentEventListener, checkPdu, checkPdu, cleanup, copy, finalize, getAgentStats, getAgentUsmStats, getConfig, getConfigFileName, getDefaultConfig, getSnmpAdaptorServer, getSysUpTime, getUseSnmpDataType, handleData, handleNewConnection, handleNotification, initialize, preSendPdu, registerMBeans, removeAgentEventListener, sendV1AuthenticationFailureTrap, sendV1ColdStartTrap, sendV1EgpNeighborLossTrap, sendV1LinkDownTrap, sendV1LinkUpTrap, sendV1Trap, sendV1Trap, sendV1Trap, sendV1Trap, sendV1WarmStartTrap, sendV2AuthenticationFailureTrap, sendV2ColdStartTrap, sendV2LinkDownTrap, sendV2LinkUpTrap, sendV2Trap, sendV2Trap, sendV2Trap, sendV2Trap, sendV2Trap, sendV2Trap, sendV2WarmStartTrap, setConfig, setDefaultMaxRepetions, setOIDTree, setPort, setUseSnmpDataType, shouldExit, start, stop, unregisterMBeans
 
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
 

Constructor Detail

SnmpAgentX

protected SnmpAgentX()
              throws Exception
Creates subagent only SnmpAgentX instance, without any config file


SnmpAgentX

protected SnmpAgentX(MBeanServer server)
              throws Exception
Creates subagent only SnmpAgentX instance, without any config file


SnmpAgentX

protected SnmpAgentX(Object configFileNameOrInputStream,
                     boolean noStandardSnmpAgent)
              throws Exception
Constructor. Uses the port number specified in the config file.

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.
noStandardSnmpAgent - if true, it does not start an SNMP agent to accept SNMP requests directly, intead, SNMP requests are passed from master agent. Otherwise, a standard agent will be started on the port number specified in the config file.

SnmpAgentX

protected SnmpAgentX(MBeanServer server,
                     Object configFileNameOrInputStream,
                     boolean noStandardSnmpAgent)
              throws Exception
Constructor. Uses the port number specified in the config file.

Parameters:
server - the MBeanServer object which is to be used to create/register MBeans
noStandardSnmpAgent - if true, it does not start an SNMP agent to accept SNMP requests directly, intead, SNMP requests are passed from master agent. Otherwise, a standard agent will be started on the port number specified in the config file.
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.

SnmpAgentX

protected SnmpAgentX(MBeanServer server,
                     Object configFileNameOrInputStream,
                     boolean noStandardSnmpAgent,
                     boolean startAgentAutomatically)
              throws Exception
Constructor. Uses the port number specified in the config file.

Parameters:
server - the MBeanServer object which is to be used to create/register MBeans
noStandardSnmpAgent - if true, it does not start an SNMP agent to accept SNMP requests directly, intead, SNMP requests are passed from master agent. Otherwise, a standard agent will be started on the port number specified in the config file.
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.

SnmpAgentX

protected SnmpAgentX(MBeanServer server,
                     DefaultAgentConfig config,
                     boolean noStandardSnmpAgent,
                     boolean startAgentAutomatically)
              throws Exception
Constructor. Uses the port number specified in the config file.

Parameters:
server - the MBeanServer object which is to be used to create/register MBeans
noStandardSnmpAgent - if true, it does not start an SNMP agent to accept SNMP requests directly, intead, SNMP requests are passed from master agent. Otherwise, a standard agent will be started on the port number specified in the config file.
config - the config object
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.

SnmpAgentX

protected SnmpAgentX(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
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.
Method Detail

startMasterAgent

public void startMasterAgent()
                      throws IOException
Starts master agent listening on port specified in the agent config file ( properties:masterAgentPort field )

Throws:
IOException

startMasterAgent

public void startMasterAgent(int port)
                      throws IOException
Starts master agent.

Parameters:
port - master agent listening TCP port, which listens for subagent connections. This port is different from standard SNMP agent UDP port (161), which is used to accept UDP requests.
Throws:
IOException

stopMasterAgent

public void stopMasterAgent()
Stops master agent whose port is specified in config file's masterAgentPort field

See Also:
stopMasterAgent(int port)

stopMasterAgent

public void stopMasterAgent(int port)
Stops master agent

Parameters:
port - the TCP port number of the master agent to be stopped
See Also:
startMasterAgent(int port)

connect

public SubAgentSession connect(String masterAgentHostName,
                               int port)
                        throws IOException
Connects this subagent to master agent. Establishes TCP connection and sends out OPEN PDU to master agent.

Parameters:
masterAgentHostName - the host name or ip address of master agent
port - master agent listening port, 705 (TCP port) by default
Throws:
IOException

getMasterAgentSysUpTime

public long getMasterAgentSysUpTime()
Returns the sysUptime of master agent, in hundredth of a second.


allocateTableIndices

protected SnmpError allocateTableIndices(SnmpVarBind[] vbs,
                                         boolean isNewIndex,
                                         boolean isAnyIndex)
This method must be implemented to process agentx-IndexAllocate-PDU.

Each passed SnmpVarBind in the array is processed until either all are successful, or one fails. If any VarBind fails, it returns an SnmpError object with its errorIndex set to indicate the failed VarBind, and its errorStatus set a constant in AgentXConst. All other VarBinds are ignored; no index values are allocated.

If both the isNewIndex and isAnyIndex are false, allocation of a specific index value is being requested. If the requested index is already allocated for v.name in the indicated context, the VarBind fails and returned errorStatus is set to AgentXConst.INDEX_ALREADY_ALLOCATED.

Parameters:
vbs - VarBind list contained in the received PDU
isNewIndex - if true, the master agent should generate the next available index value for name of the VarBind in the indicated context, with the constraint that this value must not have been allocated (even if subsequently released) to any subagent since the last re-initialization of the master agent. If no such value can be generated, the VarBind fails and returned errorStatus is set to AgentXConst.INDEX_NONE_AVAILABLE.
isAnyIndex - if true, the master agent should generate an index value for name of the VarBind in the indicated context, with the constraint that this value is not currently allocated to any subagent. If no such value can be generated, then the VarBind fails and returned errorStatus is set to AgentXConst.INDEX_NONE_AVAILABLE.
Returns:
SnmpError.NO_ERROR if everything is ok. Otherwise, an SnmpError object containing the right errorIndex and errorStatus

deallocateTableIndices

protected SnmpError deallocateTableIndices(SnmpVarBind[] vbs)
This method must be implemented to process agentx-IndexDeallocate-PDU.

Each passed SnmpVarBind is processed until either all are successful, or one fails. If any VarBind fails, it returns an SnmpError object with its errorIndex set to indicate the failed VarBind, and its errorStatus set a constant in AgentXConst. All other VarBinds are ignored; no index values are released.

Parameters:
vbs - VarBind list contained in the received PDU
Returns:
SnmpError.NO_ERROR if everything is ok. Otherwise, an SnmpError object containing the right errorIndex and errorStatus

getRegisteredSubtrees

public List getRegisteredSubtrees()
Returns:
a List containing registered subtrees. Each element of the List is a String object.

sendTrapToMasterAgents

public static boolean sendTrapToMasterAgents(SnmpTrap trap)
                                      throws IOException
Sends out trap to all connected master agents. It does nothing if this is a master agent only or no active master connection.

Returns:
a boolean value indidates whether any error occurs
Throws:
IOException - raised if trap can't be sent to master agent

addSubagentEventListener

public void addSubagentEventListener(Listener listener)
This method allows the registration of event listeners. Listener.handleMsg(Session session, Msg msg) will get called if subagent state changed

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

removeSubagentEventListener

public void removeSubagentEventListener(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

HOME

Copyright © 2002 iReasoning Inc. All Rights Reserved.