Saturday, May 4, 2013

Installing NS-2 on Ubuntu

In this year I started following the Master of Computer Science (MCS) at University of Colombo School of Computing and these days I'm following a module named "Advanced Concepts in Data Communication Networks"

The lecturer asked us to install a program called NS-2 and to play around with it as we will get an assignment on it soon!

As usual when I hear a new name, I just googled for it and found the official website: http://www.isi.edu/nsnam/ns/


What is NS-2?


NS-2 is a Network Simulator. According to Wikipedia, NS-2 is a "discrete event network simulator" and the latest available version as of now is NS-3, which is available at http://www.nsnam.org/

The difference between NS-2 and NS-3


The FAQ at www.nsnam.org clearly mentions the difference between NS-2 and NS-3. NS-3 is a new software development effort and uses C++ programs or python scripts to define simulations. However NS-2 uses OTcl for scripts. 

So the most important thing here is that NS-2 scripts will not run within NS-3.


Installing NS-2 - The Hard Way!


The installation instructions at the website is to download the source and build it. So, I downloaded the latest available ns-allinone version, i.e. ns-2.35, which was released on Nov 4, 2011.

From my experience, it's always better to install software on a Virtual Machine and try. You never know when your machine will crash, especially when doing unknown things such as building from source, which requires to install many development libraries.

I use an excellent virtualization software called VirtualBox. I created a Virtual Machine and installed Ubuntu 13.04 on it.

After installing Ubuntu 13.04, I upgraded existing software packages after updating the package list index.


sudo su
apt-get update && apt-get -y upgrade


Then I extracted the downloaded pack.

tar -xvf ns-allinone-2.35.tar.gz

Then I changed in to the directory, executed install script.

cd ns-allinone-2.35/
./install

The installation script was not successful at the first attempt. It failed many times.

Then I found out some additional packages are also needed to install NS-2 successfully.

Following is the command to install all those packages at once.

sudo apt-get install libx11-dev build-essential autoconf automake xorg-dev g++ libxmu-dev libperl4-corelibs-perl

The last package "libperl4-corelibs-perl" was not needed during installation, however some tests were failing without it.

I also got following error during the installation.

linkstate/ls.h: In instantiation of ‘void LsMap<Key, T>::eraseAll() [with Key = int; T = LsIdSeq]’:
linkstate/ls.cc:396:28:   required from here
linkstate/ls.h:137:20: error: ‘erase’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
linkstate/ls.h:137:20: note: declarations in dependent base ‘std::map<int, LsIdSeq, std::less<int>, std::allocator<std::pair<const int, LsIdSeq> > >’ are not found by unqualified lookup
linkstate/ls.h:137:20: note: use ‘this->erase’ instead
make: *** [linkstate/ls.o] Error 1
Ns make failed!
See http://www.isi.edu/nsnam/ns/ns-problems.html for problems

To fix above error, I edited linkstate/ls.h file as instructed.

I changed the line 137
from
void eraseAll() { erase(baseMap::begin(), baseMap::end()); }
to
void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); }


Now you should be able to install NS-2 successfully by running "./install" command.

Following is the output I got at the end of installation.

Ns-allinone package has been installed successfully.
Here are the installation places:
tcl8.5.10: /home/isuru/ns-allinone-2.35/{bin,include,lib}
tk8.5.10:  /home/isuru/ns-allinone-2.35/{bin,include,lib}
otcl:  /home/isuru/ns-allinone-2.35/otcl-1.14
tclcl:  /home/isuru/ns-allinone-2.35/tclcl-1.20
ns:  /home/isuru/ns-allinone-2.35/ns-2.35/ns
nam: /home/isuru/ns-allinone-2.35/nam-1.15/nam
xgraph: /home/isuru/ns-allinone-2.35/xgraph-12.2
gt-itm:   /home/isuru/ns-allinone-2.35/itm, edriver, sgb2alt, sgb2ns, sgb2comns, sgb2hierns

----------------------------------------------------------------------------------

Please put /home/isuru/ns-allinone-2.35/bin:/home/isuru/ns-allinone-2.35/tcl8.5.10/unix:/home/isuru/ns-allinone-2.35/tk8.5.10/unix
into your PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph.

IMPORTANT NOTICES:

(1) You MUST put /home/isuru/ns-allinone-2.35/otcl-1.14, /home/isuru/ns-allinone-2.35/lib, 
    into your LD_LIBRARY_PATH environment variable.
    If it complains about X libraries, add path to your X libraries 
    into LD_LIBRARY_PATH.
    If you are using csh, you can set it like:
  setenv LD_LIBRARY_PATH <paths>
    If you are using sh, you can set it like:
  export LD_LIBRARY_PATH=<paths>

(2) You MUST put /home/isuru/ns-allinone-2.35/tcl8.5.10/library into your TCL_LIBRARY environmental
    variable. Otherwise ns/nam will complain during startup.


After these steps, you can now run the ns validation suite with
cd ns-2.35; ./validate

For trouble shooting, please first read ns problems page 
http://www.isi.edu/nsnam/ns/ns-problems.html. Also search the ns mailing list archive
for related posts.


NS-2 Successful Installation



As instructed, I also executed validate script inside ns-2.35 directory. All tests were passed! :)

All tests were passed


Now you need to export paths to environment. For that, just add following to your ~/.bashrc file.

# LD_LIBRARY_PATH
# LD_LIBRARY_PATH
OTCL_LIB=/home/isuru/ns-allinone-2.35/otcl-1.14
NS2_LIB=/home/isuru/ns-allinone-2.35/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$USR_LOCAL_LIB

# TCL_LIBRARY
TCL_LIB=/home/isuru/ns-allinone-2.35/tcl8.5.10/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB

# PATH
XGRAPH=/home/isuru/ns-allinone-2.35/bin:/home/isuru/ns-allinone-2.35/tcl8.5.10/unix:/home/isuru/ns-allinone-2.35/tk8.5.10/unix
NS=/home/isuru/ns-allinone-2.35/ns-2.35/
NAM=/home/isuru/ns-allinone-2.35/nam-1.15/
export PATH=$PATH:$XGRAPH:$NS:$NAM


Now you can start a new terminal or run "source ~/.bashrc" to start using NS-2!

Installing NS-2 - The Easy Way!


Apparently the NS-2 is also available on Ubuntu Software Center! I got to know that only after installing the NS-2 in the hard way! :)

There is just one command to install!

sudo apt-get install ns2 nam xgraph


Testing NS-2 Installation



After installing you should be able to run commands "ns" & "nam".

The "ns" command will go in to a prompt with "%".

You can type "exit"! :)

I'm hoping to write another blog post on using NS-2 soon. May be after I get the assignment! :)
Post a Comment