com.adventnet.snmp.snmp2.agent
Class SnmpProxy

java.lang.Object
  |
  +--com.adventnet.snmp.snmp2.agent.Cache
        |
        +--com.adventnet.snmp.snmp2.agent.BaseSnmpStore
              |
              +--com.adventnet.snmp.snmp2.agent.SnmpStore
                    |
                    +--com.adventnet.snmp.snmp2.agent.SnmpProxy
Direct Known Subclasses:
DynamicSnmpProxy, ProxyByHost

public class SnmpProxy
extends SnmpStore
implements VarBindRequestListener, java.io.Serializable

SnmpProxy class is used to implement the Proxy bean.

The associated getRequest, getnextRequest, setRequest is proxied to another snmp agent specified as this bean's properties.

This class implements the VarBindRequestListener for handling the appropriate snmp requests and proxies to real agent.

It also extends SnmpStore for getting the SnmpAPI and proxy-session from the cache

See Also:
VarBindRequestListener, SnmpStore, Serialized Form

Field Summary
(package private)  java.lang.String agentHost
           
(package private)  int agentPortNumber
           
(package private)  long agentTimeOut
           
(package private)  SnmpAPI api
          The Snmp API thread used for callbacks by SnmpAgent
(package private)  java.lang.String community
           
protected  SnmpPDU pdu
           
(package private)  SnmpSession proxySession
          The Snmp Session used for proxying by SnmpAgent
(package private)  java.lang.String registeredOid
           
(package private)  int retries
           
(package private)  int status
           
(package private)  boolean userBasedCommunityPolicy
           
 
Fields inherited from class com.adventnet.snmp.snmp2.agent.BaseSnmpStore
debugLevel, localAddress, oldAddress, oldPort, protocol, session, snmpLog
 
Fields inherited from class com.adventnet.snmp.snmp2.agent.Cache
cache, debug
 
Constructor Summary
SnmpProxy()
          No Arg constructor Initialises the ProxySession which is shared by all the SnmpProxy.
 
Method Summary
 void addRegistrationListener(RegistrationListener l)
          adds the registration listener for this bean.This listener maintains the registration tree where VarBindRequestListeners can register for their interested OID.
 java.lang.String getAgentHost()
          Gets the proxy host name.
 int getAgentPortNumber()
          Get the agent Port Number to be proxied
 long getAgentTimeOut()
          Gets the timeout value for the response PDU which is to be proxied
(package private)  java.lang.String getkey()
           
 void getNextRequest(VarBindRequestEvent pe, AgentResource agentSource)
          method handles GetNextRequests from the manager Implementation of the VarBindRequestListener interface.
 java.lang.String getRegisteredOid()
          gets the OID which needs to be proxied
 void getRequest(VarBindRequestEvent pe)
          method handles GetRequests from the manager.
protected  SnmpPDU getRespPdu()
          This method is used when this agent acts as a proxy Agent.
protected  java.util.Vector getRespPdu(VarBindRequestEvent pe, byte command)
           
 int getRetries()
          Getter for the retries count of this entry.
 int getRowStatus()
          Getter for the status of this Proxy entry.
 int[] getSubidList()
          The subids under the Object being proxied dummy implementation of VarBindRequestListener Since we expect all the OIDS that falls under the registeredOid tree to be proxied rather than restricting to subIdList
 int getVersion()
          The Getter for the SNMP Version through the which the query has to be made.
(package private)  void initProxySession()
          This method should be called by SnmpAgent and no one else
 boolean isProxySessionAlive()
          Gets the status of the proxy session.
 boolean isProxyTimeOuts()
          Getter for Proxy TimeOuts.
 boolean isUserBasedCommunityPolicy()
          Getter which indicates whether we require a userBasedCommunityPolicy.Only if this boolean is true the community set in setCommunity method will take into effect.
 void removeRegistrationListener(RegistrationListener l)
          removes the registration listener for this bean.
 void setAgentHost(java.lang.String host)
          Set the agentHost name to which the pdu should be proxied.
 void setAgentPortNumber(int port)
          Set the agent Port Number to be proxied
 void setAgentTimeOut(long timeout)
          Set the timeout value for the response PDU which is to be proxied
 void setCommunity(java.lang.String community)
          Community for sending proxy, typically the SnmpAgent will fill based on incoming pdu
 void setProxyTimeOuts(boolean proxyTimeOuts)
          Setter for Proxy Time outs.
 void setRegisteredOid(java.lang.String oid)
          sets the OID which needs to be proxied.
 void setRequest(VarBindRequestEvent pe)
          method handles setRequest from the manager Implementation of the VarBindRequestListener interface.
 void setRetries(int retries)
          Setter for the retries count for this proxy event.
 void setRowStatus(int rs)
          Method to set the Status value of this Proxy event.
 void setUserBasedCommunityPolicy(boolean policy)
          Set this to false to indicate that the Proxy request should be sent with the community of in the DynamicRegistrationEntry.
 void setVersion(int version)
          The Setter for the SNMP Version through the which the query has to be made.
 void startProxySession()
          Opens the proxy session to proxy the SnmpPDU calls the getProxySession in SnmpStore.
 void stopProxySession()
          Stop the proxy Session and stop the api Thread associated with it.
 
