com.adventnet.snmp.snmp2
Class SnmpAPI

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--com.adventnet.snmp.snmp2.SnmpAPI
All Implemented Interfaces:
java.lang.Runnable, java.io.Serializable

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

The SnmpAPI class is a root class for AdventNet SNMP API. This class extends "java.lang.Thread". Any network management application written using AdventNet SNMP API, should instantiate this class.

The various vital informations and methods that this class contains are
1. It contains the list of all SnmpSessions which are opened with the help of this SnmpAPI instance.
2. It contains various public constants for the different SNMP versions, SNMP operations, SNMP variables, SNMP error values, SNMP exception values, SNMP table's row status values and the different access constants for these SNMP variables.
3. It contains a SnmpGroup object which maintains the various group counters for this SNMP entity.
4. It contains a list of all SecurityProviders that are installed. By default the USM (User based Security Model) is registered. This corresponds to the "usmUserTable" of the "SNMP-USER-BASED-SM-MIB" mib.
5. It contains a list of all Access Control Providers that are added by users. By default the View based Access Control Model ( VACM ) is registered. These corresponds to the "vacmContextTable", "vacmSecurityToGroupTable", "vacmAccessTable" and "vacmViewTreeFamilyTable" of the "SNMP-VIEW-BASED-ACM-MIB" mib.
6. It contains the SnmpEngineTable which cotains the engine information of various SNMPv3 engines. This table the engineName, engineID, engineTime and engineBoots of the particular SNMP entity.
7. This class holds the snmpEngineID, snmpEngineBoots and the snmpEngineTime of this SNMP entity.
8. It contains the database connection for the tables engine table, usm table and vacm tables.
9. It also provides methods which support persistency of the SecurityModel specific information in the form of serialize() and deSerialized() methods. The security configurations can be serialized so that they could be restored when the SNMPv3 entity is restarted. The SecurityModelTable implementation has to implement the serialize and deSerialize methods. In order to store/restore the configuration information, the API user has to set the file name using the setSerializeFileName method so that the serialize/deSerialize methods use this file for their operation.

The various activities that this thread performs are
1. Monitors each and every request for their timeouts.
2. Responsible for re-transmitting a request in case of a "retry".
3. Removes the received packets from the queue, when the count exceeds a threshold value.

To use the low-level API, instantiate an SnmpAPI. From there, you can create SNMP sessions, and perform SNMP operations. You can create multiple SnmpAPI instances, though there is little reason to do so for most applications.


 
 
 
The following table gives the values for the command types available in SNMP.

SNMP command. Value in decimal as a byte. Value in Hex.
GET_REQ_MSG -96 a0
GETNEXT_REQ_MSG -95 a1
GET_RSP_MSG -94 a2
SET_REQ_MSG -93 a3
TRP_REQ_MSG -92 a4
     
GETBULK_REQ_MSG -91 a5
INFORM_REQ_MSG -90 a6
TRP2_REQ_MSG -89 a7


 
 
 
The following table gives the values for SNMP Data types.

SNMP Variable Value in decimal as a byte. Value in Hex.
STRING 4 4
OBJID 6 6
INTEGER 2 2
NULLOBJ 5 5
IPADDRESS 64 40
NETWORKADDRESS 64 40
COUNTER 65 41
GAUGE 66 42
UNSIGNED32 66 42
TIMETICKS 67 43
OPAQUE 68 44
     
COUNTER64 70 46
UINTEGER32 66 42


 
 
 
The following table gives the values for the Standard SNMP Errors. Only the first 6 errors belong to SNMPv1.

SNMP Error Type Value in decimal as a byte Value in Hex
SNMP_ERR_NOERROR 0 00
SNMP_ERR_TOOBIG 1 01
SNMP_ERR_NOSUCHNAME 2 02
SNMP_ERR_BADVALUE 3 03
SNMP_ERR_READONLY 4 04
SNMP_ERR_GENERR 5 05
     
SNMP_ERR_NOACCESS 6 06
SNMP_ERR_WRONGTYPE 7 07
SNMP_ERR_WRONGLENGTH 8 08
SNMP_ERR_WRONGENCODING 9 09
SNMP_ERR_WRONGVALUE 10 0a
SNMP_ERR_NOCREATION 11 0b
SNMP_ERR_INCONSISTENTVALUE 12 0c
SNMP_ERR_RESOURCEUNAVAILABLE  13 0d
SNMP_ERR_COMMITFAILED 14 0e
SNMP_ERR_UNDOFAILED 15 0f
SNMP_ERR_AUTHORIZATIONERROR 16 10
SNMP_ERR_NOTWRITABLE 17 11
SNMP_ERR_INCONSISTENTNAME 18 12

See Also:
SnmpSession, SnmpGroup, SecurityModelTable, Serialized Form

Field Summary
static int ACCESSFORNOTIFY
          accessible-for-notify in Snmpv2.
static int ACTIVE
          The Active State of the Tables.
static int ANY_SEC_MODEL
          Constant values for "any" security model.
static byte BITSTRING
          Deprecated. This variable has been deprecated in SNMPv2 protocol.
static byte COUNTER
          SNMP Type Constants.
static byte COUNTER64
          SNMP Type Constants.
static int CREATE_AND_GO
          The createAndGo state of the Tables.
static int CREATE_AND_WAIT
          The createAndWait state of the Tables.
static int CRITICAL
          constant for critical debug messages.
static int debugLevel
          variable having debugLevel , by defaullt FATAL.
static int DESTROY
          The Destroy state of the Tables.
static java.lang.String ENCODING
          The Standard encoding string on which all encoding will be done.
static byte ENDOFMIBVIEWEXP
          SNMP v2 Null Object Exception Value.
static int FATAL
          constant for fatal debug messages.
static byte GAUGE
          SNMP Type Constants.
static byte GET_REQ_MSG
          Constant for SNMP get PDU type.
