com.adventnet.snmp.snmp2
Class SnmpSession

java.lang.Object
  extended by java.lang.Thread
      extended by com.adventnet.snmp.snmp2.SnmpSession
All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable

public class SnmpSession
extends java.lang.Thread
implements java.io.Serializable

SnmpSession is the basic communication class for performing any SNMP operations. This class extends "java.lang.Thread". This thread is the receiver thread of AdventNet SNMP API stack. This thread receives packets, decodes them and form SnmpPDU objects.

This class is thread safe. That is, a single instance of SnmpSession can be used simultaneously by a large number of threads to do SNMP operations. So there is really less need to instantiate a number of SnmpSession objects.

Some of the important features that this class has are:

The Asynchronous way of sending SNMP requests. The method "send(SnmpPDU)" can be used to send such asynchronous requests to the desired host/port. To receive the response, the SnmpClient interface should be implemented and add it using the method "addSnmpClientWithID". This method returns a id, which can be set on the SnmpPDU object before sending a request. By doing this, only that particular client will be called with the response, otherwise all the clients that has been added to this SnmpSession will be informed with the response.

The Synchronous way of sending SNMP requests. The method "syncSend(SnmpPDU)" can be used for this purpose. This method waits till the response arrives or till timeout.

Any SnmpTransportProvider implementation can be plugged into this class. The interface that should be used for this implementation is SnmpTransportProvider. By default the underlying protocol used is UDP. AdventNet SNMP API stack also provides implementation for TCP. The method "setTransportProvider(String)" can be used to set the implementation class name.

Any SNMP network management Applet can be written using this class.

While performing asynchronous SNMP operations, a delay between packets that are sent into the network can be achieved by using the method "setTimeToWait(int)". This will ensure that each packet is sent out with the specified delay.

Every request that is sent out will wait for the response till a specified timeout value. The default value of this timeout is 5 seconds. In case of retries, the timeout value increase exponentially. This timeout policy for retries can be plugged in by using the abstract class TimeoutPolicy. The "setTimeoutPolicy(TimeoutPolicy)" method can be used to achieve this.

Every response received will be given to the "callback" method of SnmpClient. Further processing will be done in the "callback" method. During this processing time some packets may get dropped. To minimize this packet loss, a separate processing thread called the "CALLBACK" thread is provided. This thread can be started by calling the method "setCallbackthread(boolean)" with the "true" value.

A sample code snippet of how to create a SnmpSession object.
SnmpAPI api = new SnmpAPI();
SnmpSession session = new SnmpSession(api);
session.open();

SnmpPDU pdu = new SnmpPDU();
pdu.setProtocolOptions(new UDPProtocolOptions("localhost"));
pdu.setCommand(SnmpAPI.GET_REQ_MSG);
pdu.addNull(new SnmpOID(".1.3.6.1.2.1.1.1.0"));
SnmpPDU response_pdu = session.syncSend(pdu);
if(response_pdu == null)
{
     System.out.println("The Request has timed out.");
}
else
{
     System.out.println(response_pdu.printVarBinds());
}

The output for the above program will be
Object ID: .1.3.6.1.2.1.1.1.0
STRING: Linux localhost 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686

See Also:
SnmpPDU, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
(package private)  SnmpAPI API
           
(package private)  boolean authenticationFailed
           
(package private)  boolean autoInformResponse
           
(package private)  java.util.Vector clients
          The SnmpClient interfaces for this session.
(package private)  boolean closeSocket
           
(package private) static java.lang.String[] cmdStr
           
(package private)  byte[] contextName
          Context name associated with the message
 boolean disableAuthTrap
           
(package private)  SnmpGroup group
           
static int IP
          Deprecated. Since all the SNMP communications go through a single transport provider, this is not needed.
(package private)  boolean isSessionEstablished
           
(package private)  boolean isTrapAuthEnabled
           
(package private)  java.lang.String[] local_addrs
          Local Addresses, hostnames or IP addresses, to bind session to.
(package private)  int local_port
          Local UDP port number, 0 is the default in which case it's system assigned
(package private)  int packetBufferSize
          Datagram packet buffer size
(package private)  java.lang.String peername
          Domain name or dotted IP address of default peer.
(package private)  int protocol
           
(package private)  ProtocolOptions protocolOptions
           
(package private)  int remote_port
          snmp target port number of peer.
(package private)  java.util.Vector requestList
           
(package private)  int RESP_QUEUE_SIZE
           
(package private)  java.util.Vector responseList
           
(package private)  int retries
          Number of retries before timeout.
(package private)  SASClient sasclient
          To get around socket access restriction in applets, the SASClient allows for using a process on the Applet host as a pass through for Snmp PDUs.
(package private) static int sasProtocol
           
(package private)  byte secLevelForTimeSync
          secLevelForTimeSync: The securityLevel that will be used when doing a timeSync for a authPriv user
(package private)  SnmpCallback snmpcallback
           
(package private)  int socketDelay
          This is the time the receiver thread waits before re-entering the blocking receive.
(package private)  int socketTimeout
          This is the socket Timeout set to default of 25ms.
(package private) static int startLocalPort
          Intoduced because of IE4.0 bug with using port 0.
(package private)  int timeout
          Number of mS until first timeout, then exponential backoff
(package private)  int TIMEOUT_QUEUE_SIZE
           
(package private)  java.util.Vector timeouts
           
static int TRANSPORT_PROVIDER
          Deprecated. Since all the SNMP communications go through a single transport provider, this is not needed.
(package private)  byte[] userName
          User Name : Is same as SecurityName for USM
(package private)  java.lang.String writeCommunity
          This is the writeCommunity used for authentication.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SnmpSession(SnmpAPI api)
          Creates a new SnmpSession object by taking the SnmpAPI instance.
 
Method Summary
 void addSnmpClient(SnmpClient client)
          Subscribe for callbacks.
 int addSnmpClientWithID(SnmpClient client)
          Subscribes for callbacks.
 int[] checkResponses()
          Checks for any outstanding responses that are still in the receive queue.
(package private)  int checkSyncResponse(int reqid)
          Checks the response PDU for request ID.
 boolean checkTimeout(int reqid)
          Returns true if the reqid is in the list of this session's timed out requests, and removes it from the list.
 void close()
          Close Snmp Session and stop receiver thread.
(package private)  void deQ(java.util.Vector v, int i)
           
(package private)  void deQ(java.util.Vector v, java.lang.Object obj)
           
(package private)  SimplePDU deQFromRequestList(int reqid)
           
(package private)  SnmpPDU deQFromResponseList(int reqid)
           
 void disableReqEcho(boolean flag)
           
(package private)  void enQ(java.util.Vector v, SimplePDU pdu)
          Place in specified queue
(package private)  void enQ(java.util.Vector v, SnmpPDU pdu)
          Place in specified queue
 SnmpVar get(SnmpOID oid)
          Deprecated. use the following instead

SnmpPDU pdu = new SnmpPDU();
pdu.addNull(oid);
pdu.setCommand(SnmpAPI.GET_REQ_MSG);
SnmpPDU response_pdu = snmpSession.syncSend(pdu);

SnmpVar var = null;
if(response_pdu != null)
{
var = response_pdu.getVariable(0);
}

 SnmpVar get(java.lang.String oidString)
          Deprecated. use the following instead

SnmpPDU pdu = new SnmpPDU();
pdu.addNull(new SnmpOID(oidString));
pdu.setCommand(SnmpAPI.GET_REQ_MSG);
SnmpPDU response_pdu = snmpSession.syncSend(pdu);

