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
wget http://nchc.dl.sourceforge.net/sourceforge/nsnam/ns-allinone-2.34.tar.gz
2. u can download it from here
Step 2: Extract
extract the tar file in home directory  i.e. /home/username
OR
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
./install
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

# LD_LIBRARY_PATH
OTCL_LIB=/your/path/ns-allinone-2.34/otcl-1.13
NS2_LIB=/your/path/ns-allinone-2.34/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB

# TCL_LIBRARY
TCL_LIB=/your/path/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB

# PATH
XGRAPH=/your/path/ns-allinone-2.34/bin:/your/path/ns-allinone-2.34/tcl8.4.18/unix:/your/path/ns-allinone-2.34/tk8.4.18/unix
NS=/your/path/ns-allinone-2.34/ns-2.34/
NAM=/your/path/ns-allinone-2.34/nam-1.14/
PATH=$PATH:$XGRAPH:$NS:$NAM

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:
    http://download.eclipse.org/tools/cdt/releases/galileo
  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/Makefile.in”and
    • Add these lines anywhere near the top of the file:CCOPT = -g
      DEFINE = -DNDEBUG
      DEFINE = -DDEBUG
    • 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 Makefile.in file:
Add -g to the line CCOPT = @V_CCOPT@
CCOPT = @V_CCOPT@ -g
Add -DNDEBUG -DDEBUG to the end of the following line:
DEFINE = -DTCP_DELAY_BIND_ALL -DNO_TK @V_DEFINE@ @V_DEFINES@ @DEFS@-DNS_DIFFUSION
-DSMAC_NO_SYNC -DCPP_NAMESPACE=@CPP_NAMESPACE@-DUSE_SINGLE_ADDRESS_SPACE -Drng_test -DNDEBUG -DDEBUG


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.




4 comments:

  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!

    ReplyDelete
  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 makefile.in, 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 \
    -I./wpan

    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

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

      Delete
  3. hi sir, i modify the dccp_tfrc.cc 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.

    ReplyDelete