Simulation Examples

Add to Favourites
Post to:

Description
NS2 simulation examples!

TCl Scripts steps
Nam Animation

Comments
Presentation Transcript Presentation Transcript

Simulation Example : Simulation Example V. Vasantha M.E., Senior Lecturer, Dept. Of Information Technology, National Engineering College, K. R. Nagar, Kovilpatti. vivekvasantha2gmail.com

A Simulation Example : 1/31/2011 V. Vasantha, National Engineering College, Kovilpatti 2 A Simulation Example

TCL Script Step 1 : 1/31/2011 V. Vasantha, National Engineering College, Kovilpatti 3 TCL Script Step 1 #Create a simulator object set ns [new Simulator]   #Open the NAM trace file set nf [open out.nam w] $ns namtrace-all $nf #Open the general trace file Set f [open out.tr w] $ns trace-all $f # has denotes a one line commentns holds the name of the new simulation

TCL Script Step 2 : 1/31/2011 V. Vasantha, National Engineering College, Kovilpatti 4 TCL Script Step 2 #Create four nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node]   #Create links between the nodes $ns duplex-link $n0 $n2 2Mb 10ms DropTail $ns duplex-link $n1 $n2 2Mb 10ms DropTail $ns duplex-link $n2 $n3 1.7Mb 20ms DropTail

TCL Script Step 3 : 1/31/2011 V. Vasantha, National Engineering College, Kovilpatti 5 TCL Script Step 3 #Set Queue Size of link (n2-n3) to 10 $ns queue-limit $n2 $n3 10   #Setup a TCP connection set tcp [new Agent/TCP] $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n3 $sink $ns connect $tcp $sink   #Setup a FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp

TCL Script Step 4 : 1/31/2011 V. Vasantha, National Engineering College, Kovilpatti 6 TCL Script Step 4 #Setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $n1 $udp set null [new Agent/Null] $ns attach-agent $n3 $null $ns connect $udp $null   #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set packet_size_ 1000 $cbr set rate_ 1mb

TCL Script Step 5 : 1/31/2011 V. Vasantha, National Engineering College, Kovilpatti 7 TCL Script Step 5 #Schedule events for the CBR and FTP agents $ns at 0.1 "$cbr start" $ns at 1.0 "$ftp start" $ns at 4.0 "$ftp stop" $ns at 4.5 "$cbr stop"   #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish"

TCL Script Step 6 : 1/31/2011 V. Vasantha, National Engineering College, Kovilpatti 8 TCL Script Step 6 #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace #Close the NAM trace file close $nf #Execute NAM on the trace file exec nam out.nam & exit 0 }   #Run the simulation $ns run

Slide 9 : 1/31/2011 V. Vasantha, National Engineering College, Kovilpatti 9 Observe your output in NAM!

Want to learn?

Sign up and browse through relevant courses.

Name:
Your Email:
Password:
Country:
Contact no:


Area code Number
Subjects you are interested in:
Word verification: (Enter the text as in image)


Sign Up Already a member? Sign In
I agree to WizIQ's User Agreement & Privacy Policy
Vasantha Vivek
Professor
User
27 Followers

Your Facebook Friends on WizIQ

Give live classes, create & sell online courses

Try it free Plans & Pricing

Connect