Methods inherited from class com.adventnet.snmp.snmp2.agent.SnmpStore
getProxySession, getTrapReceiverSession, initSnmpStore
 
Methods inherited from class com.adventnet.snmp.snmp2.agent.BaseSnmpStore
closeAll, createProtocolOptions, finalize, getSnmpAPI, getSnmpSession, getSnmpSession, initSession, initSnmpStore, isAlive, isDebug, killSnmpAgent, setDebug
 
Methods inherited from class com.adventnet.snmp.snmp2.agent.Cache
getFromCache, getMibOperations, putInCache, setMibOperations
 
Methods inherited from class java.lang.Object
, clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

agentHost

java.lang.String agentHost

agentPortNumber

int agentPortNumber

agentTimeOut

long agentTimeOut

pdu

protected SnmpPDU pdu

proxySession

SnmpSession proxySession
The Snmp Session used for proxying by SnmpAgent

api

SnmpAPI api
The Snmp API thread used for callbacks by SnmpAgent

community

java.lang.String community

userBasedCommunityPolicy

boolean userBasedCommunityPolicy

registeredOid

java.lang.String registeredOid

retries

int retries

status

int status
Constructor Detail

SnmpProxy

public SnmpProxy()
No Arg constructor Initialises the ProxySession which is shared by all the SnmpProxy.
Method Detail

setAgentHost

public void setAgentHost(java.lang.String host)
Set the agentHost name to which the pdu should be proxied.
Parameters:
host - the name of the host to proxy.

getAgentHost

public java.lang.String getAgentHost()
Gets the proxy host name.
Returns:
the Agent Host to be proxied to

setAgentPortNumber

public void setAgentPortNumber(int port)
Set the agent Port Number to be proxied
Parameters:
port - proxy agent port number

getAgentPortNumber

public int getAgentPortNumber()
Get the agent Port Number to be proxied
Returns:
the agent Port Number to be proxied

setAgentTimeOut

public void setAgentTimeOut(long timeout)
Set the timeout value for the response PDU which is to be proxied
Parameters:
timeout - the timer value

getAgentTimeOut

public long getAgentTimeOut()
Gets the timeout value for the response PDU which is to be proxied
Returns:
the agent Timeout value

getkey

java.lang.String getkey()

setCommunity

public void setCommunity(java.lang.String community)
Community for sending proxy, typically the SnmpAgent will fill based on incoming pdu

Applications such as ProxyByHost use this method to have a gateway between received community and community used to proxy

Parameters:
community - the name of the community

setUserBasedCommunityPolicy

public void setUserBasedCommunityPolicy(boolean policy)
Set this to false to indicate that the Proxy request should be sent with the community of in the DynamicRegistrationEntry. setting this false will use the community of the request pdu from the Manager to the proxied request also.
Parameters:
policy - the community policy to be followed

isUserBasedCommunityPolicy

public boolean isUserBasedCommunityPolicy()
Getter which indicates whether we require a userBasedCommunityPolicy.Only if this boolean is true the community set in setCommunity method will take into effect.
Returns:
the policy boolean value

startProxySession

public void startProxySession()
Opens the proxy session to proxy the SnmpPDU calls the getProxySession in SnmpStore.

initProxySession

void initProxySession()
                throws SnmpException
This method should be called by SnmpAgent and no one else

getRespPdu

protected SnmpPDU getRespPdu()
                      throws AgentSnmpException
This method is used when this agent acts as a proxy Agent. and to receive the response PDU from the poxy host.
Returns:
SnmpPDU received from real Agent and to be sent to manager.
Throws:
AgentSnmpException - thrown if any error occurs.

getRequest

public void getRequest(VarBindRequestEvent pe)
                throws AgentSnmpException