SnmpVar var = null;
if(response_pdu != null)
{
var = response_pdu.getVariable(0);
}

 java.lang.String getCommunity()
          Gets community for outgoing SNMPv1 and SNMPv2c requests.
 ConnectionListener getConnectionListener()
          To get reference to the ConnectionListener object.
 byte[] getContextName()
          Gets the context name associated with the SNMPv3 message.
 java.util.Vector getFailedInformRequest()
           
 java.util.Vector getInformResponsePDU()
           
 java.lang.String[] getLocalAddresses()
          Deprecated. use the following instead.
UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions();
String[] local_address = opt.getLocalAddresses();
 int getLocalPort()
          Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions();
int local_port = opt.getLocalPort();

 SnmpVar getnext(SnmpOID oid)
          Deprecated. use the following instead

SnmpPDU pdu = new SnmpPDU();
pdu.addNull(oid);
pdu.setCommand(SnmpAPI.GETNEXT_REQ_MSG);
SnmpPDU response_pdu = snmpSession.syncSend(pdu);

SnmpVar var = null;
if(response_pdu != null)
{
var = response_pdu.getVariable(0);
}

 SnmpVar getnext(java.lang.String oidString)
          Deprecated. use the following instead

SnmpPDU pdu = new SnmpPDU();
pdu.addNull(new SnmpOID(oidString));
pdu.setCommand(SnmpAPI.GETNEXT_REQ_MSG);
SnmpPDU response_pdu = snmpSession.syncSend(pdu);

SnmpVar var = null;
if(response_pdu != null)
{
var = response_pdu.getVariable(0);
}

 int getPacketBufferSize()
          Gets the Datagram Buffer Size used for receiving SNMP packets.
 java.lang.String getPeername()
          Deprecated. use the following instead.
UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions(); opt.getRemoteHost();
 int getProtocol()
          Deprecated. since all SNMP communications go through only a transportProvider, this method is not at all necessary.
 ProtocolOptions getProtocolOptions()
          This method will return the ProtocolOptions associated with this SnmpSession.
 int getReceiveBufferSize()
          Deprecated. instead use the getReceiveBufferSize method available in UDPProtocolOptions.
 int getRemotePort()
          Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions();
opt.getRemotePort();

 boolean getReport()
          Returns the status of report flag.
(package private)  SimplePDU getRequest(int reqid)
           
 int getRetries()
          Gets number of retries before timeout.
 SASClient getSASClient()
          Deprecated. use the following instead
SASProtocolOptions opt = (SASProtocolOptions)snmpSession.getProtocolOptions();
SASClient sasclient = opt.getSASClient();
 int getSASProtocol()
          Deprecated. use the following instead.

SASProtocolOptions opt = (SASProtocolOptions)snmpSession.getProtocolOptions();
int sasprotocol = opt.getProtocol();

 byte getSecLevelForTimeSync()
          Returns the securitylevel that would be used when doing a V3 timeSync for a authPriv user.
 java.text.SimpleDateFormat getSimpleDateFormat()
          Gets the SimpleDateFormat for this class.
 SnmpAPI getSnmpAPI()
          Returns the SnmpAPI reference associated with this SnmpSession.
 java.util.Vector getSnmpClients()
          Returns the clients that have been registered for callbacks or null is returned if no one is registered.
 int getSnmpClientsSize()
          Deprecated. use the following instead

int snmpClientsSize = (snmpSession.getSnmpClients()).size();

 java.util.Hashtable getSnmpClientsWithID()
          Returns the hashtable in which the clientID and the SnmpClient are associated.
 int getStartLocalPort()
          Deprecated. now the "open(Applet)" method will throw an SnmpException if it is unable to connect to the SAServer. When such an exception is received, the user should decide whether "open(void)" method should be called or not.
 int getTimeout()
          Gets the timeout value.
 int getTimeToWait()
          Gets the inter-packet delay time set on this SnmpSession object.
 java.lang.String getTransportProvider()
          This method gets the transportProvier classname.
 byte[] getUserName()
          Returns the principal for SNMPv3 messages.
 int getVersion()
          Gets snmp version for outgoing SNMP requests.
 java.lang.String getWriteCommunity()
          Gets writeCommunity for outgoing requests.
 boolean isBroadcastFeatureEnable()
          The method returns whether the API has the broadcast feature enabled or not.
 boolean isSessionEstablished()
          To get the status of the connection established using this session instance.
 boolean isSetAutoInformResponse()
          Checks if the automatic response flag for the Inform Request is set.
 boolean isTrapAuthEnable()
          Gets status of Trap Authentication for v3 pdus.
(package private)  void monitorRequests()
          Monitors user requests for timeouts, and re-transmits
 void open()
          Opens Snmp Session to communicate with an SNMP peer.
 void open(java.applet.Applet applet)
          Deprecated. use the following instead

SnmpAPI api = new SnmpAPI();
SnmpSession ses = new SnmpSession(api);
SASProtocolOptions opt = new SASProtocolOptions();
opt.setApplet(applet);
ses.setProtocolOptions(opt);
ses.open();

 java.util.Hashtable partialSet(SnmpOID[] oids, SnmpVar[] vars)
          SNMP set request method is for multiple SnmpOID argument.
 java.util.Hashtable partialSet(SnmpPDU pdu)
          SNMP set request method is for multiple SnmpOID argument.
(package private)  void processPacket(SnmpPDU pdu)
           
 SnmpPDU receive(int reqid)
          Fetches SNMP response PDU, fetches first PDU in response queue, if reqid is 0.
 void removeAllSnmpClients()
          This method removes all the SnmpClients that were registered in this SnmpSession.
 void removeConnectionListener()
          Unsubscribes for ConnectionListener.
 void removeSnmpClient(SnmpClient client)
          Unsubscribes for callbacks.
 void removeSnmpClientWithID(int clientid)
          Unsubscribe for callbacks.
 void restoreDefaultTimeoutPolicy()
          restores this SnmpSession object to have the default TimeoutPolicy.
 void run()
          The run method starts the receiver thread for this session object.
 int send(SnmpPDU pdu)
          Send SnmpPDU on the given session after encoding the PDU.
 java.util.Vector sendNotification(SnmpPDU pdu)
          Authenticates and sends the notification to all the entries that can avail of the notification filtering facility.
 SnmpVar set(SnmpOID oid, SnmpVar var)
          Deprecated. use the following instead

SnmpPDU pdu = new SnmpPDU();
SnmpVarBind varbind = new SnmpVarBind(oid, var);
pdu.addVariableBinding(varbind);
pdu.setCommand(SnmpAPI.SET_REQ_MSG);
SnmpPDU response_pdu = snmpSession.syncSend(pdu);

SnmpVar response_var = null;
if(response_pdu != null)
{
response_var = response_pdu.getVariable(0);
}

 SnmpVar set(java.lang.String oidString, java.lang.String setString, byte type)
          Deprecated. use the following instead

SnmpPDU pdu = new SnmpPDU();
SnmpVar variable = SnmpVar.createVariable(setString, type);
SnmpOID oid = new SnmpOID(oidString);
SnmpVarBind varbind = new SnmpVarBind(oid, variable);
pdu.addVariableBinding(varbind);
pdu.setCommand(SnmpAPI.SET_REQ_MSG);
SnmpPDU response_pdu = snmpSession.syncSend(pdu);

