Difference between revisions of "HOWTO use ns-3 on Windows with Visual Studio 2010"

From Nsnam
Jump to: navigation, search
(Requirements)
 
(68 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''Installation & Usage for NS3 on Windows'''
+
This page covers installation and usage for ns-3 on Windows using Visual Studio 2010 only. Please see also see [[Windows Port of ns-3 using Visual Studio|information about the port]].
 +
 
 
= Requirements =
 
= Requirements =
 
* Microsoft Visual Studio 2010
 
* Microsoft Visual Studio 2010
 
* Microsoft Windows 7 or Microsoft Windows XP
 
* Microsoft Windows 7 or Microsoft Windows XP
 
+
* Mercurial
Note: By default the /MP compiler option is set to 5 to 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 5 , based on your system's capabilities. For more on the MP option visit this [http://msdn.microsoft.com/en-us/library/bb385193.aspx link]
+
 
+
Here is a [http://www.youtube.com/watch?v=61wqGmcqnHs youtube video] showing how to locate the MP option
+
  
 
= Download =
 
= Download =
* Version (ns-3.10-Win-1.0) Pilot/Limited feature/Alpha version Implementation built on ns-3-dev(dated 02/07/2011)
+
Download via mercurial : "hg clone http://code.nsnam.org/jabraham3/ns-3-win"
Download from [http://code.nsnam.org/jabraham3/ns3-on-windows/ns-3.10-Win-1.0/raw-file/020dc57425eb/ns-3.10-Win-1.0.zip here]
+
  
 
= First Build =
 
= First Build =
Unzip the contents of the zip file into a suitable location.
 
  
Currently the Visual Studio Solution is organized into two projects. This organization is liable to change in the upcoming releases
+
Currently the Visual Studio Solution is organized into around 30 projects. Each of these projects correspond to the modules in the ns-3-dev line up (example: 'aodv').
 +
However,one project file is named "MyExample". This is the project that will carry the source code with the main function (typically your example source code)
  
# 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.
+
# Open the ns-3-dev solution file "ns-3-dev.sln" under the "ns-3-dev\windows" folder
# 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
+
# After the solution is opened, Right-click the solution "ns-3-dev" and select "Build Solution". Here is a [http://www.youtube.com/watch?v=br-WfAN3n8s youtube video] showing this.
 +
# If the build completes successfully, "MyExample.exe" will be created under the "ns-3-dev\windows\Debug" folder
  
 
+
Note: The solution has "hello-simulator.cc" as the default example.
The steps to build the ns3Main.exe executable are as follows
+
To add your own example go to this link
# 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.
+
# Once the entire solution is opened, right-click the "ns-3-dev-lib" project and select the "build" option.Here is a [http://www.youtube.com/watch?v=2QRbtax1j5Q youtube video] showing the previous two steps.
+
# After ensuring "ns-3-dev-lib.lib" is successfully built , right-click on the "Main" project and select build.Here is a [http://www.youtube.com/watch?v=1OOR_n-O35A youtube video] showing this step.
+
# 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 [http://www.youtube.com/watch?v=WfltlUv2Xic youtube video] showing this step.
+
  
 
= Running an example =
 
= Running an example =
# Open the ns3Main.exe executable
+
# The solution has "hello-simulator.cc" as the default example. To add a new example, remove "hello-simulator.cc" from the "MyExample" project ( MyExample---> Right-click "hello-simulator.cc" --> Select "Remove")
# Locate the example you want to run from the Examples tree
+
# Then Right-click "MyExample"-->Add-->Existing item --> Your example file
# Specify optional "Application arguments"
+
# Build the solution as previously described
# Specify optional logging by selecting the appropriate Log component and Log Level
+
# Select an optional logging prefix such as "Prefix Time"
+
# Select the "Play" button
+
# At the end of the simulation a message box saying "Simulation Complete" will appear.
+
  
Here is a [http://www.youtube.com/watch?v=JYRKO0ssB5o youtube video] showing the above steps
+
Here is a [http://www.youtube.com/watch?v=_1dYM3COCq4 youtube video] showing the above steps
  
= Adding your code =
+
= Debugging =
To add code to the "src" folder you must follow the instructions in the ns3 main tutorial/documentation.
+
# Set a break-point at a suitable location. Lets choose the "Insert" function in "map-scheduler.cc"
To add your script to the "Examples" tree let us walk-through an example:
+
# Hit the "debug" button at the top portion of your IDE.
 +
# Provide input to your application as you normally would.
  
* Right-click on the "MyExamples" folder under the "Main" project and select "Add->New Item" and name your file "MyFirstExample.cc"
+
Here is a [http://www.youtube.com/watch?v=YmaJ53PSXWU youtube video] showing these steps.
* Add the following piece of code to "MyFirstExample.cc"
+
  
<nowiki>
+
= Using NetAnim on Windows =
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+
* Recommended IDE: [http://qt.nokia.com/products/developer-tools/ QT Creator]
/*
+
* Building the NetAnim executable:
  * This program is free software; you can redistribute it and/or modify
+
# Download the latest version of NetAnim for Windows [http://code.nsnam.org/jabraham3/ns3-on-windows/ns-3.10-Win-1.2/raw-file/78d716fec82a/NetAnim.zip here]
  * it under the terms of the GNU General Public License version 2 as
+
# Unzip the contents of the zip file
  * published by the Free Software Foundation;
+
# Open the NetAnim.pro file using Qt Creator.
  *
+
# In Qt Creator , Select "Build All"
  * This program is distributed in the hope that it will be useful,
+
# NetAnim.exe will be available in the same directory as the NetAnim.pro file
  * 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"
+
If you get undefined reference to `WSAStartup` etc try adding the following lines to the "NetAnim.pro" file, if you use the MiniGW toolchain
# 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;
+
}
+
</nowiki>
+
* 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
+
 
  <nowiki>
 
  <nowiki>
  InsertIntoExamplesTree ("Examples_win\\MyExamples\\my_first_win_main",my_first_win_main);
+
CONFIG += network
 +
LIBS += -lwsock32
 
</nowiki>
 
</nowiki>
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.
 
 
  
* Add the function prototype of "my_first_win_main" to the header file "MyExamplesProtoTypes.h" located under the "MyExamples" folder in the "Main" project
+
or if you use Visual C++ tool chain
 
  <nowiki>
 
  <nowiki>
int my_first_win_main (int argc, char *argv[]);
+
CONFIG += network
 +
LIBS += ws2_32.lib
 
</nowiki>
 
</nowiki>
* 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 [http://www.youtube.com/watch?v=g9ThHfwsDXk youtube video] showing these steps
 
  
= Debugging =
+
Here is a youtube [http://www.youtube.com/watch?v=Sl9Xwemg6ss video] showing the above steps.
# Set a break-point at a suitable location. Lets choose the "Insert" function in "map-scheduler.cc"
+
# Hit the "debug" button at the top portion of your IDE.
+
# Provide input to your application as you normally would.
+
 
+
Here is a [http://www.youtube.com/watch?v=YmaJ53PSXWU youtube video] showing these steps.
+

Latest revision as of 16:32, 10 February 2013

This page covers installation and usage for ns-3 on Windows using Visual Studio 2010 only. Please see also see information about the port.

Requirements

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

Download

Download via mercurial : "hg clone http://code.nsnam.org/jabraham3/ns-3-win"

First Build

Currently the Visual Studio Solution is organized into around 30 projects. Each of these projects correspond to the modules in the ns-3-dev line up (example: 'aodv'). However,one project file is named "MyExample". This is the project that will carry the source code with the main function (typically your example source code)

  1. Open the ns-3-dev solution file "ns-3-dev.sln" under the "ns-3-dev\windows" folder
  2. After the solution is opened, Right-click the solution "ns-3-dev" and select "Build Solution". Here is a youtube video showing this.
  3. If the build completes successfully, "MyExample.exe" will be created under the "ns-3-dev\windows\Debug" folder

Note: The solution has "hello-simulator.cc" as the default example. To add your own example go to this link

Running an example

  1. The solution has "hello-simulator.cc" as the default example. To add a new example, remove "hello-simulator.cc" from the "MyExample" project ( MyExample---> Right-click "hello-simulator.cc" --> Select "Remove")
  2. Then Right-click "MyExample"-->Add-->Existing item --> Your example file
  3. Build the solution as previously described

Here is a youtube video showing the above 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

If you get undefined reference to `WSAStartup` etc try adding the following lines to the "NetAnim.pro" file, if you use the MiniGW toolchain

CONFIG += network
LIBS += -lwsock32

or if you use Visual C++ tool chain

CONFIG += network
LIBS += ws2_32.lib


Here is a youtube video showing the above steps.