NS2的LEACH仿真出来的nam文件拓扑的节点为什么x=0,且y=0
查看.tr文件和.nam发文件下所有的节点的x,y值都是(0,0),nam图像更没有运行出来
于是我将
if { $opt(sc) == "" } {
puts "*** NOTE: no scenario file specified."
set opt(sc) "none"
} else {
puts "Loading scenario file..."
source $opt(sc)
puts "Load complete..."
}
几行代码移动到:initial_node_pos调用方法之前,解决了节点位置为0的问题,但是nam仿真时又出现了没有数据的问题,且一按开始动画时间进度条就会变成空白,又是一个问题,这又是为什么呢?
仔细对比wireless.tcl 文件发现是由于仿真结束后将两行代码注释掉了:
proc stop {} {
global ns_ nam_vystup
$ns_ flush-trace
close $nam_vystup
#exec nam out_aodv_big_auto.nam &
#exit 0
}
这两行代码注释了导致nam没有数据收发,具体原因我也不知道为什么,只是浅薄的知道时这两行代码有问题
将这两行代码的注释去掉后,nam动画正常了
以下是我的wireless.tcl代码:
set opt(chan) Channel/WirelessChannel
set opt(prop) Propagation/TwoRayGround
#set opt(netif) NetIf/SharedMedia
set opt(netif) Phy/WirelessPhy
#set opt(mac) Mac/802_11
set opt(mac) Mac/802_11
set opt(ifq) Queue/DropTail/PriQueue
set opt(ll) LL
set opt(ant) Antenna/OmniAntenna
set opt(x) 670 ;# X dimension of the topography
set opt(y) 670 ;# Y dimension of the topography
#set opt(cp) "../mobility/scene/cbr-50-20-4-512" ;# connection pattern file
set opt(cp) ""
set opt(sc) "../mobility/scene/scen-670x670-50-600-20-2" ;# scenario file
set opt(ifqlen) 50 ;# max packet in ifq
set opt(nn) 101 ;# number of nodes
set opt(seed) 0.0
set opt(stop) 50.0 ;# simulation time
set opt(tr) out.tr ;# trace file
set opt(rp) dsdv ;# routing protocol script
set opt(lm) "on" ;# log movement
# ======================================================================
set AgentTrace ON
set RouterTrace ON
set MacTrace OFF
LL set mindelay_ 50us
LL set delay_ 25us
LL set bandwidth_ 0 ;# not used
LL set off_prune_ 0 ;# not used
LL set off_CtrMcast_ 0 ;# not used
Agent/Null set sport_ 0
Agent/Null set dport_ 0
Agent/CBR set sport_ 0
Agent/CBR set dport_ 0
Agent/TCPSink set sport_ 0
Agent/TCPSink set dport_ 0
Agent/TCP set sport_ 0
Agent/TCP set dport_ 0
Agent/TCP set packetSize_ 1460
Queue/DropTail/PriQueue set Prefer_Routing_Protocols 1
# unity gain, omni-directional antennas
# set up the antennas to be centered in the node and 1.5 meters above it
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
Antenna/OmniAntenna set Z_ 1.5
Antenna/OmniAntenna set Gt_ 1.0
Antenna/OmniAntenna set Gr_ 1.0
# Initialize the SharedMedia interface with parameters to make
# it work like the 914MHz Lucent WaveLAN DSSS radio interface
Phy/WirelessPhy set CPThresh_ 10.0
Phy/WirelessPhy set CSThresh_ 1.559e-11
Phy/WirelessPhy set RXThresh_ 3.652e-10
Phy/WirelessPhy set Rb_ 2*1e6
Phy/WirelessPhy set Pt_ 0.2818
Phy/WirelessPhy set freq_ 914e+6
Phy/WirelessPhy set L_ 1.0
# ======================================================================
proc usage { argv0 } {
puts "Usage: $argv0"
puts "\tmandatory arguments:"
puts "\t\t\[-x MAXX\] \[-y MAXY\]"
puts "\toptional arguments:"
puts "\t\t\[-cp conn pattern\] \[-sc scenario\] \[-nn nodes\]"
puts "\t\t\[-seed seed\] \[-stop sec\] \[-tr tracefile\]\n"
}
proc getopt {argc argv} {
global opt
lappend optlist cp nn seed sc stop tr x y
for {set i 0} {$i < $argc} {incr i} {
set arg [lindex $argv $i]
if {[string range $arg 0 0] != "-"} continue
set name [string range $arg 1 end]
set opt($name) [lindex $argv [expr $i+1]]
}
}
proc cmu-trace { ttype atype node } {
global ns_ tracefd
if { $tracefd == "" } {
return ""
}
set T [new CMUTrace/$ttype $atype]
$T target [$ns_ set nullAgent_]
$T attach $tracefd
$T set src_ [$node id]
$T node $node
return $T
}
proc create-god { nodes } {
global ns_ god_ tracefd
set god_ [new God]
$god_ num_nodes $nodes
}
proc log-movement {} {
global logtimer ns_ ns
set ns $ns_
source tcl/mobility/timer.tcl
Class LogTimer -superclass Timer
LogTimer instproc timeout {} {
global opt node_;
for {set i 0} {$i < $opt(nn)} {incr i} {
$node_($i) log-movement
}
$self sched 0.1
}
set logtimer [new LogTimer]
$logtimer sched 0.1
}
# ======================================================================
# Main Program
# ======================================================================
getopt $argc $argv
#
# Source External TCL Scripts
#
source tcl/lib/ns-mobilenode.tcl
#if { $opt(rp) != "" } {
source tcl/mobility/$opt(rp).tcl
#} elseif { [catch { set env(NS_PROTO_SCRIPT) } ] == 1 } {
#puts "\nenvironment variable NS_PROTO_SCRIPT not set!\n"
#exit
#} else {
#puts "\n*** using script $env(NS_PROTO_SCRIPT)\n\n";
#source $env(NS_PROTO_SCRIPT)
#}
source tcl/lib/ns-cmutrace.tcl
# do the get opt again incase the routing protocol file added some more
# options to look for
getopt $argc $argv
if { $opt(x) == 0 || $opt(y) == 0 } {
usage $argv0
exit 1
}
if {$opt(seed) > 0} {
puts "Seeding Random number generator with $opt(seed)\n"
ns-random $opt(seed)
}
#
# Initialize Global Variables
#
set ns_ [new Simulator]
set chan [new $opt(chan)]
set prop [new $opt(prop)]
set topo [new Topography]
# setup output trace file
#set tracefd [open $opt(rp).tr w]
#set tracefd [open leach.tr w]
set tracefd [open $opt(tr) w]
# try for setup output nam file
set nam_vystup [open $opt(rp).nam w]
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $nam_vystup $opt(x) $opt(y)
# end
$topo load_flatgrid $opt(x) $opt(y)
$prop topography $topo
#
# Create God
#
create-god $opt(nn)
$ns_ node-config -adhocRouting $opt(rp) \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
-channel $opt(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-wiredRouting OFF
#
# log the mobile nodes movements if desired
#
if { $opt(lm) == "on" } {
log-movement
}
#
# Create the specified number of nodes $opt(nn) and "attach" them
# the channel.
# Each routing protocol script is expected to have defined a proc
# create-mobile-node that builds a mobile node and inserts it into the
# array global $node_($i)
#
if { [string compare $opt(rp) "dsr"] == 0} {
for {set i 0} {$i < $opt(nn) } {incr i} {
dsr-create-mobile-node $i
}
} elseif { [string compare $opt(rp) "dsdv"] == 0} {
for {set i 0} {$i < $opt(nn) } {incr i} {
dsdv-create-mobile-node $i
}
} elseif { [string compare $opt(rp) "leach"] == 0} {
for {set i 0} {$i < $opt(nn) } {incr i} {
leach-create-mobile-node $i
}
} elseif { [string compare $opt(rp) "leach-c"] == 0} {
for {set i 0} {$i < $opt(nn) } {incr i} {
leach-create-mobile-node $i
}
} elseif { [string compare $opt(rp) "stat-clus"] == 0} {
for {set i 0} {$i < $opt(nn) } {incr i} {
leach-create-mobile-node $i
}
} elseif { [string compare $opt(rp) "mte"] == 0} {
for {set i 0} {$i < $opt(nn) } {incr i} {
leach-create-mobile-node $i
}
} elseif { [string compare $opt(rp) "pegasis"] == 0} {
for {set i 0} {$i < $opt(nn) } {incr i} {
leach-create-mobile-node $i
}
}
#
# Source the Connection and Movement scripts
#
if { $opt(cp) == "" } {
puts "*** NOTE: no connection pattern specified. - wireless.tcl"
set opt(cp) "none"
} else {
puts "Loading connection pattern...- wireless.tcl"
source $opt(cp)
}
#
# Tell all the nodes when the simulation ends
#
for {set i 0} {$i < $opt(nn) } {incr i} {
$ns_ at $opt(stop).000000001 "$node_($i) reset";
}
# original end $ns_ at $opt(stop).00000001 "puts \"NS EXITING...\" ; $ns_ halt"
# new end
$ns_ at $opt(stop).0001 "stop"
$ns_ at $opt(stop).000000002 "puts \"NS EXITING...\" ; $ns_ halt"
# Change for stop
proc stop {} {
global ns_ nam_vystup
$ns_ flush-trace
close $nam_vystup
exec nam out_aodv_big_auto.nam &
exit 0
}
# end of change
if { $opt(sc) == "" } {
puts "*** NOTE: no scenario file specified. - wireless.tcl"
set opt(sc) "none"
} else {
puts "Loading scenario file... - wireless.tcl"
source $opt(sc)
puts "Load complete... - wireless.tcl"
}
for {set i 0} {$i < $opt(nn)} {incr i} {
$ns_ initial_node_pos $node_($i) 6
}
puts $tracefd "M 0.0 nn $opt(nn) x $opt(x) y $opt(y) rp $opt(rp)"
puts $tracefd "M 0.0 sc $opt(sc) cp $opt(cp) seed $opt(seed)"
puts $tracefd "M 0.0 prop $opt(prop) ant $opt(ant)"
puts "Starting Simulation... - wireless.tcl"
$ns_ run
NS2的LEACH仿真出来的nam文件拓扑的节点为什么x=0,且y=0的更多相关文章
- 搭建Modelsim SE仿真环境-使用do文件仿真
本章我们介绍仿真环境搭建是基于Modelsim SE的.Modelsim有很多版本,比如说Modelsim-Altera,但是笔者还是建议大家使用Modelsim-SE,Modelsim-Altera ...
- Modelsim SE自动化仿真——如何将.do文件中自定义的库链接到testbench顶层模块
我们用Modelsim SE进行仿真时,为了方便,一般会编写.do文件来启动当前仿真.关于.do文件的编写,一般网上都有成型的模板,我们只要稍微改几个参数,就可以符合我们的仿真需求了.但是如果仿真时需 ...
- ios pod库更新到1.0或1.0.1之正确修改podfile文件
今天看到cocopods都更新到1.0.1了,之前什么时候更新到的1.0都没发现,刚刚更新一下之后,立马出现了一大堆的错误. 如果没有更新的话,建议不要更新!!!书写麻烦了! 现在记录如何一步一步去除 ...
- 节点文件将两个不同格式的XML文件,进行节点对照,并生成一个用于对照功能的XML
本文纯属个人见解,是对前面学习的总结,如有描述不正确的地方还请高手指正~ 经常有的需求是,需要将一种格式的XML转换成另一种XML.如果要实现这个功能首先需要将两个不同XML手动建立节点对比关系.然后 ...
- UNIX内核的文件数据结构 -- v 节点与 i 节点
龙泉居士:http://hi.baidu.com/zeyu203/item/cc89cfc0f36bfecc994aa07c 内核使用三种数据结构表示打开的文件(如图),他们之间的关系决定了在文件共享 ...
- C#程序中:如何删除xml文件中的节点、元素。
C#中动态的清理xml文件中的垃圾信息是程序员必会的哦.这就像数据库一样,不会清理数据怎么可以呢?其实xml文件就可以用作一个小的数据库,存储一些简单的信息.所以,用C#程序实现xml文件的增.删.改 ...
- C#程序中:如何修改xml文件中的节点(数据)
要想在web等程序中实现动态的数据内容给新(如网页中的Flash),不会更新xml文件中的节点(数据)是远远不够的,今天在这里说一个简单的xml文件的更新,方法比较基础,很适合初学者看的,保证一看就懂 ...
- chrome 和IE 上传的文件,在net 后台取值Request.Form.Files[0].FileName 的不同
chrome 和IE 上传的文件,在net 后台取值Request.Form.Files[0].FileName 的不同 chrome 获得的是不含路径的纯文件名 IE获得的是含路径的文件名
- 用webpack2.0构建vue2.0单文件组件超级详细精简实例
npm init -y 初始化项目 //-y 为自动生成package.json,如果需要自行配置,去掉-y即可 安装各种依赖项 npm install --save vue 安装vue2.0 np ...
随机推荐
- @Required 注解 ?
这个注解表明 bean 的属性必须在配置的时候设置,通过一个 bean 定义的显式的 属性值或通过自动装配,若@Required 注解的 bean 属性未被设置,容器将抛出 BeanInitializ ...
- ubuntu sublime text3 python 配置 sublime text3 python 配置
ubuntu sublime text3 python 配置 1.安装sublime text 3 安装过程非常简单,在terminal中输入: sudo add-apt-repository ...
- ubuntu 安装 mysql mariadb
本教程面向Ubuntu服务器,适用于Ubuntu的任何LTS版本,包括Ubuntu 14.04,Ubuntu 16.04,Ubuntu 18.04,甚至非LTS版本(如Ubuntu 17.10和其他基 ...
- html 常用标签及基本用法
一个网页基本是由 结构(html) + 样式(css) + 脚本(js) 组成.学习的话 应该从最基本的标签开始, 结构清晰了, 再用css美化, 最后可以用脚本加上特效 块级 和 行类标签 特点: ...
- Java/C++实现观察者模式--股票价格
当股票的价格上涨或下降5%时,会通知持有该股票的股民,当股民听到价格上涨的消息时会买股票,当价格下降时会大哭一场. 类图: Java代码: public class Investor implemen ...
- javaweb图书管理系统之不同用户跳转不同页面
关于分级自测题,我们知道该系统一共分为两个角色,一个是读者,一个是管理员,我们需要根据不同用户去到不同的页面,所以我们需要写一个登陆界面. 本文先写这个功能的实现,该功能主要在servlet里面实现. ...
- LazyCaptcha自定义随机验证码和字体
介绍 LazyCaptcha是仿EasyCaptcha和SimpleCaptcha,基于.Net Standard 2.1的图形验证码模块. 目前Gitee 52star, 如果对您有帮助,请不吝啬点 ...
- 手撕spring核心源码,彻底搞懂spring流程
引子 十几年前,刚工作不久的程序员还能过着很轻松的日子.记得那时候公司里有些开发和测试的女孩子,经常有问题解决不了的,不管什么领域的问题找到我,我都能帮她们解决.但是那时候我没有主动学习技术的意识,只 ...
- MyBatis 及 MyBatis Plus 纯注解方式配置(Spring Boot + Postgresql)
说明 当前的版本为 MyBatis 3.5.9 MyBatis Plus 3.5.1 Spring Boot 2.6.4 Postgresql 42.3.3 与 Spring Boot 结合使用 My ...
- C语言-操作符与表达式
C语言入门之操作符与表达式 前言 本篇文章主要包括各种操作符的介绍与表达式求值,欢迎各位小伙伴与我一起学习. 一.操作符 分类 算术操作符 移位操作符 位操作符 赋值操作符 单目运算符 关系操作符 逻 ...