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

2 篇文章 0 订阅

1 NS2的文件结构

2 相关术语规定

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

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

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

命名传统

3 NS2的运行

(1)NS2程序激活

>>ns [<file>] [<args>]

4 C++模块包括在NS2make实用程序中

1make实用程序的调用

>>make [-f mydescriptor]

默认的文件是Makefile.

2make编译描述符文件

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

<target1> [<target2> ...] : <dep1> [<dep2> ...]
<command1> [<command2> ...]

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

编译描述符例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 hereSuppose 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小结

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值