當我在NS-Visual-Trace-Analyzer中打開一個.tr文件時,它顯示所有的統計數據和圖形結果。但是,當我將能量模型添加到同一網絡的節點時,Visual-Trace-Analyzer顯示沒有發送或接收數據包(沒有任何事件)。如何使用Visual Trace Analyzer分析由ns2生成的跟蹤文件?
這是Tcl腳本來我努力..
`# This script is created by NSG2 beta1
#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 2 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 968 ;# X dimension of topography
set val(y) 450 ;# Y dimension of topography
set val(stop) 20.0 ;# time of simulation end
set opt(energymodel) EnergyModel ;
set opt(initialenergy) 30 ;
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#Setup topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)
#Open the NS trace file
set tracefile [open twonodes.tr w]
$ns trace-all $tracefile
#Open the NAM trace file
set namfile [open twonodes.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel
#===================================
# Mobile node parameter setup
#===================================
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON\
-movementTrace OFF \
-energyModel $opt(energymodel) \
-idlePower 1.0 \
-rxPower 1.0 \
-txPower 2.0 \
-sleepPower 0.001 \
-transitionPower 0.2 \
-transitionTime 0.005 \
-initialEnergy $opt(initialenergy)
$ns set WirelessNewTrace_ ON
#===================================
# Nodes Definition
#===================================
#Create 2 nodes
set n0 [$ns node]
$n0 set X_ 383
$n0 set Y_ 309
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 568
$n1 set Y_ 350
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
#===================================
# Generate movement
#================================
#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set tcp2 [new Agent/TCP]
$ns attach-agent $n0 $tcp2
set sink3 [new Agent/TCPSink]
$ns attach-agent $n1 $sink3
$ns connect $tcp2 $sink3
$tcp2 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $tcp2
$cbr1 set packetSize_ 1000
$cbr1 set rate_ 1.0Mb
$cbr1 set random_
$ns at 1.0 "$cbr1 start"
$ns at 20.0 "$cbr1 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam twonodes.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
'
增加了六個例子→EnergyModel-examples.tar.gz到答案。 –