[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] Simulating Ad-hoc networks on 2.1b8



Hi:

  I'm a beginner trying to simulate ad-hoc networks. I'm using the 2.1b8
version of ns (all-in-one) on a PC  running Red Hat 7.0, I also tried to
run the scripts on SunOS 5.8 machines.
 The problem is that when I use NAM I can see the nodes but they don't
move.  On the previous versions of ns the script was running fine.

  Could you please help me with these questions:

  1) Can this version of NAM support node mobility? I mean, was I supposed
     to run my ad hoc scripts without any problem (i.e. watch the nodes
     moving)?

  2) Do you have a really small sample script (2 nodes) that you know is
     working for v 2.1b8 that you can  email me? I have tried 
     the ones that come with the all-in-one and one posted previously in
     this mailing list without success.
 
  3) while running nam I get lots of this error :

Unexpected end of line in: + -t 19.289389561 -s 0 -d 2 -p tcp -e 1028 -c 2
-a 0 -i 7475 -k RTR 
Perhaps you have extra spaces at the end of the line.
Last parsed attribute flag was -k


 Thankx,

 Marco


************************ THIS IS THE SCRIPT
********************************


# ======================================================================
# Define options
# ======================================================================
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(x)              500  ;# X dimension of the topography
set val(y)              500   ;# Y dimension of the topography
set val(ifqlen)         50                         ;# max packet in ifq
set val(nn)             5                         ;# number of mobilenodes
set val(rp)             DSR                       ;# routing protocol

# ======================================================================
# Main Program
# ======================================================================


#
# Initialize Global Variables
#
set ns_         [new Simulator]

# set up topography object
set topo       [new Topography]

# create trace object for ns and nam

set tracefd     [open simple-wireless-out.tr w]
set namtrace    [open simple-wireless-out.nam w]

$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)

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

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

#
#  Create the specified number of mobilenodes [$val(nn)] and "attach" them
#  to the channel. 
#  Here two nodes are created : node(0) and node(1)

# 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 OFF \
                                        
                         
        for {set i 0} {$i < $val(nn) } {incr i} {
                set node_($i) [$ns_ node]       
                $node_($i) random-motion 0              ;# disable random
motion
        }

#
# Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes
#
$node_(0) set X_ 5.0
$node_(0) set Y_ 499.0
$node_(0) set Z_ 0.0

$node_(1) set X_ 499.0
$node_(1) set Y_ 499.0
$node_(1) set Z_ 0.0

$node_(2) set X_ 200.0
$node_(2) set Y_ 1.0
$node_(2) set Z_ 0.0

$node_(3) set X_ 10.0
$node_(3) set Y_ 1.0
$node_(3) set Z_ 0.0

$node_(4) set X_ 10.0
$node_(4) set Y_ 50.0
$node_(4) set Z_ 0.0

#
# Now produce some simple node movements
# Node_(1) starts to move towards node_(0)
#
$ns_ at 1.0 "$node_(0) setdest 50.0 499.0 30.0"
$ns_ at 3.0 "$node_(1) setdest 200.0 499.0 100.0"
$ns_ at 0.5 "$node_(2) setdest 100.0 499.0 50.0"
$ns_ at 0.5 "$node_(3) setdest 100.0 1.0 50.0"
$ns_ at 0.5 "$node_(4) setdest 250.0 499.0 50.0"

 
# Setup traffic flow between nodes

set tcp1 [new Agent/TCP]
set tcp2 [new Agent/TCP]
set tcp3 [new Agent/TCP]
set tcp4 [new Agent/TCP]

set sink1 [new Agent/TCPSink]
set sink2 [new Agent/TCPSink]
set sink3 [new Agent/TCPSink]
set sink4 [new Agent/TCPSink]

$ns_ attach-agent $node_(0) $tcp1
$ns_ attach-agent $node_(0) $tcp2
$ns_ attach-agent $node_(0) $tcp3
$ns_ attach-agent $node_(3) $tcp4

$ns_ attach-agent $node_(1) $sink1
$ns_ attach-agent $node_(2) $sink2
$ns_ attach-agent $node_(3) $sink3
$ns_ attach-agent $node_(4) $sink4

$ns_ connect $tcp1 $sink1
$ns_ connect $tcp2 $sink2
$ns_ connect $tcp3 $sink3
$ns_ connect $tcp4 $sink4

set ftp1 [new Application/FTP]
set ftp2 [new Application/FTP]
set ftp3 [new Application/FTP]
set ftp4 [new Application/FTP]

$ftp1 attach-agent $tcp1
$ftp2 attach-agent $tcp2
$ftp3 attach-agent $tcp3
$ftp4 attach-agent $tcp4

$ns_ at 1.0 "$ns_ trace-annotate \"trial!!\""

$ns_ at 1 "$ftp1 start" 
$ns_ at 2 "$ftp2 start"
$ns_ at 3 "$ftp3 start"
$ns_ at 4 "$ftp4 start"

# Define node initial position in nam

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

    # 30 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) 30
}


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

proc stop {} {
    global ns_ tracefd
    $ns_ flush-trace
    close $tracefd
    exec nam simple-wireless-out &
        exit 0
}

puts "Starting Simulation..."
$ns_ run