HOWTO use ns-3 on Windows with Visual Studio 2010

From Nsnam
Revision as of 16:45, 12 March 2011 by Jabraham3 (Talk | contribs) (Adding your code)

Jump to: navigation, search

Installation & Usage for NS3 on Windows

Requirements

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

Note: By default the /MP compiler option is set to 30 reduce build time. However, this setting can significantly impact the performance of your system if processor and memory resources are limited. Please remove this option or reduce the number from 30 , based on your system's capabilities. For more on the MP option visit this link

Here is a youtube video showing how to locate the MP option

Download

First Build

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

  1. Main project: Containing the Windows GUI components, the examples folder and the folder where your scripts may go.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 output of this project is the "ns-3-dev-lib.lib" static library which the "Main" project will link into


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

  1. 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.
  2. 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.
  3. After ensuring "ns-3-dev-lib.lib" is successfully built , right-click on the "Main" project and select build.Here is a youtube video showing this step.
  4. Watch out linker errors (some are expected during the release of ns-3.10-Win-1.0 as several components are missing.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:

  1. Right-click on the "MyExamples" folder under the "Main" project and select "Add->New Item" and name your file "MyFirstExample.cc"
  2. 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;

}

Debugging