You are on page 1of 5

2012

NS2 Installation GUIDE


on Ubuntu 10.04 LTS

Raheel Memon
System Software Laboratory
Myongji University, Yongin-si, South Korea

Step 1:
Download the ns2 software from <Link: http://www.isi.edu/nsnam/ns/ns-build.html>
I am using version ns-allinone-2.35 you may get the zip folder.
Step2:
Place the downloaded folder in /home/username folder. And unzip it. In my case I am using this
location: /home/raheel/ns-allinone-2.35
$
$
$
$

cd /home/raheel/Downloads
cp ./ns-allinone2.35 /home/raheel
cd ..
tar xvzf ns-allinone2.35

Step3:
Install dependencies
$ sudo apt-get install build-essential autoconf automake libxmu-dev gcc-4.3
Step4:
Now, change the compiler type to gcc-4.3. Open the Terminal and change the directory to nsallinone2.35
$cd /home/raheel/ns-allinone-2.35/otcl-1.13
$gedit Makefile.in
Find the following line in code:
CC= @CC@
Comment this line using # sign
#CC= @CC@
And write a new line below that line
CC= gcc-4.3
Step5:
Start installation
Change the directory to (root user #)
# cd /home/raheel/ns-allinone-2.35
#. /install
Note: root user #
Step6:
At the end of installation you will get an IMPRTANT NOTICE that you must put some paths to your
environment variables

So to add that information, edit ~/.bashrc file


$ gedit ~/.bashrc
And copy the below given information to the bashrc file at the end.
#*************************PATH SETTING FOR NS2 (V2.34)*****************#
# LD_LIBRARY_PATH
OTCL_LIB=/home/raheel/ns-allinone-2.35/otcl-1.13
NS2_LIB=/home/raheel/ns-allinone-2.35/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB
#TCL_LIBRARY
TCL_LIB=/home/raheel/ns-allinone-2.35/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
#PATH
XGRAPH=/home/raheel/ns-allinone-2.35/bin:/home/raheel/ns-allinone2.35/tcl8.4.18/unix:/home/raheel/ns-allinone-2.35/tk8.4.18/unix
#NOTE:The above two lines starting from XGRAPH should same in the same line
NS=/home/raheel/ns-allinone-2.35/ns-2.34/
NAM=/home/raheel/ns-allinone-2.35/nam-1.14/
PATH=$PATH:$XGRAPH:$NS:$NAM

NOTE: replace user name with your user name in path variables.
Congratulations you have successfully completed the installation of NS2 in ubuntu.

Check the installation if its successful:


Type:
$ns
It will bring % sign type exit to quit. And then check then nam
$nam
It will bring the nam window
This all means that installation is successful.

Simple Example:
set ns [new Simulator]

Creatingns simulator object

set tracefile [open out.tr w]


$ns trace-all $tracefile

Open trace file

set nf [open out.nam w]


$ns namtrace-all $nf

Open the nam trace file

proc finish {}
{
global ns tracefile nf
$ns flush-trace
close $nf
close $tracefile
exec nam out.nam &
exit 0
}

'finish' procedure

set n0 [$ns node]


set n1 [$ns node]
$ns simplex-link $n0 $n1 1Mb 10ms DropTail

Create your topology


- set n0 nodes.
- $ns duplex-links

set udp0 [new Agent/UDP]


$ns attach-agent $n0 $udp0
set cbr[new Application/Traffic/CBR]
$cbr attach-agent $udp0
set null0 [new Agent/Null]
$ns attach-agent $n1 $null0
$ns connect $udp0 $null0

Create your agents


-transport layer and application layers stuff

$ns at 1.0 "$cbr start"


$ns at 3.0 "finish"

Scheduling Events
- $ns at 1.0 start
and at 3.0 finish

$ns run

Save in file example1.tcl. Run using ns


$ns example1.tcl

References:
1. http://www.isi.edu/nsnam/ns/ns-build.html
2. Introduction to Network Simulator NS2 by Teerawat Issariyakul , Ekram Hossain
3. http://www.anand-iyer.com/blog/?p=22
4. http://csis.bits-pilani.ac.in/faculty/murali/resources/tutorials/ns2.htm

You might also like