2017-07-14 109 views
0

當我在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 

'

回答

0

EnergyModel:可能是‘NS-視覺,跟蹤分析儀’是由大量混淆的更多信息跟蹤文件。或者它不是要處理來自「EnergyModel」軌跡的複雜輸出。 NAM在兩種情況下表現出平等的傳播。也可以使用通常的awk和perl腳本進行分析。例如, 「數據包到達時間」 ....(1912線)

$ awk -f tess-Packets.awk twonodes.tr 
1.000000000 0 
1.004995421 0.00499542 
1.115411904 0 
1.115411904 0 
1.129437799 0.0140259 
1.143764325 0.0283524 
. 
. 
16.676762226 0.106707 
16.690768753 0.104122 
16.704875279 0.101976 
16.718961806 0.0998111 

「頂部20」 NS2 AWK腳本→awk-ns2-first.17.tar.gzhttps://drive.google.com/file/d/0B7S255p3kFXNUnRKbmhMdFNyQU0/view?usp=sharing

所有〜180 AWK,對NS2 Perl腳本:awk#perl#python__scripts-06.2017.tar.gzhttps://drive.google.com/file/d/0B7S255p3kFXNOW9HaHVoaHZzRWs/view?usp=sharing

其它仿真實例與EnergyModel:EnergyModel-examples.tar.gz https://drive.google.com/file/d/0B7S255p3kFXNRlZ2WWZmS09IdUk/view?usp=sharing

+0

增加了六個例子→EnergyModel-examples.tar.gz到答案。 –

0

這發生在我身上過了,我的能量值的禁止印刷解決它從C++到主要跟蹤文件。相反,我在cmu-trace.cc

if (thisnode) { 
     if (thisnode->energy_model()) { 
      // log detailed energy consumption 
      // total energy and breakdown in idle, sleep, transmit and receive modes 
      sprintf(pt_->buffer() + offset, 
       "[energy %f ei %.3f es %.3f et %.3f er %.3f] ", 
       thisnode->energy_model()->energy(), 
       thisnode->energy_model()->ei(), 
       thisnode->energy_model()->es(),    
       thisnode->energy_model()->et(), 
       thisnode->energy_model()->er());     
     } 
     } 

禁用sprintf函數打印能量值,以一個單獨的跟蹤文件