Installing ns-2 on Ubuntu 12.04

Recent Ubuntu releases contain many of the prerequisites for ns-2, which can relieve much of ns-2’s installation burden. This post works out the details of such an installation, compiling ns “from all the pieces”, as specified in the ns-2 documentation.

The TclCL crunch

Whereas it may seem that all important dependencies can be fetched from apt repositories, the tclcl library binary lacks support for uint64_t (at least in the 12.04 repositories tested at the time of writing), so it should be compiled from source. Another quirk is that the tclcl library has a config.h that interferes with ns’s config.h, so removing it (after tclcl binaries had been compiled) is needed for successful ns compilation. Note that even if ‘make install’ is called for tclcl, the config.h file gets installed and needs to be removed, so there is no particular advantage to calling ‘make install’.

The following sections detail the procedure.

Installation recipe

{codecitation}# This directory will be used to download and install components
export SOURCE_DIR=$HOME/src
mkdir -p $SOURCE_DIR

# Get Tcl/Tk, otcl, nam, xgraph
sudo apt-get install tcl-dev tk-dev libotcl-dev otcl-shells nam xgraph

# On Ubuntu 12.04 x86, the libotcl-dev package puts the libraries in /usr/lib/x86_64-linux-gnu.
# The following creates a link in /usr/lib
[ ! -f /usr/lib/libotcl.a ] && [ -f /usr/lib/x86_64-linux-gnu/libotcl.a ] && sudo ln -s /usr/lib/x86_64-linux-gnu/libotcl.a /usr/lib/libotcl.a

# Get and compile TclCL
curl -L | tar -xvz
cd tclcl-1.20/
./configure –prefix=$HOME
make -j8
# Remove config.h – obstructive to ns compilation
rm config.h

# Get and compile ns
curl -L | tar -xvz
cd ns-2.35/
./configure –prefix=$HOME –with-tclcl=$SOURCE_DIR/tclcl-1.20
make -j8
./validate # optional
make install -j8{/codecitation}

This installs the ns binary to $HOME/bin. It’s a good idea to add that to the PATH (e.g., add a line in .bashrc):
{codecitation}export PATH=$HOME/bin:$PATH{/codecitation}

On Ubuntu server

TclCL requires x11 header packages, obtainable with the xorg-dev package.

That’s it! The code can be modified in ~/src/ns-2.35 and installed again and again as necessary. Enjoy!

Posted in Tech Blog.

Leave a Reply

Your email address will not be published. Required fields are marked *