SnmpVar var = null;
if(response_pdu != null)
{
var = response_pdu.getVariable(0);
}

 void setAutoInformResponse(boolean flag)
          Sets the automatic response flag for the Inform Request.
 void setBroadcastFeatureEnable(boolean bool)
          The method can be used to enable/disable the broadcast feature available in the API.
 void setCallbackthread(boolean useThread)
          Sets this to true if the user wants the callback to be called from a seperate thread.
 void setCommunity(java.lang.String community)
          Sets community for outgoing SNMPv1 and SNMPv2c requests.
 void setConnectionListener(ConnectionListener connListener)
          Subscribes for ConnectionListener.
 void setContextName(byte[] name)
          Sets the context name associated with the SNMPv3 message.
 void setDisableAuthTraps(boolean trap)
           
 void setLocalAddresses(java.lang.String[] local_addrs)
          Deprecated. use the following instead.
UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions(); opt.setLocalAddresses(local_addrs);
 void setLocalPort(int local_port)
          Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions();
opt.setLocalPort(local_port);

 void setPacketBufferSize(int size)
          Sets the Datagram Buffer Size used for receiving SNMP packets.
 void setPeername(java.lang.String peername)
          Deprecated. use the following instead.
UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions(); opt.setRemoteHost(peername);
 void setProtocol(int protocol)
          Deprecated. Since all the SNMP communications go through a single transport provider, this is not needed.
 void setProtocolOptions(ProtocolOptions tParam)
          This associates the ProtocolOptions with this SnmpSession.
 void setReceiveBufferSize(int bufferSize)
          Deprecated. instead use the setReceiveBufferSize method available in UDPProtocolOptions.
 void setRemotePort(int port)
          Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions();
opt.setRemotePort(port);

 void setReport(boolean status)
          Sets the status of report flag.
 void setRetries(int retries)
          Sets number of retries before timeout.
 void setSASProtocol(int prot)
          Deprecated. use the following instead.

SASProtocolOptions opt = new SASProtocolOptions();
opt.setApplet(applet);
opt.setProtocol(SASClient.TCP_PROTOCOL); //or SASClient.HTTP_PROTOCOL
snmpSession.setProtocolOptions(opt);
snmpSession.open();

 void setSecLevelForTimeSync(byte secLevel)
          Sets the securityLevel to use when doing a V3 timeSync for a authPriv user.
 void setSimpleDateFormat(java.text.SimpleDateFormat format)
          Sets the SimpleDateFormat for this class.
 void setSocketParms(int socketTimeout, int socketDelay)
          Deprecated. since a new transportProvider implementation for udp has been added, this method no longer becomes necessary.
 void setStartLocalPort(int startLocalPort)
          Deprecated. now the "open(Applet)" method will throw an SnmpException if it is unable to connect to the SAServer. When such an exception is received, the user should decide whether "open(void)" method should be called or not.
 void setTimeout(int timeout)
          Sets the timeout value.
 void setTimeoutPolicy(TimeoutPolicy timeoutPolicy)
          sets the TimeoutPolicy for this SnmpSession.
 void setTimeToWait(int waitTime)
          Sets the inter-packet delay time.
 void setTransportProvider(java.lang.String providerClassName)
          This method sets the transportProvider classname, which will be used for communication purposes.
 void setTrapAuthEnable(boolean isAuth)
          Specify whether traps should be authenticated while receiving SNMPv3 trap messages.
 void setUserName(byte[] name)
          Sets the principal for SNMPv3 messages.
 void setVersion(int version)
          Sets snmp version for outgoing requests.
 void setWriteCommunity(java.lang.String writeCommunity)
          Sets writeCommunity for outgoing requests.
(package private)  SnmpVar snmpRequest(byte request, SnmpOID oid, SnmpVar setValue)
          snmpRequest builds PDU and makes request per argument and waits for response.
 SnmpPDU syncSend(SnmpPDU pdu)
          Sends SnmpPDU synchronously - returns response SnmpPDU.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

disableAuthTrap

public boolean disableAuthTrap

writeCommunity

java.lang.String writeCommunity
This is the writeCommunity used for authentication. This is used in SET operations only. The writeCommunity string in the pdu overrides the writeCommunity in session. This means, only when the writeCommunity string in the pdu is null, the one in session is used. If the writeCommunity is not specified, then value in community field is used. The default writeCommunity value is null.


retries

int retries
Number of retries before timeout.


sasProtocol

static int sasProtocol

timeout

int timeout
Number of mS until first timeout, then exponential backoff


secLevelForTimeSync

byte secLevelForTimeSync
secLevelForTimeSync: The securityLevel that will be used when doing a timeSync for a authPriv user


userName

byte[] userName
User Name : Is same as SecurityName for USM


contextName

byte[] contextName
Context name associated with the message


isTrapAuthEnabled

boolean isTrapAuthEnabled

packetBufferSize

int packetBufferSize
Datagram packet buffer size


peername

java.lang.String peername
Domain name or dotted IP address of default peer.


remote_port

int remote_port
snmp target port number of peer.


local_addrs

java.lang.String[] local_addrs
Local Addresses, hostnames or IP addresses, to bind session to.


local_port

int local_port
Local UDP port number, 0 is the default in which case it's system assigned


startLocalPort

static int startLocalPort
Intoduced because of IE4.0 bug with using port 0. Set this so that next available port after this will be used. The default is 6000


sasclient

SASClient sasclient
To get around socket access restriction in applets, the SASClient allows for using a process on the Applet host as a pass through for Snmp PDUs. If this variable "sasclient" is non-null, this passthrough mechanism will be used for this session instance.


clients

java.util.Vector clients
The SnmpClient interfaces for this session.


socketTimeout

int socketTimeout
This is the socket Timeout set to default of 25ms. Avoids blocking receive. Can be reduced to increase send thoroughput.


socketDelay

int socketDelay
This is the time the receiver thread waits before re-entering the blocking receive. Set to default of 50ms.


IP

public static final int IP
Deprecated. Since all the SNMP communications go through a single transport provider, this is not needed.
Static constant for identifying the IP protocol

See Also:
Constant Field Values

TRANSPORT_PROVIDER

public static final int TRANSPORT_PROVIDER
Deprecated. Since all the SNMP communications go through a single transport provider, this is not needed.
Constant for using the transport provider framework

See Also:
Constant Field Values

protocol

int protocol

autoInformResponse

boolean autoInformResponse

protocolOptions

ProtocolOptions protocolOptions

closeSocket

boolean closeSocket

group

SnmpGroup group

API

SnmpAPI API

requestList

java.util.Vector requestList

responseList

java.util.Vector responseList

timeouts

java.util.Vector timeouts

RESP_QUEUE_SIZE

int RESP_QUEUE_SIZE

TIMEOUT_QUEUE_SIZE

int TIMEOUT_QUEUE_SIZE

snmpcallback

SnmpCallback snmpcallback

authenticationFailed

boolean authenticationFailed

isSessionEstablished

boolean isSessionEstablished

cmdStr

static final java.lang.String[] cmdStr
Constructor Detail

SnmpSession

public SnmpSession(SnmpAPI api)
Creates a new SnmpSession object by taking the SnmpAPI instance. The SnmpAPI instance is required so that this session registers with the SnmpAPI and the SnmpAPI can start monitoring the sessions for timeouts and retries.

Parameters:
api - The instance of SnmpAPI
Method Detail

setBroadcastFeatureEnable

public void setBroadcastFeatureEnable(boolean bool)
The method can be used to enable/disable the broadcast feature available in the API. By default, the API has the broadcast feature enabled, and if the user wishes to disable this feature, he/she can do so by simply calling this method with "false" as value.

Parameters:
bool - the boolean value that is to enable/disable the broadcast feature in the API.
Since:
AdventNet SNMP API 4 SP2 ( Release 4.0.2 )

setDisableAuthTraps

public void setDisableAuthTraps(boolean trap)

isBroadcastFeatureEnable

public boolean isBroadcastFeatureEnable()
The method returns whether the API has the broadcast feature enabled or not.

