Sunday, 11 November 2012

How to Install and Configure NS-2 with Eclipse in Linux

Running NS-2

Ns-2 can be run both in windows or Linux platform.

Best option

  • Use Linux 

How to run NS-2 under Windows?

  • Using Cygwin (not recommended)
  • Using Virtual machine
    • Vmware station (not free)
    • WM player (free and recommended)
    • Virtualbox (free)
  • others

Installation Procedures for NS-2 (ns-allinone-2.34)

Step 1: Download

download the latest ns2 copy . their are two methods to do that
1. go to terminal and type
2. u can download it from here
Step 2: Extract
extract the tar file in home directory  i.e. /home/username
try this in terminal
tar -xzvf ns-allinone-2.34.tar.gz
step 3 :install
just type following commands

cd ns-allinone-2.34
sudo apt-get install build-essential autoconf automake libxmu-dev
Step 4: Set environment variables
$ gedit ~/.bashrc
Add the following lines to the end of the file. Remember replace “/your/path” by the folder where you have stored extracted the ns-2 file




Ensure that it immediately takes effect:
$ source ~/.bashrc

Note: the previous step is important; else you cannot successfully run ns-2.
(Alternatively, you may have to restart your X-windows, that is logout, and then login, or restart your computer.)
Now, the installation has been completed. Try:
$ ns
The “%” symbol appears on the screen. Type “exit” to quit.

Validation (optional)

To run the ns validation suite:
$ cd ns-2.34
$ ./validate

Configuring Eclipse to work with NS2

For most users of NS2, it would be easier if they can use a popular IDE to work with the files.
Here are the step by step instructions to set up NS-2.34 with Eclipse 3.5 in Ubuntu Linux.

Setting up Eclipse:
  1. Download Eclipse SDK
  2. Extract the SDK to a folder
  3. Open Eclipse
  4. Go to Help -> Install New Software. In the Work With bar type this:
  5. Choose CDT Main Features and CDT Optional Features. Install them.
    CDT stands for “C/C++ Development Tooling”
  6. If you do not have a working internet connection in the system you have installed Eclipse, instead of steps 4 and 5, download the CDT from the above mentioned site. Then move to Install New Software (see step 4) -> Add and add the archive downloaded.

Enabling debugging in NS2
  1. Edit Makefile:
    • Open “…/ns-allinone-2.34/ns-2.34/”and
    • Add these lines anywhere near the top of the file:CCOPT = -g
    • Navigate to …/ns-allinone-2.34/ns-2.34 and run “./configure”
  2. Navigate to the NS-2 folder using terminal and type ./install
  3. Also, follow the instructions are displayed at the end of a successful installation. These instructions are to modify the PATH variable and other environment variables as needed.

Adding NS-2 as a Project in Eclipse:
  1. Open Eclipse
  2. Set the workspace as the ns installation path( /home/username/ns-allinone-2.34 ) by selecting File -> Switch Workspace
  3. Choose File -> New -> Project -> C++ Project
  4. Select Project Type as Makefile Project -> Empty C++ Project.
    Toolchains: Linux GCC
  5. Enter Project Name as ns-2.34
  6. Uncheck “Use default location” then browse to the directory NS-2 source directory ( …/ns-allione-2.34/ns-2.34 )
  7. Select “Next” and “Finish.
  8. From the workspace, Selecting the NS-2 Project and choosing Project -> Build All should not give Error.
  9. Running the project must open the console with the NS-2 prompt, %
Setting Debug Configuration:
  1. Select Run -> Debug Configurations
  2. Choose C/C++ Application. Type in any name.
  3. Under the Main tab, Choose the following:
    Project as ns-2.34.
    C/C++ Application as ns. (Search Project and Choose this)
  4. Under the Debugger tab, choose GDB Debugger. Uncheck the “Stop on startup at” option.
  5. Apply and Debug.

Update from Readers: Changes to be made in file:
Add -g to the line CCOPT = @V_CCOPT@
Add -DNDEBUG -DDEBUG to the end of the following line:

Useful tips: 
Apart from doing "make clean"  every time you make changes to the c++ files, you can just delete the *.o files in that folder and just do make only. This will save your development time.


  1. When I build all project I get a fatal error: ip.h no such file or directory, could you help me to solve this problem, thank you very much!

  2. Compiler is unable to find the ip.h file. In ns2, ip.h file is placed in "common" folder and if you see the, you can see as follows that the common folder path is already included

    INCLUDES = \
    -I. @V_INCLUDE_X11@ \
    -I. \
    @V_INCLUDES@ \
    -I./tcp -I./sctp -I./common -I./link -I./queue \
    -I./adc -I./apps -I./mac -I./mobile -I./trace \
    -I./routing -I./tools -I./classifier -I./mcast \
    -I./diffusion3/lib/main -I./diffusion3/lib \
    -I./diffusion3/lib/nr -I./diffusion3/ns \
    -I./diffusion3/filter_core -I./asim/ -I./qs \
    -I./diffserv -I./satellite \

    Please make sure you have ip.h file in the common folder or you may not have changed the name or accidently deleted the ip.h file

    1. Hi, I have the same problem. I make sure I have ip.h in the project, and the file is right. Do you know other possible solutions?

  3. hi sir, i modify the file throughput equation and i make the ns-2.34 and then i found the throughput then there is no change at before and now. please help me
    by giving solution.