Simulation of Wireless Environment Using NS-2:
# 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(ifqlen) 50 ;# max packet in ifq set val(nn) 3 ;# number of mobilenodes set val(rp) AODV ;# 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
#=====================================================================
# Main Program
#======================================================================
#
# Initialize Global Variables
#
# create simulator instance
set ns_ [new Simulator]
# setup topography object
set topo [new Topography]
# define topology
$topo load_flatgrid $val(x) $val(y)
# create trace object for ns and nam
set tracefd [open out.tr w]
$ns_ trace-all $tracefd
$ns_ use-newtrace
set namtrace [open out.nam w]
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
#
# Create God
#
set god_ [create-god $val(nn)]
#
# define how node should be created
#
# configure the nodes $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 \ -movementTrace ON for {set i 0} {$i < $val(nn) } { incr i } { set node_($i) [$ns_ node] }
# Provide initial location of mobilenodes $node_(0) set X_ 5.0 $node_(0) set Y_ 5.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 490.0 $node_(1) set Y_ 285.0 $node_(1) set Z_ 0.0 $node_(2) set X_ 150.0 $node_(2) set Y_ 240.0 $node_(2) set Z_ 0.0 # 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"
# Set a TCP connection between node_(0) and node_(1) set tcp [new Agent/TCP/Newreno] set sink [new Agent/TCPSink] $ns_ attach-agent $node_(0) $tcp $ns_ attach-agent $node_(1) $sink $ns_ connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp
#Application start & stop time
$ns_ at 60.0 "$ftp start"
$ns_ at 90.0 "$ftp stop"
# Define node initial position in nam
for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam $ns_ initial_node_pos $node_($i) 30 }
# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } { $ns_ at $val(stop) "$node_($i) reset"; } $ns_ run
# 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(ifqlen) 50 ;# max packet in ifq set val(nn) 3 ;# number of mobilenodes set val(rp) AODV ;# 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
#=====================================================================
# Main Program
#======================================================================
#
# Initialize Global Variables
#
# create simulator instance
set ns_ [new Simulator]
# setup topography object
set topo [new Topography]
# define topology
$topo load_flatgrid $val(x) $val(y)
# create trace object for ns and nam
set tracefd [open out.tr w]
$ns_ trace-all $tracefd
$ns_ use-newtrace
set namtrace [open out.nam w]
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
#
# Create God
#
set god_ [create-god $val(nn)]
#
# define how node should be created
#
# configure the nodes $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 \ -movementTrace ON for {set i 0} {$i < $val(nn) } { incr i } { set node_($i) [$ns_ node] }
# Provide initial location of mobilenodes $node_(0) set X_ 5.0 $node_(0) set Y_ 5.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 490.0 $node_(1) set Y_ 285.0 $node_(1) set Z_ 0.0 $node_(2) set X_ 150.0 $node_(2) set Y_ 240.0 $node_(2) set Z_ 0.0 # 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"
# Set a TCP connection between node_(0) and node_(1) set tcp [new Agent/TCP/Newreno] set sink [new Agent/TCPSink] $ns_ attach-agent $node_(0) $tcp $ns_ attach-agent $node_(1) $sink $ns_ connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp
#Application start & stop time
$ns_ at 60.0 "$ftp start"
$ns_ at 90.0 "$ftp stop"
# Define node initial position in nam
for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam $ns_ initial_node_pos $node_($i) 30 }
# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } { $ns_ at $val(stop) "$node_($i) reset"; } $ns_ run
0 comments:
Post a Comment