Returns:
a boolean, which tells whether the API currently has the broadcast feature enabled or not.
Since:
AdventNet SNMP API 4 SP2 ( Release 4.0.2 )
See Also:
setBroadcastFeatureEnable(boolean)

setSimpleDateFormat

public void setSimpleDateFormat(java.text.SimpleDateFormat format)
Sets the SimpleDateFormat for this class. When the debug is on, the time stamp will be printed along with the packet dumps. The format of this time stamp can be changed using this method.

Parameters:
format - The SimpleDateFormat used for printing the time stamp.
Since:
AdventNet SNMP API 4 SP2 ( Release 4.0.2 )
See Also:
getSimpleDateFormat()

getSimpleDateFormat

public java.text.SimpleDateFormat getSimpleDateFormat()
Gets the SimpleDateFormat for this class.

Returns:
the SimpleDateFormat used by this class. This method will return a non-null value, only when
1. The SimpleDateFormat is previously set OR
2. When the debug mode is on and atleast one packet has been printed.
Since:
AdventNet SNMP API 4 SP2 ( Release 4.0.2 )
See Also:
setSimpleDateFormat(SimpleDateFormat)

getVersion

public int getVersion()
Gets snmp version for outgoing SNMP requests. When using this SNMPv3 API to build applications, all the SNMPv1, SNMPv2c and SNMPv3 messages can be sent and received using the same session, irrespective of the version set in the session object. The version set in session is used to set the version for outgoing messages on the session, when it is not set in the message itself. For example, if a session version is set to SnmpAPI.SNMP_VERSION_3, and a pdu is sent without setting its version explicitly (the pdu will have the default version of SnmpAPI.SNMP_VERSION_1), then an SNMPv3 message is sent to the peer SNMP entity. On the other hand, if the pdu version is set explicitly to SnmpAPI.SNMP_VERSION_2C, an SNMPv2c message will be sent to the peer entity.

It is to be noted that when an application sends an SNMPv1 pdu using a session whose version is set to SNMP_VERSION_3, an SNMPv3 message is sent to the peer. This problem arises because the API uses SNMP_VERSION_1 as the default pdu version and it could not distinguish between applications leaving the version in pdu to default and setting it explicitly to SNMP_VERSION_1. To circumvent this problem, applications should set session version to SNMP_VERSION_1 and set the pdu version explicitly to SNMP_VERSION_2C or SNMP_VERSION_3 while communicating with v2c and v3 peers.

Returns:
The version of outgoing SNMP requests.

setVersion

public void setVersion(int version)
Sets snmp version for outgoing requests. When using this SNMPv3 API to build applications, all the SNMPv1, SNMPv2c and SNMPv3 messages can be sent and received using the same session, irrespective of the version set in the session object. The version set in session is used to set the version for outgoing messages on the session, when it is not set in the message itself. For example, if a session version is set to SnmpAPI.SNMP_VERSION_3, and a pdu is sent without setting its version explicitly (the pdu will have the default version of SnmpAPI.SNMP_VERSION_1), then an SNMPv3 message is sent to the peer SNMP entity. On the other hand, if the pdu version is set explicitly to SnmpAPI.SNMP_VERSION_2C, an SNMPv2c message will be sent to the peer entity.

It is to be noted that when an application sends an SNMPv1 pdu using a session whose version is set to SNMP_VERSION_3, an SNMPv3 message is sent to the peer. This problem arises, because the API uses SNMP_VERSION_1 as the default pdu version and it could not distinguish between applications leaving the version in pdu to default and setting it explicitly to SNMP_VERSION_1. To circumvent this problem, applications should set session version to SNMP_VERSION_1 and set the pdu version explicitly to SNMP_VERSION_2C or SNMP_VERSION_3, while communicating with v2c and v3 peers.

Parameters:
version - The version of the outgoing SNMP request.

disableReqEcho

public void disableReqEcho(boolean flag)

getReceiveBufferSize

public int getReceiveBufferSize()
                         throws java.net.SocketException
Deprecated. instead use the getReceiveBufferSize method available in UDPProtocolOptions.

Gets the receive buffer size of the datagram socket.

Returns:
this method returns the receive buffer size of this datagramsocket. This method will return zero :
1. If this method is invoked even before the open method is called.
2. If the under lying protocol used is not UDP, that is, if some other transport provider is used.
Throws:
java.net.SocketException - if there is an error in the underlying protocol, such as a UDP error.
java.lang.NoSuchMethodError - if this method is invoked while using JDK lesser than 1.2. The reason is the getReceiveBufferSize method has been added in java.net.DatagramSocket only in JDK1.2 and above.

setReceiveBufferSize

public void setReceiveBufferSize(int bufferSize)
                          throws java.lang.IllegalArgumentException,
                                 java.net.SocketException
Deprecated. instead use the setReceiveBufferSize method available in UDPProtocolOptions.

Sets the receive buffer size of the datagram socket. This method will simply return if this method is invoked before calling the open method and if some other transport provider is used for communication.

Parameters:
bufferSize - the buffer Size that is to be set on the datagramSocket.
Throws:
java.lang.IllegalArgumentException - if the bufferSize is 0 or is negative.
java.net.SocketException - if there is an error in the underlying protocol, such as a UDP error.
java.lang.NoSuchMethodError - if this method is invoked while using JDK lesser than 1.2. The reason is the setReceiveBufferSize method has been added in java.net.DatagramSocket only in JDK1.2 and above.

setCallbackthread

public void setCallbackthread(boolean useThread)
Sets this to true if the user wants the callback to be called from a seperate thread. Recommended if you're doing any serious work in the callback, especially sending new requests. The SnmpAPI provides two ways of processing received messages, using the callback method. When the callbackThread is set true, the callback method is invoked from a separate thread as the response arrives. If it is set false, then callback method is invoked from the same thread as the receiver thread and subsequent responses can be received only, if the user returns from the callback method. You can set the value of callbackThread based on, whether you want callback's to be invoked from a separate thread or from the SnmpSession receiver thread itself.

The performance of the receiver thread in receiving responses or traps is little bit poorer,If we invoke the callback from a separate thread. In order to be called back when a response is received, applications should implement the SnmpClient interface and register with the SnmpSession, using the addSnmpClient() method.

Parameters:
useThread - the flag that tells, whether to use the callback thread or not.
See Also:
SnmpClient

getCommunity

public java.lang.String getCommunity()
Gets community for outgoing SNMPv1 and SNMPv2c requests. The community string in the pdu overrides the community set in session. This means, only when the community string in the pdu is null, the one in session is used. The default community value is "public".

Returns:
The community of the outgoing SNMPv1 or SNMPv2c messages.

setCommunity

public void setCommunity(java.lang.String community)
Sets community for outgoing SNMPv1 and SNMPv2c requests. The community string in the pdu overrides the community set in session. This means, only when the community string in the pdu is null, the one in session is used. The default community value is "public".

Parameters:
couumnity - The community for the outgoing SNMPv1 or SNMPv2c messages.

getWriteCommunity

public java.lang.String getWriteCommunity()
Gets writeCommunity for outgoing requests. This is used in SET operations only. The writeCommunity string in the pdu overrides the writeCommunity in session. This means, only when the writeCommunity string in the pdu is null, the one in session is used. If the writeCommunity is not specified, then value in community field is used. The default writeCommunity value is null.

Returns:
The writeCommunity value of outgoing SNMPv1 or SNMPv2c messages.

setWriteCommunity

