Hi,

I am looking at some simple simulations of ad-hoc routing protocols. I
was playing with the wired-cum-wireless example that come with ns-2,
but they don't seem to play very well with AODV.

I have put a traffic sink on the base station node and am using the
CBR traffic source to generate traffic. However, with AODV I just get
route errors - it never seems to be able to discover the route. Using
the same .tcl script but changing the routing protocol to DSDV the
simulation works and I can see traffic flows.

If I change the traffic sink so that it is another wireless node, then
everything seems to work fine. So I am guessing there is something
'strange' with my base station config...

Is anyone able to help me, please?

I am using ns-2.29. My script is as follows:


# ======================================================================
# Define options
# ======================================================================
set opt(chan)           Channel/WirelessChannel         ;# channel type
set opt(prop)           Propagation/TwoRayGround        ;#
radio-propagation model
set opt(netif)          Phy/WirelessPhy                 ;# network
interface type
set opt(mac)            Mac/802_11                      ;# MAC type
set opt(ifq)            Queue/DropTail/PriQueue         ;# interface queue type
set opt(ll)             LL                              ;# link layer type
set opt(ant)            Antenna/OmniAntenna             ;# antenna model
set opt(ifqlen)         50                              ;# max packet in ifq
set opt(nn)             3                               ;# number of mobilenodes
set opt(adhocRouting)   AODV                            ;# routing protocol

set opt(cp)             ""                              ;# connection
pattern file
set opt(sc)             "scenario/scenario.txt"         ;# node movement file.

set opt(x)              670                             ;# x
coordinate of topology
set opt(y)              670                             ;# y
coordinate of topology
set opt(seed)           0.0                             ;# seed for
random number gen.
set opt(stop)           300                             ;# time to
stop simulation

set opt(ftp1-start)     0.0
set opt(ftp2-start)     0.0

set num_wired_nodes     2
set num_bs_nodes        1

# ============================================================================
# check for boundary parameters and random seed
if { $opt(x) == 0 || $opt(y) == 0 } {
      puts "No X-Y boundary values given for wireless topology\n"
}

if {$opt(seed) > 0} {
      puts "Seeding Random number generator with $opt(seed)\n"
      ns-random $opt(seed)
}

# create simulator instance
set ns_   [new Simulator]

# set up for hierarchical routing
$ns_ node-config -addressType hierarchical
AddrParams set domain_num_ 2           ;# number of domains
lappend cluster_num 2 1                ;# number of clusters in each domain
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 1 1 4              ;# number of nodes in each cluster
AddrParams set nodes_num_ $eilastlevel ;# of each domain

set tracefd  [open simple_01_aodv.tr w]
set namtrace [open simple_01_aodv.nam w]
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)

set f0 [open sink_1_data_aodv.tr w]
set f1 [open sink_2_data_aodv.tr w]

# Create topography object
set topo   [new Topography]

# define topology
$topo load_flatgrid $opt(x) $opt(y)

# create God
create-god [expr $opt(nn) + $num_bs_nodes]

#create wired nodes
set temp {0.0.0 0.1.0}        ;# hierarchical addresses for wired domain
for {set i 0} {$i < $num_wired_nodes} {incr i} {
  set W($i) [$ns_ node [lindex $temp $i]]
}

# configure for base-station node
$ns_ node-config -adhocRouting $opt(adhocRouting) \
               -llType $opt(ll) \
               -macType $opt(mac) \
               -ifqType $opt(ifq) \
               -ifqLen $opt(ifqlen) \
               -antType $opt(ant) \
               -propType $opt(prop) \
               -phyType $opt(netif) \
               -channelType $opt(chan) \
               -topoInstance $topo \
               -wiredRouting ON \
               -agentTrace ON \
               -routerTrace ON \
               -macTrace ON \
               -movementTrace ON

#create base-station node
set temp {1.0.0 1.0.1 1.0.2 1.0.3}   ;# hier address to be used for wireless
                                   ;# domain
set BS(0) [$ns_ node [lindex $temp 0]]
$BS(0) random-motion 0               ;# disable random motion

#provide some co-ord (fixed) to base station node
$BS(0) set X_ 100.0
$BS(0) set Y_ 200.0
$BS(0) set Z_ 0.0

