adding mibs snpm v2c

447

Upload: son2483

Post on 07-Nov-2014

144 views

Category:

Documents


0 download

TRANSCRIPT

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Table of ContentsDeveloping SNMPv2c Management Applications ................................................. 7 Choosing the Application Architecture.................................................................. 9Overview............................................................................................................................ 10 Management Console Applications ................................................................................... 12 Middle-Tier Management Servers ..................................................................................... 13 Web Craft Interfaces.......................................................................................................... 15

API Overview .......................................................................................................... 16High-Level API Architecture............................................................................................... 17 Low-Level API Architecture ............................................................................................... 19 MIBs API Architecture........................................................................................................ 21 SAS API Architecture......................................................................................................... 22 RMI API Architecture ......................................................................................................... 24 CORBA API Architecture ................................................................................................... 26 EJB API Architecture ......................................................................................................... 27

Development Environment for API ....................................................................... 29Setting Up for High-Level API............................................................................................ 30 Setting Up for Low-Level API............................................................................................. 31 Setting Up for RMI API ...................................................................................................... 32 Setting Up for CORBA API ................................................................................................ 34 Setting Up for EJB API ...................................................................................................... 36

Using MIBs in Applications ................................................................................... 37Loading MIBs..................................................................................................................... 38Loading MIBs Directly .................................................................................................................... 39 Loading from Serialized Files ........................................................................................................ 42 Loading Compiled MIBs................................................................................................................. 44 Loading from Database.................................................................................................................. 46

Unloading MIBs ................................................................................................................. 48 Parsing MIBs ..................................................................................................................... 49Parsing Levels ............................................................................................................................... 50 Checks for Various Parsing Levels................................................................................................ 52 Checks in Detail ............................................................................................................................. 54

Accessing Node Information.............................................................................................. 64 Retrieving MIB Information ................................................................................................ 66 Exceptions and Error Messages........................................................................................ 67 Database Schema ............................................................................................................. 73 Macro Type Constructs...................................................................................................... 77

AdventNet, Inc.

1

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Configuring SNMP Agent Parameters .................................................................. 83SNMP Version ................................................................................................................... 84 SNMP Version ................................................................................................................... 85 Host Name......................................................................................................................... 86 Port Number ...................................................................................................................... 87 Community Name .............................................................................................................. 88 Timeout and Retries .......................................................................................................... 89 Max Repetitions ................................................................................................................. 90 Non Repeaters................................................................................................................... 91 Trap Parameters................................................................................................................ 92

Handling Datatypes................................................................................................ 94Overview............................................................................................................................ 95 SMI Datatypes ................................................................................................................... 99Integer32...................................................................................................................................... 100 INTEGER (Enumerated) .............................................................................................................. 104 Unsigned32.................................................................................................................................. 108 Gauge32 ...................................................................................................................................... 111 Counter32 .................................................................................................................................... 115 Counter64 .................................................................................................................................... 119 Timeticks...................................................................................................................................... 124 OCTET STRING .......................................................................................................................... 128 OBJECT IDENTIFIER.................................................................................................................. 132 IpAddress..................................................................................................................................... 136 Opaque ........................................................................................................................................ 140 BITS ............................................................................................................................................. 141

Textual Conventions ........................................................................................................ 145Overview ...................................................................................................................................... 146 DateAndTime ............................................................................................................................... 148 MacAddress ................................................................................................................................. 151

Data Retrieval Operations ................................................................................... 153SNMP GET ...................................................................................................................... 154 SNMP GETNEXT ............................................................................................................ 158 SNMP GETBULK............................................................................................................. 160 Polling Data ..................................................................................................................... 162

Data Altering Operations ..................................................................................... 164SNMP SET ...................................................................................................................... 165 Setting Values for Datatypes ........................................................................................... 168

AdventNet, Inc.

2

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Traps and Notifications ....................................................................................... 169Receiving Notifications .................................................................................................... 170 Sending Notifications ....................................................................................................... 174

Table Handling in Applications ........................................................................... 176SNMP Table Basics......................................................................................................... 177 Fetching Tables ............................................................................................................... 179 Getting Row Data ............................................................................................................ 184 Getting Column Data ....................................................................................................... 186 Polling Table Data ........................................................................................................... 188 Table with Notaccessible Index ....................................................................................... 190 Modifying Table Data....................................................................................................... 191 Adding a Row .................................................................................................................. 193 Deleting a Row ................................................................................................................ 196 Other Table Operations ................................................................................................... 198

Exceptions and Error Handling........................................................................... 199Error Handling.................................................................................................................. 200 High-Level API Exceptions .............................................................................................. 202 High-Level API Error Messages ...................................................................................... 203 Low-Level API Error Messages ....................................................................................... 205

Developing SNMP Application as Java Applet .................................................. 209Support Through SAS...................................................................................................... 210 Extending SAS................................................................................................................. 218 Support Through HTTP ................................................................................................... 222 Applications of SAS API .................................................................................................. 226 Installation Notes ............................................................................................................. 228

Using Transport Providers .................................................................................. 229SNMP Transport Provider................................................................................................ 230 SAS Transport Provider................................................................................................... 231 Custom Transport Provider.............................................................................................. 232 Internet Protocol Version 6 .............................................................................................. 234

Internationalization .............................................................................................. 237Using High-Level API....................................................................................................... 238 Using Low-Level API ....................................................................................................... 239

Logging Management Applications.................................................................... 240Logging Mechanism......................................................................................................... 241

Deployment Instructions ..................................................................................... 244Deploying Applications .................................................................................................... 245 Deploying Applets............................................................................................................ 246 Deploying EJB Applications............................................................................................. 247

AdventNet, Inc.

3

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Examples .............................................................................................................. 253Setting Up the Environment............................................................................................. 254Using Applications ....................................................................................................................... 255 Running Applets........................................................................................................................... 258

Data Retrieval Examples ................................................................................................. 259SNMP GET .................................................................................................................................. 260 SNMP GETNEXT......................................................................................................................... 262 SNMP GETBULK......................................................................................................................... 263 SNMP Walk.................................................................................................................................. 264

Data Altering Examples ................................................................................................... 265SNMP SET................................................................................................................................... 266 SNMP SET Without Using MIB.................................................................................................... 268

Notification and Inform Examples .................................................................................... 269Trap Receiver .............................................................................................................................. 270 Send Notifications ........................................................................................................................ 272 Send Inform Request ................................................................................................................... 274 Send v2c Inform........................................................................................................................... 275 Receive v2c Inform ...................................................................................................................... 276

Table Handling Examples................................................................................................ 277Table Retrieval - Non UI .............................................................................................................. 278 Retrieve Table - UI....................................................................................................................... 281 Walk Indexes ............................................................................................................................... 286 Get By Index ................................................................................................................................ 287 Set Table Value ........................................................................................................................... 288 Encode Table Index ..................................................................................................................... 289 Get Column.................................................................................................................................. 290 Get Row ....................................................................................................................................... 291 Get Table Info .............................................................................................................................. 292 SNMP CORBA............................................................................................................................. 292

MIB Handling Examples .................................................................................................. 294MIB Node Details ......................................................................................................................... 295 Leaf Node Details ........................................................................................................................ 296 JFC MIB Tree............................................................................................................................... 297

