Home > NS-2 > How to Install NS-2 in Ubuntu

How to Install NS-2 in Ubuntu

I presume that you already know what NS-2 is. I am gonna skip the details, and show you the steps that you need to follow for NS2 installation.

Download NS-allinone-2.35 from here. And, unzip your contents to your desired location. For example:

tar -zxvf ns-allinone-2.35.tar.gz -C /home/your_user_accnt

Before you install NS-2, please install some essential packages:

sudo apt-get install tcl8.5-dev tk8.5-dev

sudo apt-get install gcc-4.4 g++-4.4

sudo apt-get install build-essential autoconf automake

sudo apt-get install perl xgraph libxt-dev libx11-dev libxmu-dev

Open OTcl make file and change CC = @CC@ to CC=gcc-4.4, and save it. i.e.

gedit /home/your_user_accnt/ns-allinone-2.35/otcl-1.14/Makefile.in

Remove  CC = @CC@ and paste CC=gcc-4.4

You are now ready to install your ns-2.

cd /home/your_user_accnt/ns-allinone-2.35

./install

Now, you need to set some environmental variables to your hidden bashrc file.

gedit ~/.bashrc

Go to the end of the file and append the following lines :

#LD_LIBRARY_PATH

OTCL_LIB=/home/your_user_accnt/ns-allinone-2.35/otcl-1.14

NS2_LIB=/home/your_user_accnt/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/your_user_accnt/ns-allinone-2.35/tcl8.5.10/library

USR_LIB=/usr/lib

export TCL_LIBRARY=$TCL_LIB:$USR_LIB

# PATH

XGRAPH=/home/your_user_accnt/ns-allinone-2.35/bin:/home/your_user_accnt/ns-allinone-2.35/tcl8.5.10/unix:/home/your_user_accnt/ns-allinone-2.35/tk8.5.10/unix

NS=/home/your_user_accnt/ns-allinone-2.35/ns-2.35/

NAM=/home/your_user_accnt/ns-allinone-2.34/nam-1.15/

PATH=$PATH:$XGRAPH:$NS:$NAM

Save, close and reload the bashrc file.

source ~/.bashrc

If you have completed all the steps successfully, then you should be able to run NS-2. Try the following to see :

cd /home/your_user_accnt/ns-allinone-2.35/ns-2.35/tcl/ex

ns simple.tcl

Make sure, you replace your_user_accnt with your user name.