# create mobilenodes in the same domain as BS(0)
# note the position and movement of mobilenodes is as defined
# in $opt(sc)

#configure for mobilenodes
$ns_ node-config -wiredRouting OFF

for {set j 0} {$j < $opt(nn)} {incr j} {
  set node_($j) [ $ns_ node [lindex $temp [expr $j+1]] ]
  $node_($j) base-station [AddrParams addr2id [$BS(0) node-addr]]
}

#create links between wired and BS nodes

$ns_ duplex-link $W(0) $W(1) 5Mb 2ms DropTail
$ns_ duplex-link $W(1) $BS(0) 5Mb 2ms DropTail

$ns_ duplex-link-op $W(0) $W(1) orient down
$ns_ duplex-link-op $W(1) $BS(0) orient left-down

# ##########################################################################
# SETUP AND ATTACH AN EXPOO TRAFFIC SOURCE
# ##########################################################################
proc attach-expoo-traffic { node sink size burst idle rate } {
      #Get an instance of the simulator
      set ns [Simulator instance]

      #Create a UDP agent and attach it to the node
      set source [new Agent/UDP]
      $ns attach-agent $node $source

      #Create an Expoo traffic agent and set its configuration parameters
      set traffic [new Application/Traffic/Exponential]
      $traffic set packetSize_ $size
      $traffic set burst_time_ $burst
      $traffic set idle_time_ $idle
      $traffic set rate_ $rate

      # Attach traffic source to the traffic generator
      $traffic attach-agent $source
      #Connect the source and the sink
      $ns connect $source $sink
      return $traffic
}
# ##########################################################################

set sink1 [new Agent/LossMonitor]
set sink2 [new Agent/LossMonitor]
$ns_ attach-agent $node_(0) $sink1
$ns_ attach-agent $BS(0) $sink2

set source0 [attach-expoo-traffic $W(1) $sink1 200 2s 1s 100k]
set source1 [attach-expoo-traffic $node_(1) $sink2 200 2s 1s 200k]

# ##########################################################################
# RECORD THE AMOUNT OF DATA RECEIVED AT EACH DATA SINK
# ##########################################################################
proc record {} {
      global sink1 sink2 f0 f1

      #Get an instance of the simulator
      set ns [Simulator instance]

      #Set the time after which the procedure should be called again
      set time 0.5

      #How many bytes have been received by the traffic sinks?
      set bw0 [$sink1 set bytes_]
      set bw1 [$sink2 set bytes_]

      #Get the current time
      set now [$ns now]

      #Calculate the bandwidth (in MBit/s) and write it to the files
      puts $f0 "$now [expr $bw0/$time*8/1000000]"
      puts $f1 "$now [expr $bw1/$time*8/1000000]"

      #Reset the bytes_ values on the traffic sinks
      $sink1 set bytes_ 0
      $sink2 set bytes_ 0

      #Re-schedule the procedure
      $ns at [expr $now + $time] "record"
}

# ##########################################################################

# source connection-pattern and node-movement scripts
if { $opt(cp) == "" } {
      puts "*** NOTE: no connection pattern specified."
      set opt(cp) "none"
} else {
      puts "Loading connection pattern..."
      source $opt(cp)
}

if { $opt(sc) == "" } {
      puts "*** NOTE: no scenario file specified."
      set opt(sc) "none"
} else {
      puts "Loading scenario file..."
      source $opt(sc)
      puts "Load complete..."
}

# Define initial node position in nam

for {set i 0} {$i < $opt(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) 20
}

# Tell all nodes when the simulation ends
for {set i } {$i < $opt(nn) } {incr i} {
  $ns_ at $opt(stop).0 "$node_($i) reset";
}
$ns_ at $opt(stop).0 "$BS(0) reset";
$ns_ at 0.0 "record"
$ns_ at 10.0 "$source0 start"
$ns_ at 10.0 "$source1 start"
$ns_ at $opt(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"
$ns_ at $opt(stop).0001 "stop"

# ##########################################################################
# CALLED WHEN THE SIMULATION IS STOPPED.
# ##########################################################################
proc stop {} {
  global ns_ tracefd namtrace
#    $ns_ flush-trace
  close $tracefd
  close $namtrace
}
# ##########################################################################

puts "Starting Simulation..."
$ns_ run






Thanks,



Richard

Reply via email to