ns2.1b9a which is an old version NS2 has very strong OS dependency, so I choose Ubuntu 10.04(64-bit).
-------------------------------------Install NS2-----------------------------------------------------------
1) First of all, download the NS-2 package ns-allinone-2.1b9a-gcc32. http://www.isi.edu/nsnam/dist/ns-allinone-2.1b9a-gcc32.tar.gz
2) Install "build-essential" and "libxmu-dev"
sudo apt-get install build-essential
sudo apt-get install libxmu-dev
3) Because in Ubuntu10.04, the gcc compiler version is gcc-4.4 which is too high to compile ns2.19b, we have to install gcc-3.3 and g++-3.3 by ourselves.
Go to http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-3.3/ and download
"cpp-3.3_3.3.6-15ubuntu6_amd64.deb" "g++-3.3_3.3.6-15ubuntu6_amd64.deb" "gcc-3.3-base_3.3.6-15ubuntu6_amd64.deb" "gcc-3.3_3.3.6-15ubuntu6_amd64.deb" and " libstdc++5-3.3-dev_3.3.6-15ubuntu6_amd64.deb"
. (Depend on your system, the version may be different) Then install them by sudo dpkg --force-depends -i xxx.debTo check compiler version, we use ls /usr/bin/gcc* -ll or ls /usr/bin/g++* -ll. We also can add the compiler options
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-3.3
To change the default gcc version, we use
ln -sf /usr/bin/gcc-3.3 /usr/bin/gcc
ln -sf /usr/bin/g++-3.3 /usr/bin/g++
4) Now we are able to install NS2. First of all, tar xzvf ns-allinone-2.1b9a-gcc32.tar.gz and touch ns-allinone-2.1b9a/tcl8.3.2/generic/tclStubInit.c
5) Before running "./install", we have to modify some files (This is very important!!). Go to ns-allinone folder,
find . -name configure
You will see a list of configure files. Replace any line which is like system=MP-RAS-`awk '{print $3}' /etc/.relid'` to system=MP-RAS-`awk '{print $3}' /etc/.relid`
The original one will cause the error in tcl8.3.2, tk8.3.2 and otcl-1.8, checking system version (for dynamic loading)... ./configure: 1: Syntax error: Unterminated quoted string tcl8.3.2 configuration failed! Exiting
6) Modify otcl-xx/config.sub, tclcl-xx/config.sub and configure file in Nam folder.
Where "| x86 |"
appears, you must put "| x86 | x86_64 |". Where "| x86-* |" appears, you must put "| x86-* | x86_64-* |".
In nam config.sub file, it may not have "|86|", so just find out "case $basic_machine in"
It will cause the error, checking build system type... Invalid configuration `x86_64-unknown-linux-gnu': machine `x86_64-unknown' not recognized configure: error: /bin/sh ./config.sub x86_64-unknown-linux-gnu failed otcl-1.8 configuration failed! Exiting ... or x86_64-unknown-linux-gnu failed nam1.0a11a configuration failed!
7) After the modification, ns2 may be compiled successfully. Just run ./install
8) When it is done, edit .bashrc file and configure environment variables. Put them at the end of file.
export NS_HOME=/home/XX/ns-allinone-2.1b9a
export PATH=$PATH:$NS_HOME/bin:$NS_HOME/tcl8.3.2/unix:$NS_HOME/tk8.3.2/unix
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$NS_HOME/otcl-1.0a8:$NS_HOME/lib:$NS_HOME/tcl8.3.2/unix:$NS_HOME/tk8.3.2/unix
export TCL_LIBRARY=$NS_HOME/tcl8.3.2/library/
9) Finally, source .bashrc
cd ns-2.1b9a
./validate
The Test may not be successful, but it will not effect too much.
--------------------------------------Install TENS------------------------------------------------------------
10) After the NS2 installation, we will start to make The Enhanced Network Simulator (TENS). So just follow the tutorial (http://www.cse.iitk.ac.in/users/braman/tens/)
The only thing is that when type in make depend, it may have an error pcap.h is not found. So open the Ubuntu Software Center, search libpcap and install all the related packages.
11) Congratulation! It is done!