- 浏览: 887244 次
- 性别:
- 来自: 太原
文章分类
- 全部博客 (198)
- Linux/Unix (38)
- TinyOS / NS-2 for『WSN』 (44)
- 思想的拼图 (5)
- 开源 OpenSource (2)
- Framework 开发框架 (0)
- Software Engineering 软件工程 (2)
- IT项目管理 (6)
- Networking 网络技术 (2)
- Java (6)
- C语言 ANSI C (22)
- .NET / C# (9)
- C++ (12)
- Web 语言 Html/Xml (5)
- Groovy on Grails (1)
- Algorithm 算法 (1)
- Database 数据库技术 (5)
- Tools (21)
- VM 虚拟机 (3)
- WSN (wireless sensor network) (2)
- Linux 命令专辑 (3)
- PHP (0)
- 办公软件 (3)
最新评论
-
cfczdws:
感谢楼主,查了半天终于发现居然是htmlentities()做 ...
htmlentities()函数把中文转成了乱码 -
decoxiaohan:
这本书的名字 有谁知道????~~~
OMNeT++中文用户手册(完全版) -
huonie:
怎么下载啊
OMNeT++中文用户手册(完全版) -
huonie:
没有内容啊
OMNeT++中文用户手册(完全版) -
kyx0413:
谢谢先 先看看
OMNeT++中文用户手册(完全版)
Trace Analysis Example
#Create a simulator object set ns [new Simulator] #Define different colors for data flows (for NAM) $ns color 1 Blue $ns color 2 Red #Open the NAM trace file set nf [open out.nam w] $ns namtrace-all $nf #Open the Trace file set tf [open out.tr w] $ns trace-all $tf #Define a 'finish' procedure proc finish {} { global ns nf tf $ns flush-trace #Close the NAM trace file close $nf #Close the Trace file close $tf #Execute NAM on the trace file exec nam out.nam & exit 0 } #Create four nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] #Create links between the nodes $ns duplex-link $n0 $n2 2Mb 10ms DropTail $ns duplex-link $n1 $n2 2Mb 10ms DropTail $ns duplex-link $n2 $n3 1.7Mb 20ms DropTail #Set Queue Size of link (n2-n3) to 10 $ns queue-limit $n2 $n3 10 #Give node position (for NAM) $ns duplex-link-op $n0 $n2 orient right-down $ns duplex-link-op $n1 $n2 orient right-up $ns duplex-link-op $n2 $n3 orient right #Monitor the queue for link (n2-n3). (for NAM) $ns duplex-link-op $n2 $n3 queuePos 0.5 #Setup a TCP connection set tcp [new Agent/TCP] $tcp set class_ 2 $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n3 $sink $ns connect $tcp $sink $tcp set fid_ 1 #Setup a FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp $ftp set type_ FTP #Setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $n1 $udp set null [new Agent/Null] $ns attach-agent $n3 $null $ns connect $udp $null $udp set fid_ 2 #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set type_ CBR $cbr set packet_size_ 1000 $cbr set rate_ 1mb $cbr set random_ false #Schedule events for the CBR and FTP agents $ns at 0.1 "$cbr start" $ns at 1.0 "$ftp start" $ns at 4.0 "$ftp stop" $ns at 4.5 "$cbr stop" #Detach tcp and sink agents (not really necessary) $ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink" #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish" #Print CBR packet size and interval puts "CBR packet size = [$cbr set packet_size_]" puts "CBR interval = [$cbr set interval_]" #Run the simulation $ns run
代码演示了如何打开一个追踪文件并写入追踪信息。 代码建立的模拟场景可以参考Figure 4在"Simple Simulation Example"小节中。
Example 4. Trace Enabled Simple NS Simulation Script (modified from Example 3)
运行上面的脚本会生成一个NAM trace文件被NAM工具用来输入信息和一个名叫"out.tr"的trace 文件用于模拟分析。 Figure 13 说明了trace信息的格式和"out.tr"中trace数据的样例。
Figure 13. Trace Format Example
每行trace信息以事件描述符(+, -, d, r)开头、 紧接着是事件的模拟时间(秒为单位)、和起始与目的节点,这些用来标明事件是在那个连接上发生的。 "Network Components"小节中的Figure 9说明了在一个连接的哪个地方每个类型的事件被追踪。 flags项之前 (表示为"------")是数据包类型和大小(in Bytes)。 目前, NS只执行Explicit Congestion Notification (ECN 明显拥挤通告位) bit, 并没用到其余的位(remaining bits are not used)。 IPv6的flow id (fid) 可以设置给每个流flow在输入OTcl脚本。即使fid field在模拟中没有用到, 也可以把它用作分析。fid field还在为NAM的显示图像指定stream color时使用。source和destination地址项形式上是"node.port". 下一项表示网络层协议的数据包的序列号。即使UDP不使用seq, NS也保持了对UDP packet sequence number的追踪作为分析目的。最后一项表示数据包unique id。
有了模拟追踪的数据后,需要做的就剩下转换感兴趣的数据为容易理解的信息并对他进行分析。 下面是一个数据转换的例子。它使用一个用perl编写的命令叫"column",这个命令把几列数据从输入数据中选出来。 运行这个例子需要下载"column"并使它可执行(i.e. "chmod 755 column")。 然后是tunneled shell command加上awk, 它将计算CBR traffic jitter在接收节点(n3) 使用"out.tr"中的数据, 然后保存结果到"jitter.txt".
cat out.tr | grep " 2 3 cbr " | grep ^r | column 1 10 | awk '{dif = $2 - old2; if(dif==0) dif = 1; if(dif > 0) {printf("%d\t%f\n", $2, ($1 - old1) / dif); old1 = $1; old2 = $2}}' > jitter.txt |
($1带入了Figure 13 format中的time field的值,$2带入seq field的值,$1带指前面的column 1,$2带指前面的column 10。根据Figure 13的格式从0-11个项,则每行中第1个列column 1是time field,第10个列是seq field)
这个shell command 选中"CBR packet receive"类型为CBR的包在节点n3上, 选中次数(column 1)和sequence number序号 (column 10), 然后为每个序号计算和上一个数据包在接收时间的不同,然后除以2个包在seq上的不同。 下面是相应的振动波图(jitter graph)用 gnuplot 生成。X 轴表示数据包的sequence number,Y 轴表示模拟时间(in seconds.)。
Figure 14. CBR Jitter at The Receiving Node (n3)
Example Utilities小节将介绍更多的工具。
本节演示了在NS中如何生成追踪数据、如何解析数据、并如何得到可用的信息从追踪数据中。这个例子中, 在模拟后post simulation处理在命令行中进行。 下一节将会讲到如何将这些处理也可以被写在OTcl脚本中input。
发表评论
-
几种用于WSN的仿真工具
2009-12-09 15:26 4185为评价无线传感器网络协议算法的性能,仅通过实验是无法实现的,特 ... -
OMNeT++中文用户手册(完全版)
2009-11-18 22:36 16538http://www.netforum.com.cn/view ... -
改变Telos 系列节点Serial baud rate
2009-08-21 18:50 2148如果节点与PC通信时出现非正常丢包或者serial不稳定当收包 ... -
TinyOS编译问题
2009-08-18 20:47 12881. 有时候编译提示找不到某个文件时, 可能是由于在linux ... -
改变节点transmission power, radio power level (tx_power)
2009-08-11 20:03 4263使用 CC2420Packet 中 setPower 来改变每 ... -
Tcl/tk 小记
2009-07-22 23:43 14671. 检查variable变量是否声明 在使用Tcl时候会经常 ... -
NS无线仿真中无法设置节点颜色的解决方案
2009-07-22 18:57 1900NS中提供了配置节点与 ... -
awk: malloc(): memory corruption 错误
2009-07-09 21:56 7194问题如下: *** glibc detected *** aw ... -
ns2 对无线网络模拟
2009-07-06 19:52 2618在模拟无线网络时需要对tcl模拟脚本文件的参数进行设置,比如P ... -
使用Gnuplot 绘制ns2模拟结果图
2009-06-25 17:48 8167Gnuplot(command-driven inter ... -
ns2模拟无线网络的NAM动画
2009-06-24 22:26 4949无线的各个参数 ####################### ... -
ns2 模拟WSN协议之手记
2009-06-23 23:55 2861ns2中模拟WSN,用Timestamp时间戳计算点对点Del ... -
ns2 中得到Agent的实例
2009-06-16 21:02 2882下面代码说明了如何访问其他节点的Agent,以AODV协议为例 ... -
TinyOS使用MIG时报错!
2009-04-06 01:30 1796在Makefile中加入启用MIG的选项后,编译出现一下错误: ... -
Tinyos 2.0 笔记小结(1)
2009-03-16 20:11 23061. configure组件注意事项 一般在confi ... -
Tinyos 2.0使用笔记
2009-03-06 19:48 27471.编译与安装程序到节点 引用 $ make mica2 ... -
Tinyos 中常用术语
2009-03-05 03:32 1057EOFF 关断能量损耗 用于 device off, stop ... -
什么是 nx_ type
2009-03-01 03:29 1467nx_ types 是在nesC 1.2,tinyos中用到的 ... -
TinyOS 下安装 JNI 的问题
2009-02-25 00:05 31721. "java not found, not i ... -
『TinyOS』学习笔记 #11?
2009-02-20 01:09 3752Lesson 11 TOSSIM Compiling ...
相关推荐
Trace analysis ,可以用于ns2仿真的trace分析,作了一个简单的介绍
NS by Example是对初学者很好的参考书
NULL 博文链接:https://kooyee.iteye.com/blog/318646
NULL 博文链接:https://kooyee.iteye.com/blog/318644
ns的一些例子,有助于ns入门学习,ns example
ns by Example ns by Example
目录: Overview , Basics , OTcl: The User Language Simple Simulation Example Event Scheduler Network Components Packet Post Simulation , Trace Analysis Example ...
Ns2 by example for beginner user
如何使用一些工具来分析和呈现模拟结果,主要是测量端到端的延迟,而采用的方法是去分析Trace文件。
ns2 by example 经典的ns2学习资料
NS2是一款优秀而经典的网络模拟工具,然后要学好并不容易,这份精致的NS by example提供入门到精通的帮助
无线Trace的格式 老版本的Trace格式 新版的Trace格式
ns2学习笔记 c++ tcl脚本 都有描述
NS-2编程的学习文档汇编,适合入门级,包含了NS2无线模拟的Trace文件格式,NS2 进行无线模拟时 调用的类和函数并且有详细的otcl机制的说明.
NS2学习中必备资料,非常适合于初学者。提供了大量的实例,并进行细致的讲解和分析,虽然是英文,但是理解起来不难。
NS2学习笔记NS2学习笔记NS2学习笔记NS2学习笔记NS2学习笔记NS2学习笔记NS2学习笔记NS2学习笔记NS2学习笔记NS2学习笔记
关于NS2下的无线trace的分析模板,延时抖动,传输率带宽计算模板
ns by example是初学者比较实用,主要介绍了ns的初级知识,用简单的例子讲解,个人认为很有用,分享给大家看看
NS2 学习笔记,在学校NS2网络编程的时候 在网上找的很不错 适合初学者