Other Examples ............................................................................................................... 298Request Server Demo ................................................................................................................. 299 RMI Request Server Demo.......................................................................................................... 300 SnmpPoller Demo I...................................................................................................................... 302 RMI Applet Demo......................................................................................................................... 304 Property Settings Demo............................................................................................................... 306 Line Graph Demo......................................................................................................................... 308

AdventNet, Inc.

4

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Tutorials ................................................................................................................ 309Overview.......................................................................................................................... 310Beans API Tutorial ....................................................................................................................... 311 Low-Level API Tutorial................................................................................................................. 312 MIBs API Tutorial ......................................................................................................................... 314 SAS API Tutorial .......................................................................................................................... 315

Data Retrieval Tutorials ................................................................................................... 316GET, GETNEXT Using High-Level API ....................................................................................... 317 SNMP GET, GETNEXT (UI) Using High-Level API..................................................................... 319 SNMP GET, GETNEXT Using Low-Level API ............................................................................ 323 SNMP GET, GETNEXT for Applets............................................................................................. 326 SNMP GET Using SAS Transport Framework ............................................................................ 328 SNMP GET Using TCP................................................................................................................ 329 Polling with SnmpPoller ............................................................................................................... 332

Data Altering Tutorials ..................................................................................................... 334SNMP SET Using High-Level API ............................................................................................... 335 SNMP SET (UI) Using High-Level API ........................................................................................ 337 SNMP SET Using Low-Level API ................................................................................................ 340

Trap Tutorials................................................................................................................... 343Receive Trap Using High-Level API ............................................................................................ 344 Send Trap Using High-Level API.................................................................................................346 Receive Trap (UI) Using High-Level API ..................................................................................... 347 Send and Receive Trap (UI) Using High-Level API..................................................................... 349 Receive Trap (UI) Using TrapBrowser......................................................................................... 352 Receive Trap Using Low-Level API ............................................................................................. 355 Send Trap Using Low-Level API..................................................................................................358 Receive Traps for Applets............................................................................................................ 361

Table Handling Tutorials.................................................................................................. 364Retrieve Table with TableBean.................................................................................................... 365 Retrieve Table with SnmpTable................................................................................................... 367 Retrieve Table with SnmpAugmentTable .................................................................................... 369 Retrieve Table with SnmpTableModel......................................................................................... 371 Retrieve Table with SnmpTablePanel ......................................................................................... 373 Retrieve Table with SnmpTarget .................................................................................................375

MIB Handling Tutorials .................................................................................................... 377Traverse MIB (UI) with MibTree................................................................................................... 378 Browse MIB (UI) with MibBrowser ............................................................................................... 381 Retrieve MIB Node Information with MIBs API ............................................................................ 382

Other Tutorials ................................................................................................................. 384Graphs with LineGraphBean ....................................................................................................... 385 Address and Name Lookup ......................................................................................................... 387

AdventNet, Inc.

5

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

SAS as an Application ................................................................................................................. 389 SAS as Part of an Application...................................................................................................... 391

Complete Example .......................................................................................................... 393

Performance Metrics............................................................................................ 394Performance Numbers for Modules................................................................................. 395 Performance Numbers for MIB Loading Options............................................................. 396 Performance Numbers for Traps ..................................................................................... 397

Migration Guide .................................................................................................... 398Migration from 3.x to 4.0 .................................................................................................. 399High-Level API Changes.............................................................................................................. 400 Low-Level API.............................................................................................................................. 401 MIBs API Changes....................................................................................................................... 406

Migration from 2.x to 4.0 .................................................................................................. 407 Low-Level API Changes .................................................................................................. 408 MIBs API Changes .......................................................................................................... 413

FAQs...................................................................................................................... 415Beginners FAQs .............................................................................................................. 416 FAQs - General................................................................................................................ 420 FAQs - Bean Components............................................................................................... 424 FAQs - Low-Level API ..................................................................................................... 431 FAQs - MIBs API ............................................................................................................. 436 FAQs - SAS and Web Server .......................................................................................... 439 FAQs - EJB API ............................................................................................................... 441 FAQs - RMI API ............................................................................................................... 442 FAQs - CORBA API......................................................................................................... 444

Javadocs............................................................................................................... 445

AdventNet, Inc.

6

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Developing SNMPv2c Management ApplicationsChoosing the Application Architecture discusses the various kinds of network management applications and applets that can be developed using AdventNet SNMP API. API Overview discusses the usage of AdventNet SNMP API for developing the management applications and applets. It also explains how to work with the various Java packages available with this product. Using MIBs in Applications discusses the MIB-related aspects while developing the management applications. Configuring SNMP Agent Parameters discusses the common SNMPv2c parameters that need to be set while developing the applications and applets. Handling Datatypes explains about the basic datatypes, application datatypes, and textual conventions. Data Retrieval Operations discusses the data retrieval operations such as GET, GETNEXT, GETBULK, and polling. Data Altering Operations discusses the SNMP SET operation using AdventNet SNMP API. Traps and Notifications explains how to receive and send traps using AdventNet SNMP API. Table Handling in Applications explains the various table-related operations that can be performed using AdventNet SNMP API. Exceptions and Error Handling details the various errors and exceptions that are generated while using AdventNet SNMP API. Developing SNMP Application as Java Applet explains the usage of SAS in developing management applets. It also discusses the communication between applets on Java browsers that do not permit socket access to any host other than the applet host. Using Transport Providers discusses the transport providers that enable you to implement the protocol of your choice for SNMP communication. Internationalization explains the internationalization support available in AdventNet SNMP API. Logging Management Applications explains the feature used by applications to log messages while communicating with the agent. Deployment Instructions explains the steps involved in deploying the applications and applets. Examples gives the detailed instructions on the usage of various command line tools and applications that are bundled with the AdventNet SNMP API product to query the SNMP devices/applications. Tutorials helps you get familiar with the development using AdventNet SNMP API. Sample Java programs are available that can be compiled and run. Performance Metrics gives the performance numbers for the various modules of AdventNet SNMP API. Migration Guide describes the changes that have been made in this release and guides the user to upgrade to AdventNet SNMP API 4. This section is useful for the existing AdventNet SNMP API users who are migrating to the latest release. New users can skip this section.

AdventNet, Inc.

7

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

FAQs includes the list of frequently asked questions that serve as a guide to understand AdventNet SNMP API. Javadocs contains the classes and methods pertaining to various modules of AdventNet SNMP API. It is meant for developers looking to build management applications and applets based on AdventNet SNMP API.

AdventNet, Inc.

8

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Choosing the Application Architecture Overview Management Console Applications Middle-Tier Management Servers Web Craft Interfaces

AdventNet SNMP API can be used to develop Java and web-based network management applications and applets. Network management developers can use the AdventNet SNMP library to build servers, applications, applets, components, and distributed EJB, CORBA, and RMI applications. The library provides the most commonly used functions and components to make the development simpler. AdventNet SNMP API can be used for developing: Management Console Applications (Craft Interfaces) Middle-Tier Management Servers Web Craft Interfaces (Applets)

AdventNet, Inc.

9

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

