Configure NS-2 with Eclipse in Linux

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 I followed to set up NS-2.34 with Eclipse 3.5 in Ubuntu Linux.

In older versions of Eclipse, the settings might be slightly different.

I have compiled the following steps after running into various problems and errors with the setup, and solving them all. So I hope the setup will be smooth for you.

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.

Installing NS-2

  1. Download NS-2
  2. Extract NS-2 to a folder, i.e. /home/username/ns-allinone-2.34
  3. 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”
  4. Navigate to the NS-2 folder using terminal and type ./install
  5. 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

Special thanks to Ella Taha for notifying me about the correction!



Update:

I wrote this post many years ago, and I have since then moved away from using NS-2.
Here is a relatively recent post by Erlend that might be of help: Using ns-2 with Eclipse

Share this article
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

20 thoughts on “Configure NS-2 with Eclipse in Linux”

  1. Pingback: ns2 with eclipse
  2. dear hasan,

    appreciate if you could describe in detail on how to pass a tcl file as an argument to ns by using an example…really appreciate yourhelp. thank you very much.


    hasan türken:


    Fatima:

    Hi,
    I did as suggested by you. I am confused do i need to put in breakpoints in files myself. I am not sure in which files to place the breakpoints.
    Additionaly, is there any way i can debug my simulation written in tcl.
    Thanks
    VA:F [1.9.12_1141]please wait…Rating: 0.0/5 (0 votes cast)VA:F [1.9.12_1141]Rating: 0 (from 0 votes)

    You should pass your tcl file as argument to ns.
    Go to debug configurations and under arguments tab, write the name of your .tcl file. With its path of course.
    VA:F [1.9.16_1159]please wait…Rating: 0.0/5 (0 votes cast)VA:F [1.9.16_1159]Rating: +1 (from 1 vote)


  3. Fatima:

    Hi,
    I did as suggested by you. I am confused do i need to put in breakpoints in files myself. I am not sure in which files to place the breakpoints.
    Additionaly, is there any way i can debug my simulation written in tcl.
    Thanks
    VA:F [1.9.12_1141]please wait…Rating: 0.0/5 (0 votes cast)VA:F [1.9.12_1141]Rating: 0 (from 0 votes)

    You should pass your tcl file as argument to ns.

    Go to debug configurations and under arguments tab, write the name of your .tcl file. With its path of course.

  4. Thanks, I tried it with indigo and it worked fine. But, I tried with Ella way, and I got many error. Are these normal?
    I have successed configure eclipse and ns2, but I still don’t understand how to debug with eclipse. I hope you will write articles about it later. Sorry for my english :D

  5. Hi,
    I did as suggested by you. I am confused do i need to put in breakpoints in files myself. I am not sure in which files to place the breakpoints.
    Additionaly, is there any way i can debug my simulation written in tcl.
    Thanks


  6. sara:

    Hi,
    I followed all configuration steps but when i want to build ns-2.34 project , i get two following errors :
    ISO C++ forbids declaration of ‘init_misc’ with no type ns_tclsh.cc /ns-2.34 line 30 C/C++ Problem
    make: *** [ns_tclsh.o] Error 1 ns-2.34 line 0 C/C++ Problem
    Hope you can provide some help.Thank you
    VA:F [1.9.10_1130]please wait…Rating: 0.0/5 (0 votes cast)VA:F [1.9.10_1130]Rating: 0 (from 0 votes)

    I had similar issues, it was because of instead of creating a Makefile project I was creating a Project (Default option). See point 4 below
    4. Select Project Type as “Makefile” Project -> Empty C++ Project.
    Toolchains: Linux GCC

  7. Hi Ella,

    I tried the two extra changes you suggested. Strange! I am getting many errors while running the make command which are mostly related to declaring the variable types. Did you get those errors too?
    What will the changes you suggested do?

    Thanks for the help.


    Ella:

    Ok so here is what I did to make the debug work:
    I changed the Makefile.in in the ns-2x subdirectory as the following:
    1. change CCOPT = @V_CCOPT@
    to CCOPT = @V_CCOPT@ -g
    2. add -DDEBUG -DNDEBUG to the end of the DEFINE parameter such as:
    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 -DDEBUG -DNDEBUG
    now run “./configure” and then “make clean” and “make” in the same directory. After that go hit the debug button in the eclipse and enjoy what you see!
    VA:F [1.9.10_1130]please wait…Rating: 5.0/5 (1 vote cast)VA:F [1.9.10_1130]Rating: +1 (from 1 vote)

  8. Ok so here is what I did to make the debug work:
    I changed the Makefile.in in the ns-2x subdirectory as the following:
    1. change CCOPT = @V_CCOPT@
    to CCOPT = @V_CCOPT@ -g

    2. add -DDEBUG -DNDEBUG to the end of the DEFINE parameter such as:
    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 -DDEBUG -DNDEBUG

    now run “./configure” and then “make clean” and “make” in the same directory. After that go hit the debug button in the eclipse and enjoy what you see!

  9. Hi,

    I am sorry I am unable to help. I have been completely out of touch with ns2. It has been over two years since I worked on it, so am not sure how to help.
    Currently I am completely into J2EE programming.

    Apologies.
    Karthik

  10. Hi
    I followed all the steps written here in eclipse hellios, it builds and runs my tcl file with no errors . However, it doesn’t stop at the breakpoints when debugging, and debug returns the exact same thing as run.
    I would really appreciate any help!

  11. Hi,

    I followed all configuration steps but when i want to build ns-2.34 project , i get two following errors :

    ISO C++ forbids declaration of ‘init_misc’ with no type ns_tclsh.cc /ns-2.34 line 30 C/C++ Problem

    make: *** [ns_tclsh.o] Error 1 ns-2.34 line 0 C/C++ Problem

    Hope you can provide some help.Thank you

  12. Hi. I followed the steps and it works perfect. But my problem is what do I do now, because I have to run a tcl file. I Sourced the file in the ns terminal but the break points are not hit.
    Hope you can provide some help.

  13. I guess you are trying to create two projects in the same location using Eclipse.
    This is not permitted.

    Check out Help in Eclipse. Also, Google can provide you help on this

    Cheers!

  14. I read your blog “Configure NS-2 with Eclipse in Linux” and have tried to follow your procedure,but I have a problem that when I come to “browse to the directory NS-2 source directory ( …/ns-allione-2.34/ns-2.34 )”,the eclipse has a error that /home/lynn/ns/ns-allinone-2.34/ns-2.34 overlaps the location of another project: ‘ns-2.34′ .

    My eclipse galileo version Version:3.5.2
    Could you help me?

  15. Hi,
    I have tried to follow your procedure in your blog to compile ns2 using eclipse galileo. I am frustrated because I did not find the “normal” eclipse, where everything was fine. Do you know if it is possible to use that instead of eclipse galileo?

    Related to eclipse galileo, I can not see the options you described in the IDE:

    “Select Project Type as Makefile Project -> Empty C++ Project.
    Toolchains: Linux GCC”.

    My eclipse galileo version Version: 3.5.2 Build id: M20100211-1343.
    Could you help me?

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>