static byte GET_RSP_MSG
          Constant for SNMP response PDU type.
static byte GETBULK_REQ_MSG
          Constant for SNMP V2 Get Bulk PDU type.
static byte GETNEXT_REQ_MSG
          Constant for SNMP get next PDU type.
static byte INFORM_REQ_MSG
          Constant for SNMP V2 INFORM PDU type.
static byte INTEGER
          SNMP Type Constants.
static byte IPADDRESS
          SNMP Type Constants.
static byte NETWORKADDRESS
          SNMP Type Constants.
static int NOACCESS
          no access for anybody.
static int NON_CRITICAL
          constant for non-critical debug messages.
static int NONVOLATILE
          The Nonvolatile Storage type of the Tables.
static byte NOSUCHINSTANCEEXP
          SNMP v2 Null Object Exception Value.
static byte NOSUCHOBJECTEXP
          SNMP v2 Null Object Exception Value.
static int NOT_IN_SERVICE
          The notInService state of the Tables.
static int NOT_READY
          The notReady state of the Tables.
static byte NSAP
          Deprecated. This variable has been deprecated in SNMPv2 protocol
static byte NULLOBJ
          SNMP Type Constants.
static byte OBJID
          SNMP Type Constants.
static byte OPAQUE
          SNMP Type Constants.
static int OTHER
          The Other Storage type of the Tables.
static int PERMANENT
          The Permanent Storage type of the Tables.
static int RCREATE
          read-create value in Snmpv2.
static int READONLY
          The Readonly Storage type of the Tables.
static byte REPORT_MSG
          Constant for SNMP V2 Report PDU type.
static int RONLY
          read access for everyone.
static int RWRITE
          add write access for community.
static byte SET_REQ_MSG
          Constant for SNMP set request PDU type.
static byte SNMP_ERR_AUTHORIZATIONERROR
          SNMP error value.
static byte SNMP_ERR_BADVALUE
          SNMP error value.
static byte SNMP_ERR_COMMITFAILED
          SNMP error value.
static byte SNMP_ERR_GENERR
          SNMP error value.
static byte SNMP_ERR_INCONSISTENTNAME
          SNMP error value.
static byte SNMP_ERR_INCONSISTENTVALUE
          SNMP error value.
static byte SNMP_ERR_NOACCESS
          SNMP error value.
static byte SNMP_ERR_NOCREATION
          SNMP error value.
static byte SNMP_ERR_NOERROR
          SNMP error value.
static byte SNMP_ERR_NOSUCHNAME
          SNMP error value.
static byte SNMP_ERR_NOTWRITABLE
          SNMP error value.
static byte SNMP_ERR_READONLY
          SNMP error value.
static byte SNMP_ERR_RESOURCEUNAVAILABLE
          SNMP error value.
static byte SNMP_ERR_TOOBIG
          SNMP error value.
static byte SNMP_ERR_UNDOFAILED
          SNMP error value.
static byte SNMP_ERR_WRONGENCODING
          SNMP error value.
static byte SNMP_ERR_WRONGLENGTH
          SNMP error value.
static byte SNMP_ERR_WRONGTYPE
          SNMP error value.
static byte SNMP_ERR_WRONGVALUE
          SNMP error value.
 int SNMP_PORT
          The snmp port value of 161 for UDP.
 int SNMP_TRAP_PORT
          The trap port value of 162 for UDP.
static int SNMP_VERSION_1
          Constant for setting SNMP Version 1.
static int SNMP_VERSION_2
          Constant for setting SNMP Version 2 (Not supported).
static int SNMP_VERSION_2C
          Constant for setting SNMP Version 2c.
static int SNMP_VERSION_3
          Constant for the SNMP Version 3.
static java.lang.String Standard_Prefix
          Deprecated. instead use the setOIDPrefix(SnmpOID oid) and getOIDPrefix() methods.
static byte STRING
          SNMP Type Constants.
static byte TIMETICKS
          SNMP Type Constants.
static byte TRP_REQ_MSG
          Constant for SNMP trap PDU type.
static byte TRP2_REQ_MSG
          Constant for SNMP V2 Trap PDU type.
static byte UINTEGER32
          Deprecated. This variable has been deprecated in SNMP protocol.
static byte UNSIGNED32
          SNMP Type Constants.
static int VOLATILE
          The Volatile Storage type of the Tables.
static int WONLY
          only write access for community.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SnmpAPI()
          Creates a new SnmpAPI instance and initialises the authoritative snmpEngineID, snmpEngineBoots, snmpEngineTime and the providers, SecurityProvider and ACMProvider.
SnmpAPI(boolean debug)
          Creates a new SnmpAPI instance and initialises the authoritative snmpEngineID, snmpEngineBoots, snmpEngineTime and the providers, SecurityProvider and ACMProvider.
 
Method Summary
 java.util.Vector checkResponses()
          Checks each session to see if there is any outstanding response.
 java.util.Vector checkTimeouts()
          Checks each session to see if there is any outstanding Time-outs
 void close()
          Stops the API thread which monitors the session for time-outs and retries.
static boolean compare(int[] a, int[] b)
          An int array comparison routine.
static void debugPrintHigh(java.lang.Object str)
          debugPrint method for FATAL messages.
static void debugPrintLow(java.lang.Object str)
          debugPrint method for NON_CRITICAL messages.
static void debugPrintMedium(java.lang.Object str)
          debugPrint method for CRITICAL messages.
 boolean deSerialize()
          This deSerializes the SNMPV3 Security tables from the file specified by the setSerializeFileName method.
 boolean deSerializeEngineBoots()
          This deSerializes the engine boots into the file specified by the setSerializeFileName method.
 int genMsgID()
          This number is unique number that is generated for this JVM.
 int genReqID()
          This number is unique number that is generated for this JVM.
 ACMProvider getACMProvider()
          Gets the Access Control Provider maintained bu this SnmpAPI.
 java.lang.String getCharacterEncoding()
          Returns the Character encoding of the String values.
 java.lang.Object getCommunityTable()
          Deprecated. use the following instead
