Ireasoning SNMP Api User Guide
Ireasoning SNMP Api User Guide
Ireasoning SNMP Api User Guide
Table of Contents
INTRODUCTION ........................................................................................................................................................................................................................ 1
About this document .................................................................................................................................................................................................................... 1
Target Audience ........................................................................................................................................................................................................................... 1
INSTALLATION ......................................................................................................................................................................................................................... 2
Requirements ................................................................................................................................................................................................................................ 2
Installation Procedures ................................................................................................................................................................................................................ 2
USING iREASONING SNMP LIBRARY .................................................................................................................................................................................. 4
Overview and Architecture .......................................................................................................................................................................................................... 4
UML diagram ............................................................................................................................................................................................................................ 7
Configuration ............................................................................................................................................................................................................................... 8
Logger configuration .............................................................................................................................................................................................................. 8
Usage examples ............................................................................................................................................................................................................................ 8
SnmpSession class ................................................................................................................................................................................................................... 8
Synchronous SNMP Operations ............................................................................................................................................................................................ 9
Asynchronous SNMP Operations ........................................................................................................................................................................................ 10
SNMP Table Retrieval .......................................................................................................................................................................................................... 11
SnmpTrapdSession class ...................................................................................................................................................................................................... 12
SnmpTrapSender class ......................................................................................................................................................................................................... 13
SnmpPoller class ..................................................................................................................................................................................................................... 13
Java Applet Example ............................................................................................................................................................................................................ 14
FAQ ............................................................................................................................................................................................................................................ 15
RESOURCES AND REFERENCE .......................................................................................................................................................................................... 19
GLOSSARY OF TERMS ........................................................................................................................................................................................................... 20
I R E A S O N I N G S N M P L I B R A R Y
INTRODUCTION
About this document
T
he purpose of this document is to provide the reader with enough knowledge to
start developing software using the iReasoning's SNMP toolkit. Some examples are
provided to better illustrate the usage of APIs. This document is not intended to
provide detailed information about the SNMP APIs. To effectively use the APIs,
readers need to refer to javadoc help that has detailed instructions and examples.
The iReasoning SNMP API is a Java toolset that greatly simplifies the development of applications for
managing SNMP agents. It provides full support for SNMPv1, SNMPv2c and SNMPv3. The design and
implementation of this library were based on object-oriented methodology and followed recognized
design patterns. These advantages, combined with a highly optimized code base, make iReasoning
SNMP library stand out from the competition.
Target Audience
This document is intended for users and engineers who are responsible for developing SNMP based
management applications. A user of this software does not have to be an expert in network management
field. He or she should, however, be familiar with basic SNMP concepts, such as SNMP GET and
GET_NEXT operations. Some basic knowledge about Java language is required to understand
examples. This software is designed to minimize the learning curve for users and achieve a given
programming job with less code. A new user should therefore find it quite easy to learn and master this
product.
I R E A S O N I N G S N M P L I B R A R Y
Chapter
2
INSTALLATION
Requirements
Ø JDK1.2 or a later version must be installed. You can download JDK from
the Oracle’s web site (http://java.com )
Installation Procedures
Ø Download and unzip
Ø Set up CLASSPATH
On Unix/Linux:
On Unix/Linux
CLASSPATH /usr/local/ireasoning/snmp/lib/examples.jar ; export CLASSPATH
2) Run
If you do not have an snmp agent, you can run snmpd.exe (on
Windows) to start an agent listening on port 161.
Chapter
3
USING iREASONING
SNMP LIBRARY
Overview and Architecture
The iReasoning SNMP library is designed and implemented using object oriented
methodology and recognized design patterns. One of its design goals was to
minimize the learning curve of SNMP library for developers. Users only need to
know a few classes, most of complex works are hidden from them.
All versions of SNMP (SNMPv1, SNMPv2c and SNMPv3) are supported in one
library, and users do not have to learn the detailed underlying differences between
three SNMP versions. Users can always use a unified interface to access SNMP
agents speaking different SNMP protocols. The example code shipped with this
product clearly demonstrates the simplicity of this library. In those code, at first
glance, users will realize how simple it is to write code to communicate with SNMP
agents.
The central class is the SnmpSession. It provides all the necessary mechanism to
use SNMP operations. A session represents a communication channel between an
SNMP manager and an agent. To communicate with multiple agents, multiple
sessions have to be created. Each session is corresponding to each communication
channel. A session needs to be created and then a connection needs to be
established with the agent. After session is initialized, you are ready to issue SNMP
commands against the agent. There are four basic SNMP operations: GET,
GET_NEXT, SET, GET_BULK (SNMPv2c and SNMPv3). They are
represented in SnmpSession class as snmpGetRequest, snmpGetNextRequest,
snmpSetRequest, snmpGetBulkRequest methods. High-level SNMP operations,
such as GET_TABLE and WALK, are represented as snmpGetTable and
snmpWalk methods. When a session is no longer needed, it needs to be closed to
avoid resource leak.
SNMP data types are represented as child classes of SnmpDataType class. The
remote agent is represented as the SnmpTarget class. Each agent is represented by
a single SnmpTarget object. An SnmpTarget can be instantiated with the IP
address (or host name) and port number of the remote agent. Other properties
of agent, such as community name, can also be specified. The class diagram is
shown in figure 1. For detailed information about classes, you can refer to the
javadoc files shipped with this library.
The SNMP protocol uses UDP as the default transport layer protocol. UDP is
connectionless and the delivery of packets is not guaranteed, but it is an efficient
way to transport small amount of data. The iReasoning SNMP API architecture
also supports TCP besides UDP. SNMP over TCP is a good fit for transferring
large amount of data. The built-in features of TCP, such as flow control and
efficient segmentation, make TCP perform better than UDP in this case. The agent
has to be able to support SNMP over TCP so that the SNMP manager can choose
TCP as an underlying transport layer protocol.
I R E A S O N I N G S N M P L I B R A R Y
A MIB parser utility is also included in the library. MibUtil class can be used to
parse MIBs and resolve OID and variable binding’s value. It can look up MIB
node name from OID value as well. MibUtil’s parseMib method can parse MIB
and return a tree data structure. Here is an output from mibparser.java sample
code, which illustrates how to use MIB parser.
I R E A S O N I N G S N M P L I B R A R Y
UML diagram
Session
Trarget
-target : Trarget
-host : String
+getState() : int -port : int
#open(in target : Trarget) 1 1
+close()
SnmpSession SnmpTrapdSession
-snmpTarget : SnmpTarget
+send(in pdu : SnmpPdu) : SnmpPdu +waitForTrap() : SnmpDataType
+snmpGet(in oid : SnmpOID) : SnmpPdu SnmpTarget
+snmpGetNext(in oid : SnmpOID) : SnmpPdu
+snmpGetBulk(in pdus : SnmpOID[], in nonRepeaters : int, in maxRepetitions : int) : SnmpPdu -community : String
+snmpSet() 1 1
* *
SnmpPdu
<<interface>>
SnmpDataType
+getType() : int
+getTypeString() : String
1 +copy() : SnmpDataType
1
1
*
11
Configuration
Config files are located at ./config directory by default. You can add a java
environment variable to set a new config directory. For example:
java -Dcom.ireasoning.configDir=d:\config …
Logger configuration
The iReasoning SNMP library has a built-in logger. The logger is configurable
through the Logger.prop file located at ./config directory. You can change the
logging level or just disable the logger. The output of logging message is also
configurable. It can be system’s standard out or file. Check out Logger.prop
for detailed information.
The popular open source log4j package is also supported. To switch to log4j
logger, you just need to add one line of code in the beginning of your
program:
com.ireasoning.util.Logger.setUseLog4j(true);
If using log4j, the Logger.prop will no longer be used. You need to configure
the log4j logger or provide a config file for it. You can still use the log
methods in the Logger class to log messages, then they will be delegated to
corresponding methods in log4j logger.
Usage examples
In your source file, you need to import the following iReasoning SNMP
packages:
import com.ireasoning.protocol.*;
import com.ireasoning.protocol.snmp.*;
SnmpSession class
In this example, MIB-II is loaded by calling loadMib2 method. Then we can use
snmpGetTable method with MIB node name “ifTable” to retrieve whole table.
Table information is stored in SnmpTableModel object. SnmpTableModel
implements Swing’s TreeModel interface, so it can be easily used to create a
JTable component. The following is a screenshot of tcpConnTable retrieval
(result of running snmpgettable.java example that is bundled with this product).
SnmpTrapdSession class
SnmpTrapSender class
This class can be used to send out all three versions of SNMP traps. Although
SnmpSession class also can be used to send out trap if properly configured, it is
much easier to do it using this class instead.
SnmpPoller class
This class can send out SNMP GetRequest and GetNextRequest to agents
periodically. The interval is configurable.
...
...
Java code and HTML files are located at examples/snmp/applet. This example
shows how to retrieve agent information within a java applet. Because of
security restrictions of Java applet, the snmp agent and the web server have to
be running on the same machine.
I R E A S O N I N G S N M P L I B R A R Y
FAQ
• Ease of use. You can take a look at the example code, such as
snmpgetnext.java or snmpwalk.java , to see how easy to implement
SNMPv1/v2c/v3 operations
• High performance. All code bases are highly optimized to maximize
performance and minimize overhead
• The first Java SNMP product to support both DES and strong 128-bit
AES encryption algorithms
• Support all SNMP versions (SNMPv1, SNMPv2c, SNMPv3)
• Conform to the EJB specification
• Robust and powerful SMIv1/SMIv2 MIB parser
• Support both UDP and TCP transport layers
properly decode request messages and process the resulting data. In testing,
OUSPG found multiple vulnerabilities in the way many SNMP agents
decode and process SNMP request messages.
This advisory is not applicable to iReasoning SNMP library because it does
not have SNMP agent functionality and does not accept SNMP request
messages.
Q. What is AES standard? And how does 128-bit AES encryption compare
to DES?
A. Excerpt from NIST (National Institute of Standards and Technology) website:
"The Advanced Encryption Standard (AES) is a new Federal Information Processing Standard
(FIPS) Publication that will specify a cryptographic algorithm for use by U.S. Government
organizations to protect sensitive (unclassified) information. NIST also anticipates that the AES
I R E A S O N I N G S N M P L I B R A R Y
will be widely used on a voluntary basis by organizations, institutions, and individuals outside of
the U.S. Government - and outside of the United States - in some cases.
The AES is being developed to replace DES, but NIST anticipates that Triple DES will
remain an approved algorithm (for U.S. Government use) for the foreseeable future. Single
DES is being phased out of use, and is currently permitted in legacy systems,
only.
Assuming that one could build a machine that could recover a DES key in a second (i.e., try 255
keys per second), then it would take that machine approximately 149 thousand-billion (149
trillion) years to crack a 128-bit AES key. To put that into perspective, the universe is believed to
be less than 20 billion years old."
See "The AES Cipher Algorithm in the SNMP User-based Security Model" for
more details on AES in SNMP.
Q. How can I make SNMP requests with object names instead of numeric
OIDs?
A. iReasoning SNMP library includes a MIB parser. You need to load MIB files
first by using MibUtil.loadMib method. To load MIB-II (RFC1213), you can call
MibUtil.loadMib2() method. After necessary MIB files are loaded, you then can use
MibUtil class' other method to do translation between object name and numeric
OID. Check out example code for more information.
RESOURCES AND
REFERENCE
_____________________________________________
http://www.iReasoning.com/
v SNMP FAQ
http://www.faqs.org/faqs/snmp-faq/part1/
v SNMP RFCs
http://directory.google.com/Top/Computers/Internet/Protocols/SNMP
/RFCs/
http://www.simpleweb.org/
http://java.com
I R E A S O N I N G S N M P L I B R A R Y
GLOSSARY OF TERMS
______________________________________________
JAVA
MIB
OID
PDU
Protocol Data Unit (PDU), basically a fancy word for packet. PDUs are
the building blocks of SNMP messages.
SNMP
TCP
Transport Layer
TRAP
UDP
UML