如何使用Visual Trace Analyzer分析ns2生成的跟踪文件?

时间:2017-07-14 05:05:08

标签: ns2

当我在NS-Visual-Trace-Analyzer中打开.tr文件时,它会显示所有统计信息和图形结果。但是,当我将能量模型添加到同一网络的节点时,Visual-Trace-Analyzer显示没有发送或接收的数据包(不是任何事件)。

这是我正在尝试的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

&#39;

2 个答案:

答案 0 :(得分:0)

EnergyModel:可能是NS-Visual-Trace-Analyzer&#39;被跟踪文件中的更多信息搞糊涂了。或者它并不意味着处理来自&#34; EnergyModel&#34;的复杂输出。跟踪。 NAM在两种情况下显示相同的传输。也可以使用通常的awk和perl脚本进行分析。例如,&#34;数据包到达时间&#34; ....(1,912行)

$ 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

&#34;前20&#34; ns2 awk脚本→awk-ns2-first.17.tar.gz https://drive.google.com/file/d/0B7S255p3kFXNUnRKbmhMdFNyQU0/view?usp=sharing

所有~180 awk,ns2的perl脚本:awk#perl#python__scripts-06.2017.tar.gz https://drive.google.com/file/d/0B7S255p3kFXNOW9HaHVoaHZzRWs/view?usp=sharing

使用EnergyModel的其他模拟示例:EnergyModel-examples.tar.gz https://drive.google.com/file/d/0B7S255p3kFXNRlZ2WWZmS09IdUk/view?usp=sharing

答案 1 :(得分:0)

这也发生在我身上,我通过禁用从c ++到主跟踪文件的能量值打印来解决它。相反,我将能量值打印到单独的跟踪文件

in 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功能。