How to install ns-2 with CRCN patch on Ubuntu 10.04

This is the step by step guide for installing ns-2 with CRCN (cognitive radio cognitive network) patch on Ubuntu 10.04. We divide this guide into two main parts: mandatory steps and optional steps. The former is necessary to make standard ns-2 runs with CRCN patch, which includes standard ns-2 installation procedure and CRCN patch application procedure. The latter is optional for make your coding work easier.

Please note that we use:

  • ns-2.31 version as what it is shown in the CRCN homepage. Thus, all the steps are specific to ns-2.31 only.
  • /opt/<program-name> as installation directory, so you need to adjust it according to your specific situation.
  • ~/Download directory to store downloaded files.
  • vi text editor to edit text file. As alternative, gedit will do as well.
  • ichristian as username.

Mandatory Steps

Standard ns-2.31 installation

Step 1: Download ns-2.31 allinone package

First download the ns-2.31 allinone package here. Next, extract ns-allinone-2.31.tar.gz to ns-2 installation directory:

cd /opt
sudo mkdir ns-2
sudo chown ichristian:ichristian ns-2
cd ns-2
cp -rp ~/Download/ns-allinone-2.31.tar.gz /opt/ns-2
tar -zvxf ns-allinone-2.31.tar.gz

Step 2: Install required packages

sudo apt-get install build-essential autoconf automake
sudo apt-get install libxt-dev libx11-dev libxmu-dev
sudo apt-get install xorg-dev g++ xgraph gnuplot

Also install gcc-4.3 from synaptic package manager.

Step 3: Modify shared library for OTCL

Edit file of otcl-1.13 as follows:

cd /opt/ns-2/ns-allinone-2.31/otcl-1.13
* search for 'Linux': type "/Linux"
* edit SHLIB_LD from 'ld-shared' to 'gcc -shared'
* save and quit: type ":wq"

Rebuild otcl-1.13's configure script:

autoconf  -f

Step 4: Apply patch for nam

This is to fix the following error while invoking nam from standard ns-2.31 package:

: no event type or button # or keysym
while executing
"bind Listbox <MouseWheel> {
%W yview scroll [expr {- (%D / 120) * 4}] units
invoked from within
"if {[tk windowingsystem] eq "classic" || [tk windowingsystem] eq "aqua"} {
bind Listbox <MouseWheel> {
%W yview scroll [expr {- (%D)}] units
bind Li..."

First, download patch here. Next, apply the patch as follows:

cp -p ~/Download/tk-8.4-lastevent.patch /opt/ns-2/ns-allinone-2.31/tk8.4.14
cd /opt/ns-2/ns-allinone-2.31/tk8.4.14
patch -p0 < tk-8.4-lastevent.patch

Step 5: Add some more c flag

This is to fix the warnings that come with standard ns-2.31 package while compiling:

./common/packet.h:358: warning: deprecated conversion from string constant to ‘char*’

Include the flags in file as follows:

cd /opt/ns-2/ns-allinone-2.31/ns-2.31
* search for CCOPT: type "/CCOPT"
* change the line as follows:
     before:  CCOPT: @V_CCOPT@
     after:   CCOPT: @V_CCOPT@ -g -Wno-write-strings
* save and quit: type ":wq"

Step 6: Install standard ns-2.31

export CC=gcc-4.3
cd /opt/ns-2/ns-allinone-2.31

Step 7: Setup environment variable

vi ~/.bashrc
* append the following lines:


    # PATH
* save and quit: type ":wq"
source ~/.bashrc

Step 8: Fix error while doing 'make depend'

The following error happens when we invoke 'make depend' command:

/bin/sh: Syntax error: Bad fd number
make: *** [depend] Error 2

This is because the default ubuntu 10.04 setting uses dash instead of bash for sh command. Thus, rename the old link of /bin/sh to dash and create new link of /bin/sh to bash.

cd /bin
sudo mv sh sh_orig
sudo ln -s /bin/bash sh

Step 9: Compile again to make sure that the error is disappear

cd /opt/ns-2/ns-allinone-2.31/ns-2.31
make clean
make depend

Step 10: Check if ns is correctly installed


If you see %, then go to next step. Otherwise, error occurs. Check previous steps.

Step 11: Check if nam is correctly installed


If you see nam window popping up, go to next step. Otherwise, you have got error. Check previous steps.

Step 12: Validate ns-2 installation

cd /opt/ns-2/ns-allinone-2.31/ns-2.31

It takes around 35 minutes to complete. Make sure that all tests are passed.


  1. Installing ns-2.31 on Ubuntu 10.10 for novice, from a novice, Soliloquy
  2. Installing ns2.31 on Ubuntu7.04, ns-2 wiki
  3. FAQ ns-2 & Linux, Ejaz Ahmed
  4. Configure NS-2 with Eclipse in Linux, Soliloquy

CRCN patch installation

Step 1: Download CRCN patch
First download CRCN patch here. Next, copy to ns-2 installation directory and unzip it:

cp -rp ~/Download/ /opt/ns-2
cd /opt/ns-2

Step 2: Backup the standard ns-2

Simply copy the current ns-allinone-2.31 directory and rename copied one as ns-allinone-2.31_orig:

cp -rp ns-allinone-2.31 ns-allinone-2.31_orig

Step 3: Apply CRCN patch
Replace all files in each directory of crcn to the corresponding directory in ns-2.31 directory. Particularly for additional directory wcett, simply copy it to ns-2.31 directory.
Modify Makefile file to include wcett directory and other additional files while compiling ns-2

cd /opt/ns-2/ns-allinone-2.31/ns-2.31
vi Makefile
* search for 'OBJ_CC': type "/OBJ_CC"
* add the following lines at the end of the list (that is, before '$(OBJ_STL)':
    wcett/wcett_logs.o wcett/wcett.o \
    wcett/wcett_rtable.o wcett/wcett_rqueue.o \
    mac/macng.o mac/maccon.o \
    mac/macngenhanced.o \
* save and quit: type ":wq"

Step 4: Compile the ns-2 again

make clean
make depend

Make sure that all compilation is withour error.


  1. Installation, CRCN User Guide
  2. Cognitive Radio Network Simulator installation, tutorMicman

Optional Steps

Eclipse IDE installation and configuration

Step 1: Download Eclipse IDE for C/C++

Download eclipse here. Note that we use Eclipse IDE for C/C++ Linux Developers (includes Incubating components). Other version for C/C++ development will do as well, as long as it has CDT (C development tool) module installed. Extract eclipse-linuxtools-indigo-SR1-incubation-linux-gtk.tar.gz to eclipse installation directory:

cd /opt
sudo mkdir eclipse
sudo chown ichristian:ichristian eclipse
cd eclipse
cp -rp ~/Download/eclipse-linuxtools-indigo-SR1-incubation-linux-gtk.tar.gz /opt/eclipse
tar -zvxf eclipse-linuxtools-indigo-SR1-incubation-linux-gtk.tar.gz

Step 2: Setup environment variable

vi ~/.bashrc
* append the following lines:
* save and quit: type ":wq"
source ~/.bashrc

Step 3: Add ns-2 as C++ project to eclipse

  • Open Eclipse
  • Set the workspace (/home/ichristian/workspace) by selecting File -> Switch Workspace
  • Choose File -> Import
  • Select C/C++, Existing Code as Makefile project
  • Browse existing code location (/opt/ns-2/ns-allinone-2.31/ns-2.31)
  • Select Toolchain: Linux GCC
  • Select "Finish"

Step 4: Try to build from eclipse

  • From the workspace (left pane), select the ns-2.31 Project
  • Choose Project -> Clean..

You should see the similar output of make clean in eclipse console window.

  • Choose Project -> Build All

You should see the compilation output in eclipse console window.

Step 5: Run the program

  • Choose Run -> Run As -> local C/C++ application
  • Select "ns" as Binaries, and chose "OK"
  • Select "gdb/mi" configuration (only for the first run), and chose "OK"

You should see ns-2 prompt '%' in eclipse console window.


  1. Configure NS-2 with Eclipse in Linux, Soliloquy
  2. Eclipse 3.7 (Indigo) for C/C++ Programming, How To Install Eclipse CDT 8.0 and Get Started

Opengrok source code browser installation and configuration

Step 1: Download opengrok

Download opengrok 0.10 here. Then, extract opengrok-0.10.tar.gz to opengrok installation directory:

cd /opt
sudo mkdir opengrok
sudo chown ichristian:ichristian opengrok
cd opengrok
cp -rp ~/Download/opengrok-0.10.tar.gz /opt/opengrok
tar -zvxf opengrok-0.10.tar.gz

Step 2: Install required programs

Opengrok requires Tomcat webserver for web based user interface and exuberant-ctags for indexing source codes.

sudo apt-get install exuberant-ctags tomcat6

Check whether tomcat6 webserver is working properly:

  • Type on your browser: "localhost:8080"

If it displays "It works!", then go to next step. Otherwise, tomcat6 installation is still not correct. check previous step..

Step 3: Deploy the web application of opengrok

cd /opt/opengrok/opengrok-0.10/bin
sudo ./Opengrok deploy

Check whether web application of opengrok is working

  • Type on your browser: "localhost:8080/source"

If it displays "Open Grok", then go to next step. Otherwise, deployment is still not correct. check previous step..

Step 4: Indexing source codes

Create opengrok data directory (only for initial deployment):

sudo mkdir /var/opengrok

Index source codes of interest (in our example, it is located in /opt/ns-2/ns-allinone-2.31/ns-2.31):

cd /opt/opengrok/opengrok-0.10/bin
sudo ./Opengrok index /opt/ns-2/ns-allinone-2.31/ns-2.31

After this, you can start browsing the codes by accessing "localhost:8080/source" from web browser.


  1. How to install OpenGrok, OpenSolaris
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License