OverviewNetwork management applications differ widely in the scope of their design, implementation, and deployment. Building such applications requires the understanding of many aspects of network management as well as software technologies. The management needs can be any of the following. Network management, system management, or device management Generic or customized management

The following are the types of applications that can be developed to meet the above-mentioned management needs. Embedded applications Operating system specific or cross-platform implementations Standalone applications Web-based applications and applets Distributed applications GUI or non-GUI (command line) applications Components used in other applications

The application that is developed can be any of the following.

The type of management application that needs to be developed largely depends on the purpose of the application. AdventNet SNMP API comes with the necessary APIs, which can help you in developing the applications of your choice.

Network Management and Device ManagementNetwork management is primarily concerned with managing an entire network that is made up of number of devices. Device management is considered with managing a device as an individual entity. A management application developed for network management monitors the network and the devices in the network. A device management application is used to manage a particular device in the network. Here, the network itself is used only as a medium to monitor the device remotely. The application does not have any control over the network.

Generic and Customized Management ApplicationsThe network management needs mandate the management application to be as generic as possible or custom-tailored for a specific network or device. A generic management application typically loads any MIB, receive any trap message, communicate with any type of device, query and poll any SNMP node, and so on. Although a generic management application has its advantages, its utility is limited. Even the simplest management operations might need to be done repetitively. Customized applications have specific user interface and most of the complex requests can be handled in few mouse clicks. Graphical representation and automating several routine tasks are the part of the customized approach. The applications can also completely isolate the user from the underlying protocol used. One disadvantage is that they are tailor made for the associated MIB. Any change in the MIB is difficult to handle in the application.

AdventNet, Inc.

10

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Types of ApplicationsIn today's heterogeneous network environment, deciding on the type of applications becomes critical. The targeted customer base predominantly dictates the choice of the type of application. Most applications fall under any one of the following categories. Embedded applications - depend on the device. Most devices, such as switches, routers, and printers have embedded applications installed in it which can be used to manage the device. Operating system specific or cross-platform implementations - depend on the end user. If the end users use a particular operating system, the application can be developed pertaining to that OS. On the other hand, if multiple operating systems (Windows, Unix, or Macintosh) are used, it is better to develop the application that supports cross platform. In this case, a cross-platform language, such as Java should be used. Standalone applications - depends on customer needs and the managed device. These applications are implementation specific. Web-based applications and applets - This has the advantage of leveraging the Internet technologies. The application can be installed in a web server and the front end can access through the browser itself. This is implementation specific. Distributed applications - depend on users and managed devices. If the users or devices to be managed are distributed, distributed applications are required. Distributed applications can be developed using CORBA or RMI technologies.

Command-Line ApplicationsCommand-line applications or tools are the simplest applications that can be developed for the SNMP management. Typically, these tools are used to send single request messages to the agent, receive responses, and display them in the console. These tools can also act as daemon process to receive and display traps. Command-line tools are normally used for fetching small amount of information, testing the MIB variables implemented by the agent, receiving debug information for a particular variable, testing whether a node is SNMP enabled, and so on. The usage of the command-line tools requires the user to have a good knowledge of SNMP. The user must understand the SNMP concepts such as community, OIDs, data types, SNMP errors, etc. in order to use the tools effectively.

GUI ApplicationsA simple command-line application has its limitations. After some time, it becomes complicated and tedious to use. Migrating to GUI environment gives the advantage of having an intuitive application with menu bars, toolbars, drag-and-drop components, graphs, and many more features.

Using AdventNet SNMP APIAdventNet SNMP API with its hierarchy of Java packages enables developing the above-mentioned type of applications in a simpler and quicker way. The various packages available with this product allows flexible selection of the desired level of library support. You can either access detailed SNMP information using low-level API or choose higher-level Java Beans for simpler programming.

AdventNet, Inc.

11

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Management Console ApplicationsWhen you are looking to build a management application where: there is no constraint on the size of the application the management console application need not be dynamic the performance of the management console is critical all the management operations need not be distributed or centralized

you can go in for building standalone management console application.

Management console applications provide the ability to manage and monitor all your network resources from a central location. The resources can be routers, switches, printers, or server applications. The management console can be used to perform the following operations. Configuration and tuning of device parameters Trending to study device performance Troubleshooting devices Alerts through emails and pagers under critical conditions

These applications can be built using the high-level or low-level AdventNet SNMP API. The high-level API has built-in UI and non-UI bean components, which makes the building of management console simple. Some of the bean components are as follows. SnmpTarget SnmpRequestServer - used for performing device configuration. SnmpTableModel - used to alter/configure SNMP tables graphically. SnmpPoller - used to perform trending of device parameters (such as network interface traffic) LineGraph, BarGraph - used to display the trending data graphically. SnmpTrapReceiver - used to receive traps or alerts from devices.

When the footprint of the management console has to be minimum, the low-level API can be used directly with MIBs support. Although the time taken to develop the application console is more when compared to using the high-level API, the low-level API can be used in applications where smaller footprint is required.

AdventNet, Inc.

12

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Middle-Tier Management ServersThe multi-tier architecture includes a back-end database, a middle tier of servers and clients. The back-end database has all the common data. The middle tier usually consists of a set of servers that performs processing. The client tier consists of thin clients, which can be HTML-only, Java applets, Java applications, or other suitable clients. When you are looking to build a management application, where: the management application has to be thin multiple administrators using the management application should be able to talk to the server all the processing of data should be done at the server side and passed on to the client there is a need for more then one management application using a centralized server

you can opt for this middle-tier architecture.

Some of the benefits of the three-tier model are as follows. Scalability: The key benefit is improved scalability as the servers can be deployed on many machines and the processing can be distributed. And the back-end requires connection only from servers and not from every client. Re-usability: If the same kind of processing needs to be done by more than one client, the server can do the processing which can be used by all clients. This results in easy maintenance of code. Data integrity: All updates are done through the middle tier and therefore the middle tier can validate the data that is updated in the database. The clients do not have direct access to the database thereby eliminating the risk of a client corrupting the data. Reduced uploading time: Changes to business logic can be updated only on the servers resulting in easy maintenance and faster deployment.

AdventNet, Inc.

13

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

In the middle-tier architecture, AdventNet SNMP API can be used for: Data collection Status polling Network configuration

The client can use the distributed APIs of AdventNet, such as RMI and CORBA to access the middle tier. The back-end is the network from where the data is collected by the middle tier. Therefore the clients, the core APIs, and the network form a hybrid 3-tier model. Almost all the high-level APIs are supported from RMI and CORBA API. For building scalable NMS, the AdventNet APIs can be used in the middle tier and XML can be used for communication between the client and the server.

AdventNet, Inc.

14

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Web Craft InterfacesWhen you are looking to build a management application, where: the management application has to be viewed from anywhere by using a web browser there is a need for more than one administrator to manage there is a size restriction for the management application you are looking for a web-based tool for managing your network

you can opt for building applets.

Although applets are restricted from performing socket-related operations, AdventNet's SAS facilitates a full-featured applet interface. It can overcome the limitations imposed on applets by the Java security model. Therefore with AdventNet SNMP API and SAS, you can develop applets that can perform file operations, socket operations, and database queries.

AdventNet, Inc.

15

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

API Overview High-Level API Architecture Low-Level API Architecture MIBs API Architecture SAS API Architecture RMI API Architecture CORBA API Architecture EJB API Architecture

