AIM:
How to Install
1 copy ns2-allinone....tar.gz at some folder
/home/ns
2. Extract the tar file
"/tar -xzvf
ns-allinone2.1b8a.tar.gz“
3. Change the current directory to unzipped folder
“cd ns-allinone-2.1b8a“
4. write "./install" and enter
How to Configure
5. after installation set path for two
folders
1.
for ns folder --> "ns-2.1b8a"
2.
for nam folder --> "nam-1.0a10"
"gedit
.bash_profile" then write the following at the end of file
PATH=$PATH:$HOME/bin:/home/ns/ns-allinone-2.1b8a/ns-2.1b8a:
/home/ns/ns-allinone-2.1b8a/nam-1.0a10:
/home/ns/ns-allinone-2.1b8a/xgraph-12.1
export
PATH
6. Now verify the installation by running
verification script
“./validate”
How to How to run NS2 script
7. Write TCL script in *.tcl file by using
any
text editor like vi or gedit
8. Run your tcl script and generate .nam or
.tr files
"ns test.tcl" or “./ns test.tcl”
9. Run Network Animator
"nam out.nam" or “./nam out.nam”
Functionality of NS-2
Element of NS-2
•
Create
the event scheduler
•
Turn on
tracing
•
Create
network
•
Setup
routing
•
Insert
errors
•
Create
transport connection
•
Create
traffic
•
Transmit
application-level data
2)Create a script that simulates the simplest topology using NS-2 simulator.
Objectives:
- Get a basic
understanding of the way objectives interact in ns.
- Lay the
foundations for more complicated simulations.
Code:
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute nam on the trace file
exec nam –a out.nam&
exit 0
}
#Create two nodes
set n0 [$ns node]
set n1 [$ns node]
#Create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
#Call the finish procedure after 5 seconds of simulation
time
$ns at 5.0 "finish"
$ns run