Dear all,

 

Does anyone have successful experience in using MAC/Simple for wireless ad
hoc simulation? I wrote the following script to run simulation. When I set
the MAC type as MAC/802_11, the simulation ran just fine. But when I set the
MAC type as MAC/Simple, segmentation fault was reported. And if I change the
number of source nodes to one, the simulation can also success even using
MAC/Simple. Does anyone try MAC/Simple before? Can anyone tell me if there
is something wrong with my script or there is bug in NS2?  I am using
NS2.29. Thank you in advance!!

 

Kai Bai 

 

 

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/Simple                 ;# 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)             51                          ;# number of mobilenodes

set val(rp)             DSR                       ;# routing protocol

set val(x)            400

set val(y)            420

 

 

puts "This is a sensor network simulation by kai."

# Initialize Global Variables

set ns_              [new Simulator]

set tracefd     [open relib.tr w]

$ns_ use-newtrace 

$ns_ trace-all $tracefd

 

set namtrace [open relib.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)

 

# New API to config node: 

# 1. Create channel (or multiple-channels);

# 2. Specify channel in node-config (instead of channelType);

# 3. Create nodes for simulations.

 

# Create channel #1 and #2

set chan_1_ [new $val(chan)]

set chan_2_ [new $val(chan)]

 

# Create node(0) "attached" to channel #1

 

# configure node, please note the change below.

$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) \

                   -topoInstance $topo \

                   -agentTrace OFF \

                   -routerTrace OFF \

                   -macTrace ON \

                   -movementTrace OFF \

                   -channel $chan_1_ 

 

set cols [expr floor(sqrt($val(nn)-1))]

set rows [expr ceil(($val(nn)-1)/$cols)]

set colinterval [expr floor($val(x)/($cols-1)) - 1]

set rowinterval [expr floor(($val(y)-20)/($rows-1)) - 1]

 

# 8.5872e-4,For 40m transmission range. 

# 7.214e-3 for 100m transmission range

Phy/WirelessPhy set Pt_ 7.214e-3

 

 

for {set i 0} {$i < $val(nn) } {incr i} {

     set node_($i) [$ns_ node]   

     $node_($i) random-motion 0

    }

 

for {set i 0} {$i < $val(nn) } {incr i} {

         $ns_ initial_node_pos $node_($i) 20

}

 

#

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

#

#calculate node position

set colnum 1

set rownum 1

set cols [expr int($cols)]

set rows [expr int($rows)]

for {set i 0} {$i < [expr $val(nn)-1]} {incr i} {

  if {$colnum > $cols} {

    set colnum 1

    set rownum [expr $rownum+1]

  }

 

  if {$colnum == 1} {

    set xpos($i) 1

  } else {

    set xpos($i) [expr $xpos([expr $i - 1]) + $colinterval]

  }

  if {$rownum == 1} {

    set ypos($i) 1

  } else {

    set ypos($i) [expr $ypos([expr $i - $cols]) + $rowinterval]

  }

  

  set colnum [expr $colnum+1]

}

 

for {set i 0} {$i < [expr $val(nn)-1]} {incr i} {

  $node_($i) set X_ $xpos($i)

  $node_($i) set Y_ $ypos($i)

}

 

#setup the sink position

$node_([expr $val(nn)-1]) set X_ [expr $val(x)/2]

$node_([expr $val(nn)-1]) set Y_ [expr $val(y)-10]

$node_([expr $val(nn)-1]) set Z_ 0.0

$ns_ at 0.01 "$node_([expr $val(nn)-1]) setdest [expr $val(x)/2] [expr
$val(y)-10] 15.0"

 

# assume stationary networks

for {set i 0} {$i < [expr $val(nn)-1]} {incr i} {

  $ns_ at 0.01 "$node_($i) setdest $xpos($i) $ypos($i) 15.0"

}

 

 

 

 

# Setup traffic flow between nodes

# TCP connections between node_(0) and node_(1)

 

set sink_0 [new Agent/Null]

 

$ns_ attach-agent $node_([expr $val(nn)-1]) $sink_0

for {set i 0} {$i < [expr $val(nn)-1]} {incr i} {

  set src0_($i) [new Agent/UDP]

  $ns_ attach-agent $node_($i) $src0_($i)

  $ns_ connect $src0_($i) $sink_0

}

 

 

set cbr_0 [new Application/Traffic/CBR]

$cbr_0 set packetSize_ 30

$cbr_0 set interval_ 1.0

$cbr_0 attach-agent $src0_(2)

 

set cbr_2 [new Application/Traffic/CBR]

$cbr_2 set packetSize_ 30

$cbr_2 set interval_ 1.0

$cbr_2 attach-agent $src0_(4)

 

$ns_ at 0.5 "$cbr_0 start"

$ns_ at 2.5 "$cbr_2 start"

 

#

# Tell nodes when the simulation ends

#

for {set i 0} {$i < $val(nn) } {incr i} {

    $ns_ at 100.0 "$node_($i) reset";

}

$ns_ at 100.0 "stop"

$ns_ at 100.01 "puts \"NS EXITING...\" ; $ns_ halt"

proc stop {} {

    global ns_ tracefd

    $ns_ flush-trace

    close $tracefd

}

 

puts "Starting Simulation..."

$ns_ run

Reply via email to