This section explains the architecture of the different modules available as part of the AdventNet SNMP API distribution and the functions and features available with them.

AdventNet, Inc.

16

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

High-Level API ArchitectureThe high level API is a set of UI and non-UI Java components, which act as a standard reference base for both application developer and tool vendors. This allows building more flexible applications, applets, and components. A number of enhancements have been added as well, making the use of the high-level APIs much more productive in building applications. The components can be used in any Java Bean Builder or directly in the Java code. The purpose of the high-level APIs is to make it easier to develop management applications using the SNMP libraries. The benefits of using the high-level APIs include: Increased functionality using library methods, which includes the performance of GET, GETNEXT, GETBULK, and SET operations on multiple variables, sending traps, getting all instances of variables under an object identifier, etc. Usage of AdventNet SNMP Java components in Bean Builder. Increased support for SNMP tables. The high-level beans are lightweight sharing the underlying resources, such as SnmpSession, SnmpAPI, and MibOperations. The bean components hide the complexities of using the lowlevel APIs. While instantiating these beans in applets, you have to pass the applet instance so that it can internally use the SAS for performing SNMP operations. Therefore, all the complexities of using low-level APIs and SAS are hidden from the user and taken care by the high-level API. Sometimes, it may become necessary for a bean to use a separate session instead of sharing the same session with other beans. In such cases, the beans have to be instantiated with the port and session name as arguments. To use the transport provider, where you can plug-in your own transport protocol, the constructor that takes ProtocolOptions as the argument can be used. The API implements the UDP/IP as the default protocol implementation and provides TCP/IP as the reference implementation. For synchronous operations, the SnmpTarget bean can be used and for asynchronous operations, the SnmpRequestServer bean can be used. The MibBrowser bean which is a full fledged UI component for management operations, makes use of the SnmpRequestServer bean.

The following are the points to be noted while using the high-level APIs.

The non-UI beans, which uses the low-level API and MIBs, form the backbone of the high-level API and the UI beans are built on top of the non-UI beans.

AdventNet, Inc.

17

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

The following are the components available in the beans package that can be used in developing management applications or applets. SnmpTarget - for synchronous SNMP operations. SnmpRequestServer - for asynchronous SNMP operations. SnmpPoller - for polling SNMP data with specified polling intervals. SnmpTrapReceiver - for receiving traps. NotificationAdaptor - for using with TrapReceiver.

SnmpTable - for working with tabular SNMP data.

The above components are not user interface components. The following UI beans are provided in the ui package. SnmpTableModel is an extension of the SnmpTable component in the beans package and is designed for working with JFC-swing components. TableBean is an implementation of the combination of the JTable and the SnmpTableModel components, where JTable provides the view/controller and the SnmpTableModel is the model. SnmpTablePanel is a component for working with large tables. TrapParserBean is used for parsing the trap events. TrapBrowser is used to display the traps received by the TrapReceiver. TrapViewer is used to receive the traps and display the trap information. LineGraphBean is for plotting the polled data from SNMP data sources. MibTree is for viewing the SNMP MIBs in applets and applications. MibBrowser is an SNMP MIB browser that can be embedded in any management application or applet. PropertySettings is used for setting properties of other bean components. PropertyCombiner component is for passing one object from one bean to group of other beans. This is mainly used for setting properties of SNMP beans.

AdventNet, Inc.

18

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Low-Level API ArchitectureThe low-level API is the collection of basic classes that implement SNMP according to v1, v2c, and v3 standards. The low-level API consists of the snmp2 Java package, which enables you to work directly with the details of SNMP and helps reduce the size of your management applet or application. The following figure illustrates the organization of the low-level SNMP API packages.

The low-level API consists of the following functional modules. The SNMP transport provider framework provides a transparent layer for the communication classes to transport SNMP packets to devices over any protocol. API users can achieve this by plugging in their own protocol implementation or protocol provider into the framework. For example, transport providers for UDP, IPX, TCP, and Serial Port can be easily plugged into the framework. The API uses UDP/IP as the default underlying protocol for SNMP communication. A reference protocol provider implementation for TCP/IP has also been provided. The SNMP transport provider framework uses the configured protocol and is responsible for all communications between the manager and the agent. The Communication classes can be used to establish SNMP sessions with peer SNMP entities. The classes also provide APIs to set session parameters, such as the SNMP version, authentication parameters, and so on. These classes are the foundation on which the Java Beans components support and RMI/CORBA API support are built.

AdventNet, Inc.

19

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

The Variable classes correspond to the various SNMP data types, such as INTEGER, OBJECT IDENTIFIER, COUNTER, etc. Each of these classes has a one-to-one relationship with the SNMP data types. For example, the SnmpInt class corresponds to the INTEGER data type. You are required to work with these classes while sending requests and receiving responses. It is important that you are familiar with them, even if you are developing applications using the Java Beans components or RMI/CORBA components. Security API implements the procedures for providing the SNMP message level security and for controlling access to management information, in addition to defining the mechanism for remote configuration and administration of SNMPv3 entities. The AdventNet SNMPv3 security classes implement the two models USM and VACM based on the new security framework. Security and Access Frameworks API enables you to define and implement your own messagelevel security and access control.

AdventNet, Inc.

20

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

MIBs API ArchitectureApplications or applets can access MIB information through the MIBs API. The MIB information can be present in a text file, database, or a serialized file. The MIBs API provides methods to access MIB node information, such as syntax (the data type of the node), access type (read, write, etc.), status (obsolete, current, etc.) and others. Based on these information, the application or applet can perform the various SNMP operations.

The MIB files may import some node information from other MIB modules. In such cases, the Parser automatically loads the imported module to get the information of objects imported from that particular module. For faster loading, the MIBs can be parsed and saved as .cmi files. The parsed MIB information can also be stored in the database or stored as serialized objects by using the API. The subsequent loading of the MIB file can be from the .cmi, database, or from serialized objects thus avoiding the parsing of the MIB file again. In the MIBParser, standard nodes and TCs defined in RFC1902 and SNMPv2-TC are predefined. Therefore, the MIBs that import these standard nodes or TCs can be loaded without loading the imported module.

AdventNet, Inc.

21

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

SAS API ArchitectureManagement clients that run as applets can be developed using the AdventNet SNMP API. Due to the Java security restrictions, applets cannot directly communicate with SNMP agents. To overcome this, the SAS server can be used as a gateway between the applet (SAS client) and the agent. It should be noted that the SAS server has to run on the same machine from which the applet is downloaded. The applet can connect with the SAS server and send the SNMP requests to SAS, which in turn forwards it to the corresponding SNMP agent. When SAS receives the response, it sends it back to the applet or the SAS client.

Applets can communicate with the SAS server through any protocol (TCP and HTTP implementations are provided). TCP is the default protocol used. HTTP can be used in case of communication across a firewall. The SAS API is built on top of a protocol-independent transport provider framework so that users can plug-in their own transport protocol implementations between the SAS client and the server. This would be required only if the protocol is other than TCP or HTTP (for example, SSL).

AdventNet, Inc.

22

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

