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

📄 node116.html

📁 相关搜索: ns2仿真结果分析 all-awk ns2 ns2 无限网络中awk文件 ... [2.tcl.rar] - 在ns2平台上实现对AODV协议的模拟
💻 HTML
字号:
<html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><!--Converted with jLaTeX2HTML 2002 (1.62) JA patch-1.4patched version by:  Kenshi Muto, Debian Project.LaTeX2HTML 2002 (1.62),original version by:  Nikos Drakos, CBLU, University of Leeds* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan* with significant contributions from:  Jens Lippmann, Marek Rouchal, Martin Wilck and others --><HTML><HEAD><TITLE>10.6.3 Linking the ``ping'' Agent with OTcl</TITLE><META NAME="description" CONTENT="10.6.3 Linking the ``ping'' Agent with OTcl"><META NAME="keywords" CONTENT="everything"><META NAME="resource-type" CONTENT="document"><META NAME="distribution" CONTENT="global"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"><META NAME="Generator" CONTENT="jLaTeX2HTML v2002 JA patch-1.4"><META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"><LINK REL="STYLESHEET" HREF="everything.css" tppabs="http://www.isi.edu/nsnam/ns/doc/everything.css"><LINK REL="next" HREF="node117.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node117.html"><LINK REL="previous" HREF="node115.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node115.html"><LINK REL="up" HREF="node113.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node113.html"><LINK REL="next" HREF="node117.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node117.html"></HEAD><BODY ><!--Navigation Panel--><A NAME="tex2html3084"  HREF="node117.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node117.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html3078"  HREF="node113.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node113.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html3072"  HREF="node115.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node115.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html3080"  HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html"><IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="file:/usr/share/latex2html/icons/contents.png"></A> <A NAME="tex2html3082"  HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html"><IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="file:/usr/share/latex2html/icons/index.png"></A> <BR><B> Next:</B> <A NAME="tex2html3085"  HREF="node117.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node117.html">10.6.4 Using the agent</A><B> Up:</B> <A NAME="tex2html3079"  HREF="node113.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node113.html">10.6 Creating a New</A><B> Previous:</B> <A NAME="tex2html3073"  HREF="node115.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node115.html">10.6.2 The recv() and</A> &nbsp <B>  <A NAME="tex2html3081"  HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>  &nbsp <B>  <A NAME="tex2html3083"  HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html">Index</A></B> <BR><BR><!--End of Navigation Panel--><H2><A NAME="SECTION03763000000000000000"></A><A NAME="sec:agents:exlinkage"></A><BR>10.6.3 Linking the ``ping'' Agent with OTcl</H2><P>We have the methods and mechanisms for establishing OTcl Linkage earlierChapterchap:otcl:intro.This section is a brief review of the essential features of thatearlier chapter, and describes the minimum functionality required to create the ping agent.<P>There are three items we must handle to properly link our agentwith Otcl.First we need to establish a mapping between the OTcl namefor our class and the actual object created when aninstantiation of the class is requested in OTcl.This is done as follows:<PRE>        static class ECHOClass : public TclClass {        public:                ECHOClass() : TclClass("Agent/ECHO") {}                TclObject* create(int argc, const char*const* argv) {                        return (new ECHO_Agent());                }        } class_echo;</PRE>Here, a <EM>static</EM> object ``class_echo'' is created. It's constructor(executed immediately when the simulator is executed) places the class name``Agent/ECHO'' into the OTcl name space.The mixing of case is by convention;recall from Section&nbsp;<A HREF="node24.html#sec:TclClass" tppabs="http://www.isi.edu/nsnam/ns/doc/node24.html#sec:TclClass">3.5</A> in the earlier chapters thatthe ``/'' character is a hierarchy delimiter for the interpreted hierarchy.The definition of the []create method specifies how a C++shadow object should be created whenthe OTcl interpreter is instructed to create anobject of class ``Agent/ECHO''.  In this case, a dynamically-allocatedobject is returned.  This is the normal way new C++ shadow objectsare created.<P>Once we have the object creation set up, we will want to linkC++ member variables with corresponding variables in the OTclnname space, so that accesses to OTcl variables are actuallybacked by member variables in C++.Assume we would like OTcl to be able to adjust the sendinginterval and the packet size.This is accomplished in the class's constructor:<PRE>        ECHO_Agent::ECHO_Agent() : Agent(PT_ECHO)        {                bind_time("interval_", &amp;interval_);                bind("packetSize_", &amp;size_);        }</PRE>Here, the C++ variables <TT>interval_</TT> and <TT>size_</TT> arelinked to the OTcl instance variables <TT>interval_</TT> and<TT>packetSize_</TT>, respectively.Any read or modify operation to the Otcl variables will resultin a corresponding access to the underlying C++ variables.The details of the []bind methods are described elsewhereSectionsec:VarBinds.The defined constant <TT>PT_ECHO</TT> is passed to the []Agentconstuctor so that the []Agent::allocpkt method may setthe packet type field used by the trace supportSectionsec:traceptype.In this case, <TT>PT_ECHO</TT> represents a new packet type and must be defined in trace.hSectionsec:traceformat.<P>Once object creation and variable binding is set up, we maywant to create methods implemented in C++ but which canbe invoked from OTclSectionsec:Commands.These are often control functions that initiate, terminate ormodify behavior.In our present example, we may wish to be able to start theping query agent from OTcl using a ``start'' directive.This may be implemented as follows:<PRE>        int ECHO_Agent::command(int argc, const char*const* argv)        {                if (argc == 2) {                        if (strcmp(argv[1], "start") == 0) {                                timeout(0);                                return (TCL_OK);                        }                }                return (Agent::command(argc, argv));        }</PRE>Here, the []start method available to OTcl simply callsthe C++ member function []timeout which initiates thefirst packet generation and schedules the next.Note this class is so simple it does not even include away to be stopped.<P><HR><!--Navigation Panel--><A NAME="tex2html3084"  HREF="node117.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node117.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html3078"  HREF="node113.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node113.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html3072"  HREF="node115.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node115.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html3080"  HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html"><IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="file:/usr/share/latex2html/icons/contents.png"></A> <A NAME="tex2html3082"  HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html"><IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="file:/usr/share/latex2html/icons/index.png"></A> <BR><B> Next:</B> <A NAME="tex2html3085"  HREF="node117.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node117.html">10.6.4 Using the agent</A><B> Up:</B> <A NAME="tex2html3079"  HREF="node113.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node113.html">10.6 Creating a New</A><B> Previous:</B> <A NAME="tex2html3073"  HREF="node115.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node115.html">10.6.2 The recv() and</A> &nbsp <B>  <A NAME="tex2html3081"  HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>  &nbsp <B>  <A NAME="tex2html3083"  HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html">Index</A></B> <!--End of Navigation Panel--><ADDRESS>2003-09-23</ADDRESS></BODY></HTML>

⌨️ 快捷键说明

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