#SoftwareEngineer #SalesforceDeveloper #RubyonRails #Music

Installing Network Simulator 2 in Ubuntu

Are you baffled by random errands saying “  ns2 doesn’t work on ubuntu “ and so ?

Are you a linux geek don’t wanna boot to windows for network simulator software ?

did your lab admin made a mess with your system in the name of installing ns2 :D ?

_then you are in a right place :) _

You can make NS working in your system by putting little effort  on your ubuntu :)

Step 1:

Download network simulator software from here

if you prefer other old versions you can swich by viewing files in that page

the file will be of almost 57 MB

**Step 2: **

Extract the files to your own desired directory

I did in **/home/karthik/Desktop/ **

step 3:

now go to your working directory of ns2 by

cd /home/karthik/Desktop/ns-allinone-2.34

step 4:

Run this command to check any unresolved dependencies existing between installation

sudo apt-get install build-essential autoconf automake libxmu-dev

run the command ./install in terminal

it will take around 5 minutes

step 5:

Well Thats were your installation of ns2 exits :)

now you have to configure to make it alive

you have to edit in the shell

run gedit ~./bashrc

add at end of the file this lines

remember change  /home/karthik/Desktop/ **to your file path say **/home/host-name/

** **

# LD_LIBRARY_PATH OTCL_LIB=/home/karthik/Desktop/ns-allinone-2.34/otcl-1.13 NS2_LIB=/home/karthik/Desktop/ns-allinone-2.34/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/karthik/Desktop/ns-allinone-2.34/tcl8.4.18/library USR_LIB=/usr/lib export TCL_LIBRARY=$TCL_LIB:$USR_LIB

# PATH XGRAPH=/home/karthik/Desktop/ns-allinone-2.34/bin: /home/karthik/Desktop/ ns-allinone-2.34/tcl8.4.18/unix : /home/karthik/Desktop/ns-allinone-2.34/tk8.4.18/unix NS=/home/karthik/Desktop/ns-allinone-2.34/ns-2.34/ NAM=/home/karthik/Desktop/ns-allinone-2.34/nam-1.14/ PATH=$PATH:$XGRAPH:$NS:$NAM

now save the file and close it

run** source ~/.bashrc**

ignore if any errors ;)

then run** ./validate**

this is the longest step it takes 30-45 minutes hence you can have a meal during the course of time ;)

**step 6: **

this  is editing thing ( optional )

just make  links to the files in /home/karthik/Desktop/ns-allinone-2.34/bin ** by right click on all files and choose **make link

copy  all and paste to **/usr/bin/ **directory  by running

sudo nautilus

then** rename** the file name for eg) link to ns ** to **ns and so on . do this till all files are renamed .

**step 7: **

Sample code

now u can check out a demo to test you ns 2 by writing a sample code as below :

#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 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”

#Run the simulation $ns run

now copy this code and paste to a file say  myfirstprogram.tcl

then run ns myfirstprogram.tcl

you must see a window like this :

my ubuntu screen running NS2

and  …   You did it , Enjoy   :)