The transport provider interfaces with the SNMP API to communicate between the client and the server. It essentially acts as a bridge between the SNMP API and the actual transport protocol. The advantage of using this approach is that the SNMP API need not be aware of the underlying protocol used. For using a particular protocol as the transport, the user has to implement that protocol and plug-in (or register) it with the transport provider. Only one transport protocol can register with the provider at a time.

AdventNet, Inc.

23

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

RMI API ArchitectureThe RMI APIs support using RMI from remote clients to perform SNMP operations. The advantage of using the RMI APIs is to allow a server to perform the SNMP functions, while the clients only make the RMI calls to the server. In other words, the server can run on the web server, while applets make RMI calls to the server to perform SNMP functions. For example, the server can load MIB's and a client can avail the information in the MIBs without loading them each time it is started.

The RMI server can be started as a standalone server, or as part of another Java application, say a web server. The main interface or origin for all RMI operations is the com.adventnet.snmp.rmi.SnmpFactory interface. This interface is implemented by the com.adventnet.snmp.rmi.SnmpFactorImpl class, which can be started from the command line or from another Java application. When started from the command line, this class is published as AdventnetSnmpFactory and registered with the RMI registry. When started from another Java application, the user has to publish the factory interface to allow remote access. The SnmpFactory interface has methods for creating instances of classes for SNMP services on the server. These methods return RMI interfaces for getting access to the services provided by the SNMP service classes. These service interfaces very closely follow the SNMP beans classes in the com.adventnet.snmp.beans package. For example, this following code shows how the com.adventnet.snmp.rmi.SnmpTarget interface is obtained on a remote RMI client. String hostname = "myserver"; SnmpFactory factory = (com.adventnet.snmp.rmi.SnmpFactory) Naming.lookup( "rmi://" + hostname + "/AdventnetSnmpFactory" ); // Get an SnmpTarget object SnmpTarget target = factory.createTarget(); Once the com.adventnet.snmp.rmi.SnmpTarget interface is obtained, the RMI client can use its methods similar to a local instance of SnmpTarget. The method signatures between the corresponding beans and RMI interfaces are mostly identical.

AdventNet, Inc.

24

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

The following SNMP service interfaces are provided in the com.adventnet.snmp.rmi package. SnmpTarget SnmpRequestServer SnmpTrapReceiver SnmpPoller SnmpTable MibOperations

Examples of using these services are provided in the rmiclient directory.

AdventNet, Inc.

25

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

CORBA API ArchitectureAdventNet SNMP API supports CORBA access to the SNMP API. For a typical non-CORBA or nonRMI client, you need the com.adventnet.snmp package classes in order to perform any SNMP operations, such as GET or SET. With CORBA and RMI packages, it is possible for a client to ask a server to perform these operations and obtain the result. A CORBA client needs the classes in com.adventnet.snmp.corba package to access these services. The CORBA IDL for the SNMP (corba.idl) is published as part of the AdventNet SNMP API package. One reason for providing the IDL file is that you can convert it into any other language mapping API and use it in the client application programs.

There are sample client-side Java applications in the corbaclient directory that provide many of the SNMP operations with all direct SNMP API calls in snmpget are replaced with CORBA invocations.

AdventNet, Inc.

26

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

EJB API ArchitectureAdventNet SNMP for EJB has been designed to support EJB applications, and conform to the EJB standards. The EJB standard restricts the Enterprise Java Bean from performing certain functions, such as socket access. In order to perform protocol operations, such as receiving traps while conforming to the EJB standard, an architecture suitable for SNMP operations for EJB is required. AdventNet SNMP API provides a solution to this. The protocol-specific functions needed by EJB components are provided by the SnmpEJBServer factory that runs outside the EJB container. This operates in a similar fashion to the SNMP RMI factory. This provides the SNMP protocol operations, such as accessing sockets, receiving traps, polling, and so on, which are not permitted in Enterprise Java Beans. These server functions are implemented using AdventNet's SNMP support for RMI. The Enterprise Java Beans use the SnmpEJBServer to create SNMP bean instances for protocol operations as required. These bean instances are used by the EJBs and garbage collected when the EJB instance is deleted, or when specifically de-referenced by the EJB. EJBs need to take of passivation, i.e. where the EJB is temporarily removed from memory and serialized to disk, because RMI references are not restored when the EJB instance is restored to memory. The EJB needs to use the JNDI to cache the RMI reference when it is being passivated. Future releases of AdventNet SNMP EJB will simplify this process and offer pooling of the SNMP bean instances. AdventNet provides the SNMP EJBs that can be used with this architecture. This release includes Session EJBs for synchronous SNMP operations and SNMP table support. More EJBs will be provided shortly. Application developers will build their own EJBs for specific SNMP-enabled applications, which can use the provided SNMP EJBs or directly use the SnmpEJBServer. The web container with JSP and Servlet pages connects to the EJBs to serve clients, as per the typical EJB Application Architecture. The HTML clients connect to the web container, which serves the HTML pages over HTTP. The Java clients may use the web container, but more often directly connect to the Session EJBs within the EJB container, using JNDI look-up and the home interfaces to get access to the EJB instances.

AdventNet, Inc.

27

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

The architecture for SNMP for EJB is illustrated below.

The EJB does a JNDI look-up for the SnmpEJBServer, which permits clustering and load balancing of multiple SnmpEJBServer factories, when using clustering with the application server. Support for these capabilities vary with the particular application server being used. Typically, multiple SnmpEJBServer instances would be deployed on different servers, and using JNDI naming, the deployed EJBs will be load balanced over these SnmpEJBServer instances.

AdventNet, Inc.

28

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Development Environment for API Setting Up for High-Level API Setting Up for Low-Level API Setting Up for RMI API Setting Up for CORBA API Setting Up for EJB API

This section explains the development environment needed for developing applications and applets using various APIs.

AdventNet, Inc.

29

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Setting Up for High-Level APIThe high-level API allows building more flexible applications, applets, and components that incorporate SNMP functions provided by the low-level API. The high-level API hides most of the SNMP and MIB details and is much more productive in building applications. The classes needed for developing applications and applets using the high-level API are provided by the com.adventnet.snmp.beans and com.adventnet.snmp.ui packages. The CLASSPATH should be set to AdventNetSnmp.jar and AdventNetLogging.jar in the directory. Applications developed using the high-level API should import the beans and the ui packages. If additional MIB support is required, the com.adventnet.snmp.mibs package should also be imported.

AdventNet, Inc.

30

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Setting Up for Low-Level APIThe low-level API allows the developer to work with all the details of SNMP and MIB. If developers are particular about reducing the size of the application or applet, the low-level API can be used. The classes needed for developing applications and applets using the low-level API are provided by com.adventnet.snmp.snmp2.usm and com.adventnet.snmp.snmp2.vacm packages that support SNMPv3. The CLASSPATH should be set to AdventNetSnmp.jar and AdventNetLogging.jar in the directory.

AdventNet, Inc.

