栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

《Introduction to NetworkSimulator NS2》Chapter 2:NS2基础知识

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

《Introduction to NetworkSimulator NS2》Chapter 2:NS2基础知识

1 NS2的文件结构

2 相关术语规定

(1)具有一对一对应关系的C++和OTcl类层次结构是分别称为编译层次结构和解释层次结构。在编译的层次结构中,它们被引用分别作为变量和函数。被解释的层次结构称为实例变量(instvars)和实例过程(instprocs)。

(2)C++中称为Objects的在OTcl中称为instance;

(3)NS2有两种语言,A和B是两种语言对同一对象的描述,那么他们互为影子对象。

命名传统

3 NS2的运行 (1)NS2程序激活

>>ns [] []

4 将C++模块包括在NS2和make实用程序中 (1)make实用程序的调用

>>make [-f mydescriptor]

默认的文件是Makefile.

(2)make编译描述符文件

描述符文件包含如何重新编译源代码的说明并重新链接。同样,默认描述符文件是名为“Makefile”的文件描述符文件包含组成可执行文件的源代码文件的名称、它们之间的相互依赖关系以及如何重建或重新编译每个文件。这样的描述是通过一系列所谓的依赖关系规则指定的。每个规则接受三个组件,即目标、依赖项和命令。以下内容是依赖项规则的格式:

[ ...] : [ ...]
[ ...]

括号内的所有内容都是可选的。目标通常是需要重新生成的文件的名称,如果对强制冒号(:)之后指定的依赖项文件进行任何修改,则需要重新生成该文件。如果注意到任何更改,将执行第二行和后续行以重新生成目标文件。

编译描述符例1:

# makefile of channel
channel : main.o fade.o model.o
cc -o channel main.o fade.o model.o
main.o : main.c
cc -c main.c
fade.o : fade.c
cc -c fade.c
model.o : model.c model.h
cc -c model.c
clean :
rm main.o fade.o model.o

首先检查目标通道,并发现该通道依赖于对象文件main.o 、fade.o、 model.o
,make程序接下来将检查上述每一个文件是否被指定为目标文件。如果是这种情况,make程序进一步检查main.o的依赖对象,果然有“main.o : main.c”。同理,继续检查main.c是否被列为目标文件。如果main.c没有被列为目标对象则执行“main.o : main.c”后面的“cc -c main.c”。同样的处理方式用于fade.o 、model.o。更新完后,返回channel目标,执行“cc -o channel main.o fade.o model.o”。最后,我们发现了伪目标“clean”, 此目标是“清理”,通常执行内务管理功能,例如清理编译和链接后不再需要的所有对象文件。

编译描述符文件中的宏定义,例1可被改写为如下形式,简称为例2:

# makefile of channel
OBJS = main.o fade.o model.o
COM = cc
channel : ${OBJS}
${COM} -o channel ${OBJS}
main.o : main.c
${COM} -c main.c
fade.o : fade.c
${COM} -c fade.c
model.o : model.c model.h
${COM} -c model.c
clean :
rm ${OBJS}

where $fCOMg and $fOBJSg are used in the place of “cc” and “main.o fade.o model.o,” respectively.

(3)NS2编译描述符文件“Makefile”

•INCLUDES = : The items behind this keyword are the directory which shouldbe included into the NS2 environment.
• OBJ_CC = and OBJ_STL = : The items behind these two keywords constitute the entire NS2 object files. When a new CCC module is developed, its corresponding object file name with “.o” extension should be added here.
• NS_TCL_LIB = : The items that bind these keywords are the Tcl file of NS2. Again, when a new OTcl module is developed, its corresponding Tcl file name should be added here。Suppose a module consisting of C++  files “myc.cc” and “myc.h” and a Tcl file “mytcl.tcl.” Suppose further that these files are created in a directory myfiles under the NS2 home directory. Then this module can be incorporated into NS2 using the following steps:
1. Include a string “-I./myfiles” into the Line beginning with INCLUDES = in the “Makefile.”
2. Include a string “myfile/myc.o” into the Line beginning with OBJ_CC = or OBJ_STL = in the “Makefile.”
3. Include a string “myfile/mytcl.tcl” into the Line beginning with NS_TCL_LIB = in the “Makefile.”
4. Run “make” from the shell. After running “make,” an executable file “ns” is created. We can now use this file “ns” to run simulation

5小结

NS2由OTcl和C++组成。C++对象使用TclCl映射到OTcl句柄。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/960562.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号