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

📄 otcl.html

📁 相关搜索: ns2仿真结果分析 all-awk ns2 ns2 无限网络中awk文件 ... [2.tcl.rar] - 在ns2平台上实现对AODV协议的模拟
💻 HTML
字号:
<html><head><title>OTcl: The User Language</title></head><body background="parchment.gif" tppabs="http://nile.wpi.edu/NS/Icons/parchment.gif" text="#000000" link="#0000FF"vlink="#000080" alink="#FF0000"><br><center><h2>OTcl: The User Language</h2></center><br><br><dl><p>As mentioned in the overview section, NS is basically an <ahref="javascript:if(confirm('http://bmrc.berkeley.edu/research/cmt/cmtdoc/otcl  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://bmrc.berkeley.edu/research/cmt/cmtdoc/otcl'" tppabs="http://bmrc.berkeley.edu/research/cmt/cmtdoc/otcl"target=_top>OTcl</a> interpreter with network simulation objectlibraries.  It is very useful to know how to program in OTcl to useNS.  This section shows an example Tcl and OTcl script, from which onecan get the basic idea of programming in OTcl. These examples are fromthe 5th VINT/NS Simulation Tutorial/Workshop. This section and thesections after assumes that the reader <ahref="javascript:if(confirm('http://www.isi.edu/nsnam/ns/ns-build.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.isi.edu/nsnam/ns/ns-build.html'" tppabs="http://www.isi.edu/nsnam/ns/ns-build.html"target=_top>install</a>ed NS, and is familiar with C and C++.</p><p>Example 1 is a general Tcl script that shows how to create aprocedure and call it, how to assign values to variables, and how tomake a loop. Knowing that OTcl is Object-orieneted extension of Tcl,it is obvious that all Tcl commands work on OTcl - the relationshipbetween Tcl and Otcl is just same as C and C++. To run this script youshould download <a href="ex-tcl.tcl" tppabs="http://nile.wpi.edu/NS/Example/ex-tcl.tcl">ex-tcl.tcl</a>, and type"<font color=GREEN>ns ex-tcl.tcl</font>" at your shell prompt - thecommand "ns" starts the NS (an OTcl interpreter). You will also getthe same results if you type "<font color=GREEN>tclex-tcl.tcl</font>", if tcl8.0 is installed in your machine.</p><p align="center"><a href="ex-tcl.tcl" tppabs="http://nile.wpi.edu/NS/Example/ex-tcl.tcl"><img src="ex1.gif" tppabs="http://nile.wpi.edu/NS/Figure/ex1.gif" border=1alt="ex-tcl.tcl"></a><br><br> <b>Example 1.</b> A Sample Tcl Script</p><p>In Tcl, the keyword <b>proc</b> is used to define a procedure,followed by an procedure name and arguments in curly brackets. Thekeyword <b>set</b> is used to assign a value to avariable. [<b>expr</b> ...] is to make the interpreter calculate thevalue of expression within the bracket after the keyword. One thing tonote is that to get the value assigned to a variable, <b>$</b> is usedwith the variable name. The keyword <b>puts</b> prints out thefollowing string within double quotation marks. The following showsthe result of Example 1.</p><p align="center"><img src="ex1_result.gif" tppabs="http://nile.wpi.edu/NS/Figure/ex1_result.gif"></p><p>The next example is an object-oriented programming example inOTcl. This example is very simple, but shows the way which an objectis created and used in OTcl. As an ordinary NS user, the chances thatyou will write your own object might be rare. However, since all ofthe NS objects that you will use in a NS simulation programming,whether or not they are written in C++ and made available to OTcl viathe linkage or written only in OTcl, are essentially OTcl objects,understanding OTcl object is helpful.</p><p align="center"><a href="ex-otcl.tcl" tppabs="http://nile.wpi.edu/NS/Example/ex-otcl.tcl"><img src="ex2.gif" tppabs="http://nile.wpi.edu/NS/Figure/ex2.gif" border=1alt="ex-otcl.tcl"></a><br><br><b>Example 2.</b> A Sample OTcl Script</p><p>Example 2 is an OTcl script that defines two object classes, "mom"and "kid", where "kid" is the child class of "mom", and a memberfunction called "greet" for each class. After the class definitions,each object instance is declared, the "age" variable of each instanceis set to 45 (for mom) and 15 (for kid), and the "greet" memberfunction of each object instance is called. The keyword <b>Class</b>is to create an object class and <b>instproc</b> is to define a memberfunction to an object class. Class inheritance is specified using thekeyword <b>-superclass</b>. In defining member functions, <b>$self</b>acts same as the "this" pointer in C++, and <b>instvar</b> checks ifthe following variable name is already declared in its class or in itssuperclass. If the variable name given is already declared, thevariable is referenced, if not a new one is declared. Finally, tocreate an object instance, the keyword <b>new</b> is used as shown inthe example. Downloading <a href="ex-otcl.tcl" tppabs="http://nile.wpi.edu/NS/Example/ex-otcl.tcl">ex-otcl.tcl</a>and executing "<font color=GREEN>ns ex-otcl.tcl</font>" will give youthe following result:</p><p align="center"><img src="ex2_result.gif" tppabs="http://nile.wpi.edu/NS/Figure/ex2_result.gif"></p></dl></body></html>

⌨️ 快捷键说明

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