31

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Setting Up for RMI APIThe classes needed for RMI client to access AdventNet SNMP API are provided by the com.adventnet.snmp.rmi package. The CLASSPATH should be set to AdventNetSnmp.jar, AdventNetLogging.jar, and AdventNetRMI.jar. The RMI interface and the implementation classes internally uses the high-level API. The RMI service interfaces very closely follow the SNMP beans classes in the com.adventnet.snmp.beans package. Therefore, the users do not have to bother about the underlying SNMP communication that is wrapped in the RMI classes. The steps involved in providing RMI access to SNMP services are: 1. Run the RMI registry. To start the RMI registry server, type the following command from the DOS prompt or UNIX shell. rmiregistry The above command starts the RMI registry listening at the default port 1099. 2. Type the following command to start the AdventNet RMI Server. java com.adventnet.snmp.rmi.SnmpFactoryImpl The above command binds the AdventNet RMI server with the RMI registry at the default port 1099. If the AdventNet RMI server starts successfully, a message 'Factory is ready' is displayed. Now, the AdventNet RMI server is ready to process the client requests. The SnmpFactoryImpl class has methods, such as createRequestServer, createTable, and createTarget that are used by the client applications to create the instances after getting the remote object handle. The client applications need to do the following. 1. Get the remote objects handle. com.adventnet.snmp.rmi.SnmpFactory factory = (com.adventnet.snmp.rmi.SnmpFactory) Naming.lookup("rmi:///AdventnetSnmpFactory"); The above code returns a remote interface object of type SnmpFactoryImpl class. 2. Invoke methods of the SnmpFactoryImpl class. com.adventnet.snmp.rmi.SnmpTarget target = factory.createTarget(); The above code creates a SnmpTargetImpl instance, which internally calls the SnmpTarget bean. After this, the target instance can be used in the same way as in the high-level API. Note: Certain operations, such as target.loadMibs("../RFC1213-MIB") are relative to the server path because the objects are remotely executed. A number of client examples are provided in the rmiclient directory, including an applet example. Start the rmiget client application example from the same host as follows. java rmiget localhost .1.3.6.1.2.1.1.1.0 The above command results in a GET operation to the localhost on the OID. If the localhost has a SNMP agent installed, you get the sysDescr message. Otherwise, a time out message is displayed.

AdventNet, Inc.

32

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

To run the rmiget client application example from a remote host, type the following command. java rmiget -SnmpServer SERVER:8001 localhost .1.3.6.1.2.1.1.1.0 It is assumed that the RMI SNMP server is running on a machine named "SERVER" on the port 8001 and you want the GET operation performed on SERVER itself. The argument "localhost" below specifies that GET operation is performed on the "localhost" as seen from the RMI SNMP server. To start the RMI applet example, type the following. appletviewer rmiAppletDemo.html You may need to edit the HTML file to point at the agent of your choice.

AdventNet, Inc.

33

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Setting Up for CORBA APIThe classes needed for CORBA client to access the AdventNet SNMP API are provided in the com.adventnet.snmp.corba package. The CLASSPATH should be set to AdventNetSnmp.jar, AdventNetLogging.jar, and AdventNetCorba.jar. The CORBA interfaces and the implementation classes internally use the high-level API. Therefore, the users need not bother about the underlying SNMP communication that is wrapped in the CORBA classes. The Java files of the CORBA package are generated from corba.idl, available with the AdventNet SNMP package, using Sun's idltojava compiler. The idltojava compiler generates the respective stubs and skeletons for each interface declared in the corba.idl file. These stubs and skeletons are used by the server as well as the client-side code. For example, for the SnmpTarget interface in the corba.idl file, the following Java files are generated. _SnmpTargetImplBase.java _SnmpTargetStub.java SnmpTarget.java SnmpTargetHolder.java SnmpTargetHelper.java

The steps involved in developing management applications using CORBA interfaces and implementation classes are: 1. Run the Java IDL name server. tnameserv -ORBInitialPort serverport The above command starts the name server listening at the specified port. If the server port is not specified, the name server starts at the default port 900. tnameserv -ORBInitialPort 8000 The above command starts the name server listening at port 8000. 2. Start the AdventNet CORBA server. java com.adventnet.snmp.corba.server The above command binds the AdventNet CORBA server with the name server at the default port 900. If the AdventNet CORBA server starts successfully then the following message is displayed. "Factory is ready Server is ready Ready to receive client requests ... " 3. To start the CORBA server at different port, type the following command. java com.adventnet.snmp.corba.server -ORBInitialPort nameserverport e.g java com.adventnet.snmp.corba.server -ORBInitialPort 8000 The server class does the following on startup. //initialize the ORB org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null); //Create the "Factory" com.adventnet.snmp.corba.SnmpFactory factory = new com.adventnet.snmp.corba.SnmpFactoryImpl ("AdventnetSnmpFactory"); //Export to the ORB the newly created object orb.connect(factory); //Use Naming Service and bind the Object Reference in Naming

AdventNet, Inc.

34

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

The SnmpFactory interface has several methods, such as createRequestServer, createTable, createTarget, etc., and the corresponding destroy methods that are used by the client applications to create and destroy the respective instances after getting the remote object handle. The client applications need to do the following. 1. Initialize the ORB. org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null); 2. Use naming service. org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); 3. Narrow the object reference. NamingContext ncRef = NamingContextHelper.narrow(objRef); 4. Bind the object reference in naming. NameComponent nc = new NameComponent("AdventnetSnmpFactory", ""); NameComponent[] path = {nc}; 5. Bind to the factory object. com.adventnet.snmp.corba.SnmpFactory factory = com.adventnet.snmp.corba.SnmpFactoryHelper.narrow(ncRef.resolve(path)); 6. Get a target object. com.adventnet.snmp.corba.SnmpTarget target = factory.createTarget(); The above code creates an SnmpTargetImpl instance that internally calls the SnmpTarget bean. After this, the target instance can be used in the same way as in the high-level API. Note: Certain operations, such as target.loadMibs("../RFC1213-MIB"), are relative to the server path because the objects are remotely executed.

AdventNet, Inc.

35

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Setting Up for EJB APIThe SnmpTarget interface of the EJB API is used in the client application for performing many of the common operations, such as GET, GETNEXT, and SET operations. The EJB standard restricts users from performing certain protocol functions, such as socket access. The protocol-specific functions required by the EJB components are provided by an SnmpEJBServer factory that runs outside the EJB container. This operates in a similar fashion to the SNMP RMI factory. The SnmpEJBServer factory should be started within the EJB application server. Following are the jar files available in the \SNMPAPI\reference\ejb directory. std_MibOperationsEJB.jar std_SnmpTableEJB.jar std_SnmpTargetEJB.jar

These jar files conform to the EJB standards. The deployment procedure would be different for each EJB application server as there are wide range of EJB servers available in the market. The classes needed for EJB client to access the AdventNet SNMP API are provided in the com.adventnet.snmp.ejb package. The CLASSPATH should be set to AdventNet SNMP directory or the AdventNetEJB.jar Requirements The standard jar file available with AdventNet EJB API should also contain the weblogic-ejb-jar.xml file with the ejb-jar.xml file. For example, if the std_SnmpTargetEJB.jar is to be added to the WebLogic server, the jar file should contain the following in the package structure according to the EJB standards. SnmpTarget.class SnmpTargetEJB.class SnmpTargetHome.class ejb-jar.xml weblogic-ejb-jar.xml Note: The above example assumes that the EJB application server is BEA Weblogic Server 5.1. Go through the deployment procedure provided in the WebLogic documentation for more details.

AdventNet, Inc.

