0

I've simulated an adhoc network using ns2, and generated NAM trace file. When I open this file using NAM, it shows nodes by numbered circles, but when I play the animation, nothing happens. Also reducing or increasing speed does not change the behavior.

Now, the question is: what can I do to make NAM display the transmissions between nodes in its animation?

Ahmad
  • 5,551
  • 8
  • 41
  • 57

2 Answers2

0

I think that this problem caused by misconfiguration of the recording animation event.Try this code :

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
Ali Parsa
  • 111
  • 5
  • I've done something like this and the script creates the .nam file, but when I open it in NAM, it shows nothing but nodes placed in their positions, and no transmissions are happening. – Ahmad Mar 23 '17 at 12:56
  • Not all ns2 protocols will support nam. ? Which protocol are you using ? ... About nam : The basic "nam commands" are shown here http://www.isi.edu/nsnam/ns/tutorial/nsscript1.html – Knud Larsen Mar 23 '17 at 21:13
  • I have edit my answer and insert a sample code of the ad hoc networks.Try above code and inform me about your result – Ali Parsa Mar 24 '17 at 06:30
0

Try this example.
Configuration, Ubuntu 14., NS2 ver. 2.35
Requirements, NS2 should be available.
Save the file as 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
matthias_h
  • 11,356
  • 9
  • 22
  • 40