HOWTO use ns-3 on Windows with Visual Studio 2010

From Nsnam
Revision as of 03:07, 31 March 2011 by Jabraham3 (Talk | contribs) (Distributed-simulation)

Jump to: navigation, search

Installation & Usage for NS3 on Windows

Requirements

  • Microsoft Visual Studio 2010
  • Microsoft Windows 7 or Microsoft Windows XP

Download

  • Version (ns-3.10-Win-1.3) Pilot/Limited feature/Alpha version Implementation built on ns-3-dev(dated 02/07/2011)

Download from here

  • Version (ns-3.10-Win-1.2) Pilot/Limited feature/Alpha version Implementation built on ns-3-dev(dated 02/07/2011)

Download from here

  • Version (ns-3.10-Win-1.1) Pilot/Limited feature/Alpha version Implementation built on ns-3-dev(dated 02/07/2011)

Download from here

First Build

Currently the Visual Studio Solution is organized into three projects. This organization is liable to change in the upcoming releases

  1. Main project: Containing the Windows GUI components.The output of this project is the ns3Main.exe executable.
  2. ns-3-dev-lib project: Containing the "src" folder from the parent ns-3 project, the examples folder and the folder where your scripts may go.The output of this project is the "ns-3-dev-lib.lib" static library which the "Main" project will link into
  3. Misc project: Containing code from "contrib" folder and other 3rd party code.

The steps to build the ns3Main.exe executable are as follows

  1. Unzip the contents of the zip file into a suitable location.
  2. Open the "ns-3-dev.sln" Visual studio 2010 solution file by double-clicking it.This file is located under the "Windows\ns-3-dev" folder.
  3. Once the entire solution is opened, right-click the "ns-3-dev-lib" project and select the "build" option.Here is a youtube video showing the previous two steps.
  4. After ensuring "ns-3-dev-lib.lib" is successfully built,right-click on the "Misc" project and select "Build". After ensuring "Misc.lib" is built, right-click on the "Main" project and select "Build".Here is a youtube video showing this step.
  5. Locate the "ns3Main.exe" file (Located under "Windows\ns-3-dev\Debug")and double-click it.Here is a youtube video showing this step.

Running an example

  1. Open the ns3Main.exe executable
  2. Locate the example you want to run from the Examples tree
  3. Specify optional "Application arguments"
  4. Specify optional logging by selecting the appropriate Log component and Log Level
  5. Select an optional logging prefix such as "Prefix Time"
  6. Select the "Play" button
  7. At the end of the simulation a message box saying "Simulation Complete" will appear.

Here is a youtube video showing the above steps

Adding your code

To add code to the "src" folder you must follow the instructions in the ns3 main tutorial/documentation. To add your script to the "Examples" tree let us walk-through an example:

  • Right-click on the "MyExamples" folder under the "ns-3-dev-lib" project and select "Add->New Item" and name your file "MyFirstExample.cc"
  • Add the following piece of code to "MyFirstExample.cc"
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation;
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */

 # include "ns3/core-module.h"
 # include "MyExamplesProtoTypes.h"
 NS_LOG_COMPONENT_DEFINE ("MyFirstExample");
 using namespace ns3;

 int 
 my_first_win_main (int argc, char *argv[])
 {
   NS_LOG_UNCOND ("Hello from My first");
   return 0;
 }

  • Add the function prototype of "my_first_win_main" to the header file "MyExamplesProtoTypes.h" located under the "MyExamples" folder in the "ns-3-dev-lib" project
int my_first_win_main (int argc, char *argv[]);


  • Open "MainDlg.cpp" under "Source Files" under the "Main Project" and go to the bottom of the function void CMainDlg::PopulateExamplesTree() to the comments // Add your custom examples here
  • Add the following line of code at this point
  InsertIntoExamplesTree ("Examples_win\\MyExamples\\my_first_win_main",my_first_win_main);

where "my_first_win_main" is the function you added in MyFirstExample.cc and "Examples_win\\MyExamples\\my_first_win_main" sets your example at your desired location in the Examples tree.


  • Right-click the "Main" project and select "Build" to build NS3Main.exe and execute it as explained earlier. Your newly added example should now appear in the examples tree.

Here is a youtube video showing these steps

Debugging

  1. Set a break-point at a suitable location. Lets choose the "Insert" function in "map-scheduler.cc"
  2. Hit the "debug" button at the top portion of your IDE.
  3. Provide input to your application as you normally would.

Here is a youtube video showing these steps.

Using NetAnim on Windows

  • Recommended IDE: QT Creator
  • Building the NetAnim executable:
  1. Download the latest version of NetAnim for Windows here
  2. Unzip the contents of the zip file
  3. Open the NetAnim.pro file using Qt Creator.
  4. In Qt Creator , Select "Build All"
  5. NetAnim.exe will be available in the same directory as the NetAnim.pro file

Here is a youtube video showing the above steps.


  • Using NetAnim.exe along with NS3Main.exe:
  1. Ensure that the Path to qmake and the Qt dlls are added to the PATH system Environment variable. For example:C:\Qt\2010.05\qt\qmake;C:\Qt\2010.05\qt\bin. (Skipping this step might result in errors such as "*.dll is missing" when you run NetAnim.exe)
  2. Open NS3Main.exe, and Click "Set NetAnim Location" to point NS3Main.exe to the location of NetAnim.exe. If things went well, this step needs to be done only once for each version of NS3.
  3. NetAnim can be used in two modes
    1. Mode 1: Post-simulation Animation using Capture files:
      1. First a routine simulation is run which captures the traffic to a trace file. One example of this is "Examples\dumbbell-animation_win.cc"
      2. If the location of NetAnim.exe is not yet set, please click "Set NetAnim Location".Once the simulation is complete, click "Read Trace File" and point NetAnim to the Location of the trace file. (if these steps complain about missing dlls ensure that PATH system Environment variable is correctly set.A video of the above steps is here
    2. Mode 2: In-simulation Animation via a TCP connection between Ns3 and NetAnim:
      1. In this mode, NS3 transfers information to be plotted to NetAnim.exe via a TCP connection. NS3Main.exe will have to listen for incoming connections from NetAnim via a suitable port. This port can be specified via the Application argument "--port=5006" for example in the case of dumbbell-animation.
      2. Once the listening port is specified, run the simulation like you would do normally.
      3. Specify the port to which NetAnim should connect to via the "Port" Text box in the "NetAnim" group control.
      4. Click on "Start NetAnim" to connect it to NS3Main.exe
      5. If everything goes well, NetAnim should be able to create a visualization as the simulation progresses.A video of the above steps is here

Distributed-simulation

  • Requirements:
    • OpenMPI_v1.5.3-2_win32 or higher. Visit this link
    • ns-3.10_Win-1.3 or higher
  • Steps:
    • Install Open MPI. Default installation locations are recommended. In Windows 7 systems it is usually installed at "C:\Program Files (x86)\OpenMPI_v1.5.3-win32"
    • Open the "ns-3-dev-MPI.sln" solution file under the "Windows\ns-3-dev" folder
    • Build "ns-3-dev-lib-MPI" and "Misc-MPI" projects (Right-click each of the projects and select "Build")
    • After ensuring "ns-3-dev-lib-MPI.lib" and "Misc-MPI.lib" are built, open the visual studio command prompt. For more on the Visual Studio Command prompt , visit this link
    • Change to the mpi examples directory "ns-3-dev\examples_Win\mpi"
    • Enter the command "nmake clean" followed by "nmake all"