NAM中的无线Adhoc网络动画

时间:2017-01-19 15:28:37

标签: ns2 nam

我使用ns2模拟了一个adhoc网络,并生成了NAM跟踪文件。当我使用NAM打开此文件时,它通过编号的圆圈显示节点,但是当我播放动画时,没有任何反应。降低或提高速度也不会改变行为。

现在,问题是:如何让NAM在动画中显示节点之间的传输?

2 个答案:

答案 0 :(得分:0)

我认为这个问题是由于录制动画事件配置错误引起的。请尝试以下代码:

set val(chan)           Channel/WirelessChannel    ;# channel type
set val(prop)           Propagation/Nakagami       ;# 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)             5                      ;# number of mobilenodes
set val(rp)             AODV                       ;# routing protocol
set val(x)      200
set val(y)      200
# ======================================================================
# Main Program
# ======================================================================
set ns_     [new Simulator]
set tracefd     [open simple-udp.tr w]
$ns_ trace-all $tracefd

set namtrace [open simple-udp.nam w]
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
#########################################
# set up topography object
set topo       [new Topography]

$topo load_flatgrid $val(x) $val(y)

#
# Create God
#
create-god $val(nn)
# configure node

    $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) \
            -channelType $val(chan) \
            -topoInstance $topo \
            -agentTrace ON \
            -routerTrace ON \
            -macTrace ON \
            -movementTrace OFF\
            # -OutgoingErrProc UniformErr   
set node_(0) [$ns_ node]    
$node_(0) random-motion 0

set node_(1) [$ns_ node]    
$node_(1) random-motion 0

set node_(2) [$ns_ node]    
$node_(2) random-motion 0

set node_(3) [$ns_ node]    
$node_(3) random-motion 0

set node_(4) [$ns_ node]    
$node_(4) random-motion 0


#
# Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes
#

$node_(0) set X_ 0
$node_(0) set Y_ 0
$node_(0) set Z_ 0.0

$node_(1) set X_ 70
$node_(1) set Y_ 50
$node_(1) set Z_ 0.0

$node_(2) set X_ 70
$node_(2) set Y_ 0
$node_(2) set Z_ 0.0

$node_(3) set X_ 70
$node_(3) set Y_ -50
$node_(3) set Z_ 0.0

$node_(4) set X_ 400
$node_(4) set Y_ 0
$node_(4) set Z_ 0.0
for {set i 0} {$i < $val(nn)} {incr i} {
$ns_ initial_node_pos $node_($i) 30
}

#Setup first UDP connection
set udp [new Agent/UDP]
$ns_ attach-agent $node_(0) $udp
set null [new Agent/LossMonitor]
$ns_ attach-agent $node_(4) $null
$ns_ connect $udp $null
$udp set fid_ 5


#Setup first CBR over first UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 500
$cbr set rate_ 100kb
$cbr set random_ false
$ns_ at 0.0 "$cbr start"
$ns_ at 10.0 "$cbr stop"
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at 10.01 "$node_($i) reset";
}
$ns_ at 10.0 "stop"
$ns_ at 10.01 "puts \"NS EXITING...\" ; $ns_ halt"
proc stop {} {
    global ns_ tracefd namtrace
    $ns_ flush-trace
    close $tracefd
    close $namtrace
}

puts "Starting Simulation..."
$ns_ run

答案 1 :(得分:0)

尝试以下示例。
配置,Ubuntu 14,NS2版本。 2.35
要求,NS2应该可用。
将文件另存为test.tcl

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)     4                          ;# number of mobilenodes
set val(rp)     AODV                       ;# routing protocol
set val(x)      827                        ;# X dimension of topography
set val(y)      470                        ;# Y dimension of topography
set val(stop)   2.0                        ;# time of simulation end
# 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 trace file
set tracefile [open test.tr w]
$ns trace-all $tracefile
#Open the NAM 
set namfile [open test.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];
# node parameters
$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 ON
# Nodes definition        
set n0 [$ns node]
$n0 set X_ 199
$n0 set Y_ 200
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 349
$n1 set Y_ 364
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 590
$n2 set Y_ 370
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 727
$n3 set Y_ 172
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
# Agents - UDP 
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n3 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 0.0 "$cbr0 start"
$ns at 2.0 "$cbr0 stop"
proc finish {} {
    global ns tracefile namfile
    $ns flush-trace
    close $tracefile
    close $namfile
    exec nam test.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