public void setWriteCommunity(java.lang.String writeCommunity)
Sets writeCommunity for outgoing requests. This is used in SET operations only. The writeCommunity string in the pdu overrides the writeCommunity in session. This means, only when the writeCommunity string in the pdu is null, the one in session is used. If the writeCommunity is not specified, then value in community field is used. The default writeCommunity value is null.

Parameters:
writeCommunity - The writeCommunity for the outgoing SNMPv1 or SNMPv2c messages.

getRetries

public int getRetries()
Gets number of retries before timeout. The retries in the pdu overrides the retries value in session. This means, only when the retries in the pdu is 0, the session value is used. The default value of retries is 0.

Returns:
The retries value being used by the session.

setRetries

public void setRetries(int retries)
Sets number of retries before timeout. The retries in the pdu overrides the retries value in session. This means, only when the retries in the pdu is 0, the session value is used. The default value of retries is 0. The timeout value grows exponentially for each retries. Timeout value is doubled for each retry. For example, if the timeout is set to 5000 (meaning 5 seconds) and retries is set to 2, the first retransmission will happen after 5 seconds, the second after 15 seconds etc. This exponential way of timeout policy can be changed using the TimeoutPolicy class. This method will not set the value, if it is negative.

Parameters:
retries - The retries value to be used by the session.
See Also:
TimeoutPolicy

setSASProtocol

public void setSASProtocol(int prot)
Deprecated. use the following instead.

SASProtocolOptions opt = new SASProtocolOptions();
opt.setApplet(applet);
opt.setProtocol(SASClient.TCP_PROTOCOL); //or SASClient.HTTP_PROTOCOL
snmpSession.setProtocolOptions(opt);
snmpSession.open();

Method to set the protocol used by SASClient The value for protocol can be either TCP_PROTOCOL (1) or HTTP_PROTOCOL (2). TCP_PROTOCOL will use Tcp/Ip connection and forward the snmp request to SAS and HTTP_PROTOCOL will use HTTP protocol and forward the request to the servlet loaded with the web server This has to be set before calling the open method. By default the value of protocol is 1.

Parameters:
prot - the protocol that is to be used for SNMP communications.

getSASProtocol

public int getSASProtocol()
Deprecated. use the following instead.

SASProtocolOptions opt = (SASProtocolOptions)snmpSession.getProtocolOptions();
int sasprotocol = opt.getProtocol();

Method to get the protocol used by SASClient The value for protocol can be either TCP_PROTOCOL or HTTP_PROTOCOL. Using TCP_PROTOCOL will use Tcp/Ip connection and forward the snmp request to SAS and using HTTP_PROTOCOL will use HTTP protocol and forward the request to the servlet loaded with the web server This has to be set before calling the open method. By default the value of protocol is 1.

Returns:
the sasprotocol that is used.

getTimeout

public int getTimeout()
Gets the timeout value. The timeout is the time to wait for the first response in milli-seconds, before attempting a retransmission. The default value of timeout is 5000 milliseconds.

Returns:
The timeout value in milliseconds used for monitoring the SNMP requests.

setTimeout

public void setTimeout(int timeout)
Sets the timeout value. The timeout is the time to wait for the first response in milli-seconds, before attempting a retransmission.The timeout in the pdu overrides the timeout value in session. This means, only when the timeout in the pdu is 0, the session timeout value is used. The default value of timeout is 5000 milliseconds. The timeout value to be set should be in milliseconds.

Parameters:
timeout - The timeout value to be used for monitoring the SNMP requests.

getSecLevelForTimeSync

public byte getSecLevelForTimeSync()
Returns the securitylevel that would be used when doing a V3 timeSync for a authPriv user. Can be Snmp3Message.AUTH_PRIV(3) or Snmp3Message.AUTH_NO_PRIV(1). Usually the time sync packet will be sent with AUTH_NO_PRIV security level, but this can be configured using this method.

Returns:
The securityLevel.

setSecLevelForTimeSync

public void setSecLevelForTimeSync(byte secLevel)
Sets the securityLevel to use when doing a V3 timeSync for a authPriv user. Can be either Snmp3Message.AUTH_PRIV(3) or Snmp3Message.AUTH_NO_PRIV(1). Default is Snmp3Message.AUTH_NO_PRIV

Parameters:
secLevel - The securityLevel

getUserName

public byte[] getUserName()
Returns the principal for SNMPv3 messages. The user name in the pdu over rides the one in session. This means, only when the user name in the pdu is null, the one in session is used.

Returns:
The principal for SNMPv3 messages.

setUserName

public void setUserName(byte[] name)
Sets the principal for SNMPv3 messages. The user name in the pdu over rides the one in session. This means, only when the user name in the pdu is null, the one in session is used.

Parameters:
name - The principal for SNMPv3 messages.

setContextName

public void setContextName(byte[] name)
Sets the context name associated with the SNMPv3 message.

Parameters:
name - the contextName associated with the SNMPv3 message.

getContextName

public byte[] getContextName()
Gets the context name associated with the SNMPv3 message. The context name in the pdu over rides the one in session. This means, only when the context name in the pdu is null, the one in session is used.

Returns:
The contextName associated with the SNMPv3 message.

setTrapAuthEnable

public void setTrapAuthEnable(boolean isAuth)
Specify whether traps should be authenticated while receiving SNMPv3 trap messages. Default value is false.

Parameters:
isAuth - Set this to true if traps should be authenticated while receiving SNMPv3 trap messages. False otherwise.

isTrapAuthEnable

public boolean isTrapAuthEnable()
Gets status of Trap Authentication for v3 pdus. If the status is true, then the traps should be authenticated while receiving SNMPv3 trap messages. False otherwise.

Returns:
The status value true or false if traps should be authenticated while receiving SNMPv3 trap messages.

getPacketBufferSize

public int getPacketBufferSize()
Gets the Datagram Buffer Size used for receiving SNMP packets. The default value is 64K.

Returns:
the datagram packet buffer size in bytes.

setPacketBufferSize

public void setPacketBufferSize(int size)
Sets the Datagram Buffer Size used for receiving SNMP packets. Use this method only in case you would need to have a buffer size in excess of 8000 bytes

Parameters:
size - The size of the datagram packet buffer to be used in bytes. An initial allocation of 64K is made by default.

getPeername

public java.lang.String getPeername()
Deprecated. use the following instead.
UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions(); opt.getRemoteHost();

Gets domain name or dotted IP address of peer entity. The remoteHost attribute of SnmpPDU overrides the peername in SnmpSession. This means, when remoteHost is null in SnmpPDU, messages are sent to the host, peername, in session. When remoteHost is not null in SnmpPDU, messages are sent to the remoteHost. It is always good to set the host in Snmp session to which Snmp requests are frequently sent. Default peername is null.

Returns:
The domain name or the dotted IP address of the peer.

setPeername

public void setPeername(java.lang.String peername)
Deprecated. use the following instead.
UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions(); opt.setRemoteHost(peername);

Sets domain name or dotted IP address of default peer. The remoteHost attribute of SnmpPDU overrides the peername in SnmpSession. This means, when remoteHost is null in SnmpPDU, messages are sent to the host, peername, in session. When remoteHost is not null in SnmpPDU, messages are sent to the remoteHost. It is always good to set the peername in SnmpSession to which SNMP requests are frequently sent. Default peername is null.

Parameters:
peername - the peername to which the SNMP communications should take place.

getRemotePort

public int getRemotePort()
Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions();
opt.getRemotePort();

Gets the remote udp port on the peer that this session is used to communicate with. The remotePort parameter in SnmpPDU overrides the one in session. It is always good to set the remote Port in session to which messages are often sent. When remotePort in SnmpPDU is 0 (default), the message is sent to remotePort specified in the session. The default value of remotePort in session is 0.

