[ns] How to change the number of sessions in AODV simulation

paul bollot paulbollot at gmail.com
Sat Mar 22 21:18:44 PDT 2008


Dear friends:

I'm trying to simulate AODV protocol with ns2, i got some problems.

First i tried to simulate a AODV protocol with a single session,  attaching
the UDP agent to two nodes ( 21 as a sender and 6 as a receiver), as you can
view in the tcl file.

 I would like to know how to change the number of sessions between sources
and destinations?

I would appreciate a lot your help or suggestion.

regards


# ======================================================================
# Define options
# ======================================================================
set val(ifqlen)         50                         ;# max packet in ifq
set val(nn)             50                          ;# number of mobilenodes
set val(rp)           AODV                ;# routing protocol
set val(chan)       Channel/WirelessChannel
set val(prop)       Propagation/TwoRayGround
set val(netif)      Phy/WirelessPhy
set val(mac)        Mac/802_11
set val(ifq)        Queue/DropTail/PriQueue
set val(ll)         LL
set val(ant)        Antenna/OmniAntenna
set val(stop)     100
#set val(cp)         "cbr-50-10-2"
set val(sc)             "scene-50n-50p-20M-100t-500-500"


#ns-random 0

# Initialize Global Variables
set ns_ [new Simulator]
set tracefd [open aodv.tr w]
$ns_ trace-all $tracefd

set namtrace [open aodv.nam w]
$ns_ namtrace-all-wireless $namtrace 500 500
proc stop {} {
    global ns_ tracefd namtrace
    $ns_ flush-trace
    close $tracefd
    close $namtrace
    exec nam aodv.nam & exit 0
}
# set up topography
set topo [new Topography]
$topo load_flatgrid 500 500

# Create God
set god_ [create-god $val(nn)]


# Create the specified number of mobilenodes [$val(nn)] and "attach" them
# to the channel.
# configure node
set channel [new Channel/WirelessChannel]
$channel set errorProbability_ 0.0

        $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 $channel \
    -topoInstance $topo \
    -agentTrace ON \
    -routerTrace ON\
    -macTrace OFF \
    -movementTrace OFF

 for {set i 0} {$i < $val(nn) } {incr i} {
  set node_($i) [$ns_ node]
  $node_($i) color red
  $node_($i) random-motion 0;
 }



# Define traffic model
#
puts "Loading scenario file..."
source $val(sc)
#
# Define node movement model
#
#puts "Loading connection pattern..."
#source $val(cp)
set udp_(0) [new Agent/UDP]
$ns_ attach-agent $node_(21) $udp_(0)
set null_(0) [new Agent/Null]
$ns_ attach-agent $node_(6) $null_(0)
set cbr_(0) [new Application/Traffic/CBR]
$cbr_(0) set packetSize_ 512
$cbr_(0) set interval_ 0.5
$cbr_(0) set random_ 1
$cbr_(0) set maxpkts_ 10000
$cbr_(0) attach-agent $udp_(0)
$ns_ connect $udp_(0) $null_(0)
$ns_ at 8.0 "$cbr_(0) start"
# Define node initial position in nam

#$ns_ color Blue 1
#udp_(0) set class_ 1

$ns_ at 2.0 "$node_(5) color Red"
$ns_ at 2.0 "$node_(1) color Red"
for {set i 0} {$i < $val(nn)} {incr i} {

    # 20 defines the node size in nam, must adjust it according to your
scenario
   # The function must be called after mobility model is defined

    $ns_ initial_node_pos $node_($i) 50
}

# Tell nodes when the simulation ends
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at $val(stop).0 "$node_($i) reset";
 }
$ns_ at $val(stop).0 "stop"
$ns_ at $val(stop).01 "puts \"NS EXITING...\" ; $ns_ halt"


puts "Starting Simulation..."
$ns_ run


More information about the Ns-users mailing list