Accessing Node Information

 

When a MIB file is loaded using the Miboperations class, a MibModulelink to javadocs instance is created to store the information about the module loaded from the MIB file. The MibModule class is used to restrict the MIB operations to a specific MIB module.

 

Some methods are present in both the MibModule class and the MibOperations class. If a method in MibOperations is used, it is applicable for the node in all the MIBs loaded in the application. If a method in the MibModule class is used, it is restricted to that particular module.

 

The MIB file is parsed and MibNodelink to javadocs objects are created to store information about each node. The MibNode class represents a MIB node in a MIB module tree. It contains references to its parents and children and also to its dependents.

 

The LeafSyntax class represents the syntax of a leaf node in a MIB module.

 

The MibNode and the LeafSyntax classes provide the methods necessary to access the information on the nodes in the MIB file. Apart from this, the classes also provide the following functions to the management applets and applications.

The MIB file has to be loaded first using the loadMibModule() of the MibOperations class. Then the getMibNode() is called to get the node associated with the MIB variable's object ID. This method can be called only when the name of the MIB module is not known.

 

MibOperations mibops = new MibOperations();

try {

mibops.loadMibModule("RFC1213-MIB");

}

catch (Exception e)

{

System.out.println("Exception : "+e);

System.exit(1);

}

MibNode node = mibops.getMibNode("sysDescr");

 

If the module name is known, the getMibNode() method of the MibModule class can be used to get the MIB node. When the getMibNode() method of the MibOperations class is called, the MIB node is searched in all the loaded MIB modules. Moreover, when a node occurs in more than one module, this method always returns the first occurrence of the node. For example, when getMibNode() method of MibOperations is called for the "rmon" node present in both RFC1271-MIB and RMON2-MIB, the MIB information corresponding to the first loaded module is returned. Therefore, to get a specific MIB node, it is advisable to use the getMibNode() method of the MibModule class.

 

The MibNode class has methods to get all the details about a MIB variable. For example, the following code snippet gives some information about the selected MibNode.

 

System.out.println("Syntax:"+node.getSyntax());

System.out.println("Access:"+node.printAccess());

System.out.println("Status:"+node.getStatus());

System.out.println("Reference:"+node.getReference());

System.out.println("OID:"+node.getNumberedOIDString());

System.out.println("Node:"+node.getOIDString());

System.out.println("Description:"+node.getDescription());

 

The LeafSyntax class can be used to get the data type and value of the MibNode as shown below.

 

LeafSyntax leafnode = node.getSyntax();

System.out.println("Value : "+leafnode.getType());

System.out.println("Data-type : "+leafnode.getEquivname());

 

Ability to walk the loaded MIB modules as an ordered list of objects

 

The getNextLeafNode() in the MibNode class returns the next leaf node by searching through the current module. This is useful for agents or manager applications looking for the OID or label for the next MIB node for GETNEXT requests. This method spans multiple modules.

 

The getIndexes(MibOperations) and getIndexNames() in MibNode class is used for getting the index name/node of the table. The getIndexNames() returns vector of indexes (as String) for the table when invoked on the entry node of the table. On the other hand, getIndexes() returns vector of indexes (as MibNode) when invoked on any of the column nodes except the entry node of the table.

 

Ability to access nodes with specific relationships to other nodes

 

Typically the relationship among the nodes are represented as parent-child or root-node because the MIBs are organized in an hierarchical format. The mibs package provides several methods that can be used to access the nodes with specific relationships.

 

The method getParent() in the MibNode class gets the parent node of the current node and the method getChild(int subId) returns the child node corresponding to the particular subId. The getChildList() returns the nodes children as a vector.

 

The methods getRootNode() and the getRootNodes() in the MibModule class is used to get a reference to the root node in the loaded MibModule. If a module contains a single root node, both the methods getRootNode() and getRootNodes() return the root node. If a module contains more than one root node, the getRootNode() method returns null and the getRootNodes() method returns a vector of root nodes.

 

MibOperations mibops = new MibOperations();

MibModule mibmodule;

MibNode node;

Vector childnodes;

mibmodule = mibops.getMibModule(your_mib_file_here);

node = mibmodule.getRootNode();

childnodes = node.getChildList();

..

..

 

The methods isAncestorOf() and isDescendantOf() is used to check whether the nodes is an ancestor or descendant of the specified node. The getCommonAncestorWith(MibNode) method returns the common parent node of the selected MIB node.



Copyright © 2012, ZOHO Corp. All Rights Reserved.