Returns:
The remote port on the peer that this session is used to communicate.

setRemotePort

public void setRemotePort(int port)
Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions();
opt.setRemotePort(port);

Sets the remote udp port on the peer that this session is used to communicate with. The remotePort parameter in SnmpPDU overrides the one in session. It is a good idea to set remotePort in session to which messages are often sent. When remotePort in SnmpPDU is 0, the message is sent to remotePort specified in the session. The default value of remotePort in session is 0.

Parameters:
port - The remote port on the peer that this session is used to communicate.

getReport

public boolean getReport()
Returns the status of report flag. Reports are forwarded to appln. if set to true. Default is false.

Returns:
the report flag that is set in this session object.

setReport

public void setReport(boolean status)
Sets the status of report flag. Reports are forwarded to appln. if this flag is set to true. Default is false.

Parameters:
status - the report status flag that is to be set in this session.

getLocalAddresses

public java.lang.String[] getLocalAddresses()
Deprecated. use the following instead.
UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions();
String[] local_address = opt.getLocalAddresses();

Gets local Addresses, hostnames or IP addresses, to bind session to. It is to be noted, that this method returns an array of Strings with the address values and the current behaviour is that the local address of the last string in array is used to bind the session.

Returns:
A String array of the addresses.

setLocalAddresses

public void setLocalAddresses(java.lang.String[] local_addrs)
Deprecated. use the following instead.
UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions(); opt.setLocalAddresses(local_addrs);

Sets local Addresses, hostnames or IP addresses, to bind session to. If null, will use default address(es) assigned by DatagramSocket(). It is to be noted that setLocalAddresses( ) takes a string array, as the argument and the current behaviour is that it binds the session with the local address, which happens to be the last string in array. If any of the string in this array is given as empty or null it is taken as localhost, since java.net.InetAddress.getByName("") or java.net.InetAddress.getByName(null) will return only localhost.

Parameters:
local_addrs - An array of Strings which contain the address to which the session is bound. Only the address in the last String is bound to the session.

getLocalPort

public int getLocalPort()
Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions();
int local_port = opt.getLocalPort();

Gets local UDP port number at which the datagram packets are sent and received. 0 is the default port number in which case it's system assigned.

Returns:
The port number on which the datagram packets are sent and received in this session.

setLocalPort

public void setLocalPort(int local_port)
Deprecated. use the following instead.

UDPProtocolOptions opt = (UDPProtocolOptions)snmpSession.getProtocolOptions();
opt.setLocalPort(local_port);

Sets local UDP port number at which the datagram packets are sent and received. 0 is the default port number in which case it's system assigned

Parameters:
local_port - The port number on which the datagram packets are to be sent and received in this session.

getStartLocalPort

public int getStartLocalPort()
Deprecated. now the "open(Applet)" method will throw an SnmpException if it is unable to connect to the SAServer. When such an exception is received, the user should decide whether "open(void)" method should be called or not.

Gets the port , 6000 is the default. This is used because of IE4.0 bug with using port 0 in case of applets. If the local UDP port is 0 and in case of applets using IE4.0, the startLocalPort value is used instead of local UDP port.

Returns:
The startLocalPort to be used in case of applets.

setStartLocalPort

public void setStartLocalPort(int startLocalPort)
Deprecated. now the "open(Applet)" method will throw an SnmpException if it is unable to connect to the SAServer. When such an exception is received, the user should decide whether "open(void)" method should be called or not.

Sets this so that next available port after this will be used. This is used beacuse of IE4.0 bug with using port 0 in case of applets. If the local UDP port is 0 and in case of applets using IE4.0, the startLocalPort value is used instead of local UDP port. The default value is 6000. If the socket cannot be opened at this port then the next available port is used instead.

Parameters:
startLocalPort - The port at which to send and receive datagram packets in case of applets using IE4.0.

getSASClient

public SASClient getSASClient()
Deprecated. use the following instead
SASProtocolOptions opt = (SASProtocolOptions)snmpSession.getProtocolOptions();
SASClient sasclient = opt.getSASClient();

To get around socket access restriction in applets, the SASClient allows for using a process on the Applet host as a pass through for Snmp PDUs. If this variable "sasclient" is non-null, this passthrough mechanism will be used for this session instance.

Returns:
The SASClient.

getSnmpClients

public java.util.Vector getSnmpClients()
Returns the clients that have been registered for callbacks or null is returned if no one is registered.

Returns:
The clients that have been registered for callbacks or null.

getSnmpClientsSize

public int getSnmpClientsSize()
Deprecated. use the following instead

int snmpClientsSize = (snmpSession.getSnmpClients()).size();

Returns the number of clients that have registered for callbacks.

Returns:
The count of the clients that have registered for callbacks.

getSnmpClientsWithID

public java.util.Hashtable getSnmpClientsWithID()
Returns the hashtable in which the clientID and the SnmpClient are associated.

Returns:
The Hashtable which contains the clientIDs as the keys and the SnmpClients as their elements. Each SnmpClient will have a unique clientID. These clientIDs will be generated automatically, when the addSnmpClientWithID(SnmpClient) method is called with a SnmpClient as the argument.

addSnmpClient

public void addSnmpClient(SnmpClient client)
Subscribe for callbacks. This adds your SnmpClient interface implementation to this session, which will invoke your class callbacks, authenticate and debug functions. The SnmpClient interface is implemented by applications that wish to send and receive messages asynchronously. The callback( ) method is automatically called in when a response arrives. This method will add the client to it's list of clients only if the argument is not null.

Parameters:
client - the SnmpClient that is to be added to this SnmpSession instance.
See Also:
SnmpClient

addSnmpClientWithID

public int addSnmpClientWithID(SnmpClient client)
Subscribes for callbacks. This adds your SnmpClient interface implementation to this session, which will invoke your class callbacks, authenticate and debug functions. The SnmpClient interface is implemented by applications that wish to send and receive messages asynchronously. The callback( ) method is automatically called when a response arrives. This method will add the client to it's list of clients only if the argument is not null.

Parameters:
client - the SnmpClient that is to be added to this SnmpSession.
Returns:
id for client added .Set this id in PDU while sending request for invoking callback of particular client. For the callback of the SnmpClient ( which is added by addSnmpClientWithID ) to be called, the corresponding clientID should be set in the PDU before making any SNMP request. If the clientID is not set in the PDU, then the callback ( of the client that is added through addSnmpClientWithID ) will not be called. This method will return zero, when a null is passed to it.
See Also:
SnmpClient

removeSnmpClient

public void removeSnmpClient(SnmpClient client)
Unsubscribes for callbacks. This removes your SnmpClient interface implementation from this session. The SnmpClient interface is implemented by applications that wish to send and receive messages asynchronously, or applications that wish to implemet its own authentication function. The SnmpClient interface provides a callback method that avoids polling done to check for responses. The callback( ) method is automatically called when a response arrives.

See Also:
SnmpClient

removeAllSnmpClients

public void removeAllSnmpClients()
This method removes all the SnmpClients that were registered in this SnmpSession.


removeSnmpClientWithID

public void removeSnmpClientWithID(int clientid)
Unsubscribe for callbacks. This removes your SnmpClient interface implementation from this session. The SnmpClient interface is implemented by applications that wish to send and receive messages asynchronously, or applications that wish to implemet its own authentication function. The SnmpClient interface provides a callback method that avoids polling done to check for responses. The callback( ) method is automatically called when a response arrives.

Parameters:
id - that the client has got while calling addSnmpClientWithID() method.

setProtocol

public void setProtocol(int protocol)
Deprecated. Since all the SNMP communications go through a single transport provider, this is not needed.

