Getting Started with NS-3 and QtCreator

NS-3 is a free discrete-event network simulator for internet systems, targeted primarily for research and educational use. In this blog post I will show how to set up NS-3 on Linux (Ubuntu 14.04 LTS) and how to configure QtCreator as an IDE for your project.

Notice that you can find much more details on NS-3 installation and usage following NS-3 Tutorial and reading NS-3 wiki page. However this blog post will show only the necessary steps to get the whole thing running.

Install NS-3

In order to get started download NS-3 using a Tarball and extract it:

In the extracted folder ns-allinone-3.22 you can find ./build.py python script. But before we start building NS-3 we should install some dependencies:

Now we are ready to build NS-3. For the quick and easy build we can use the python script:

This script will call WAF build tool to do the actual building.
Or if we want to have more control over the build system we can use WAF directly. In order to do this we first need to configure the build system and afterwards invoke the build command. To see all available options type:

To configure the build system for static build in release mode use:

And afterwards build NS-3:

You will see a lot of compiler output messages displayed as the build script builds the various pieces of NS-3. Finally you should see ‘build’ finished successfully message and a list of built modules.
Now you can run the unit tests of the NS-3 distribution in order to verify that the distribution has built correctly.

It is important  that the summary line at the end tells that all tests passed and none of them failed or crashed.

Set up IDE

  • Download and install QtCreator from here.
  • Open QtCreator and go to File menu and select New File or Project.
  • Select Non-Qt Project -> Plain C++ Project and click on Choose… button.
  • Choose name and location of the project and click on Next >
  • Continue clicking on Next > and Finish.

For the demonstration purposes let us take the source code of the first NS-3 tutorial and compile it in QtCreator. You will find the code in your NS-3 distribution in ns-3.22/examples/tutorial/first.cc file. Copy and paste the whole code into main.cpp in QtCreator.

Now it is time to let QtCreator know where your NS-3 headers are located and which libraries should be linked to the project. To do so, open the project “<project-name>.pro” file and add INCLUDEPATH and LIBS as follows:

With this lines we are telling QtCreator to look for the headers and libraries in “/home/includeb/projects/ns-allinone-3.22/ns-3.22/build” folder and to link the debug versions of core, network, internet, point-to-point, applications, stats, bridge and mpi libraries to the project.

After adding this lines to the project file you should run Build -> Run qmake and finally  Build -> Build Project “ProjectName”.

QtCreator + NS-3 screenshot
QtCreator + NS-3 screenshot