36

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Using MIBs in Applications Loading MIBs Unloading MIBs Parsing MIBs Accessing Node Information Retrieving MIB Information Exceptions and Error Messages Database Schema Macro Type Constructs

Management applications and applets need to perform MIB-related operations, such as loading and parsing of MIBs, accessing the nodes in a MIB tree, getting information from leaf nodes, and so on. The MIB support API (mibs package) in AdventNet SNMP API provides the necessary support to perform these kinds of MIB-related operations.

AdventNet, Inc.

37

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Loading MIBs Loading MIBs Directly Loading from Serialized Files Loading Compiled MIBs Loading from Database

AdventNet SNMP API provides flexible ways of loading MIBs in the applications. Management applications and applets can use any of the above options for loading the MIB modules. The MIB file can contain one or more MIB modules. The API loads all the dependency files to resolve the MIB module. The standard OIDs and TCs defined in RFC1155-SMI, RFC1212-SMI are already predefined in the API. If the MIB file imports any of the standard nodes defined in these two modules and the imported module is not present, the module is loaded. Therefore, it is optional to have a dependency file which has only the above-mentioned standard OID and TCs defined. In case of other nodes, when the imported file is not present or if the file does not contain the definition for that particular node, IMPORTS FAILED error is thrown.

AdventNet, Inc.

38

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Loading MIBs DirectlyApplications can load the MIB modules directly from a file, URL or a Jar file. The MibOperations class in the MIB support API provides the methods necessary to load and unload MIB modules in the management applications and applets. If the application is developed using the low-level API, the MibOperations class has to be explicitly instantiated. If the high-level API or distributed API is used for building applications, the MibOperations class need not be instantiated. The following piece of code illustrates how applications use MibOperations to load MIB files. MibOperations mibops = new MibOperations(); try { mibops.loadMibModule("RFC1213-MIB"); } catch (Exception ex){ System.err.println("Error loading MIBs: " +ex); } The high-level and distributed APIs include built-in support for commonly used MIB operations and therefore the MibOperations class need not be explicitly called. However for advanced MIB support, the high-level APIs can get the handle of MibOperations using the getMibOperations() method. The following table lists the methods to be used for loading MIB files in the management applications and applets. API Name Class/Component Name API Method Remarks The loadMibModule method loads a MIB module from a file .or using the URL that specifies the location of the MIB module. The loadMibModules method loads a set of MIB modules specified by file names separated by space. This method loads the MIB modules specified by file names separated by space. A MIB file is loaded in a common place and is used by all the other Beans in that application or applet. - same as above - same as above - same as above -

MIB

MibOperations

loadMibModule(Applet, URL) loadMibModules(String) loadMibModules(Applet, String)

High Level

SnmpTarget SnmpRequestServer SnmpPoller SnmpTable

loadMibs(String)

SnmpTarget SnmpRequestServer SnmpTarget CORBA SnmpRequestServer 1. MibOperationsEJB EJB 2. SnmpTargetEJB RMI

loadMibs(String) loadMibs(String) 1. loadMibModule(String) 2. loadMibs(String)

AdventNet, Inc.

39

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Factors to Consider While Loading MIB Files1. The imported modules should be present in the current directory or the directory in which the MIB file is present. For example, the dependency file for the IF-MIB should be present in the same directory or in the current directory. 2. If the imported module is in a different directory, we can set the search path before loading the MIB. The search path can be set by using the method setMibPath(String). The API searches for the module in the path specified. Multiple paths can be given separated by a pipe(|) symbol. The following code snippet shows how to load a MIB file which has its dependency file in another directory. For example, if the IF-MIB is in mibs directory and if SNMPv2-MIB (dependency file for IFMIB) is in the patchmibs directory, the following code shows how to load IF-MIB. MibOperations mibops = new MibOperations(); try { mibops.setMibPath(" /home/mibs/ | /home/patchmibs/ "); mibops.loadMibModule("IF-MIB"); } catch (Exception ex) { System.err.println("Error loading MIBs: " +ex); } 3. The API can load MIB files with the extensions mib, txt,and my. The method setMibFileExtension(String) can be used to set the MIB file extension for the file to be loaded. Multiple extensions can be given separated by a space or a comma. Note that the extension names should not be cmi or cds because these extensions are reserved for loading compiled MIBs. Note: In 2.x releases, if the imported module is not found while parsing, the setThrowFileNotFound(boolean) method (now deprecated) controls whether a FileNotFound exception should be thrown by loadMibModule(). This should be not be used anymore because now it is mandatory that the imported modules should be present in the directory in which the MIB files are loaded.

Loading Multiple Revisions of MibModulesAdventNet SNMP API supports loading multiple revisions of MibModules. The setMultipleRevision(String revisionFileNames) method, is used for loading multiple revisions of MibModules, where the revision file names are given separated by a space or a pipe (|) symbol. If we want to load multiple revisions of RFC1213-MIB, file names of this revision modules have to be set. For example, if the multiple revisions of RFC1213-MIB are in the files RFC1213-MIB.txt, RFC1213-MIB.mib, etc. we have to set these file names using the following method. mibops.setMultipleRevision("../mibs/RFC1213MIB.txt|../mibs/RFC1213-MIB.mib"); After setting the multiple revisions, we should load these files explicitly. While loading, the file name is checked with the revisionFileNames we have set. If the file name matches, the modules are loaded with the names ModuleName+REVISION1, ModuleName+REVISION2, and so on. mibops.loadMibModules("../mibs/RFC1213-MIB.txt | .../mibs/RFC1213MIB.mib | ../mibs/RFC1213-MIB.my"); In this case, the modules will be loaded with the name of RFC1213-MIBREVISION1, RFC1213MIBREVISION2, RFC1213-MIB. We have not set the file RFC1213-MIB.my in the setMultipleRevision() method and therefore it is loaded with the name of RFC1213-MIB.

AdventNet, Inc.

40

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

The files set in the setMultipleRevision() method and the files that are loaded should be exactly the same. If the file set in the setMultipleRevison() method is with respect to the relative path and the file loaded is with respect to the absolute path, both the files are considered as different although the path of the files is the same. For example, if the file set is ../mibs/RFC1213-MIB.txt, and the file loaded is /home/mibs/RFC1213-MIB.txt, both these file names are considered as different and the module is loaded as RFC1213-MIB. The method getMultipleRevision() returns the multiple revision, if set. Otherwise it returns an empty string. The method isMultipleRevision() is used to know whether the multiple revision is set or not. Applications can use addLabel(String addLabel) to add a label that is not treated as a reserved word by the parser. For example, "DisplayString", "PhysAddress", "TestAndIncr", "TimeStamp", "MacAddress", "RowStatus", "TimeInterval" and "DateAndTime" are not treated as reserved words. If your MIB uses some of the standard textual conventions or reserved words as a label for the MIB node, you can use the addLabel() method to tell the parser not to treat it as a reserved word. For example, if you do not wish to treat UInteger32 as a reserved word while parsing your MIB, use the following code. MibOperations mibops = new MibOperations(); mibOps.addLabel("UInteger32"); try { mibops.loadMibModule("your-MIB"); } catch (Exception ex) { System.err.println("Error loading MIBs: " +ex); }

AdventNet, Inc.

41

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Loading from Serialized FilesApplications can also save the MIB file as serialized Java objects and load from them. This reduces the loading time and enables distribution of serialized Java objects without distributing the MIB files. Serialization is not supported in applets.

The setSerializeMibs(boolean) method lets applications serialize the loaded MIBs. The following code shows how applications serialize a MIB module. MibOperations mibops = new MibOperations(); mibops.setSerializeMibs(true); try { mibops.loadMibModule("RFC1213-MIB"); } catch (Exception ex) { System.err.println("Error loading MIBs: "+ex); } The MIB modules are serialized in a file with the same name with an extension ser. For example, if the module name is RFC1213-MIB, the serialized file is created with the name RFC1213-MIB.ser. The setSerializedMibFileName(String) method can be used to specify the name of the serialized file. In the following code snippet, the loaded "RFC1213-MIB" module is serialized in the name of "myfilename". MibOperations mibops = new MibOperations(); mibops.setSerializedMibFileName("myfilename"); mibops.setSerializeMibs(true); try { mibops.loadMibModule("RFC 1213-MIB"); } catch (Exception ex) { System.err.println("Error loading MIBs: "+ex); }

AdventNet, Inc.

42

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

The method getSerializedMibFileName()

can be used to get the serialized MIB file name.

The setLoadFromSerializedMibs(boolean) method is used to specify that the MIB module should be loaded from the serialized file. If the serialized file is not present, the MIB file is parsed and the serialized file is created. Next time, the MIB file is loaded from the .ser file. MibOperations mibops = new MibOperations(); mibops.setLoadFromSerializedMibs(true); try { mibops.loadMibModule("RFC1213-MIB"); } catch (Exception ex) { System.err.println("Error loading MIBs: "+ex); } The serialization of the MIB module can be done even after the MIB file is loaded (except when it is loaded from a database). The option of loading MIB files as serialized files cannot be used with applets because of restrictions in file creation. However, we can load the already created serialized files in the applets. In that case the setLoadFromSerializedMibs(boolean) is set to true. By default, this method is set to false. If we have only the cmi file, we cannot use the serialized MIBs option. This is because we have no ser file or the original MIB file. In such cases, we can use the method, setSerializeMibs(true). This loads the MIB module from the cmi file and serializes it. After serializing, we can load this serialized file by setting setLoadFromSerializedMibs() to true. This method cannot be used if the MIB file is loaded from a database because the data is stored in the database and therefore the serialization is not possible. Note: If the MIB is loaded with the Serialized MIBs option with parsing level equal to or above NORMAL and if the MIB has errors, the serialized files will not be created.

AdventNet, Inc.

43

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Loading Compiled MIBsAdventNet SNMP API allows loading of compiled MIB files. The compiled MIB files reduce the loading time considerably when compared to direct loading. This is because, the parsing and syntax validation is done only once and not every time the MIB file is loaded. Once the validation is done, the compiled file information is stored in a proprietary format. Next time when the MIB file is loaded, the syntax validation is avoided and the tree is constructed directly. This leads to performance improvement and more compact applications can be developed.

To store the compiled file information, the following file types are used. cmi - contains MIB information, such as name of a node, syntax, parent, sub-id, trap details, and textual conventions. cds - contains the description and reference of the nodes in the MIB.

For example for RFC1213-MIB, the compiled MIB files are RFC1213-MIB.cmi, and RFC1213MIB.cds. The setLoadFromCompiledMibs(boolean) method defines whether the MIB files can be loaded as compiled MIBs. By default, this value is set to false so that the user can directly load the MIB file as provided. When setLoadFromCompiledMibs() is set to true and the MIB file is loaded, the API loads the cmi and cds files. If these files are not present, the API parses the MIB file, writes the output to the cmi and cds files, and loads the MIB file as the compiled MIB file. Subsequent loading can be done by giving only the module name or .cmi. In both cases, the API loads the compiled MIB file. The advantage of using this option is that the MIB file need not be parsed each time it is loaded and the loading is thread safe. While loading compiled MIBs, it is sufficient to load only the cmi file. The cmi file has a reference to the cds files. The cds file should not be loaded directly. If the information in the cds file, such as description and reference is not required, we can set setReadDesc() to false. In this case, the parser loads only the cmi file and the loading is much faster.

AdventNet, Inc.

44

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Note: After loading the MIB file as a compiled MIB file, if you modify the MIB file and load it again, the changes are not get reflected in the loaded MIB file. You have to remove the existing cmi and cds files and then load the MIB to get the changes reflected. The setOverwriteCMI(boolean) method in the MibOperations class can be used to overcome this restriction. By default, the value is set to false. If it is set to true, the cmi and cds files are created each time the MIB is loaded. Setting this boolean to true is recommended only if you have modified the MIB file. Otherwise, this will lead to unnecessary increase in the load time. The option of loading MIB files as compiled files cannot be used with applets because of restrictions in file creation. However, we can load the already created compiled files in the applets. In that case the setLoadFromCompiledMibs() is set to true. By default, this method is set to false. To convert the MIB files to the cmi and cds format, the MibToCMI utility can be used. This class is available in the AdventNetSnmp.jar. To use this utility, set the CLASSPATH to the classes directory and give the following command. java com.adventnet.snmp.utils.MibToCMI .. This conversion can be done for individual files or for entire directory. If the utility is used across directories, the existing cmi and cds files should first be deleted from the directory. We can also create compiled MIBs using the createCompiledMibs(String) MibOperations class. Note: The cmi file is dependent on the release version and the SNMP version. It is possible that a cmi file created in one version may not be loaded in another version and therefore the exception "Compiled Mib is corrupted" may be thrown. If the MIB is loaded with the compiled MIBs option with parsing level equal to or above NORMAL and if the MIB has errors, the cmi files will not be created. method in the

AdventNet, Inc.

45

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

Loading from DatabaseAdventNet SNMP API allows loading MIB modules from the database. The MIB files can be stored in any RDBMS, such as MySql or Oracle. Applications can load these MIB files directly from the database.

Loading MIB files from a database gives the following advantages to applications. Scalability - database feature is particularly useful when the number of MIB files to be loaded are high. Applications can load hundreds of MIB files at a time. Memory Usage - Information is stored in the database and we cache only the referred node objects.

The performance of getting the node information using the database option is less than the other loading options without considering the network traffic. The API uses Java Database Connectivity (JDBC) for the database support. Applications should use a valid JDBC driver of the respective databases to enable the database support. To add database support for loading MIBs, applications should first initialize the necessary database parameters. The initJdbcParams(driverName, URL, userName, passWord) method is used for initializing the database parameters. The following are the arguments of the method. driverName - Name of the database driver URL - URL pointing to the database userName - Name of the user passWord - Password for the user

After initializing the database parameters, the value of the setLoadFromDatabase(boolean flag) method is set to true to enable the database support. By default, the value is set to false.

AdventNet, Inc.

46

AdventNet SNMPAPI 4 SNMPv2c :: Help Documentation

When setLoadFromDatabase() is set to true and loadMibModules(String fileNames) is called, the application loads the MIB file from the database. If the MIB files are not present in the database, the MIB files are loaded in the database and then loaded in the application. After loading the MIB files from the database, if any changes are made to it a