6.4   Dynamic MIB Additions

As an aid to developing an SNMP agent and its associated MIB, the MIB tree can be dynamically changed at run-time from alternate tasks in VxWorks. The functions snmpdTreeAdd( ) and snmpdTreeRemove( ) can be used to dynamically add and remove sections of a MIB tree, respectively. For more information, see the explanations of each function in F. SNMP Reference.


*   

WARNING: Sections of the MIB tree can only be removed dynamically if they are added dynamically.

A MIB addition which is to be added dynamically to the data tree is developed in a similar fashion to that developed at compile-time.

  1. Define the information to be managed.

  1. Express the information as a MIB definition.

  1. Add the new variables to the system.

  1. Write the method routines

  1. Build the new Management Information Base

  1. Load the new MIB into a running SNMP agent

Rather than walk through each step, please refer to the above examples in 6.3 Compile-time MIB Extensions for instructions on Steps 1 through 4.

Example 6-6:  Refer to the above examples for illustrations of Steps 1 through 4.


*   

NOTE: If you develop the new MIB extension in the same file as the standard MIB, you can easily extract the new information using the EXCLUDE directive (or the mibcomp option -exclude). For more information, see 5.1 Configuring VxWorks for Use with WindNet SNMP and The EXCLUDE Keyword.

Step 5:   (Dynamic) Build the New Management Information Base

Use mibcomp to compile the new MIB information into a C representation of the new data tree. Use the -leaf option to generate a C header file that defines constants specifying the last component of each object's identifier (OID) as well as any enumerated values associated with the object's SYNTAX and any known bounds on the object's value. (See A. The MIB Compiler User's Guide for more information on mibcomp and its options.)

Example 6-7:  Generating a C Representation of the MIB Data Structure

(The \ character in these command lines indicates continuation onto the next line.)

% mibcomp -l $WIND_BASE/target/src/snmpv1/mibs rfc1155.smi rfc1213.mib \ 
-start wrs -o mibhand.h -skel.h demo.mib
% mibcomp -l $WIND_BASE/target/src/snmpv1/mibs rfc1155.smi rfc1213.mib \ -start wrs -o demomib.c demo.mib
% mibcomp -l $WIND_BASE/target/src/snmpv1/mibs -leaf rfc1155.smi \ rfc1213.mib -start wrs -o mibleaf.h demo.mib

Now compile these C files as shown in the example below.

Example 6-8:  Compiling and Linking the Generated Files into a Single Module

This example shows commands for compiling for a 68020-based target. (The \ character indicates continuation onto the next line.)

% cc68k -m68020 -msoft-float -O -fvolatile -fno-builtin -Wall -ansi \ 
-nostdinc -DCPU=MC68020 -DVXWORKS -I$WIND_BASE/target/h \ 
-I$WIND_BASE/target/h/snmp/ -I. -c demo.c demomib.c
% ld68k -r -o demomodule.o demomib.o demo.o

Step 6:   (Dynamic) Load the New MIB Into a Running SNMP Agent

Use the ld( ) routine under VxWorks to load the newly-created module into VxWorks. Once the module is loaded, use snmpdTreeAdd( ) to add the module to the running MIB.

(For more information on ld( ), see the VxWorks Reference Manual. For more information on snmpdTreeAdd( ), see the appropriate manual page in F. SNMP Reference.)

Example 6-9:  Loading New MIB Information into a VxWorks Target

This example loads the new MIB information into a running VxWorks target and adds the information to the MIB tree on the running SNMP agent. NOTE: perform these operations on the VxWorks target, for example in a shell window.

ld < demomodule.o
snmpdTreeAdd ("1.3.6.1.4.1.731", & wrs_node);

*   

NOTE: Depending on how views were initialized in the agent, you may now need to update the view tables. See 4.9 View Tables.