Cheers.


					
Advertisements
Categories: NS-2 Tags: , , , ,
  1. hicham
    March 10, 2013 at 3:28 pm

    Hi,
    I follow your instruction but when I exectu ns simple.tcl
    it tell me to install ns2 with : sudo apt-get install ns2
    and when I re-execut ns simple.tcl
    the answer : running nam…
    ns: finish: couldn’t execute “nam”: no such file or directory
    while executing
    “exec nam out.nam &”
    (procedure “finish” line 8)
    invoked from within
    “finish”
    where is the problem do you have any idea why ?
    thank you for your support

    • March 11, 2013 at 9:01 pm

      maybe, you forgot to set environmental variables to your hidden bashrc file, or you forgot to reload that bashrc file. Please follow the steps where you have to set environmental variables, and make sure you replace your_user_accnt by your user name.

      • hicham
        March 11, 2013 at 9:09 pm

        yeah ! I checked but it was correct it was missing nam install so I did it and it works very well ” sudo apt-get install nam ”
        thank you so much for support !
        by the way to you have any idea how we install Vanet or a traffic generator on NS2 2.35
        have a nice day Mr.Safiqul !

  2. March 12, 2013 at 12:52 pm

    Glad to hear :). Read the NS-Manual first, and you may also read Introduction to NS-2 Simulator.

    Have a Nice day 🙂

  3. Swati
    April 20, 2013 at 11:33 am

    Thanks a lot,it helped me to get out of mess of 6 hours.
    Can we simulate wireless networks in NS2?

  4. Swati
    April 20, 2013 at 11:37 am

    One more question why u didn’t use ./validate.
    Will it be better to use that too also or no need of that??

    • April 24, 2013 at 1:09 pm

      Hi, I think I used ./validate to validate my installed NS-2. You should try to validate your installed ns-2, and it will take a long time till it completely validates the system !

  5. Shafaru Mukail
    May 23, 2013 at 5:37 pm

    shafaru@shafaru-HP-Pavilion-g6-Notebook-PC:~/ns-allinone-2.34/ns-2.34$ ns test.tcl
    shafaru@shafaru-HP-Pavilion-g6-Notebook-PC:~/ns-allinone-2.34/ns-2.34$ Cannot connect to existing nam instance. Starting a new one…

    nam: Unable to open the file “–a.nam”

    • June 1, 2013 at 6:57 pm

      Sorry for the late response. I didn’t get your problem. Try exec nam out.nam & instead of exec nam -a …..

  6. janmejay
    May 28, 2013 at 4:32 pm

    sir,when i run the command ns simple.tcl
    it gives as ns command not found

    • June 1, 2013 at 6:54 pm

      You need to set the environmental variables to your hidden bashrc file. Also, Replace you_user_acct with your user name.

  7. Felix Fong
    July 27, 2013 at 8:07 am

    running nam…
    ns: finish: couldn’t execute “nam”: no such file or directory
    while executing
    “exec nam out.nam &”
    (procedure “finish” line 8)
    invoked from within
    “finish”

    May I know is this a problem??

  8. S MALAA
    September 25, 2013 at 3:27 pm

    i give this ‘sudo apt-get install update’

    it shows like this in terminal :

    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package update

    wt can i do?
    it means
    plz tell me quickly

  9. S MALAA
    September 25, 2013 at 5:06 pm

    if i type the command ns i got ‘%’ and the sample program also run successfully

    but while validating the result is ‘some test failed’
    wt can i do
    plz tell me quickly.

    • September 25, 2013 at 7:03 pm

      Maybe you haven’t installed all the required packages. Try the following:

      apt-get install libx11-dev xorg-dev libxmu-dev libperl4-corelibs-perl

  10. infotech
    November 10, 2013 at 4:23 am

    Is the procedure same for installation of NS2.34 ? instead of otcl-1.14/Makefile.in i have otcl-1.13/Makefile.in
    I need to install ns2.34 version only for my project,could you please help ?

  11. Riana
    November 23, 2013 at 10:43 am

    can you please help me with delay calculation awk files for satellite links? trace file is:

    + 1.0000 66 26 cbr 210 ——- 0 66.0 67.0 0 0 37.90 -122.30 48.90 -120.94
    – 1.0000 66 26 cbr 210 ——- 0 66.0 67.0 0 0 37.90 -122.30 48.90 -120.94
    r 1.0063 66 26 cbr 210 ——- 0 66.0 67.0 0 0 37.90 -122.30 48.90 -120.94
    + 1.0063 26 37 cbr 210 ——- 0 66.0 67.0 0 0 48.90 -120.94 32.60 -87.51
    – 1.0063 26 37 cbr 210 ——- 0 66.0 67.0 0 0 48.90 -120.94 32.60 -87.51
    r 1.0186 26 37 cbr 210 ——- 0 66.0 67.0 0 0 48.90 -120.94 32.60 -87.51
    + 1.0186 37 48 cbr 210 ——- 0 66.0 67.0 0 0 32.60 -87.51 48.90 -57.74
    – 1.0186 37 48 cbr 210 ——- 0 66.0 67.0 0 0 32.60 -87.51 48.90 -57.74
    r 1.0300 37 48 cbr 210 ——- 0 66.0 67.0 0 0 32.60 -87.51 48.90 -57.74
    + 1.0300 48 67 cbr 210 ——- 0 66.0 67.0 0 0 48.90 -57.74 42.30 -71.10
    – 1.0300 48 67 cbr 210 ——- 0 66.0 67.0 0 0 48.90 -57.74 42.30 -71.10
    r 1.0364 48 67 cbr 210 ——- 0 66.0 67.0 0 0 48.90 -57.74 42.30 -71.10
    + 61.0100 66 26 cbr 210 ——- 0 66.0 67.0 1 1 37.90 -122.30 45.33 -120.70
    – 61.0100 66 26 cbr 210 ——- 0 66.0 67.0 1 1 37.90 -122.30 45.33 -120.70
    r 61.0151 66 26 cbr 210 ——- 0 66.0 67.0 1 1 37.90 -122.30 45.33 -120.70
    + 61.0151 26 37 cbr 210 ——- 0 66.0 67.0 1 1 45.33 -120.70 29.02 -87.46
    – 61.0151 26 37 cbr 210 ——- 0 66.0 67.0 1 1 45.33 -120.70 29.02 -87.46
    r 61.0279 26 37 cbr 210 ——- 0 66.0 67.0 1 1 45.33 -120.70 29.02 -87.46
    + 61.0279 37 48 cbr 210 ——- 0 66.0 67.0 1 1 29.02 -87.46 45.33 -57.50
    – 61.0279 37 48 cbr 210 ——- 0 66.0 67.0 1 1 29.02 -87.46 45.33 -57.50
    r 61.0398 37 48 cbr 210 ——- 0 66.0 67.0 1 1 29.02 -87.46 45.33 -57.50
    + 61.0398 48 67 cbr 210 ——- 0 66.0 67.0 1 1 45.33 -57.50 42.30 -71.10
    – 61.0398 48 67 cbr 210 ——- 0 66.0 67.0 1 1 45.33 -57.50 42.30 -71.10
    r 61.0458 48 67 cbr 210 ——- 0 66.0 67.0 1 1 45.33 -57.50 42.30 -71.10
    + 121.0200 66 26 cbr 210 ——- 0 66.0 67.0 2 2 37.90 -122.30 41.76 -120.53
    – 121.0200 66 26 cbr 210 ——- 0 66.0 67.0 2 2 37.90 -122.30 41.76 -120.53
    r 121.0243 66 26 cbr 210 ——- 0 66.0 67.0 2 2 37.90 -122.30 41.76 -120.53
    + 121.0243 26 37 cbr 210 ——- 0 66.0 67.0 2 2 41.76 -120.53 25.45 -87.42
    – 121.0243 26 37 cbr 210 ——- 0 66.0 67.0 2 2 41.76 -120.53 25.45 -87.42
    r 121.0374 26 37 cbr 210 ——- 0 66.0 67.0 2 2 41.76 -120.53 25.45 -87.42
    + 121.0374 37 48 cbr 210 ——- 0 66.0 67.0 2 2 25.45 -87.42 41.76 -57.33
    – 121.0374 37 48 cbr 210 ——- 0 66.0 67.0 2 2 25.45 -87.42 41.76 -57.33
    r 121.0497 37 48 cbr 210 ——- 0 66.0 67.0 2 2 25.45 -87.42 41.76 -57.33
    + 121.0497 48 67 cbr 210 ——- 0 66.0 67.0 2 2 41.76 -57.33 42.30 -71.10
    – 121.0497 48 67 cbr 210 ——- 0 66.0 67.0 2 2 41.76 -57.33 42.30 -71.10
    r 121.0557 48 67 cbr 210 ——- 0 66.0 67.0 2 2 41.76 -57.33 42.30 -71.10
    + 181.0300 66 26 cbr 210 ——- 0 66.0 67.0 3 3 37.90 -122.30 38.19 -120.39
    – 181.0300 66 26 cbr 210 ——- 0 66.0 67.0 3 3 37.90 -122.30 38.19 -120.39
    r 181.0339 66 26 cbr 210 ——- 0 66.0 67.0 3 3 37.90 -122.30 38.19 -120.39
    + 181.0339 26 37 cbr 210 ——- 0 66.0 67.0 3 3 38.19 -120.39 21.87 -87.40
    – 181.0339 26 37 cbr 210 ——- 0 66.0 67.0 3 3 38.19 -120.39 21.87 -87.40
    r 181.0474 26 37 cbr 210 ——- 0 66.0 67.0 3 3 38.19 -120.39 21.87 -87.40
    + 181.0474 37 48 cbr 210 ——- 0 66.0 67.0 3 3 21.87 -87.40 38.19 -57.19
    – 181.0474 37 48 cbr 210 ——- 0 66.0 67.0 3 3 21.87 -87.40 38.19 -57.19
    r 181.0600 37 48 cbr 210 ——- 0 66.0 67.0 3 3 21.87 -87.40 38.19 -57.19
    + 181.0600 48 67 cbr 210 ——- 0 66.0 67.0 3 3 38.19 -57.19 42.30 -71.10
    – 181.0600 48 67 cbr 210 ——- 0 66.0 67.0 3 3 38.19 -57.19 42.30 -71.10
    r 181.0664 48 67 cbr 210 ——- 0 66.0 67.0 3 3 38.19 -57.19 42.30 -71.10
    + 241.0400 66 26 cbr 210 ——- 0 66.0 67.0 4 4 37.90 -122.30 34.61 -120.30
    – 241.0400 66 26 cbr 210 ——- 0 66.0 67.0 4 4 37.90 -122.30 34.61 -120.30
    r 241.0442 66 26 cbr 210 ——- 0 66.0 67.0 4 4 37.90 -122.30 34.61 -120.30
    + 241.0442 26 37 cbr 210 ——- 0 66.0 67.0 4 4 34.61 -120.30 18.29 -87.40
    – 241.0442 26 37 cbr 210 ——- 0 66.0 67.0 4 4 34.61 -120.30 18.29 -87.40
    r 241.0580 26 37 cbr 210 ——- 0 66.0 67.0 4 4 34.61 -120.30 18.29 -87.40
    + 241.0580 37 48 cbr 210 ——- 0 66.0 67.0 4 4 18.29 -87.40 34.61 -57.10
    – 241.0580 37 48 cbr 210 ——- 0 66.0 67.0 4 4 18.29 -87.40 34.61 -57.10
    r 241.0710 37 48 cbr 210 ——- 0 66.0 67.0 4 4 18.29 -87.40 34.61 -57.10
    + 241.0710 48 67 cbr 210 ——- 0 66.0 67.0 4 4 34.61 -57.10 42.30 -71.10
    – 241.0710 48 67 cbr 210 ——- 0 66.0 67.0 4 4 34.61 -57.10 42.30 -71.10
    r 241.0781 48 67 cbr 210 ——- 0 66.0 67.0 4 4 34.61 -57.10 42.30 -71.10
    + 301.0500 66 26 cbr 210 ——- 0 66.0 67.0 5 5 37.90 -122.30 31.04 -120.23
    – 301.0500 66 26 cbr 210 ——- 0 66.0 67.0 5 5 37.90 -122.30 31.04 -120.23
    r 301.0550 66 26 cbr 210 ——- 0 66.0 67.0 5 5 37.90 -122.30 31.04 -120.23
    + 301.0550 26 37 cbr 210 ——- 0 66.0 67.0 5 5 31.04 -120.23 14.72 -87.40
    – 301.0550 26 37 cbr 210 ——- 0 66.0 67.0 5 5 31.04 -120.23 14.72 -87.40
    r 301.0691 26 37 cbr 210 ——- 0 66.0 67.0 5 5 31.04 -120.23 14.72 -87.4

    i don’t have either the pkt id or the sequence no, i tried this:

    BEGIN {
    count = 0;

    }

    {
    if($3 == “66” && $1 == “+”) {

    start_time[i] = $2;

    } else if(($4 == “67”) && ($1 == “r”)) {

    end_time[i] = $2;

    } else if($1 == “D” && $5 == “cbr”) {

    end_time[i] = -1;

    }

    }
    END {

    for(i=0; i 0) {

    delay[i] = end_time[i] – start_time[i];

    count++;

    }

    else

    {

    delay[i] = -1;

    }
    }

    for(i=0; i 0) {

    n_to_n_delay = n_to_n_delay + delay[i];
    print ” End-to-End Delay = ” n_to_n_delay * 1000 ” ms”;
    }

    }
    print ” End-to-End Delay = ” n_to_n_delay * 1000 ” ms”;

    print “\n”;

    }

    It prints End-to-End Delay = 0 ms always.

  12. jitendra
    February 16, 2014 at 12:19 am

    thank u and cheers with weeds

  13. Alagappan
    July 14, 2014 at 6:39 am

    while executing this ”sudo apt-get install tcl8.5-dev tk8.5-dev”, it is showing
    E: Unable to locate package dev

    • July 25, 2014 at 2:37 pm

      Again, sorry for the late response. Hope you have solved your problem.. If not, then:

      sudo apt-get update
      sudo apt-get install build-essential

      • July 26, 2014 at 4:31 am

        i need to execute c++ file associated with tcl script. i have downloaded cpptcl-1.1.3.tar.gz, i checked out my pc with seperately compiling sample programs from tcl and C++, but i would like to know how to add this downloaded library file cpptcl.h to existing ns-2.35 package

        Yours ideas wouldbe helpful

        Thanks in advance

      • July 26, 2014 at 10:42 am

        Please refer to the ns-2 manual. You may also check Marc Greis tutorial (http://www.isi.edu/nsnam/ns/tutorial/index.html)

  14. Alagappan
    July 14, 2014 at 6:43 am

    sir , how to set the path , how to view .bashrc file,pls reply , i need ur help

  15. August 1, 2014 at 1:42 pm

    hi i can execute tcl file and .cc file individually in my ns-2.35 , i wouldnt get how to integrate cc and tcl file? and hpw to add library package to tcl header

    i am stucking at this moment since last one week, kindly reply soon

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: