Escolar Documentos
Profissional Documentos
Cultura Documentos
=====================================================================
======================================================================
Main Program
======================================================================
#
# Initialize Global Variables
#
set ns [new Simulator]
set
$ns
set
$ns
f [open four.tr w]
trace-all $f
nf [open four.nam w]
namtrace-all-wireless $nf 670 670
-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) random-motion 0
;# disable random motion
}
#
#
# Define node movement model
#
puts "Loading connection pattern..."
#
# Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes
#
$node_(0) set X_ 5.0
$node_(0) set Y_ 2.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 390.0
$node_(1) set Y_ 385.0
$node_(1) set Z_ 0.0
#
# Now produce some simple node movements
# Node_(1) starts to move towards node_(0)
#
$ns at 50.0 "$node_(1) setdest 45.0 40.0 45.0"
# Define node initial position in nam
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) 40
}
set udp0 [new Agent/UDP]
$ns attach-agent $node_(0) $udp0
array set dbans {
"how are you" "fine"
"Are you there" "yes"
"hi" "Thanks"
"" "Not Found"
}
set udp1 [new Agent/UDP]
$ns attach-agent $node_(1) $udp1
$ns connect $udp0 $udp1
#
#
#
#
#
#
#
#
you to send packets of whatever size you need in your simulation without
actually generating a string of that length. Also, note that the length
you specify must not be larger than the maximum UDP packet size (the default
is 1000 bytes)
if the send procedure is called without a second argument (e.g. "send 100")
then a packet of the specified length (or multiple packets, if the number
is too high) will be sent, but without any data. In that case, process_data
will not be called at the receiver.
#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
$ns at 150.0 "$node_($i) reset";
}
$ns at 150.0 "stop"
$ns at 150.01 "puts \"NS EXITING...\" ; $ns halt"
proc stop {} {
global ns f nf
$ns flush-trace
close $f
close $nf
}
puts "Starting Simulation..."
$ns run