Sets the protocol to be used by the session. Currently valid values The default value is IP.

Parameters:
protocol - The value for identifying the IP protocol. The constant value for IP is provided in this class.

setAutoInformResponse

public void setAutoInformResponse(boolean flag)
Sets the automatic response flag for the Inform Request. If this flag is set to true, then the SNMP stack automatically sends a Get Reponse message back to the sender. The default value is true.

Parameters:
flag - boolean value of the flag to be set.

isSetAutoInformResponse

public boolean isSetAutoInformResponse()
Checks if the automatic response flag for the Inform Request is set. The default value is true.

Returns:
boolean value of the Inform Request response flag.

getSnmpAPI

public SnmpAPI getSnmpAPI()
Returns the SnmpAPI reference associated with this SnmpSession.

Returns:
the SnmpAPI reference associated with this SnmpSession.

run

public void run()
The run method starts the receiver thread for this session object. Waits for incoming datagrams, and updates SnmpSession object with received Datagrams. The API user need not call this method explicitly.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

open

public void open()
          throws SnmpException
Opens Snmp Session to communicate with an SNMP peer. Once the SnmpSession is instantiated, it has to be opened with this method so that a datagram socket is opened for SNMP communications. This method also starts the receiver thread which waits for incoming datagrams. This method should be called only once for an instance of SnmpSession. If it is called for the next time then an SnmpException will be thrown.

Throws:
SnmpException - is thrown for the following reasons:
(i) on socket error, that is, if trying to open the session in an already occupied port.
(ii) when this method is called for the second time
See Also:
SnmpException

setTransportProvider

public void setTransportProvider(java.lang.String providerClassName)
This method sets the transportProvider classname, which will be used for communication purposes.

Parameters:
providerClassName - The class name of the transport provider, through which the SNMP communication will take place.
Since:
AdventNet SNMP API 4.

getTransportProvider

public java.lang.String getTransportProvider()
This method gets the transportProvier classname.

Returns:
the transportProvider class name.
Since:
AdventNet SNMP API 4.

open

public void open(java.applet.Applet applet)
          throws SnmpException
Deprecated. use the following instead

SnmpAPI api = new SnmpAPI();
SnmpSession ses = new SnmpSession(api);
SASProtocolOptions opt = new SASProtocolOptions();
opt.setApplet(applet);
ses.setProtocolOptions(opt);
ses.open();

Open Snmp Session to communicate with an SNMP peer, using the applet host server as a pass through. If the connection to the applet server process is successfully established, sasclient will be set to the SASClient instance.If not it is set null.If, unsuccessful it will try a local socket.

Parameters:
the - applet instance needed to create a SASClient.
Throws:
SnmpException - is thrown on socket error.
See Also:
SASClient

setTimeoutPolicy

public void setTimeoutPolicy(TimeoutPolicy timeoutPolicy)
sets the TimeoutPolicy for this SnmpSession.

Parameters:
timeoutPolicy - this is the user's own implementation of TimeoutPolicy

restoreDefaultTimeoutPolicy

public void restoreDefaultTimeoutPolicy()
restores this SnmpSession object to have the default TimeoutPolicy. The exponential TimeoutPolicy is the default timeout policy.

See Also:
TimeoutPolicy

close

public void close()
Close Snmp Session and stop receiver thread. This method will simply return if it is called even before calling the open method or if it is called for the second time.


send

public int send(SnmpPDU pdu)
         throws SnmpException
Send SnmpPDU on the given session after encoding the PDU. This is an asynchronous request, returns after transmission. Uses the "checkResponses()" or "checkTimeouts()" methods to look for responses or timeouts. Throws SnmpException on decode error, UnknownHost and send error.

Parameters:
pdu - The instance of SnmpPDU
Returns:
Message ID for v3 request and the Request ID for v1/v2c request.
Throws:
SnmpException - is thrown on the following conditions:
(i) Socket send error.
(ii) If the command is not set on the pdu.
(iii) If the pdu argument is null.
(iv) If this method is called even before the open method is called.
(v) If some encode error occurs.

syncSend

public SnmpPDU syncSend(SnmpPDU pdu)
                 throws SnmpException
Sends SnmpPDU synchronously - returns response SnmpPDU. On failure throws SnmpException. This is a synchronous request, returns after receiving SNMP response, or timing out.

Parameters:
pdu - The SnmpPDU that is to be sent.
Returns:
The response PDU. Null if the request timed out.
Throws:
SnmpException - is thrown on the following conditions:
(i) Socket send error.
(ii) If the command is not set on the pdu.
(iii) If the pdu argument is null.
(iv) If this method is called even before the open method is called.
(v) If some encode error occurs.

checkSyncResponse

int checkSyncResponse(int reqid)
                throws SnmpException
Checks the response PDU for request ID.

Parameters:
reqid - The request id of a request.
Returns:
if same 0,Timed out -1 otherwise 0.
Throws:
SnmpException - is thrown on error.

get

public SnmpVar get(java.lang.String oidString)
            throws SnmpException
Deprecated. use the following instead

SnmpPDU pdu = new SnmpPDU();
pdu.addNull(new SnmpOID(oidString));
pdu.setCommand(SnmpAPI.GET_REQ_MSG);
SnmpPDU response_pdu = snmpSession.syncSend(pdu);

SnmpVar var = null;
if(response_pdu != null)
{
var = response_pdu.getVariable(0);
}

SNMP get request method is for single String OID argument. Builds PDU and makes get request and waits for the response. Returns null if timed out.

Throws:
SnmpException - is thrown on error.

get

public SnmpVar get(SnmpOID oid)
            throws SnmpException
Deprecated. use the following instead

SnmpPDU pdu = new SnmpPDU();
pdu.addNull(oid);
pdu.setCommand(SnmpAPI.GET_REQ_MSG);
SnmpPDU response_pdu = snmpSession.syncSend(pdu);

SnmpVar var = null;
if(response_pdu != null)
{
var = response_pdu.getVariable(0);
}

SNMP get request method for single SnmpOID argument. Builds PDU and makes get request and waits for response. Returns null if timeout.

Throws:
SnmpException - is thrown on error.

getnext

public SnmpVar getnext(java.lang.String oidString)
                throws SnmpException
Deprecated. use the following instead

SnmpPDU pdu = new SnmpPDU();
pdu.addNull(new SnmpOID(oidString));
pdu.setCommand(SnmpAPI.GETNEXT_REQ_MSG);
SnmpPDU response_pdu = snmpSession.syncSend(pdu);

SnmpVar var = null;
if(response_pdu != null)
{
var = response_pdu.getVariable(0);
}

SNMP getnext request method is for single String OID argument. Builds PDU and makes getnext request and waits for the response. Returns null if timed out.

Throws:
SnmpException - is thrown on error.

getnext

public SnmpVar getnext(SnmpOID oid)
                throws SnmpException
Deprecated. use the following instead

SnmpPDU pdu = new SnmpPDU();
pdu.addNull(oid);
pdu.setCommand(SnmpAPI.GETNEXT_REQ_MSG);
SnmpPDU response_pdu = snmpSession.syncSend(pdu);

SnmpVar var = null;
if(response_pdu != null)
{
var = response_pdu.getVariable(0);
}

SNMP getnext request method for single SnmpOID argument. Builds PDU and makes getnext request and waits for response. Returns null if timeout.

Throws:
SnmpException - is thrown on error.

set

public SnmpVar set(java.lang.String oidString,
                   java.lang.String setString,
                   byte type)
            throws SnmpException
Deprecated. use the following instead