method handles GetRequests from the manager. Implementation of the VarBindRequestListener interface.
Specified by:
getRequest in interface VarBindRequestListener
Parameters:
pe - the VarBindRequestEvent contains varbinds and information about the manager.
Throws:
AgentSnmpException - thrown if any error occurs.

getNextRequest

public void getNextRequest(VarBindRequestEvent pe,
                           AgentResource agentSource)
                    throws AgentSnmpException
method handles GetNextRequests from the manager Implementation of the VarBindRequestListener interface.
Specified by:
getNextRequest in interface VarBindRequestListener
Parameters:
pe - the VarBindRequestEvent contains varbinds and information about the manager.
agentSource - the AgentResource created for this request.
Throws:
AgentSnmpException - thrown if any error occurs.

setRequest

public void setRequest(VarBindRequestEvent pe)
                throws AgentSnmpException
method handles setRequest from the manager Implementation of the VarBindRequestListener interface.
Specified by:
setRequest in interface VarBindRequestListener
Parameters:
pe - the VarBindRequestEvent contains varbinds and information about the manager.
Throws:
AgentSnmpException - thrown if any error occurs.

getSubidList

public int[] getSubidList()
The subids under the Object being proxied dummy implementation of VarBindRequestListener Since we expect all the OIDS that falls under the registeredOid tree to be proxied rather than restricting to subIdList

Hence the subidlist is null.i.e registered for the full tree.

Returns:
null

getRespPdu

protected java.util.Vector getRespPdu(VarBindRequestEvent pe,
                                      byte command)

isProxySessionAlive

public boolean isProxySessionAlive()
Gets the status of the proxy session.
Returns:
true if the Session is alive

stopProxySession

public void stopProxySession()
                      throws SnmpException
Stop the proxy Session and stop the api Thread associated with it.
Throws:
SnmpException - thrown if any session socket error occurs.
See Also:
initProxySession()

setRegisteredOid

public void setRegisteredOid(java.lang.String oid)
sets the OID which needs to be proxied. If any pdu comes for the oid under the registeredOid tree, it gets proxied to specified agent unless the incoming oid is particularly registered by some other VarBindRequestListener.

Default value is ".1.3.6.1.2"

For example, If any other VarBindRequestListener is registered for oid .1.3.6.1.2.1.1.1 - SysDecr ,and if incoming pdu is for SysDecr then it will be given to that Listener rather proxying it to real Agent.

Parameters:
oid - value of the OID

getRegisteredOid

public java.lang.String getRegisteredOid()
gets the OID which needs to be proxied
Returns:
the value of OID

addRegistrationListener

public void addRegistrationListener(RegistrationListener l)
adds the registration listener for this bean.This listener maintains the registration tree where VarBindRequestListeners can register for their interested OID.
Parameters:
l - the registration listener to whom this SnmpProxy registers.

removeRegistrationListener

public void removeRegistrationListener(RegistrationListener l)
removes the registration listener for this bean.
Parameters:
l - the registration listener to whom this SnmpProxy has registered.

isProxyTimeOuts

public boolean isProxyTimeOuts()
Getter for Proxy TimeOuts.
Returns:
The proxy Agent's timeout option. true specifies that the Master agent will show timeout if the sub agent is not running.

setProxyTimeOuts

public void setProxyTimeOuts(boolean proxyTimeOuts)
Setter for Proxy Time outs. This flag specifies whether to send General Error or Time Out when the Sub Agent is down. By default false.
Parameters:
proxyTimeOuts - The proxy Agent's timeout option.

setVersion

public void setVersion(int version)
                throws java.lang.IllegalArgumentException
The Setter for the SNMP Version through the which the query has to be made.
Parameters:
version - the SNMP Version in which the proxy queries are to be forwarded. 1 for Snmp Version 1 and 2 for Snmp Version 2
Throws:
java.lang.IllegalArgumentException - if the Version set is not a valid one.

getVersion

public int getVersion()
The Getter for the SNMP Version through the which the query has to be made.
Returns:
The SNMP Version in which the proxy queries are to be forwarded.

setRetries

public void setRetries(int retries)
Setter for the retries count for this proxy event.
Parameters:
retries - the number of times, MasterAgent should retry to get a response from the SubAgent - default 0.

getRetries

public int getRetries()
Getter for the retries count of this entry.
Returns:
the Retries count of this entry.

setRowStatus

public void setRowStatus(int rs)
Method to set the Status value of this Proxy event. Setting this other than active(1) will stop proxying the request.
Parameters:
rs - int specifying the status of this Proxy entry - default 1.

getRowStatus

public int getRowStatus()
Getter for the status of this Proxy entry.
Returns:
The status int of this event.