getSecurityProvider().getTable(1); // where 1 stands for v1 security model.
static java.sql.Connection getConnection()
          Returns the database connection instance corresponding to this SnmpAPI instance.
 boolean getDebug()
          Defines whether debugging output is being generated.
 java.lang.String GetEngineBootsSerializeFileName()
          Gets the fileName into which the SNMPv3 engineBoots are to be stored so that they are persistant.
static int getMajorVersion()
          Returns the major version of this release of SNMP Library.
static int getMinorVersion()
          Returns the minor version of this release of SNMP Library.
 SnmpNotifyFilterProfileTable getNotifyFilterProfileTable()
          Gets the SnmpNotifyFilterProfileTable that is associated with this SnmpAPI instance.
 SnmpNotifyFilterTable getNotifyFilterTable()
          Gets the SnmpNotifyFilterTable that is associated with this SnmpAPI instance.
 SnmpNotifyTable getNotifyTable()
          Gets the SnmpNotifyTable that is associated with this SnmpAPI instance.
static SnmpOID getOIDPrefix()
          This method returns the OID prefix that is set before.
static int getPatchVersion()
          Returns the patch version of this release of SNMP Library.
static SASClient getSASClient()
          Returns the SASClient instance which has been created at last through the SnmpSession class.
 SecurityProvider getSecurityProvider()
          Gets the SecurityProvider maintained by this SnmpAPI.
 java.lang.String getSerializeFileName()
          Gets the fileName into which the SNMPv3 configuration tables are to be serialized.
 java.util.Vector getSessionList()
          Get the List of SNMP sessions managed under this SnmpAPI instance.
 SnmpEngineTable getSnmpEngine()
          Gets the SnmpEngineTable reference.
 int getSnmpEngineBoots()
          Gets the SnmpEngineBoots (number of times this SNMP engine has booted of this SNMP entity.
 byte[] getSnmpEngineID()
          Gets the authoritative SnmpEngineID associated with this SNMP entity.
 int getSnmpEngineTime()
          Gets the SnmpEngineTime.
 SnmpGroup getSnmpGroup(java.lang.String local_address, int port)
          Gets the SnmpGroup Object corresponding to the SnmpSession's local_addrs and local_port.
static java.sql.Statement getStatement()
          Returns the Statement instance corresponding to this SnmpAPI instance
 SnmpTargetAddrExtTable getTargetAddrExtTable()
          Gets the SnmpTargetAddrExtTable corresponding to this SnmpAPI.
 com.adventnet.snmp.snmp2.SnmpTargetAddrTable getTargetAddrTable()
          Gets the SnmpTargetAddrTable corresponding to this SnmpAPI.
 com.adventnet.snmp.snmp2.SnmpTargetParamsTable getTargetParamsTable()
          Gets the SnmpTargetParamsTable corresponding to this SnmpAPI.
 int getTimeWindow()
          Gets the time window in which messages are accepted by this SNMP engine.
 java.lang.Object getUSMTable()
          Deprecated. use the following instead.
 SnmpApi.getSecurityProvider().getTable(USM_SECURITY_MODEL); // where USM_SECURITY_MODEL = 3
 java.lang.String getV3ConfigTable()
          Gets the table name that was configured for V3.
static java.lang.String getVersionString()
          Returns a string describing this version of SNMP Library.
 void initACMProvider()
          This method initializes the Access Control Provider by reading from the file acmProvider.config .
 void initJdbcParams(java.lang.String driverName, java.lang.String urlString, java.lang.String userName, java.lang.String password)
          This method should be invoked to initialize the Jdbc Parameters in case of database support.
 void initSecurityProvider()
          This method initializes the SecurityProvider by reading from the file securityProvider.confg .
 boolean isCommunityAuthentication()
          Gets the Community Authentication flag for this SnmpAPI instance.
 boolean isNotificationFiltering()
          Gets the notification filtering flag for this SnmpAPI instance.
 boolean isV3DatabaseFlag()
          Gets the Database flag for this SnmpAPI instance.
 void run()
          This method starts the API thread which monitors the sessions to look for the requests which have timed out and retransmits the pdu if required.
 boolean serialize()
          This serializes the SNMPV3 Security tables into the file specified by the setSerializeFileName method.
 boolean serializeEngineBoots()
          This serializes the engine boots into the file specified by the setSerializeFileName method.
 void setCharacterEncoding(java.lang.String encoding)
          Sets the Character encoding of the String values.
 void setCommunityAuthentication(boolean commAuthFlag)
          Enables/Disables the community authentication flag.
 void setDebug(boolean debug)
          Defines whether debugging output should be generated.
static void setDebugLevel(int level)
          sets debugLevel FATAL or CRITICAL or NON_CRITICAL.
 void setEngineBootsSerializeFileName(java.lang.String name)
          Sets the fileName into which the SNMPv3 engineBoots are to be stored so that they are persistant.
 void setNotificationFiltering(boolean notifyFilterFlag)
          Enables/Disables the notification filtering.
static void setOIDPrefix(SnmpOID oid)
          This is added to any Object ID that does not begin with a '.'.
 void setSerializeFileName(java.lang.String name)
          Sets the fileName into which the SNMPv3 configuration tables are to be serialized.
 void setSnmpEngineBoots(int boots)
          Sets the SnmpEngineBoots (number of times this SNMP engine has booted of this SNMP entity.
 void setSnmpEngineID(byte[] id)
          Sets the authoritative SnmpEngineID for this SNMP entity.
 void setSnmpEngineTime(int time)
          Sets the SnmpEngineTime, the time in seconds after this SNMP engine has booted.
 void setTimeWindow(int win)
          Sets the time window in which messages should be accepted by this SNMP engine
static void setupStdOutErr()
          Deprecated. please use the logging framework instead.
static void setupStdOutErr(java.lang.String dirStr)
          Deprecated. please use the logging framework instead.
 void setV3ConfigTable(java.lang.String tableName)
          Sets the configured tableName specified in the case of V3Database.
 void setV3DatabaseFlag(boolean dBaseFlag)
          Sets the Database flag in the case of V3.
 void start()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OTHER

public static final int OTHER
The Other Storage type of the Tables.

VOLATILE

public static final int VOLATILE
The Volatile Storage type of the Tables.

NONVOLATILE

public static final int NONVOLATILE
The Nonvolatile Storage type of the Tables.

PERMANENT

public static final int PERMANENT
The Permanent Storage type of the Tables.

READONLY

public static final int READONLY
The Readonly Storage type of the Tables.

ENCODING

public static java.lang.String ENCODING
The Standard encoding string on which all encoding will be done.

SNMP_PORT

public int SNMP_PORT
The snmp port value of 161 for UDP.

SNMP_TRAP_PORT

public int SNMP_TRAP_PORT
The trap port value of 162 for UDP.

SNMP_VERSION_1

public static final int SNMP_VERSION_1
Constant for setting SNMP Version 1.

SNMP_VERSION_2C

public static final int SNMP_VERSION_2C
Constant for setting SNMP Version 2c.

SNMP_VERSION_2

public static final int SNMP_VERSION_2
Constant for setting SNMP Version 2 (Not supported).

SNMP_VERSION_3

public static final int SNMP_VERSION_3
Constant for the SNMP Version 3.

GET_REQ_MSG

public static final byte GET_REQ_MSG
Constant for SNMP get PDU type.

GETNEXT_REQ_MSG

public static final byte GETNEXT_REQ_MSG
Constant for SNMP get next PDU type.

GET_RSP_MSG

public static final byte GET_RSP_MSG
Constant for SNMP response PDU type.

SET_REQ_MSG

public static final byte SET_REQ_MSG
Constant for SNMP set request PDU type.

TRP_REQ_MSG

public static final byte TRP_REQ_MSG
Constant for SNMP trap PDU type.

GETBULK_REQ_MSG

public static final byte GETBULK_REQ_MSG
Constant for SNMP V2 Get Bulk PDU type.

INFORM_REQ_MSG

public static final byte INFORM_REQ_MSG
Constant for SNMP V2 INFORM PDU type.

TRP2_REQ_MSG

public static final byte TRP2_REQ_MSG
Constant for SNMP V2 Trap PDU type.

REPORT_MSG

public static final byte REPORT_MSG
Constant for SNMP V2 Report PDU type.

SNMP_ERR_NOERROR

public static final byte SNMP_ERR_NOERROR
SNMP error value.

SNMP_ERR_TOOBIG

public static final byte SNMP_ERR_TOOBIG
SNMP error value.

SNMP_ERR_NOSUCHNAME

public static final byte SNMP_ERR_NOSUCHNAME
SNMP error value.

SNMP_ERR_BADVALUE

public static final byte SNMP_ERR_BADVALUE
SNMP error value.

SNMP_ERR_READONLY

public static final byte SNMP_ERR_READONLY
SNMP error value.

SNMP_ERR_GENERR

public static final byte SNMP_ERR_GENERR
SNMP error value.

SNMP_ERR_NOACCESS

public static final byte SNMP_ERR_NOACCESS
SNMP error value.

SNMP_ERR_WRONGTYPE

public static final byte SNMP_ERR_WRONGTYPE
SNMP error value.

SNMP_ERR_WRONGLENGTH

public static final byte SNMP_ERR_WRONGLENGTH
SNMP error value.

SNMP_ERR_WRONGENCODING

public static final byte SNMP_ERR_WRONGENCODING
SNMP error value.

SNMP_ERR_WRONGVALUE

public static final byte SNMP_ERR_WRONGVALUE
SNMP error value.

SNMP_ERR_NOCREATION

public static final byte SNMP_ERR_NOCREATION
SNMP error value.

SNMP_ERR_INCONSISTENTVALUE

public static final byte SNMP_ERR_INCONSISTENTVALUE
SNMP error value.

SNMP_ERR_RESOURCEUNAVAILABLE

public static final byte SNMP_ERR_RESOURCEUNAVAILABLE
SNMP error value.

SNMP_ERR_COMMITFAILED

public static final byte SNMP_ERR_COMMITFAILED
SNMP error value.

SNMP_ERR_UNDOFAILED

public static final byte SNMP_ERR_UNDOFAILED
SNMP error value.

SNMP_ERR_AUTHORIZATIONERROR

public static final byte SNMP_ERR_AUTHORIZATIONERROR
SNMP error value.

SNMP_ERR_NOTWRITABLE

public static final byte SNMP_ERR_NOTWRITABLE
SNMP error value.

SNMP_ERR_INCONSISTENTNAME

public static final byte SNMP_ERR_INCONSISTENTNAME
SNMP error value.

INTEGER

public static final byte INTEGER
SNMP Type Constants.

STRING

public static final byte STRING
SNMP Type Constants.

BITSTRING

public static final byte BITSTRING
Deprecated. This variable has been deprecated in SNMPv2 protocol.

SNMP Type Constants.

OBJID

public static final byte OBJID
SNMP Type Constants.

NULLOBJ

public static final byte NULLOBJ
SNMP Type Constants.

IPADDRESS

public static final byte IPADDRESS
SNMP Type Constants.

NETWORKADDRESS

public static final byte NETWORKADDRESS
SNMP Type Constants.

COUNTER

public static final byte COUNTER
SNMP Type Constants.

GAUGE

public static final byte GAUGE
SNMP Type Constants.

UNSIGNED32

public static final byte UNSIGNED32
SNMP Type Constants.

TIMETICKS

public static final byte TIMETICKS
SNMP Type Constants.

OPAQUE

public static final byte OPAQUE
SNMP Type Constants.

UINTEGER32

public static final byte UINTEGER32
Deprecated. This variable has been deprecated in SNMP protocol.

SNMP Type Constants.

NSAP

public static final byte NSAP
Deprecated. This variable has been deprecated in SNMPv2 protocol

SNMP Type Constants.

COUNTER64

public static final byte COUNTER64
SNMP Type Constants.

NOSUCHOBJECTEXP

public static final byte NOSUCHOBJECTEXP
SNMP v2 Null Object Exception Value.

NOSUCHINSTANCEEXP

public static final byte NOSUCHINSTANCEEXP
SNMP v2 Null Object Exception Value.

ENDOFMIBVIEWEXP

public static final byte ENDOFMIBVIEWEXP
SNMP v2 Null Object Exception Value.

RONLY

public static final int RONLY
read access for everyone.

WONLY

public static final int WONLY
only write access for community.

RWRITE

public static final int RWRITE
add write access for community.

NOACCESS

public static final int NOACCESS
no access for anybody.

RCREATE

public static final int RCREATE
read-create value in Snmpv2.

ACCESSFORNOTIFY

public static final int ACCESSFORNOTIFY
accessible-for-notify in Snmpv2.

Standard_Prefix

public static java.lang.String Standard_Prefix
Deprecated. instead use the setOIDPrefix(SnmpOID oid) and getOIDPrefix() methods.

This is added to any Object ID string, that does not begin with a '.'. Since it is static, the change made in this variable will be reflected in all SnmpAPI instances used by the client application. Used primarily when creating an SnmpOID instance.
See Also:
SnmpOID

ACTIVE

public static final int ACTIVE
The Active State of the Tables.

NOT_IN_SERVICE

public static final int NOT_IN_SERVICE
The notInService state of the Tables.

NOT_READY

public static final int NOT_READY
The notReady state of the Tables.

CREATE_AND_GO

public static final int CREATE_AND_GO
The createAndGo state of the Tables.

CREATE_AND_WAIT

public static final int CREATE_AND_WAIT
The createAndWait state of the Tables.

DESTROY

public static final int DESTROY
The Destroy state of the Tables.

ANY_SEC_MODEL

public static final int ANY_SEC_MODEL
Constant values for "any" security model.

FATAL

public static final int FATAL
constant for fatal debug messages.

CRITICAL

public static final int CRITICAL
constant for critical debug messages.

NON_CRITICAL

public static final int NON_CRITICAL
constant for non-critical debug messages.

debugLevel

public static int debugLevel
variable having debugLevel , by defaullt FATAL.
Constructor Detail

SnmpAPI

public SnmpAPI()
Creates a new SnmpAPI instance and initialises the authoritative snmpEngineID, snmpEngineBoots, snmpEngineTime and the providers, SecurityProvider and ACMProvider. The SnmpEngineID is initialised to a randorm value of 12 octets and the snmpEngineBoots and snmpEngineTime are initialised to value 0. The attributes snmpEngineID, snmpEngineBoots and snmpEngineTime are useful only for an agent side implementation. These default values can be overriden by the respective set methods of these attributes. These three attributes are not relevant for a manager side implementation.

The constructor also instantiates the different SnmpV3 configuration tables i.e USMUserTable, SnmpEngineTable, VacmContextTable, VacmGroupTable, VacmGroupAccessTable and VacmViewTreeTable. These tables are used to store the different users, SNMPv3 entity and the vacm information. The API user need not instantiate these configuration tables and instead, has to use the methods provided in this class to access these tables.

See Also:
SnmpEngineTable

SnmpAPI

public SnmpAPI(boolean debug)
Creates a new SnmpAPI instance and initialises the authoritative snmpEngineID, snmpEngineBoots, snmpEngineTime and the providers, SecurityProvider and ACMProvider. The debug flag will be set to the value passed as parameter. The SnmpEngineID is initialised to a randorm value of 12 octets and the snmpEngineBoots and snmpEngineTime are initialised to value 0. The attributes snmpEngineID, snmpEngineBoots and snmpEngineTime are useful only for an agent side implementation. These default values can be overriden by the respective set methods of these attributes. These three attributes are not relevant for a manager side implementation.

The constructor also instantiates the different SnmpV3 configuration tables i.e USMUserTable, SnmpEngineTable, VacmContextTable, VacmGroupTable, VacmGroupAccessTable and VacmViewTreeTable. These tables are used to store the different users, SNMPv3 entity and the vacm information. The API user need not instantiate these configuration tables and instead, has to use the methods provided in this class to access these tables.

Parameters:
debug - The debug flag to be set for this SnmpAPI instance.
See Also:
SnmpEngineTable
Method Detail

start

public void start()
Overrides:
start in class java.lang.Thread

getTargetAddrTable

public com.adventnet.snmp.snmp2.SnmpTargetAddrTable getTargetAddrTable()
Gets the SnmpTargetAddrTable corresponding to this SnmpAPI.

setCommunityAuthentication

public void setCommunityAuthentication(boolean commAuthFlag)
Enables/Disables the community authentication flag.
Parameters:
commAuthFlag - The community Authentication flag to be set.

setNotificationFiltering

public void setNotificationFiltering(boolean notifyFilterFlag)
Enables/Disables the notification filtering.
Parameters:
notifyFilterFlag - The notification filter flag to be set.

isCommunityAuthentication

public boolean isCommunityAuthentication()
Gets the Community Authentication flag for this SnmpAPI instance.

isNotificationFiltering

public boolean isNotificationFiltering()
Gets the notification filtering flag for this SnmpAPI instance.

getNotifyTable

public SnmpNotifyTable getNotifyTable()
Gets the SnmpNotifyTable that is associated with this SnmpAPI instance.
Returns:
SnmpNotifyTable associated with this SnmpAPI instance.

getNotifyFilterTable

public SnmpNotifyFilterTable getNotifyFilterTable()
Gets the SnmpNotifyFilterTable that is associated with this SnmpAPI instance.
Returns:
SnmpNotifyFilterTable associated with this SnmpAPI instance.

getNotifyFilterProfileTable

public SnmpNotifyFilterProfileTable getNotifyFilterProfileTable()
Gets the SnmpNotifyFilterProfileTable that is associated with this SnmpAPI instance.
Returns:
SnmpNotifyFilterProfileTable associated with this SnmpAPI instance.

getTargetParamsTable

public com.adventnet.snmp.snmp2.SnmpTargetParamsTable getTargetParamsTable()
Gets the SnmpTargetParamsTable corresponding to this SnmpAPI.
Returns:
SnmpTargetParamsTable associated with this SnmpAPI instance.

getCommunityTable

public java.lang.Object getCommunityTable()
Deprecated. use the following instead
getSecurityProvider().getTable(1); // where 1 stands for v1 security model.

Gets the SnmpCommuityTable corresponding to this SnmpAPI.
Returns:
returns the community table as an object of SnmpCommunityTable.

getTargetAddrExtTable

public SnmpTargetAddrExtTable getTargetAddrExtTable()
Gets the SnmpTargetAddrExtTable corresponding to this SnmpAPI.
Returns:
returns the instance of SnmpTargetAddrExtTable maintained by this SnmpAPI object.

getSessionList

public java.util.Vector getSessionList()
Get the List of SNMP sessions managed under this SnmpAPI instance.

setDebug

public void setDebug(boolean debug)
Defines whether debugging output should be generated. In the debug mode, the PDU data is printed in hex format.
See Also:
SnmpClient.debugPrint(java.lang.String)

getDebug

public boolean getDebug()
Defines whether debugging output is being generated. In the debug mode, the PDU data is printed in hex format.
See Also:
SnmpClient.debugPrint(java.lang.String)

getStatement

public static java.sql.Statement getStatement()
Returns the Statement instance corresponding to this SnmpAPI instance
Returns:
the Statement corresponding to this SnmpAPI instance.

getConnection

public static java.sql.Connection getConnection()
Returns the database connection instance corresponding to this SnmpAPI instance.
Returns:
the Connection instance corresponding to this SnmpAPI instance.

getSASClient

public static SASClient getSASClient()
Returns the SASClient instance which has been created at last through the SnmpSession class. Opening an instance of SnmpSession passing applet as an argument will create an instance of SASClient and this SASClient instance will be stored in the SnmpAPI (the API instance which is passed to the constructor of SnmpSession).
Returns:
returns the SASClient maintained by this object.

initJdbcParams

public void initJdbcParams(java.lang.String driverName,
                           java.lang.String urlString,
                           java.lang.String userName,
                           java.lang.String password)
                    throws java.sql.SQLException,
                           java.lang.ClassNotFoundException
This method should be invoked to initialize the Jdbc Parameters in case of database support. If this method is invoked the DataBase flag will be set.
Parameters:
driverName - Name of the DataBase driver.
URL - URL pointing to the DataBase file name
userName - userName
passWord - password
Throws:
java.sql.SQLException - if the database connection could not be established
java.lang.ClassNotFoundException - if the driver class is not present in the classpath

setV3ConfigTable

public void setV3ConfigTable(java.lang.String tableName)
Sets the configured tableName specified in the case of V3Database.
Parameters:
tableName - the name of the table that should be configured.

getV3ConfigTable

public java.lang.String getV3ConfigTable()
Gets the table name that was configured for V3.
Returns:
returns the SNMPv3 config table that was set previously.

setV3DatabaseFlag

public void setV3DatabaseFlag(boolean dBaseFlag)
Sets the Database flag in the case of V3.
Parameters:
dBaseFlag - the flag to be set.

isV3DatabaseFlag

public boolean isV3DatabaseFlag()
Gets the Database flag for this SnmpAPI instance.

run

public void run()
This method starts the API thread which monitors the sessions to look for the requests which have timed out and retransmits the pdu if required. This thread can be stopped by the close method provided in this class. The outstanding requests are monitored for time-outs. If the request has timedout, then the pdu is retransmitted. If there are no more retries, then pdu is removed from the request list and prints the time out message if the debug is true.
Overrides:
run in class java.lang.Thread

close

public void close()
Stops the API thread which monitors the session for time-outs and retries. Thread.stop() is deprecated in JDK 1.2 .

genReqID

public int genReqID()
This number is unique number that is generated for this JVM. This integer is a constantly increasing number. This number starts from zero. The range of numbers that it produces are -2147483648 through 2147483647 except zero. Once this count reaches the maximun positive, it switches over to the negative side.
Returns:
returns the unique number which can be used for setting the request id.

genMsgID

public int genMsgID()
This number is unique number that is generated for this JVM. This integer is a constantly increasing number. This number starts from zero. The range of numbers that it produces are -2147483648 through 2147483647 except zero. Once this count reaches the maximun positive, it switches over to the negative side.
Returns:
returns the unique number which can be used for setting the message id.

checkResponses

public java.util.Vector checkResponses()
Checks each session to see if there is any outstanding response.
Returns:
list of sessions with outstanding responses.
See Also:
SnmpSession

checkTimeouts

public java.util.Vector checkTimeouts()
Checks each session to see if there is any outstanding Time-outs
Returns:
returns a vector of SnmpSession objects with requests that have timed out.
See Also:
SnmpSession

setCharacterEncoding

public void setCharacterEncoding(java.lang.String encoding)
Sets the Character encoding of the String values. The default will be ISO8859_1 which is the standard. All the string encoding will be done based on this encoding string.Refer the following page for the encoding string that are supported.
Parameters:
encoding - the string based on which the string encoding is to be done.
See Also:
getCharacterEncoding()

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Returns the Character encoding of the String values. The default will be ISO8859_1 which is the standard. All the string encoding will be done based on this encoding string.Refer the following page for the encoding string that are supported.
Returns:
the string based on which the string encoding is to be done.
See Also:
#setCharacterEncoding()

setOIDPrefix

public static void setOIDPrefix(SnmpOID oid)
This is added to any Object ID that does not begin with a '.'. Since it is static, the change made in this variable will be reflected in all SnmpAPI instances used by the client application. Used primarily when creating an SnmpOID instance. If the argument is null or if oid.toIntArray() returns null, then the oid prefix will be assumed to be empty.
Parameters:
oid - The prefix that will be added before oids.
See Also:
SnmpOID

getOIDPrefix

public static SnmpOID getOIDPrefix()
This method returns the OID prefix that is set before. If the OID prefix is not set previously, then the default OID namely ".1.3.6.1.2.1" will be returned.
Returns:
the OID prefix.

getSnmpEngineID

public byte[] getSnmpEngineID()
Gets the authoritative SnmpEngineID associated with this SNMP entity. Used for an agent side implementation.
Returns:
The authoritative SnmpEngineID.

setSnmpEngineID

public void setSnmpEngineID(byte[] id)
Sets the authoritative SnmpEngineID for this SNMP entity. Used for an agent side implementation.
Parameters:
id - The authoritative SnmpEngineID to be used.

getSnmpEngineBoots

public int getSnmpEngineBoots()
Gets the SnmpEngineBoots (number of times this SNMP engine has booted of this SNMP entity. Used for the agent side implemenation.
Returns:
The snmpEngineBoots of this SNMPv3 entity.

setSnmpEngineBoots

public void setSnmpEngineBoots(int boots)
Sets the SnmpEngineBoots (number of times this SNMP engine has booted of this SNMP entity. Used for the agent side implementation.
Parameters:
boots - The snmpEngineBoots for this SNMPv3 entity. Note : The boots value should be in between 0 and 2147483647.

getSnmpEngineTime

public int getSnmpEngineTime()
Gets the SnmpEngineTime. Returns the time in seconds since the engine has been booted. Used for the agent side implementation
Returns:
The time in seconds since the agent has been booted.

setSnmpEngineTime

public void setSnmpEngineTime(int time)
Sets the SnmpEngineTime, the time in seconds after this SNMP engine has booted. Used for an agent side implementation.
Parameters:
time - The time in seconds. This is used by the the authoritative SNMP engine to set the engineTime value i.e the time in seconds after the SNMP engine has booted.

setTimeWindow

public void setTimeWindow(int win)
Sets the time window in which messages should be accepted by this SNMP engine
Parameters:
win - The time in seconds to set the timeWindow attribute.

getTimeWindow

public int getTimeWindow()
Gets the time window in which messages are accepted by this SNMP engine.
Returns:
The timeWindow value in seconds within which the SNMP engine has to accept the message.

getUSMTable

public java.lang.Object getUSMTable()
Deprecated. use the following instead.
 SnmpApi.getSecurityProvider().getTable(USM_SECURITY_MODEL); // where USM_SECURITY_MODEL = 3

Gets the USMUserTable reference. The USMUserTable is instantiated by the constructor in this class. The USMUserTable has a list of USMUserEntries. Use this reference in all the places where this table needs to be referenced.
Returns:
The USMUserTable reference.

getSnmpEngine

public SnmpEngineTable getSnmpEngine()
Gets the SnmpEngineTable reference. The SnmpEngineTable is instantiated by the constructor in this class. The SnmpEngineTable has a list of SnmpEngineEntries. Use this reference in all the places where this table needs to be referred.
Returns:
The SnmpEngineTable reference.
See Also:
SnmpEngineTable

initSecurityProvider

public void initSecurityProvider()
                          throws SnmpException
This method initializes the SecurityProvider by reading from the file securityProvider.confg . It will register all the security models specified in the securityProvider.config file.
Throws:
SnmpException - if the file could not be found or if the security model could not be registered.

initACMProvider

public void initACMProvider()
                     throws SnmpException
This method initializes the Access Control Provider by reading from the file acmProvider.config . It will register all the access control models specified in the acmProvider.properties file.
Throws:
SnmpException - if the file could not be found or if the access control model could not be registered.

getSecurityProvider

public SecurityProvider getSecurityProvider()
Gets the SecurityProvider maintained by this SnmpAPI.
Returns:
securityProvider maintained by this SnmpAPI.

getACMProvider

public ACMProvider getACMProvider()
Gets the Access Control Provider maintained bu this SnmpAPI.
Returns:
ACMProvider maintained by this SnmpAPI.

getSnmpGroup

public SnmpGroup getSnmpGroup(java.lang.String local_address,
                              int port)
Gets the SnmpGroup Object corresponding to the SnmpSession's local_addrs and local_port. The SnmpGroup counters are maintained for each SNMP entity i.e for each local_address, local_port pair in the SnmpSession. To get the group counter values, the API user will have to retrive the SnmpGroup object using this method.
Parameters:
local_address - The address to which the session is bound. The local_address should be a string representation of the ipAddress.
port - The port at which the session is bound.
Returns:
gp the SnmpGroup object corresponding to the specified address and port.
See Also:
SnmpGroup

setSerializeFileName

public void setSerializeFileName(java.lang.String name)
Sets the fileName into which the SNMPv3 configuration tables are to be serialized. The security and access control configurations can be serialized so that they can be restored when the SNMPv3 entity is restarted. Right now the USMUserTable and the access control configurations tables which include VacmConetxtTable, VacmGroupTable, VacmGroupAccessTable and VacmViewTreeTable can be serialized. In order to store configuration information files, the API user has to set the file name in which configuration information needs to be serialized using this method.
Parameters:
name - The fileName into which the SNMPv3 configuration tables can be serialized.

getSerializeFileName

public java.lang.String getSerializeFileName()
Gets the fileName into which the SNMPv3 configuration tables are to be serialized. The security and access control configurations can be serialized so that they can be restored when the SNMPv3 entity is restarted. Right now the USMUserTable and the access control configuration tables which include VacmConetxtTable, VacmGroupTable, VacmGroupAccessTable and VacmViewTreeTable can be serialized. In order to store configuration information files, the API user has to set the file name in which configuration information needs to be serialized using the setSerializeFileName method. This method returns the fileName in which the SNMPv3 configuration tables are serialized.
Returns:
serializeFileName. The fileName into which the tables can be serialized

serialize

public boolean serialize()
                  throws SnmpException
This serializes the SNMPV3 Security tables into the file specified by the setSerializeFileName method. The security configurations can be serialized so that they can be restored when the SNMPv3 entity is restarted. The class that extends the securityModelTable should implement the serialize(ObjectOutputStream out) method. In order to store configuration information files, the API user has to set the file name in which configuration information needs to be serialized using the setSerializeFileName method. The serialize method serializes the SNMPv3 security tables.
Returns:
true if the serialization was successful. Returns false if the fileName into which the tables are to be serialized is null.
Throws:
SnmpException - If the serialization throws an IOException
See Also:
SecurityModelTable

deSerialize

public boolean deSerialize()
                    throws SnmpException
This deSerializes the SNMPV3 Security tables from the file specified by the setSerializeFileName method. The security configurations can be serialized so that they can be restored when the SNMPv3 entity is restarted. The class that extends the securityModelTable should implement the serialize(ObjectOutputStream out) method. This method deSerializes the file specified in the setSerializeFileName method to restore the SNMPv3 security tables.
Returns:
true if the deSerialization was successful. Returns false if the fileName into which the tables are to be deSerialized is null.
Throws:
SnmpException - If the deSerialization throws an IOException
See Also:
SecurityModelTable

setEngineBootsSerializeFileName

public void setEngineBootsSerializeFileName(java.lang.String name)
Sets the fileName into which the SNMPv3 engineBoots are to be stored so that they are persistant. The engineBoots are stored in a serialized file. The engine boots value will be serialized so that they can be restored when the SNMPv3 entity is restarted and serialized. In order to store configuration information files, the API user has to set the file name in which configuration information needs to be serialized using this method.
Parameters:
name - The fileName into which the engine boots can be serialized.

GetEngineBootsSerializeFileName

public java.lang.String GetEngineBootsSerializeFileName()
Gets the fileName into which the SNMPv3 engineBoots are to be stored so that they are persistant. The engineBoots are stored in a serialized file. The engine boots value will be serialized so that they can be restored when the SNMPv3 entity is restarted and serialized. In order to store configuration information files, the API user has to set the file name in which configuration information needs to be serialized using this method.
Returns:
the fileName into which the engine boots can be serialized.

serializeEngineBoots

public boolean serializeEngineBoots()
                             throws SnmpException
This serializes the engine boots into the file specified by the setSerializeFileName method. The engine boots value will be serialized so that they can be restored when the SNMPv3 entity is restarted and serialized. In order to store configuration information files, the API user has to set the file name in which configuration information needs to be serialized using this method.
Returns:
true if the serialization was successful. Returns false if the fileName into which the value is to be serialized is null.
Throws:
SnmpException - If the serialization throws an IOException

deSerializeEngineBoots

public boolean deSerializeEngineBoots()
                               throws SnmpException
This deSerializes the engine boots into the file specified by the setSerializeFileName method. The engine boots value will be serialized so that they can be restored when the SNMPv3 entity is restarted and serialized. In order to store configuration information files, the API user has to set the file name in which configuration information needs to be serialized using this method.
Returns:
true if the serialization was successful. Returns false if the fileName into which the value is to be serialized is null.
Throws:
SnmpException - If the serialization throws an IOException

compare

public static boolean compare(int[] a,
                              int[] b)
An int array comparison routine. Returns true if both the arrays are equal. Compares all the elements in int array. Returns false if the two int arrays are not equal or if the two arrays are of different lengths.
Parameters:
a - The int array to be compared.
b - The int array to be compared.
Returns:
if a equals b. False otherwise.

setDebugLevel

public static void setDebugLevel(int level)
sets debugLevel FATAL or CRITICAL or NON_CRITICAL.

debugPrintHigh

public static void debugPrintHigh(java.lang.Object str)
debugPrint method for FATAL messages.

debugPrintMedium

public static void debugPrintMedium(java.lang.Object str)
debugPrint method for CRITICAL messages.

debugPrintLow

public static void debugPrintLow(java.lang.Object str)
debugPrint method for NON_CRITICAL messages.

setupStdOutErr

public static void setupStdOutErr()
Deprecated. please use the logging framework instead.

makes logs directory for stdout and stderr files.

setupStdOutErr

public static void setupStdOutErr(java.lang.String dirStr)
Deprecated. please use the logging framework instead.

makes specified directory for stdout and stderr files.

getMajorVersion

public static int getMajorVersion()
Returns the major version of this release of SNMP Library.
Returns:
the major version of this release of SNMP Library.

getMinorVersion

public static int getMinorVersion()
Returns the minor version of this release of SNMP Library.
Returns:
the minor version of this release of SNMP Library.

getPatchVersion

public static int getPatchVersion()
Returns the patch version of this release of SNMP Library.
Returns:
the patch version of this release of SNMP Library.

getVersionString

public static java.lang.String getVersionString()
Returns a string describing this version of SNMP Library.
Returns:
a string describing this version of SNMP Library.


Copyright (c)AdventNet Inc., 1996-2004