Doc1 - Merged (1) - Merged
Doc1 - Merged (1) - Merged
# 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) CMUPriQueue ;# 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) 3 ;# number of
mobilenodes
set val(rp) DSR ;# routing protocol
set val(x) 500 ;# X dimension of
topography
set val(y) 400 ;# Y dimension of
topography
set val(stop) 150 ;# time of simulation end
create-god $val(nn)
#
# Create nn mobilenodes [$val(nn)] and attach them to the channel.
#
# Generation of movements
$ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"
$ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"
$ns at 110.0 "$node_(0) setdest 480.0 300.0 5.0"
$ns run
#Create a simulator object
set ns [new Simulator]
#Schedule events for the CBR agent and the network dynamics
$ns at 0.5 "$cbr0 start"
$ns rtmodel-at 1.0 down $n(1) $n(2)
$ns rtmodel-at 2.0 up $n(1) $n(2)
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
#####################################################################
################http://www.ns2blogger.blogspot.in/###################
#####################################################################
# ======================================================================
# Define options
# ======================================================================
set f1 [open s1 a]
set f2 [open s2 a]
set f3 [open s3 a]
set f4 [open s4 a]
# define topology
$topo load_flatgrid $opt(x) $opt(y)
# create God
create-god $opt(nn)
#-=-=-=-NAM=-=-=-=--=-=-=-=-=-=-=-=-=---=-=---=-=-=-=-=
#set ns_ [new Simulator]
set f0 [open wir7.tr w]
$ns_ trace-all $f0
$ns_ use-newtrace
set namtrace [open out.nam w]
$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)
#=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#create wired nodes
proc stop {} {
global ns_ tracefd namtrace opt f0
global ns_ f1 f2 f3 f4 tcp1 tcp2 tcp3 tcp4 mbw1 mbw2 mbw3 mbw4 rate size
global sink
$ns_ flush-trace
close $tracefd
close $f0
close $namtrace
#received bytes
set bw1 [$tcp1 set ndatabytes_]
set bw2 [$tcp2 set ndatabytes_]
set bw3 [$tcp3 set ndatabytes_]
set bw4 [$tcp4 set ndatabytes_]
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail MAC/802_3
Channel]
# PPP