Вы находитесь на странице: 1из 8

How to Install NS-2.35 in 14.

04
Installation of Network Simulator (NS-2.35) in Ubuntu 14.04.

Step 0: Download NS-2.35 to your home directory:


1. First of all, download Network Simulator (NS- 2.35) from the following link:
(http://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.35/ns-allinone2.35.tar.gz/download).
Downloaded it into your /home/sois/Desktop/ns2/ns2.35/ directory.

Step 1: Setting up the Prerequisites


1. Now update the Ubuntu with its latest components. Open up a terminal and run this command:
1 sudo apt-get update
2 sudo apt-get dist-upgrade
3 sudo apt-get update

2. Run the following to install some essential packages required by the NS commands before
installing the NS:
1 sudo apt-get install build-essential autoconf automake
2 sudo apt-get install tcl8.5-dev tk8.5-dev
3 sudo apt-get install perl xgraph libxt-dev libx11-dev libxmu-dev
4 sudo apt-get install gcc-4.4

Step 3: Extract and Install NS


1. Extract the downloaded NS package either using the right click context menu "Extract here" or
using the following command from a terminal:
1 cd /home/sois/Desktop/ns2.35
2 tar -xvzf ns-allinone-2.35.tar.gz

2. After extracting the "ns-allinone-2.35" folder, open up the file "/ns-allinone-2.35/ns2.35/linkstate/ls.h" in an editor. You can do it from the terminal. We have to make some changes
in the ls.h file else it will show an error while installing the NS. Once you have opened the file
move to the line 137 and replace the erase with this->erase and save the file.

NOTE: If you don't make the above stated change then you will see an error while
installing the NS (image 3 below).

3. Now its time to finally install the NS. Open up a terminal and move to the directory where you
have extracted the package, in our case its /home/sois/Desktop/ns2/ns2.35/ and install NS using
the following commands:
1 cd /home/ sois/Desktop/ns2/ns2.35/ns-allinone-2.35
2 sudo ./install

It will take around 15 minutes.

Step 4: Set the Environment Variables


1. Assuming everything went well in the previous step and you have successfully installed your
NS. Now there are some environment variables that need to be added to your profile. This can be
done by editing the ".profile" file.
This can be done by editing the .bashrc file. Open a new terminal and open the file using:
1 sudo gedit ~/.bashrc

Open a new terminal and open the file using:


sudo gedit .profile
NOTE: You may want to create a backup of the .profile before editing, the easiest way is to copy
the file to a different location. Later you can replace the edited .profile with the copied one in
case something goes sideways or if you want to remove the NS.
The .profile file looks like this
2. Add the following lines AT THE END of the file. Be sure to change "/path_to" to the

path of where you have extracted the NS (e.g. '/home/user_name/Documents').

# ~/.profile: executed by the command interpreter for login shells.


# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
2. Add the following lines AT THE END of the file.
# LD_LIBRARY_PATH
OTCL_LIB=/home/sois/Desktop/ns-2.35/ns-allinone-2.35/otcl-1.14/
NS2_LIB=/home/sois/Desktop/ns-2.35/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/sois/Desktop/ns-2.35/ns-allinone-2.35/tcl8.5.10/library/
USR_LIB=/usr/lib/
export TCL_LIBRARY=$TCL_LIBRARY:$TCL_LIB:$USR_LIB
# PATH
XGRAPH=/home/sois/Desktop/ns-2.35/ns-allinone-2.35/xgraph12.2/:/home/sois/Desktop/ns-2.35/ns-allinone-2.35/bin/:/home/sois/Desktop/ns2.35/ns-allinone-2.35/tcl8.5.10/unix/:/home/sois/Desktop/ns-2.35/ns-allinone2.35/tk8.5.10/unix/
NS=/home/sois/Desktop/ns-2.35/ns-allinone-2.35/ns-2.35/
NAM=/home/sois/Desktop/ns-2.35/ns-allinone-2.35/nam-1.15/

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

# LD_LIBRARY_PATH
OTCL_LIB=/path_to/ns-allinone-2.35/otcl-1.14/
NS2_LIB=/path_to/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=/path_to/ns-allinone-2.35/tcl8.5.10/library/
USR_LIB=/usr/lib/
export TCL_LIBRARY=$TCL_LIBRARY:$TCL_LIB:$USR_LIB
# PATH
XGRAPH=/path_to/ns-allinone-2.35/xgraph-12.2/:/path_to/ns-allinone2.35/bin/:/path_to/ns-allinone-2.35/tcl8.5.10/unix/:/path_to/ns-allinone2.35/tk8.5.10/unix/
NS=/path_to/ns-allinone-2.35/ns-2.35/
NAM=/path_to/ns-allinone-2.35/nam-1.15/
export PATH=$PATH:$XGRAPH:$NS:$NAM

3. Save the file and restart the system, alternatively you can just reload the .bashrc as:
1 source ~/.bashrc

source ~/.profile
check

ns
should give %
check nam
should display nam window
if it is not working
copy nam file from ns-2.35/nam folder to bin folde

Step 4: Validate the Installation


You need to validate NS to check if everything is OK but beware it will take lot of time (about
1:30 hrs). Open up a terminal and move to the directory /home/sois/Desktop/ns2/ns2.35/nsallinone-2.35/ns-2.35/' and run:
1 ./validate

./validate
That is it ! You can now run ns from a terminal window by executing: ns
If you received the % sign, it means that NS is running. Congratulations !!
Referrence:
http://installwithme.blogspot.in/2014/05/how-to-install-ns-2.35-in-ubuntu-13.10-or-14.04.html

---------------------------------------------end-----------------------------------------------------------------------

Uninstalling the NS
If you want to remove the NS from your system then follow these steps:

1 Delete the directory 'ns-allinone-2.35'.


2 Delete the ns related files from '/user/local/bin'.
3 Edit the '.bashrc file' and remove the paths that you have added during the

installation.
4 Restart the system and run following commands one by one:
5 sudo apt-get autoremove
6 sudo apt-get clean

Some Common Problems


1. Many people are getting the following error when they run the ns after the
installation:

If you get this error then kindly ensure that you have set the path (as in step 3) correctly
and try restarting the system. If the error persists then try running the ns from '/nsallinone-2.35/ns-2.35/bin/'.