set ns [new Simulator]
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 (ifqlen) 50 ;# max packet in ifq
set val (nn) 5 ;# number of mobilenodes
set val (rp) AODV ;# routing protocol
set val (x) 2200 ;# X dimension of topography
set val (y) 500 ;# Y dimension of topography
set val (stop) 150 ;# time of simulation end
set tracefd [open simple.tr w]
set windowVsTime2 [open win.tr w]
set tracefile1 [open out.tr w]
set winfile [open WinFile w]
$ns trace-all $tracefile1
$ns trace-all $tracefd
set namfile [open out.nam w]
$ns namtrace-all $namfile
set topo [new Topography]
top load_flatgrid $val(x) $val(y)
create-god $val(nn)
# 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 ON \
-movementTrace OFF
#Creating five mobile nodes
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns node]
#$node_($i) random-motion 0
}
#initial location of mobilenodes
for {set i 0} {$i < $val(nn)} {incr i} {
$node_($i) set X_[expr ($i+1)*200]
$node_($i) set Y_250.0
$node_($i) set Z_0.0
}
# Setting up a UDP connection between node_(0) and node_(4)
set udp [new Agent/UDP]Size
$ns attach-agent $node_(0) $udp
set null [new Agent/Null]
$ns attach-agent $node_(4) $null
$ns connect $udp $null
$udp set fid_ 2
#Setting up a CBR over UDP connection between nodes 0 and 4
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set packetSize_ 1000
$cbr set rate_ 0.01Mb
$cbr set random_ false
proc plotWindow {tcpSource file} {
global ns
set time 0.1
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file"
$ns at 1.1 "plotWindow $tcp $windowVsTime2"
}
#Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn)} {incr i} {
$ns at $val(stop) "$node_($i) reset";
}
$ns at $val(stop) "stop"
$ns at [expr $val(stop)+0.1] "puts \"End Simulation\"; $ns halt"
$ns at 0.1 "cbr start"
#$ns at 10.0 "$node_(0) setdest 45.0 285.0 5.0"
for {set i 0} {$i < $val(nn)} { incr i } {
$ns initial_node_pos $node_($i)
}
proc stop {} {
global ns tracefd
global ns tracefile1 namfile
$ns flush-trace
close $tracefile1
close $namfile
close $tracefd
exec nam out.nam &
exit ()
}
#$ns duplex-link $n0 $n2 2Mb 10ms DropTail
#$ns duplex-link $n1 $n2 2Mb 10ms DropTail
#$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
#$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
#$ns duplex-link $n3 $n4 0.5Mb 40ms DropTail
#$ns duplex-link $n3 $n5 0.5Mb 30ms DropTail
set lan [$ns new Lan "$node_(5)" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Cd Channel]
#$ns duplex-link-op $n0 $n2 orient right-down
#$ns duplex-link-op $n1 $n2 orient right-up
#$ns simplex-link-op $n2 $n3 orient right
#$ns simplex-link-op $n3 $n2 orient left
#$ns duplex-link-op $n3 $n4 orient right-up
#$ns duplex-link-op $n3 $n5 orient right-down
#$ns queue-limit $n2 $n3 20
#$ns at 124.5 "cbr stop"
#$ns at 125.0 "finish"
$ns run
Bookmarks