leach分析1

来源:互联网 发布:winrar软件破解版 编辑:程序博客网 时间:2024/06/06 06:44

        首先对wireless.tcl进行分析,先对默认的脚本选项进行初始化:

set opt(chan)Channel/WirelessChannel
set opt(prop) Propagation/TwoRayGround
set opt(netif)Phy/WirelessPhy
set opt(mac) Mac/802_11
set opt(ifq) Queue/DropTail/PriQueue
set opt(ll) LL
set opt(ant)          Antenna/OmniAntenna
set opt(x) 0      ;# X dimension of the topography
set opt(y) 0 ;# Y dimension of the topography
set opt(cp) ""
set opt(sc) "../mobility/scene/scen-670x670-50-600-20-2" ;# scenario file

set opt(ifqlen)50;# max packet in if
set opt(nn) 51 ;# number of nodes
set opt(seed) 0.0
set opt(stop) 10.0 ;# simulation time
set opt(tr) out.tr ;# trace file
set opt(rp)            dsdv            ;# routing protocol script
set opt(lm)        "on"           ;# log movement

在这个wireless.tcl中设置了一些全局变量:

#
# Initialize Global Variables
#
set ns_ [new Simulator]
set chan         [new $opt(chan)]
set prop         [new $opt(prop)]
set topo         [new Topography]
set tracefd [open $opt(tr) w]
$topo load_flatgrid $opt(x) $opt(y)
$prop topography $topo

这些初始化将在后面的使用中用到,该文件最重要的是创建leach节点:创建方法如下:

} elseif { [string compare $opt(rp) "leach"] == 0} { 
for {set i 0} {$i < $opt(nn) } {incr i} {
leach-create-mobile-node $i
}

如果路由协议是leach协议,则在Uamps.tcl中调用leach-create-mobile-node方法创建leach节点。将在第二小节讲如何创建leach节点。

for {set i 0} {$i < $opt(nn) } {incr i} {
   
    $ns_ at $opt(stop).000000001 "$node_($i) reset"; //完成后,重置节点的应用
}
$ns_ at $opt(stop).00000001 "puts \"NS EXITING...\" ; $ns_ halt"
if { $opt(sc) == "" } {
puts "*** NOTE: no scenario file specified."
        set opt(sc) "none"
} else {
puts "Loading scenario file..."
source $opt(sc)
puts "Load complete..."
}

ns在什么时候结束simulation,并告诉ns加载sc场景文件。

最后$ns_  run则ns就开始运行了。