Reading Notes on NS2(10)

本文介绍了NS2中的数据跟踪方法,包括Trace和Monitor的使用,以及Nam工具进行动画演示的过程。涵盖Trace文件格式解析、不同类型的Trace记录、模拟事件的详细记录方法、动画演示的设置及布局等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

数据的记录与动画演示

 

在模拟过程中,数据跟踪和采集的方法有多种,大体可以分为两大类:
(1)模拟的执行过程中直接显示跟踪数据
(2)将采集到的数据直接存放到一个文件中,以便后期的处理和分析(常用)

在NS2中有两种主要不同的数据监视器对象
(1)Trace
该对象详细地记录了模拟的整个过程,包括每一个数据分组到达、离开链路或队列,以及分组被丢弃等信息,并存储于Trace文件中。
(2)Monitor
用来记录各种有用的数值,比如到达、离开链路或队列的数据分组数、字节数等。

 

[1] Trace的使用
Trace的功能是能够详细地记录模拟过程,同时,用户也可以根据自己的需要记录模拟过程中的任何一个细节。
注意:
(1)NS2提供了各种不同的Trace类型,且都继承于OTcl的Trace类,实现不同的功能。
(2)可以通过Tcl代码查看NS2支持的各种Trace类(P.66)

在Tcl中使用Trace,分为两种情况:
(1)记录整个模拟过程的事件,将所有模拟细节都记录下来。
(2)根据需要记录模拟过程中的某些细节,记录一部分事件。

NS2的Simulator类内部定义了各种过程来支持Trace的使用,具体如下:
(1) $ns trace-all <tracefile>
记录整个模拟过程,将模拟过程的所有数据写入Trace文件中,<tracefile>为Trace文件的文件句柄。
(2) $ns trace-queue <n1> <n2> <optional:file>
记录节点n1和n2间链路的事件,并将相关数据写入名为<file>的Trace文件中,其中<file>为可选项。
(3) $ns flush-trace
清空模拟过程中所有Trace对象的缓冲区。

 

[2] Trace文件格式
在模拟有线网络时,得到默认的Trace文件的每条记录包含了以下12项:

Event|Time|From node|To node|Pkt Type|Pkt size|Flags|Fid|Src addr|Dst addr|Seq num|Pkt id

(1)Event:发生事件的类型(四种)
+ :分组enqueue事件
- :分组dequeue事件
r :目的节点receive事件
d :队列drop事件
(2)Time:事件发生的时间
(3)From node:发送分组节点的id
(4)To node:接收分组节点的id
(5)Pkt Type:分组类型
(6)Pkt size:分组大小
(7)Flags:标志项
(8)Fid:流标识符
(9)Src addr:源地址,格式为node.port
(10)Dst addr:目的地址,格式为node.port
(11)Seq num:分组的序列号
(12)Pkt id:分组的唯一标识符

 

[3] Monitor的使用
在NS2中,监测有两种:
(1)队列监测(Queue Monitoring)
(2)流监测(Per-Flow Monitoring)
详见P.69

 

[4] 动画演示
NS2可以使用Nam工具对整个模拟过程进行动画演示。Nam是基于Tcl/TK的动画演示工具,用来把模拟的过程用可视化的方式呈现出来,从而可以让使用者用“看”的方式去了解封包传送是如何从源端送到接收端。
注意:
(1)使用Nam的第一步是产生一个Nam跟踪文件。

(2)Nam提供3种通用的布局方法

方法1:
在有线网络中,用户可以通过链路的方位确定布局,链路的方位一般用链路和水平线之间的夹角来表示。
这种布局方式适用于小型和手工生成的拓扑。

方法2:
自动布局的方法。
这种方法适用于网络节点较多的情况。

方法3:
x、y坐标方式布局。
这种方式用来进行无线环境的拓扑构造。

(3)设置与节点相关的显示属性

(4)设置与链路相关的显示属性

(5)设置数据流的颜色

(6)在脚本中运行Nam的方法

 

[5] 相关命令总结

The Network Simulator, Version 3 -------------------------------- Table of Contents: ------------------ 1) An overview 2) Building ns-3 3) Running ns-3 4) Getting access to the ns-3 documentation 5) Working with the development version of ns-3 Note: Much more substantial information about ns-3 can be found at http://www.nsnam.org 1) An Open Source project ------------------------- ns-3 is a free open source project aiming to build a discrete-event network simulator targeted for simulation research and education. This is a collaborative project; we hope that the missing pieces of the models we have not yet implemented will be contributed by the community in an open collaboration process. The process of contributing to the ns-3 project varies with the people involved, the amount of time they can invest and the type of model they want to work on, but the current process that the project tries to follow is described here: http://www.nsnam.org/developers/contributing-code/ This README excerpts some details from a more extensive tutorial that is maintained at: http://www.nsnam.org/documentation/latest/ 2) Building ns-3 ---------------- The code for the framework and the default models provided by ns-3 is built as a set of libraries. User simulations are expected to be written as simple programs that make use of these ns-3 libraries. To build the set of default libraries and the example programs included in this package, you need to use the tool 'waf'. Detailed information on how use waf is included in the file doc/build.txt However, the real quick and dirty way to get started is to type the command ./waf configure --enable-examples followed by ./waf in the the directory which contains this README file. The files built will be copied in the build/ directory. The current codebase is expected to build and run on the set of platforms listed in the RELEASE_NOTES file. Other platforms may or may not work: we welcome patches to improve the portability of the code to these other platforms. 3) Running ns-3 --------------- On recent Linux systems, once you have built ns-3 (with examples enabled), it should be easy to run the sample programs with the following command, such as: ./waf --run simple-global-routing That program should generate a simple-global-routing.tr text trace file and a set of simple-global-routing-xx-xx.pcap binary pcap trace files, which can be read by tcpdump -tt -r filename.pcap The program source can be found in the examples/routing directory. 4) Getting access to the ns-3 documentation ------------------------------------------- Once you have verified that your build of ns-3 works by running the simple-point-to-point example as outlined in 4) above, it is quite likely that you will want to get started on reading some ns-3 documentation. All of that documentation should always be available from the ns-3 website: http:://www.nsnam.org/documentation/. This documentation includes: - a tutorial - a reference manual - models in the ns-3 model library - a wiki for user-contributed tips: http://www.nsnam.org/wiki/ - API documentation generated using doxygen: this is a reference manual, most likely not very well suited as introductory text: http://www.nsnam.org/doxygen/index.html 5) Working with the development version of ns-3 ----------------------------------------------- If you want to download and use the development version of ns-3, you need to use the tool 'mercurial'. A quick and dirty cheat sheet is included in doc/mercurial.txt but reading through the mercurial tutorials included on the mercurial website is usually a good idea if you are not familiar with it. If you have successfully installed mercurial, you can get a copy of the development version with the following command: "hg clone http://code.nsnam.org/ns-3-dev"
最新发布
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值