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

📄 snmp_overview.tex

📁 xorp源码hg
💻 TEX
📖 第 1 页 / 共 2 页
字号:
Figure \ref{fig:xorp-if-diag} illustrates the functionality implemented by \texttt{xorp\_if\_mib\_module}.\begin{figure}  \begin{center}    \includegraphics[width=1\textwidth]{figs/snmp_fig2}  \end{center}  \caption{Functionality of xorp\_if\_mib\_module}  \label{fig:xorp-if-diag}\end{figure}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\subsection{Modifying XORP's configuration from within a MIB module}MIB modules use XORP's IPC library \cite{xorp:xrl} to communicate to XORPprocesses.  Each MIB module has the responsibility to pull the relevantmanagement information from the appropriate process (\eg BGP MIB data from BGPprocess).  For that effect, the MIB module must use the XRL Interfacesupported by the XRL targets it needs to communicate to (see\cite{xorp:xrl_interfaces} for details on how to subclass XRL Interface Clientclasses).  MIB modules, though, MUST not modify any configuration settings byaccessing the process directly.  The current state of configuration ismaintained by the router manager process, so bypassing it would cause the realand the recorded configurations to be out of sync.  Instead, configurationchanges should be requested to the router manager via configuration commands,that is, XRLs such as the ones appearing in the template files (seexorp/etc/templates/*.tp).Figure \ref{fig:mib-class-diag} illustrates how the MIB modules should read andchange XORP configuration.\begin{figure}  \begin{center}    \includegraphics[width=1\textwidth]{figs/snmp_fig1}  \end{center}  \caption{MIB module interactions with the router manager}  \label{fig:mib-class-diag}\end{figure}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\section{A reference implementation of a MIB module}So far we've talked Net-SNMP configuration.  In this section we'll coverhow to write a MIB module.  Currently (March 2007) we provide a fullimplementation of RFC 1657, the MIB for BGP4.  You will find the MIB modulefiles in xorp/mibs/bgp4\_mib\_1657*.  What follows is a description the toolsand process followed to implement this module.  You should refer to thekdoc documentation as well as the source itself for more details.   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\subsection{The textual MIB definition file}The first step to write a MIB module should be writing or getting the ASN.1 MIBdefinition file.  If you are implementing an existing protocol, chances arethat there is already a published RFC with the MIB definition for it.  In thissection we'll use BGP4-MIB to illustrate the process of writing a MIB module,which is published in RFC 1657 and you will find inxorp/mibs/textual/BGP4-MIB.txt.You will also have to  make your textual MIB file accessible to the Net-SNMPtools.  See the \texttt{mibs} and \texttt{mibdirs} directives in the man pagesnmp.conf(5).  One way to do this is to copy our MIB onto the defaultdirectory, and then set the MIBS environment variable:\begin{verbatim}$ cp BGP4-MIB.txt /usr/local/share/snmp/mibs$ export MIBS=+BGP4-MIB\end{verbatim}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\subsection{Net-SNMP handlers}Net-SNMP 5.x.x uses handlers to process SNMP requests.  When a MIB module isloaded, it registers one or more handlers (callbacks) on a given OID in the OIDtree.  When a request arrives for that OID subtree, the registered handlersare called in sequence until the request is fully processed.  There aremultiple pre-written handlers (helpers, in Net-SNMP nomenclature) that dealwith certain parts of the processing.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\subsection{Using mib2c}Net-SNMP provides what is usually termed as ''MIB compiler'' (\texttt{mib2c}),a tool that will read MIB ASN.1 definition files and generate C code templatesto ease the development of handlers.  \texttt{mib2c} takes a configurationfile as a parameter that will determine which helper handlers to use.The MIB compiler is not installed by default with Net-SNMP.  If you haveNet-SNMP installed in your system and you invoke \texttt{mib2c} you'll probablyget this message:\begin{verbatim}ERROR: You don't have the SNMP perl module installed.  Please obtainthis by getting the latest source release of the net-snmp toolkit fromhttp://www.net-snmp.org/download/ .  Once you download the source andunpack it, the perl module is contained in the perl/SNMP directory.See the INSTALL file there for instructions.\end{verbatim}This is what it took to install it in a FreeBSD system:\begin{verbatim}$ pwd/usr/ports/net/net-snmp/work/net-snmp-5.0.8/perl$ perl Makefile.PL ; gmake ; gmake installWriting Makefile for NetSNMP::default_storeWriting Makefile for NetSNMP::ASNWriting Makefile for NetSNMP::OID...\end{verbatim}Now you can invoke \texttt{mib2c}.  The following command says ''create atemplate C file for bgpVersion, which is a scalar, and  name itbgp4\_mib\_1657\_bgpversion''.\begin{verbatim}$ mib2c -i -c mib2c.scalar.conf -f bgp4_mib_1657_bgpversion bgpversionwriting to bgp4_mib_1657_bgpversion.hwriting to bgp4_mib_1657_bgpversion.c\end{verbatim}In a similar way, if we want to generate C templates for a SNMP table we woulduse:\begin{verbatim}$ mib2c -i -c mib2c.iterate.conf -f bgp4_mib_1657_bgppeertable bgpPeerTablewriting to bgp4_mib_1657_bgppeertable.hwriting to bgp4_mib_1657_bgppeertable.c\end{verbatim}Note that although there are other conf files, only the two presented in thissection can be used with XORP's asynchronous architecture.  You can finddetails on those files by omitting the -c option when invoking \texttt{mib2c}. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\subsection{Using delegated requests}  The asynchronous nature of XORP communications prevents handlers fromprocessing SNMP requests synchronously.  Handlers initiate XRL requests forother XORP processes, and return control to the SNMP agent before the reply isreceived.  Net-SNMP allows that by providing the \texttt{delegated} flag in theSNMP request structure.  The agent will not send a reply to a request for aslong as that flag is set.  In XORP MIBs, you would normally set the delegatedflag when your handler is called, and clear it whenever the XRL callback whoreceives the data from a XORP process is executed.  There is an additionalexample of a delegated request in\verb1http://www.net-snmp.org/tutorial-5/agent/delayed__instance_8c-example.html1\footnote{Thisexample uses the function \texttt{netsnmp\_handler\_check\_cache()} which youwill see that it's not used in our code.  The reason is that it is incompatiblewith the code generated by mib2c.iterate.conf}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\subsection{Caching tables inside the agent}SNMP is layered on a connectionless protocol (UDP).  This means that no statecan be maintained between two different requests.  A consequence of this isthat a table must be searched for \emph{each} element on the table,regardless on whether the table is sorted or not.  Now, how efficient is thissearch?The code generated with \texttt{mib2c.iterate.conf} is designed to deal withunsorted tables, so a GETNEXT request for a single element in the tableproduces $num\_rows$ calls to the user provided handlers, or$O(num\_cols*num\_rows^{2})$ to read the entire table.  Althought this isacceptable for most of the small tables typically found in MIB modules, it isprohibitive for large tables, such as \texttt{BGP4-MIB::bgp4PathAttrTable}($\approx100,000$ rows).  To address this problem, we have cached \texttt{BGP4-MIB::bgp4PathAttrTable} inside the SNMP agent process space in a sorted data structure.  Thiseliminates the need to use XRLs to process an SNMP request, and reduces thecomplexity to read the entire table to $O(num\_cols*num\_rows*log(num\_rows))$.The configuration file used to generate the code for cached tables is\texttt{mib2c.array-user.conf}.There are plans to include caching built in inside Net-SNMP.  When thathappens, this strategy may not longer be necessary. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\section{Launching Net-SNMP via the router manager}You can have the rtrmgr process start the SNMP agent.  In order to do that, youshould modify your agent snmpd.conf (by default in /usr/local/share/snmp) toload xorp\_if\_module at start up. After that, you can modify your config.bootfile to load MIB modules when the agent is started, or to do it whenever aparticular protocol comes up. See \texttt{\$\{XORP\}/etc/templates/snmp.tp} for definition of the SNMPconfiguration tree.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     APPENDIX%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\appendix\section{Modification History}\begin{itemize}  \item June 9, 2003: Initial version 0.3 completed.  \item August 28, 2003: Updated to match XORP release 0.4.  \item November 6, 2003: Updated the version to 0.5, and the date.  \item July 8, 2004: Updated the version to 1.0, and the date.  \item April 13, 2005: Updated the version to 1.1, and the date.  \item March 8, 2006: Updated the version to 1.2, and the date.  \item August 2, 2006: Updated the version to 1.3, and the date.  \item March 20, 2007: Updated the version to 1.4, and the date.\end{itemize}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     BIBLIOGRAPHY%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\bibliography{../tex/xorp}\bibliographystyle{plain}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\end{document}

⌨️ 快捷键说明

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