Installation of ns 2.35 in ubuntu 14.04
Download ns2.35 all in one package
We are going to install ns2.35 on ubuntu 14.04 or later versions.
NS2.35 all in one package can be downloaded from http://sourceforge.net/projects/nsnam/files/latest/download
The package ns-allinone-2.35.tar.gz downloaded has to be moved to home directory( Home folder) /home/user_name
Extracting the package
Open terminal and type the following commands,
tar -xvzf ns-allinone-2.35.tar.gz
tar -xvzf ns-allinone-2.35.tar.gz
Now All the files will be extracted into a folder called “ns-allinone-2.35” in home directory
Install Dependent packages for ns 2.35
Ns2 requires a few packages to be pre installed. It also requires the GCC- version 4.3 to work correctly. So install all of them by using the following command:
sudo apt-get install build-essential autoconf automake libxmu-dev
One of the dependencies mentioned is the compiler GCC-4.3, which is no longer available, and thus we have to install GCC-4.4 version. The version 4.4 is the oldest we can get. To do that, use the follwoing command:
sudo apt-get install gcc-4.4
Once the installation is over , we have to make a change in the “ls.h” file. Use the following steps to make the changes:
Navigate to the folder “linkstate”, use the following command. Here it is assumed that the ns folder extracted is in the home folder of your system.
Now open the file named “ls.h” and scroll to the 137th line. In that change the word “error” to “this->error”. The image below shows the line 137 (highlighted in the image below) after making the changes to the ls.h file.To open the file use the following command:
Now there is one more step that has to be done. We have to tell the ns which version of GCC will be used. To do so, go to your ns folder and type the following command:
sudo gedit ns-allinone-2.35/otcl-1.14/Makefile.in
In the file, change Change CC= @CC@ to CC=gcc-4.4 (NOTE : If you are using ubuntu 16.04 do not modify this )
Now we are ready to install ns2. To do so we first require root privileges and then we can run the install script. Use the following two commands:
Installation will take 10- 15 minutes, after successfull installation the last messages will tell you how to add path variable to execute ns2 correctly.
Adding the Path variables
The final step is to tell the system, where the files for ns2 are installed or present. To do that, we have to set the environment path using the “.bashrc” file. In that file, we need to add a few lines at the bottom. The things to be added are given below. But for the path indicated below, many of those lines have “/home/sharvin/ns-allinone-2.35/….” , but that is where I have my extracted folder. Make sure you replace them with your path. For example, if you have installed it in a folder “/home/abc”, then replace “/home/akshay/ns-allinone-2.35/otcl-1.14” with “/home/abc/ns-allinone-2.35/otcl-1.14”.
my home directory is /home/sharvin
to get your home directory, open terminal and type pwd , you get result like /home/sharvin/
so your user directory is sharvin.
Do this for all the required lines.
sudo gedit ~/.bashrc
Lines to be added:
# LD_LIBRARY_PATH OTCL_LIB=/home/sharvin/ns-allinone-2.35/otcl-1.14 NS2_LIB=/home/sharvin/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/sharvin/ns-allinone-2.35/tcl8.5.10/library USR_LIB=/usr/lib export TCL_LIBRARY=$TCL_LIB:$USR_LIB # PATH XGRAPH=/home/sharvin/ns-allinone-2.35/bin:/home/sharvin/ns-allinone-2.35/tcl8.5.10/unix:/home/sharvin/ns-allinone-2.35/tk8.5.10/unix #the above two lines beginning from xgraph and ending with unix should come on the same line NS=/home/sharvin/ns-allinone-2.35/ns-2.35/ NAM=/home/sharvin/ns-allinone-2.35/nam-1.15/ PATH=$PATH:$XGRAPH:$NS:$NAM
Once the changes have been made, save the file and restart the system.
To check whether the installation was successfull type ns in terminal, if a % symbol appears , then the installation is successfully done