Sei sulla pagina 1di 4

Wireless Simulation Scenario and CBR Traffic Generation in NS-2.

xx Scenario Generation:
Instead of specifying and control each nodes' position and movement pattern, we can use a
CMU tool "Setdest" to generate large number of nodes and their movements. The tool uses a
random waypoint model.
Setdest:
Setdest tool is used to generate the positions of nodes and their moving speed and moving
directions. There are two versions for setdest. Version 2 is most recently implemented and used.
Version 1:
The signature is:
setdest -v 1 -n $numnodes -p $pt -M $maxspeed -t $simtime -x $maxx -y $maxy
For example: setdest -v 1 -n 50 -p 0 -M 20 -t 900 -x 1500 -y 300
This will generate a 1500*300 topology with 50 nodes random distributed labeled by a
XY(Z) coordinates. (Note that, there is a bug in the README file, which gives a wrong option
for specifying the speed, we should use "-M" instead of "-s").
After the initial position information, the nodes are specified with their movement destination
and speed.
Version 2:
The signature is:
setdest -v <2> -n <nodes> -s <speed type> -m <min speed> -M <max speed> -t <simulation
time> -P <pause type> -p <pause time> -x <max X> -y <max Y>
Where,

-v version number; Here 2

-n number of nodes. Generated node number will be 0 to (n-1)

-s speed type (uniform, normal); s=1 uniform speed from min to max; s=2 normal speed
clipped from min to max.

-m minimum speed > 0 .

-M maximum speed

-P pause type (constant, uniform); P=1 constant pause; P=2 uniform pause [0, 2*p]

-p pause time (a median if uniform is chosen)

-x x dimension of space

-y y dimension of space

After running the command a scenario will be generated. Pipe the scenario in file
For Example:
setdest -v 2 -n 10 -m 10 -M 100 -t 20 -P 1 -p 10 -x 200 -y 400 > scen-exp1
CBR Traffic Generation
Cbrgen:
This is done with the help of cbrgen.tcl file executing with ns command. Open terminal in ~nsallinone-2.31/ns-2.31/indep-utils/cmu-scen-gen .
The signature is:
ns cbrgen.tcl [-type cbr|tcp] [-nn nodes] [-seed seed] [-mc connections] [-rate rate]
Where,

-type traffic type (tcp, udp/cbr)

-nn the highest node number(node number will be 0 to nn)

-seed seed for random variable generation which is used to create random number of
source-destination pair

-mc maximum number of connections; i.e.; source-destination pair.

-rate it is the inverse of the interval between packet transmission & should be <0

After running the command a Cbr traffic will be generated. Pipe the traffic in file.
For Example :
ns cbrgen.tcl -type cbr -nn 9 -seed 1 -mc 10 -rate .25 > cbr-exp1
For Further Explanation: Go through the source code ~ns-allinone-2.31/ns-2.31/indep-utils/cmuscen-gen/cbrgen.tcl
How to generate random traffic between nodes?
In Ns-2 directory the following file exists:
(...../ns-2.33/indep-utils/cmu-scen-gen/cbrgen.tcl)
This file generates CBR and TCL traffic, usually people uses CBR connections
for testing.
Example of using :
# ns cbrgen.tcl -type cbr -nn 100 -seed 0.0001 -mc 50 -rate 4.0
>traffic/cbr_50mc

This command will generate 50 CBR connection randomly chosen form 100
nodes , default packet size 512 Byte with rate 4.0 packets per second.
Seed is the random variable seed.

The default send time is between 0-180sec so if you want to change, you
have to change it in the code.
Advice: keep a Backup for the original file and make a note for yourself and
record any small change you make in any file.
> this symbol to pip the output to a file.

Example from traffic file:


# 4 connecting to 2 at time 232.83468593509622
#
set udp_(0) [new Agent/UDP]
$ns_ attach-agent $node_(4) $udp_(0)
set null_(0) [new Agent/Null]
$ns_ attach-agent $node_(2) $null_(0)
set cbr_(0) [new Application/Traffic/CBR]
$cbr_(0) set packetSize_ 512
$cbr_(0) set interval_ 0.25
$cbr_(0) set random_ 1
$cbr_(0) set maxpkts_ 10000
$cbr_(0) attach-agent $udp_(0)
$ns_ connect $udp_(0) $null_(0)
$ns_ at 232.83468593509622 "$cbr_(0) start"

How to generate motion?


Simple random motion: in the TCL file use this command
$node_($i) random-motion 1 (0 means disable the random motion)
Motion according to Random way point (used in many papers but also
some papers argue its not realistic)
In directory: .../ns-2.33/indep-utils/cmu-scen-gen/setdest use the command
setdest Example:
#./setdest -v 2 -n 3 -s 1 -m 1 -M 20 -t 900 -P 1 -p 0 -x 1900
-y 1900>/motion/motion_20_P0.

This command will generate motion file describe 3 nodes movement in


1900x1900m area, -m is the minimum speed (DONOT MAKE it 0), -p is the
pause time. If the simulation time is 900sec, and you make the pause time
= 900 so no motion =0 means high mobility. So some research use it as a
testing parameter 0, 100, 200, ......... to see the effect of mobility. -s and
-P is the speed type (uniform, or normal) and pause time type (constant,
uniform) respectively.
For more details in same directory check setdist.cc its comments are nice.
Example of output
$node_(0) set X_ 1744.228508719134
$node_(0) set Y_ 325.212204443323
$node_(0) set Z_ 0.000000000000
$node_(1) set X_ 553.858741769246
$node_(1) set Y_ 1698.232341355720
$node_(1) set Z_ 0.000000000000
$node_(2) set X_ 165.302585853016
$node_(2) set Y_ 1622.769709056266
$node_(2) set Z_ 0.000000000000
$ns_ at 0.000000000000 "$node_(0) setdest 457.106263185410
1777.141193962975 1.535010722532"
$ns_ at 0.000000000000 "$node_(1) setdest 997.470612282373
758.477350362411 10.958303861163"
$ns_ at 0.000000000000 "$node_(2) setdest 956.347404075847
1088.748901630699 7.328960216470"
1 [setdest newX newY speed]

Potrebbero piacerti anche