Thursday, August 19, 2010

Ns2 Building Experiences

NS-2 is useful for a variety of researches related to networking. However, there might be difficult to install all the necessary packages of ns-2 in any platform. it may be troublesome, especially with specific combination of the ns2 versions and OS versions. the more problems lie on the issues of gcc and NS2 versions. Here, I share my personal experiences of building NS2 over Linux systems, namely Fedora, Ubuntu.

For the NS2 case, the most relevant is the Gcc compiler. Installing the latest version
of ns-2 (ns-2.33) with gcc 4.1.2 is not difficult at all because the source code has mapped to the current gcc configuration. Even though there is a small bug in ./configure of tk, tcl, otcl, less attempt has been done compare to the older version. You can't compile ns-2.27 (and 2.26 too) with gcc3.4.2, even with new versions of linux distributions. There is Error of "tclcl make failed".
The old version such as ns-2.26 will not work with current gcc 4.1.2. So we’ve to install the gcc-2.95.

HOW-TO:

1. Download the all-in-one package of ns-2 and unzip it:
OR by command line, do following
cd to home directory and type:
wget http://www.isi.edu/nsnam/dist/ns-allinone-2.26.tar.gz;
tar -xzvf ns-allinone-2.26.tar.gz;
2. install the following Debian packages:
  • apt-get install gcc-2.95
  • apt-get install g++-2.95
  • apt-get install libstdc++2.10-glibc2.2
  • apt-get install libx11-dev
  • apt-get install libxt-dev
3. In my shell (tcsh), there were several changes needed in the configure files to compensate for stricter parsing. All lines of the form:
system=MP-RAS-`awk ‘{print }’ /etc/.relid’`

need changed to:

system=MP-RAS-`awk ‘{print }’ /etc/.relid`

That is, the second to last character (') needs to be deleted. In ns-allinone-2.26, this occurs in four places (files and line numbers):

./tcl8.3.2/unix/configure:4701
./tcl8.3.2/unix/configure:5705
./tk8.3.2/unix/configure:1520
./otcl-1.0a8/configure:4167

4. Set your compiler environment variables in the terminal in which you will run the install script such that they point to the 2.95 version of the tools instead of the default ones. In the C shell:
setenv CC /usr/bin/gcc-2.95;
setenv CPP /usr/bin/cpp-2.95;
setenv CXX /usr/bin/g++-2.95;

Use the paths appropriate for your system. If you use the bash shell, the general form for setting an environment variable is:

export CC=/usr/bin/gcc-2.95;

Now, the configure scripts will use these versions of the compiler tools.

5. When compiling the TCL/C++ interface (e.g., tclcl-1.0b13), I received a warning that stopped the compilation that line 193 of /usr/include/sys/types.h does not declare anything. Though this is not generally recommended, I used the -fpermissive option for the compiler to continue compilation.

In the file /usr/local/dload/ns-allinone-2.26/tclcl-1.0b13/Makefile.in, I changed the CCOPT parameter on line 56 to be:

CCOPT = -fpermissive @V_CCOPT@

6. At this point, I just had to run the install script an everything compiled (with lots of warnings) except for nam which I didn’t need since I don’t use the visualization tools in ns-2.
/usr/local/dload/ns-allinone-2.26/install

(Make sure you run this in the terminal in which the CC, CPP, and CXX variables are set appropriately)

7. Now, to get your existing ns-2 code to compile (i.e., the code in /usr/local/ns-2.26), you need to reconfigure your Makefile by specifying the new paths:

cd /usr/local/ns-2.26; ./configure –with-tcl=/usr/local/dload/ns-allinone-2.26/tcl8.3.2 –with-tk=/usr/local/dload/ns-allinone-2.26/tk8.3.2 –with-otcl=/usr/local/dload/ns-allinone-2.26/otcl-1.0a8 –with-tclcl=/usr/local/dload/ns-allinone-2.26/tclcl-1.0b13

Note that this will overwrite your existing Makefile, so if there was anything specific that you needed in it, you should move those commands to the Makefile.in file in /usr/local/ns-2.26.

....Now successful to install old version...