SnmpPDU pdu = new SnmpPDU();
SnmpVar variable = SnmpVar.createVariable(setString, type);
SnmpOID oid = new SnmpOID(oidString);
SnmpVarBind varbind = new SnmpVarBind(oid, variable);
pdu.addVariableBinding(varbind);
pdu.setCommand(SnmpAPI.SET_REQ_MSG);
SnmpPDU response_pdu = snmpSession.syncSend(pdu);

SnmpVar var = null;
if(response_pdu != null)
{
var = response_pdu.getVariable(0);
}

SNMP set request method for single String OID argument. Builds PDU and makes set request and waits for response. Returns null if timed out.

Parameters:
oidString - The String oid.
setString - String value.
type - Type of the variable
Returns:
The SnmpVar ,the variable.
Throws:
SnmpException - is thrown on error.

set

public SnmpVar set(SnmpOID oid,
                   SnmpVar var)
            throws SnmpException
Deprecated. use the following instead

SnmpPDU pdu = new SnmpPDU();
SnmpVarBind varbind = new SnmpVarBind(oid, var);
pdu.addVariableBinding(varbind);
pdu.setCommand(SnmpAPI.SET_REQ_MSG);
SnmpPDU response_pdu = snmpSession.syncSend(pdu);

SnmpVar response_var = null;
if(response_pdu != null)
{
response_var = response_pdu.getVariable(0);
}

SNMP set request method is for single SnmpOID argument. Builds PDU and makes set request and waits for the response. Returns null if timeout.

Parameters:
oidString - The String oid.
var - The SnmpVar ,the variable.
Returns:
The SnmpVar ,the variable.
Throws:
SnmpException - is thrown on error.

partialSet

public java.util.Hashtable partialSet(SnmpOID[] oids,
                                      SnmpVar[] vars)
                               throws SnmpException
SNMP set request method is for multiple SnmpOID argument. Builds PDU and attempts to do a partial set in case of failure of the first request by sending multiple requests until success. Returns Hashtable of error status for oids which caused errors. The key in the table indicates the oid number which caused the error and the value gives the error status. Returns null in case of timeout. Empty Hashtable in case of no errors.

Parameters:
oids - The array of SnmpOID.
vars - The array of SnmpVar.
Returns:
Error status Hashtable.
Throws:
SnmpException - is thrown on error.

partialSet

public java.util.Hashtable partialSet(SnmpPDU pdu)
                               throws SnmpException
SNMP set request method is for multiple SnmpOID argument. This builds PDU and attempts to do a partial set, in case of failure of the * first request by sending multiple requests until success. Returns Hashtable of error status for oids which caused errors. The key in the table indicates the oid number which caused the error and the value gives * the error status. Returns null, in case of time-out. Empty Hashtable in case of no errors.

Parameters:
pdu - SnmpPDU.
Returns:
Error status Hashtable.
Throws:
SnmpException - is thrown on error.

snmpRequest

SnmpVar snmpRequest(byte request,
                    SnmpOID oid,
                    SnmpVar setValue)
              throws SnmpException
snmpRequest builds PDU and makes request per argument and waits for response. Returns SnmpVar or null if timeout.

Parameters:
request - The request
oid - The SnmpOID
setValue - The SnmpVar ,the variable.
Returns:
The SnmpVar ,the variable.
Throws:
SnmpException - is thrown on error.

receive

public SnmpPDU receive(int reqid)
Fetches SNMP response PDU, fetches first PDU in response queue, if reqid is 0. Takes PDU off the response queue.

Parameters:
reqid - The request id.
Returns:
The pdu.

checkTimeout

public boolean checkTimeout(int reqid)
Returns true if the reqid is in the list of this session's timed out requests, and removes it from the list. Returns false if not in list.

Parameters:
reqid - The request id for which the timeout status is to be known.
Returns:
true if timed out else false.

checkResponses

public int[] checkResponses()
Checks for any outstanding responses that are still in the receive queue.

Returns:
The list of requests, i.e. request ids.

enQ

void enQ(java.util.Vector v,
         SnmpPDU pdu)
Place in specified queue

Parameters:
v - Vector
pdu - SnmpPDU

enQ

void enQ(java.util.Vector v,
         SimplePDU pdu)
Place in specified queue

Parameters:
v - Vector
pdu - SimplePDU

deQ

void deQ(java.util.Vector v,
         java.lang.Object obj)

deQ

void deQ(java.util.Vector v,
         int i)

getRequest

SimplePDU getRequest(int reqid)

deQFromResponseList

SnmpPDU deQFromResponseList(int reqid)

deQFromRequestList

SimplePDU deQFromRequestList(int reqid)

monitorRequests

void monitorRequests()
Monitors user requests for timeouts, and re-transmits


setSocketParms

public void setSocketParms(int socketTimeout,
                           int socketDelay)
Deprecated. since a new transportProvider implementation for udp has been added, this method no longer becomes necessary.

Params to set socket timeout and delay. The first param sets the socketTimeout. The second is the delay the receiver sleeps through before entering the blocking receive again. Defaults are 250 and 0 respectively

Parameters:
socketTimeout - The timeout for the socket in ms
socketDelay - The delay in ms

processPacket

void processPacket(SnmpPDU pdu)
Parameters:
packet - The Datagram packet
pdu - The SnmpPDU

setProtocolOptions

public void setProtocolOptions(ProtocolOptions tParam)
This associates the ProtocolOptions with this SnmpSession.

Parameters:
tParam - ProtocolOptions to be set.

getProtocolOptions

public ProtocolOptions getProtocolOptions()
This method will return the ProtocolOptions associated with this SnmpSession.

Returns:
The ProtocolOptions corresponding to this SnmpSession.

getProtocol

public int getProtocol()
Deprecated. since all SNMP communications go through only a transportProvider, this method is not at all necessary.

This returns the protocol associated with this session object

Returns:
The protocol corresponding to this session object

setConnectionListener

public void setConnectionListener(ConnectionListener connListener)
Subscribes for ConnectionListener. This adds your ConnectionListener interface implementation to this session, which will invoke your checkConnectionStatus(), processConnectionDown(), processConnectionUp() functions.

Parameters:
connListener - - ConnectionListener instance.
See Also:
ConnectionListener

removeConnectionListener

public void removeConnectionListener()
Unsubscribes for ConnectionListener. This removes your ConnectionListener interface implementation from this session.


getConnectionListener

public ConnectionListener getConnectionListener()
To get reference to the ConnectionListener object.

Returns:
ConnectionListener object.
See Also:
ConnectionListener

isSessionEstablished

public boolean isSessionEstablished()
To get the status of the connection established using this session instance.

Returns:
true if the connection is alive else false.

sendNotification

public java.util.Vector sendNotification(SnmpPDU pdu)
                                  throws SnmpException
Authenticates and sends the notification to all the entries that can avail of the notification filtering facility.

Parameters:
pdu - The SnmpPDU instance that contains the SnmpOID to be used for notification filtering.
Returns:
Vector which contains a list of trap/inform request PDU's that were sent, if the notifyType is TRAP/INFORM.
Throws:
SnmpException

setTimeToWait

public void setTimeToWait(int waitTime)
Sets the inter-packet delay time. This method can be used to set the time delay which is required between consecutive SNMP requests due to low bandwidth in a network.

Parameters:
waitTime - The inter-packet delay time. Warning : This method should be used only when the underlying protocol is UDP.The timeout value to be set for the request should be taken care by the user.

getTimeToWait

public int getTimeToWait()
Gets the inter-packet delay time set on this SnmpSession object.

Returns:
The inter-packet delay time.

getFailedInformRequest

public java.util.Vector getFailedInformRequest()

getInformResponsePDU

public java.util.Vector getInformResponsePDU()