📄 x-mibcomp4.html
字号:
</dl></dl><dd><div class="Item"><a name="83524"> </a><b class="symbol_UC">INDEX</b> </div><dl class="margin"><dl class="margin"><dl class="margin"><dd><div class="Indent3"><a name="84050"> </a>When you create a table in your MIB, you must declare how the table is indexed. You do this by including an <b class="symbol_UC">INDEX</b> clause in the definition of the "conceptual row" object.<sup><a href="#foot"><b class="FootnoteMarker">1</b></a></sup></><br><dd><div class="Indent3"><a name="83528"> </a>Following is an example of the use of <b class="symbol_UC">INDEX</b> from the RFC1213-MIB module (<b class="file">rfc1213.mib</b>):</><br></dl></dl><dl class="margin"><dd><pre class="Code3"><b><a name="83529"> ifEntry OBJECT-TYPE SYNTAX IfEntry ACCESS not-accessible STATUS mandatory DESCRIPTION "An interface entry containing objects at the subnetwork layer and below for a particular interface." INDEX { ifIndex } ::= { ifTable 1 }</a></b></pre></dl></dl></dl><dl class="margin"><dd><p class="Body"><a name="83530"> </a>An <b class="symbol_UC">OBJECT-TYPE</b> invocation ends with a line equating the object's name to an object identifier <b class="symbol_UC">OBJECT IDENTIFIER</b>. The object identifier comes after a "<b class="symbol_lc">::=</b>" and must be unique. Such object identifiers are constructed by combining the name of a group this object is under with this object's number within that group.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="83531">Traps</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="83532"> </a>You can also specify traps in your MIB. In SNMPv1, traps are defined using the <b class="symbol_UC">TRAP-TYPE</b> macro. SNMPv1 traps are identified by simple integers.</p><dd><p class="Body"><a name="83533"> </a>Following is a sample trap definition:</p><dl class="margin"><dd><pre class="Code2"><b><a name="83534">exTrap TRAP-TYPE ENTERPRISE examples VARIABLES { exFirstObject } DESCRIPTION "An example trap." ::= 1</a></b></pre></dl></dl><dl class="margin"><dd><div class="Item"><a name="83535"> </a><b class="symbol_UC">ENTERPRISE</b> <br></div><dl class="margin"><dl class="margin"><dl class="margin"><dd><div class="Indent3"><a name="84064"> </a>The <b class="symbol_UC">ENTERPRISE</b> variable specifies the object identifier to send in the <b class="symbol_UC">TRAP</b> message. If its <b class="symbol_UC">ENTERPRISE</b> is <b class="symbol_lc">snmp</b>, the object identifier <b class="symbol_UC">OBJECT IDENTIFIER</b> is the value of <b class="symbol_lc">sysObjectID</b> (from RFC1213-MIB).</><br></dl></dl></dl><dd><div class="Item"><a name="84065"> </a><b class="symbol_UC">VARIABLES</b> <br></div><dl class="margin"><dl class="margin"><dl class="margin"><dd><div class="Indent3"><a name="84066"> </a>A trap may carry a list of variables, specified in the <b class="symbol_UC">VARIABLES</b> clause. Variable names are separated by commas. If the trap carries no variables, this clause may be omitted.</><br></dl></dl></dl><dd><div class="Item"><a name="83537"> </a><b class="symbol_UC">DESCRIPTION</b> <br></div><dl class="margin"><dl class="margin"><dl class="margin"><dd><div class="Indent3"><a name="84061"> </a>A trap specification contains a text string describing the trap. The string is enclosed in quotation marks (<b class="symbol_lc">"</b>...<b class="symbol_lc">"</b>).</><br><dd><div class="Indent3"><a name="83538"> </a>The value after "<b class="symbol_lc">::=</b>" in a <b class="symbol_UC">TRAP-TYPE</b> invocation is a simple integer; the <b class="symbol_UC">ENTERPRISE</b> clause indicates the "naming authority" controlling the assignment of these integers.</><br></dl></dl></dl></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="83539">End</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="83540"> </a>A MIB ends with the keyword <b class="symbol_UC">END</b>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="83542">A.4.2 <b class="command">mibcomp</b> Extensions</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83543"> </a><b class="command">mibcomp</b> extends the normal MIB syntax with three new keywords: <b class="symbol_UC">DEFAULT</b>, <b class="symbol_UC">FORCE-INCLUDE</b>, and <b class="symbol_UC">EXCLUDE</b>.</p><dd><p class="Body"><a name="83544"> </a>All three of these keywords may be used at the beginning of a MIB description file, between the module name and the line:</p><dl class="margin"><dd><pre class="Code2"><b><a name="83545">DEFINITIONS ::= BEGIN</a></b></pre></dl><dd><p class="Body"><a name="83546"> </a>For instance:</p><dl class="margin"><dd><pre class="Code2"><b><a name="83547">EXAMPLE-MIB FORCE-INCLUDE <stdio.h> DEFAULT get-function get_%n EXCLUDE exFirstObject DEFINITIONS ::= BEGIN EXPORTS examples; IMPORTS enterprises FROM RFC1155-SMI;</a></b></pre></dl><dd><p class="Body"><a name="83548"> </a>The <b class="symbol_UC">DEFAULT</b> keyword can also be embedded in <b class="symbol_UC">OBJECT-TYPE</b> definitions as the final line before "<b class="symbol_lc">::=</b>". For instance:</p><dl class="margin"><dd><pre class="Code2"><b><a name="83549">-- define a couple of objects exFirstObject OBJECT-TYPE SYNTAX ExampleType ACCESS read-write STATUS mandatory DESCRIPTION "First example object." DEFAULT get-function get_%n ::= { examples 1 }</a></b></pre></dl><dd><p class="Body"><a name="83550"> </a>These new keywords are not compatible with other software that processes MIB specifications. For greater compatibility, you can also use them inside comments. If the keyword immediately follows the comment characters, <b class="command">mibcomp</b> recognizes it as the appropriate keyword. Otherwise, <b class="command">mibcomp</b> ignores the word as a comment. For instance:</p><dl class="margin"><dd><pre class="Code2"><b><a name="83551">--EXCLUDE exFirstObject</a></b></pre></dl><dd><p class="Body"><a name="83552"> </a>is equivalent to</p><dl class="margin"><dd><pre class="Code2"><b><a name="83553">EXCLUDE exFirstObject</a></b></pre></dl><dd><p class="Body"><a name="83554"> </a>However,</p><dl class="margin"><dd><pre class="Code2"><b><a name="83555">-- EXCLUDE exFirstObject</a></b></pre></dl><dd><p class="Body"><a name="83556"> </a>is a comment (note the space between the second dash and the word <b class="symbol_UC">EXCLUDE</b>).</p><dd><p class="Body"><a name="83557"> </a>We recommend that you organize your MIBs as sets of standard MIB files (extracted from RFCs and draft specifications, or written by you) that do not use the extended keywords at all, with <i class="emphasis">control files</i> which complement them and which specify the extended keywords. The control files can also be specific to projects and products, and allow you to maintain only one set of MIB specifications, varying the control files as you change the implementation of MIBs from product to product.</p></dl></dl><dl class="margin"><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="83559">The <b class="symbol_UC">FORCE-INCLUDE</b> Keyword</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="83560"> </a>The <b class="symbol_UC">FORCE-INCLUDE</b> keyword directs <b class="command">mibcomp</b> to produce <b class="symbol_lc">#include</b> statements in C-code output files. When you refer to structures or variables declared in header files provided by other software, you can force the files to be included using the <b class="symbol_UC">FORCE-INCLUDE</b> keyword.</p><dd><p class="Body"><a name="83561"> </a>The <b class="symbol_UC">FORCE-INCLUDE</b> keyword takes one argument: the name of the file to be included, exactly as it should appear in the resulting <b class="symbol_lc">#include</b> statement.<sup><a href="#foot"><b class="FootnoteMarker">2</b></a></sup> For instance:</p><dl class="margin"><dd><pre class="Code2"><b><a name="83565">--FORCE-INCLUDE <asn1.h></a></b><dd> <b><a name="83566">--FORCE-INCLUDE <mib.h></a></b><dd> <b><a name="83567">--FORCE-INCLUDE <snmpdefs.h></a></b><dd> <b><a name="83568">--FORCE-INCLUDE <snmp.h></a></b><dd> <b><a name="83569">--FORCE-INCLUDE <snmpstat.h></a></b><dd> <b><a name="83570">--FORCE-INCLUDE "mibhand.h"</a></b></pre></dl><dd><p class="Body"><a name="83571"> </a><b class="command">mibcomp</b> remembers and uses all <b class="symbol_UC">FORCE-INCLUDE</b> statements from all input files, no matter which input file they appear in, and outputs a corresponding <b class="symbol_lc">#include</b> statement for each one at the top of any C-code output files. <b class="command">mibcomp</b> provides no protection against duplicate <b class="symbol_lc">#include</b> files. The order of the <b class="symbol_lc">#include</b> files in the output corresponds to the order in which <b class="command">mibcomp</b> encounters the <b class="symbol_UC">FORCE-INCLUDE</b> statements.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="83573">The <b class="symbol_UC">DEFAULT</b> Keyword</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="83574"> </a>The <b class="symbol_UC">DEFAULT</b> keyword associates MIB implementation information with MIB objects. This information is needed by the <b class="command">-mib.c</b>, <b class="command">-skel</b>, and <b class="command">-skel.h</b> output options. If you are using any of these options with <b class="command">mibcomp</b>, you must supply <b class="symbol_UC">DEFAULT</b> keywords to provide the required information. If you are not using these options, you can ignore the <b class="symbol_UC">DEFAULT</b> keyword.</p><dd><p class="Body"><a name="83575"> </a>The <b class="symbol_UC">DEFAULT</b> keyword takes two arguments. The first tells <b class="command">mibcomp</b> which function or value is being set. The second provides a string which identifies the function or value.</p><dd><p class="Body"><a name="83576"> </a>The general form of a <b class="symbol_UC">DEFAULT</b> statement is:</p><dl class="margin"><dd><pre class="Code2"><b><a name="83577">DEFAULT <i class="textVariable">label</i> <i class="textVariable">string</i></a></b></pre></dl><dd><p class="Body"><a name="83578"> </a>where<i class="textVariable"> label</i> identifies one of the functions or values that the SNMP agent associates with each object. The <i class="textVariable">string</i> argument is either the name of a C function or a C expression, depending on whether <i class="textVariable">label</i> identifies a function or a value, respectively. As with the argument to the <b class="symbol_UC">FORCE-INCLUDE</b> keyword, the <i class="textVariable">string</i> argument to the <b class="symbol_UC">DEFAULT</b> keyword should be exactly as you want it to appear in the output file.<sup><a href="#foot"><b class="FootnoteMarker">3</b></a></sup></p><dd><p class="Body"><a name="83582"> </a>The <b class="symbol_UC">DEFAULT</b> labels that specify method routines come in two parallel sets, one of which specifies a <i class="emphasis">synchronous</i> method routine, the other of which specifies <i class="emphasis">asynchronous</i> method routines. See <a href="c-agent6.html#83771"><i class="title">4.6 Method Routines</i></a> for more details on these two kinds of method routines. You can use both synchronous and asynchronous method routines within a MIB, but all the method routines for a particular MIB object must be of the same kind. This is true whether the method routine for a particular MIB object is specified explicitly via a <b class="symbol_UC">DEFAULT</b> statement associated directly with the MIB object, or is inherited from a node higher in the MIB tree.</p><dd><p class="Body"><a name="84070"> </a><b class="command">mibcomp</b> supports the following <b class="symbol_UC">DEFAULT</b> labels:</p></dl><dl class="margin"><dd><div class="Item"><a name="84071"> </a><b class="symbol_lc">test-function <br></b></div><dl class="margin"><dl class="margin"><dl class="margin"><dd><div class="Indent3"><a name="84072"> </a>This is the name of a C function for the target agent to call which informs the agent whether or not this object really exists, and, for <b class="symbol_UC">SET</b> requests, whether or not the new values specified by the request are permissible. Every <b class="symbol_lc">read-only</b>, <b class="symbol_lc">read-write</b>, or <b class="symbol_lc">read-create</b> object must have either a <b class="symbol_lc">test-function</b> or a <b class="symbol_lc">test-function-async</b> associated with it.</><br></dl></dl></dl><dd><div class="Item"><a name="83588"> </a><b class="symbol_lc">test-function-async</b> <br></div><dl class="margin"><dl class="margin"><dl class="margin"><dd><div class="Indent3"><a name="84074"> </a>This is exactly like <b class="symbol_lc">test-function</b> except that it specifies an asynchronous method routine.</><br></dl></dl></dl><dd><div class="Item"><a name="83589"> </a><b class="symbol_lc">next-function</b> <br></div><dl class="margin"><dl class="margin"><dl class="margin"><dd><div class="Indent3"><a name="84076"> </a>This is the name of a C function for the target agent to call which, when passed an object and instance identifier, returns the object and instance identifier of the "next" object. Every <b class="symbol_lc">read-only</b>, <b class="symbol_lc">read-write</b>, or <b class="symbol_lc">read-create</b> object must have either a <b class="symbol_lc">next-function</b> or a <b class="symbol_lc">next-function-async</b> associated with it.</><br></dl></dl></dl><dd><div class="Item"><a name="83590"> </a><b class="symbol_lc">next-function-async</b> <br></div><dl class="margin"><dl class="margin"><dl class="margin"><dd><div class="Indent3"><a name="84078"> </a>This is exactly like <b class="symbol_lc">next-function</b> except that it specifies an asynchronous method routine.</><br></dl></dl></dl><dd><div class="Item"><a name="83591"> </a><b class="symbol_lc">set-function</b> <br></div><dl class="margin"><dl class="margin"><dl class="margin"><dd><div class="Indent3"><a name="84080"> </a>This is the name of a C function for the target agent to call which sets the value of a MIB object. Every <b class="symbol_lc">read-write</b> or <b class="symbol_lc">read-create</b> object must have either a <b class="symbol_lc">set-function</b> or a <b class="symbol_lc">set-function-async</b> associated with it.</><br></dl></dl></dl><dd><div class="Item"><a name="83592"> </a><b class="symbol_lc">set-function-async</b> <br></div><dl class="margin"><dl class="margin"><dl class="margin">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -