Basically NS 2 programming
contains the following steps.
1.Create the event scheduler2.Turn on tracing
3.Creating network
a) Computing setup routing - rtproto
b) Creating transport connection-Agents
c) Creating traffic-Applications
4. Monitoring
a) Visualization using nam
Note: every tcl script must write in small letters only except protocol agents i.e. TCP, FTP,UDP
Example
Every ns2 script starts with creating simulator objectset ns [new Simulator]
How to create node
set n0 [$ns node]
set n1 [$ns node]
Creating link
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
This line tells the simulator object to connect the nodes n0 and n1 with a duplex link with the bandwidth.1Megabit, a delay of 10ms and a DropTail queue.
· How
to use Trace?
We use simulator to see results. How is it achieved? Using trace
Two types of trace
1. generic trace
for use with xgraph, and other things
2. nam trace
for use with visualization
# open trace file
set tracefile [open out.tr w]
$ns trace-all $tracefile
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
Since we have started tracing, we should end also. For this we use finish procedure.
We use simulator to see results. How is it achieved? Using trace
Two types of trace
1. generic trace
for use with xgraph, and other things
2. nam trace
for use with visualization
# open trace file
set tracefile [open out.tr w]
$ns trace-all $tracefile
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
Since we have started tracing, we should end also. For this we use finish procedure.
#Define a
'finish' procedure
proc finish {}
{
global ns tracefile nf
$ns flush-trace
close $nf
close $tracefile # close tracefile
exec nam out.nam & #Execute nam on the trace file
exit 0
}
proc finish {}
{
global ns tracefile nf
$ns flush-trace
close $nf
close $tracefile # close tracefile
exec nam out.nam & #Execute nam on the trace file
exit 0
}
Finish procedure is forced to be called at the end with the line
$ns at 5.0 “finish”
$ns at 5.0 “finish”
Every tcl script
must contain following statement
$ns run
$ns run
No comments:
Post a Comment