⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c-extend3.html

📁 vxworks相关论文
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title>    Extending the WindNet SNMPv1/v2c Agent   </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a></a><a href="c-extend.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-extend2.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-extend4.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="83539">6.3  &nbsp;&nbsp;Compile-time MIB Extensions</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83540"> </a>There are six steps involved in making MIB extensions to the SNMPv1 agent:</p></dl><dl class="margin"><p><ol class="List"><li value="1."><a name="83541"> </a>Define the information to be managed.</li></ol></p><p><ol class="List"><li value="2."><a name="83542"> </a>Express the information as a MIB definition.</li></ol></p><p><ol class="List"><li value="3."><a name="83543"> </a>Add the new variables to the system.</li></ol></p><p><ol class="List"><li value="4."><a name="83544"> </a>Write the method routines</li></ol></p><p><ol class="List"><li value="5."><a name="83545"> </a>Build the agent.</li></ol></p><p><ol class="List"><li value="6."><a name="83546"> </a>Integrate the agent into VxWorks.</li></ol></p></dl><dl class="margin"><dd><p class="Body"><a name="83547"> </a>Each of the above steps is explained in one of the following sections. We are providing an example MIB extension which continues throughout each of the examples in these sections. The extension adds support for the VxWorks system configuration group (sysconfig), which is used to get or set the target's user-name and password. These are objects can be used by VxWorks when accessing a host over a network. In addition, the system can be rebooted by changing the value of the <i class="textVariable">sysState</i> variable.</p></dl></dl><dl class="margin"><dd><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><a name="83556"><br></a><img border="0" alt="*" src="icons/note.gif">&nbsp;&nbsp;&nbsp;</td><td><div class="Note"><hr><b class="symbol_UC">NOTE: </b>The standard Management Information Base known as MIB-II is defined in the file <b class="file">$WIND_BASE/target/src/snmpv1/agent/snmpMib2.mib</b>. Additional Management Information Base information can be defined in any file, or as part of the MIB-II Management Information Base in <b class="file">snmpMib2.mib</b>. The running example in this section shows the newly-developed MIB in a separate file from the MIB-II standard MIB, <b class="file">snmpMib2.mib</b>. MIB information does not need to be in separate files; we show it that way here for purposes of clarity.<hr></div></td></tr></table></dl><dl class="margin"><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h4 class="HStep"><i><a name="83557">Step 1: &nbsp;&nbsp;Defining the Information to be Managed</a></i></h4></font><dl class="margin"><dd><p class="Body"><a name="83558"> </a>The first step in extending the VxWorks SNMP agent MIB involves defining what information is to be managed with SNMP.</p><dd><p class="Body"><a name="83559"> </a>There are many standard MIB definitions available for a wide array of applications. If possible, use a standard MIB module to convey the information. Some of the standard MIB modules are shown in <a href="x-snmpRefList.html#83419"><i class="title">E.&nbsp;SNMP Reference List</i></a>. In addition, for your convenience, there are MIB modules provided in the directory <b class="file">$WIND_BASE/target/src/snmpv1/mibs</b>.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h4 class="HStep"><i><a name="83564">Step 2: &nbsp;&nbsp;Creating a MIB Definition</a></i></h4></font><dl class="margin"><dd><p class="Body"><a name="83565"> </a>Once the information to be managed with SNMP has been defined, the next step is to have this information expressed in concise MIB format (using a stylized subset of the language Abstract Syntax Notation One, or ASN.1). If you are using a standard MIB module, then this step may already be completed. There is a selection of publicly-available standard MIB modules in the directory <b class="file">$WIND_BASE/target/src/snmpv1/mibs</b>. </p><dd><p class="Body"><a name="83566"> </a>The concise MIB format defined by RFC 1212 provides a straightforward method of describing MIB modules. This is the standard method by which SNMP MIB modules are described, and it is the input format expected by the MIB compiler.</p></dl></dl><h4 class="EntityTitle"><a name="83567"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 6-1:&nbsp;&nbsp;MIB Definition for the Systems Group</font></a></h4><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83568"> </a>This example illustrates a MIB definition for the systems group, which allows access to the username, password, etc. on a VxWorks system. This document is in ASN.1 format. Filename: <b class="file">demo.mib</b> (<i class="emphasis">Note:</i> this file is not included as part of this distribution.)</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="83569">        VXDEMO-MIB      --FORCE-INCLUDE &lt;mib.h&gt;     --FORCE-INCLUDE &lt;snmpdefs.h&gt;     --FORCE-INCLUDE "mibhand.h"          DEFINITIONS ::= BEGIN      -- Title:            VxWorks Demo MIB version 1.0      IMPORTS         MODULE-IDENTITY,          OBJECT-TYPE         FROM SNMPv2-SMI             enterprises                  FROM RFC1155-SMI             DisplayString                 FROM RFC1213-MIB                 ;      wrs        OBJECT IDENTIFIER ::=     { enterprises 731 }     demos        OBJECT IDENTIFIER ::=     { wrs 1 }      -- Module Identification Definition.      windDemo MODULE-IDENTITY         LAST-UPDATED "9312030000Z"         ORGANIZATION "Wind River Systems"         CONTACT-INFO             "        Technical Support                      Postal: Wind River Systems                     1010 Atlantic Avenue                     Alameda, CA  94501                     US                      Tel: +1 800 545 WIND                     Fax: +1 510 814 2104                      E-mail: support@wrs.com"         DESCRIPTION                 "This is the VxWorks demo MIB module.  It is provided as                  an example of how to make extensions to the VxWorks SNMPv1/v2c                 Agent MIB."      ::= { demos 1 }      windObjects OBJECT IDENTIFIER ::= { windDemo 1 }      -- Groups in the VxWorks Demo MIB      sysconfig OBJECT IDENTIFIER ::= { windObjects 1 }      -- System Configuration Group      -- This group provides VxWorks system configuration information.       -- It is used to get/set the target's user name, and     -- password.  These objects are used by VxWorks when accessing      -- a host over the network.  In addition, the system can be      -- rebooted by changing the value of the sysState variable.      sysState OBJECT-TYPE         SYNTAX  INTEGER {             system-running(1), -- System is up and running.             system-reboot(2) &nbsp; -- System is to be rebooted.                 }         MAX-ACCESS read-write         STATUS current         DESCRIPTION             "The VxWorks target status is reported through this             field.  The only valid state that this field can be             set to is system-reboot.  The system will be rebooted             five seconds after changing the state."          ::= { sysconfig 1 }      sysUserName OBJECT-TYPE         SYNTAX DisplayString (SIZE (0..255))         MAX-ACCESS read-write         STATUS current         DESCRIPTION             "The user name the VxWorks target uses for remote             machine access."          ::= { sysconfig 2 }      sysUserPassw OBJECT-TYPE         SYNTAX DisplayString (SIZE (0..255))         MAX-ACCESS read-write         STATUS current         DESCRIPTION             "The user password the VxWorks target uses for remote             machine access."          ::= { sysconfig 3 }  END </a></b></pre></dl></dl><dl class="margin"><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h4 class="HStep"><i><a name="83665">Step 3: &nbsp;&nbsp;Adding New Variables to the System</a></i></h4></font><dl class="margin"><dd><p class="Body"><a name="83666"> </a>Now that the MIB definition has been defined, the next step is to add any new MIB variables it requires to the system (and create the routines to access and manipulate them). For example, if the MIB module defined a MIB object representing the number of packets received by a network interface, then this step would involve adding the counter to the network interface code (and perhaps a function call to obtain this number). </p><dd><p class="Body"><a name="83667"> </a>VxWorks already contains the code to access the user name and password. With this example, we are adding the capability to get or change the system state, including the ability to reboot; this is the only functionality we are adding with this example.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h4 class="HStep"><i><a name="83668">Step 4: &nbsp;&nbsp;Creating the Method Routines</a></i></h4></font><dl class="margin"><dd><p class="Body"><a name="83669"> </a>Once the MIB definition has been written and compiled and the new variables added to the system, the next step is to write method routines to support the new MIB module. The method routines are called by the agent to manipulate the variables that were newly added to the MIB. </p><dd><p class="Body"><a name="83670"> </a>The method routines can be written entirely by hand. However, the <b class="command">mibcomp</b> command can be used to generate C stubs and source code for the method routines. See <a href="x-mibcomp.html#83422"><i class="title">A.&nbsp;The MIB Compiler User's Guide</i></a> for details.After the stubs have been generated and the method routines document has been reviewed, the next step is to augment the stubs with code specific to your application.</p></dl></dl><h4 class="EntityTitle"><a name="83674"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 6-2:&nbsp;&nbsp;Invocation of <b class="command">mibcomp</b> </font></a></h4><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83675"> </a>Compile the demo module <b class="file">demo.mib</b> using <b class="command">mibcomp</b>, making sure to include any standard modules which are referenced by the module (see the IMPORTS section). This example shows the use of the option <b class="command">-start</b> to place the new variables as a subtree under <b>iso.private.enterprises.wrs</b>. (This example is a single command line; the <b>\</b> character indicates continuation onto the next line.)</p><dl class="margin"><dd><pre class="Code2"><b><a name="83676"></b><tt class="output">% </tt><b>mibcomp -l $WIND_BASE/target/src/snmpv1/mibs -stub -start wrs \ -o demo.c rfc1155.smi rfc1213.mib demo.mib</a></b></pre></dl><dd><p class="Body"><a name="83677"> </a>After the stubs have been generated and the method routines document has been reviewed, the next step is to augment the stubs with code specific to your application. </p></dl></dl><h4 class="EntityTitle"><a name="83678"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 6-3:&nbsp;&nbsp;Default Output of <b class="command">mibcomp</b></font></a></h4><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83679"> </a>The following example shows <b class="command">mibcomp</b> default output before user augmentation. Filename: <b class="file">demo.c</b> (<i class="emphasis">Note:</i> this file is not included as part of this distribution.)</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="83680">#include &lt;asn1.h&gt; #include &lt;buffer.h&gt; #include &lt;mib.h&gt; #include &lt;localio.h&gt; #include &lt;snmpdefs.h&gt; #include &lt;snmp.h&gt; #include &lt;auxfuncs.h&gt; #include "mibleaf.h"  /*  * Method routines for the sysconfig variables:  *  *   sysState -- read-write  * The VxWorks target status is reported through this  * field.  The only valid state that this field can be  * set to is system-reboot.  The system will be rebooted  * five seconds after changing the state.  *  *   sysUserName -- read-write  * The user name the VxWorks target uses for remote  * machine access.  *  *   sysUserPassw -- read-write  * The user password the VxWorks target uses for remote  * machine access.  */  /* An internal routine to retrieve the values of the variables, used  * by the method routines sysconfig_get and sysconfig_next.  * You need to replace the type STRUCT_sysconfig with something  * appropriate to your system. */ static int   sysconfig_get_value(OIDC_T      lastmatch,                       SNMP_PKT_T *pktp,                       VB_T       *vbp,                       STRUCT_sysconfig *data)     /* !!! */ {   switch(lastmatch) {   case LEAF_sysState:     /* Values:      *  system-running(1) = VAL_sysState_system_running      *  system-reboot(2)  = VAL_sysState_system_reboot      */     getproc_got_int32(pktp, vbp, data-&gt;sysState);    /* !!! */     break;   case LEAF_sysUserName:     /* if the data being returned is in dynamic storage and needs      * to be free'd, change the 0 argument to a 1. */     getproc_got_string(pktp, vbp, string_length(data-&gt;sysUserName),          data-&gt;sysUserName, 0, VT_STRING);    /* !!! */     break;   case LEAF_sysUserPassw:     /* if the data being returned is in dynamic storage and needs      * to be free'd, change the 0 argument to a 1. */     getproc_got_string(pktp, vbp, string_length(data-&gt;sysUserPassw),          data-&gt;sysUserPassw, 0, VT_STRING);    /* !!! */     break;   default:     return GEN_ERR;   }   return NO_ERROR; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -