Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Channel/WirelessChannel
set val(prop)
Propagation/TwoRayGround
set val(netif)
Phy/WirelessPhy
set val(mac)
Mac/802_11
set val(ifq)
Queue/DropTail/PriQueue
set val(ll)
LL
set val(ant)
Antenna/OmniAntenna
2000
set val(y)
2000
set val(ifqlen)
100
set val(seed)
0.0
;#random seed
set val(adhocRouting)
[routing protocol]
set val(nn)
[no. of nodes]
set val(cp)
set val(sc)
set val(stop)
[simulation duration]
;# simulation time
(b) After setting up the initial parameters, we now create the simulator objects
#---------------------------------------------------------------------#
[new Simulator]
[new Topography]
NOTE:
(i) GOD or General Operations Director is a ns-2 simulator object, which is used to store global information about
the state of the environment, network, or nodes that an omniscient observer would have, but that should not be made
known to any participant in the simulation.
(ii) The load_flatgrid object is used to specify a 2-D terrain. Support is available for simulation of 3D terrains for
more realistic depiction of scenarios.
(d) Attach the nodes to the channel and specify their movements
#
to the channel.
source $val(cp)
# Define traffic model
puts "Loading scenario file..."
source $val(sc)
# Define node initial position in nam
for {set i 0} {$i < $val(nn)} {incr i} {
# 50 defines the node size in nam, must adjust it according to your
scenario
Back Notes:
1) Pt_ is the antenna power, and it is used to set the distance,
for e.g.
Phy/WirelessPhy set Pt_ 7.214e-3
Top
Template
Top
Creating link
Simple Examples
Top
So far we are not talking about data flow. Here we will explain with CBR protocol.
Example1:( CBR over UDP)
set ns [new Simulator]
proc finish {}
{
global ns tracefile nf
$ns flush-trace
close $nf
close $tracefile
exec nam out.nam &
exit 0
}
'finish' procedure
Scheduling Events
- $ns at 1.0 start
and at 3.0 finish
$ns run
Result
Before 1.0ms
After 1.0ms
Top
proc finish {}
{
global ns tracefile nf
$ns flush-trace
close $nf
close $tracefile
exec nam out.nam &
exit 0
}
'finish' procedure
Scheduling Events
- $ns at 1.0 start
and at 3.0 finish
$ns run
Result:
Before 1.0ms
After 1.0ms
Top
proc finish {}
{
global ns tracefile nf
$ns flush-trace
close $nf
close $tracefile
exec nam out.nam &
exit 0
}
'finish' procedure
Scheduling Events
- $ns at 1.0 start
and at 3.0 finish
$ns run
Result:
Here we are using FTP Application agent as a traffic generator instead of CBR. The difference is CBR traffic
generator will produce constant bit rate where as FTP traffic generator produces maximum available bit rate.
We are writing code
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
After 1.0ms
# 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) 50 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 1000 ;# X dimension of topography
set val(y) 1000 ;# Y dimension of topography
set val(stop) 150 ;# time of simulation end
set ns [new Simulator]
close $namtrace
exec nam simwrls.nam &
}
$ns run
Tcl example]
set val(chan)
set val(prop)
set val(netif)
set val(mac)
set val(ifq)
set val(ll)
set val(ant)
set val(ifqlen)
this example will generate positions and transmission range for 100 nodes in
1900x1900m area in the file topology_100_1900.
$node_(0) set X_ 1267.6484042162301
$node_(0) set Y_ 47.771891694409724
$node_(0)
$node_(0)
$node_(1)
$node_(1)
$node_(1)
$node_(1)
set Z_
radius
set X_
set Y_
set Z_
radius
0.0
214.2403287413718
804.46613477750975
1733.0320414775199
0.0
204.81749854740571