Trail 4
Trail 4
Trail 4
# <http://wushoupong.googlepages.com/nsg>
#===================================
# Simulation parameters setup
#===================================
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/SMAC ;# 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) 4 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 1049 ;# X dimension of topography
set val(y) 597 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end
#for energy
set opt(energymodel) EnergyModel ;
#set opt(energymodel) RadioModel ;
set opt(radiomodel) RadioModel ;
set opt(initialenergy) 1000 ;# Initial energy in Joules
#set opt(logenergy) "on" ;# log energy every 150 seconds
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
create-god $val(nn)
#===================================
# Nodes Definition
#===================================
#Create 4 nodes
set n0 [$ns node]
$n0 set X_ 499
$n0 set Y_ 497
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 649
$n1 set Y_ 497
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 799
$n2 set Y_ 497
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 949
$n3 set Y_ 497
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n3 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over UDP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $udp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run