Difference between revisions of "Ns-3 on Visual Studio"

From Nsnam
Jump to: navigation, search
(add visual studio summary)
(Phase 2 – Visual Studio Windows Conditional Compilation: Questions to clarify the requirements)
Line 38: Line 38:
 
Code to the example programs to produce crashdump files under the Release configuration (similar to core files produced under the Unix variant operating systems).
 
Code to the example programs to produce crashdump files under the Release configuration (similar to core files produced under the Unix variant operating systems).
  
 +
==== Additional CrashHandler header ====
 
This includes adding an additional header file
 
This includes adding an additional header file
  
Line 44: Line 45:
 
#endif</nowiki>
 
#endif</nowiki>
  
 +
* ''Suggest adding this to'' <code>src/core/model/command-line.h</code>, since all executables'' should ''(at least in the main tree) have a'' <code>CommandLine</code> ''instance.'' [[User:Pdbarnes|Pdbarnes]] ([[User talk:Pdbarnes|talk]])
 +
 +
==== Instantiating the CrashHandler ====
 
And an additional installation function  
 
And an additional installation function  
  
Line 56: Line 60:
 
to each main program.
 
to each main program.
  
 +
* ''What scope and lifetime does the'' <code>CCrashHandler</code> ''instance require?  Can it be a data member of'' <code>CommandLine</code> ''? Or a global declared in'' <code>src/core/model/command-line.cc</code>''?'' [[User:Pdbarnes|Pdbarnes]] ([[User talk:Pdbarnes|talk]])
 +
 +
==== Loading DLLs ====
 
Modification of existing code or addition of new code for the Windows configuration.  For example
 
Modification of existing code or addition of new code for the Windows configuration.  For example
  
Line 64: Line 71:
 
   LoadLibraryA("wave.dll");
 
   LoadLibraryA("wave.dll");
 
#endif</nowiki>
 
#endif</nowiki>
 +
 +
* ''Where does this stanza have to occur?  In the main program?  Can it occur in code in a dll itself (building dll A, which depends on dll B)?  How can we leverage the module dependencies already captured in wscript files? [[User:Pdbarnes|Pdbarnes]] ([[User talk:Pdbarnes|talk]])
  
 
The modifications in this phase affect a minority of the NS-3 source code files.
 
The modifications in this phase affect a minority of the NS-3 source code files.

Revision as of 18:24, 4 April 2018

Main Page - Current Development - Developer FAQ - Tools - Related Projects - Project Ideas - Summer Projects

Installation - Troubleshooting - User FAQ - HOWTOs - Samples - Models - Education - Contributed Code - Papers

This is a page to summarize the Visual Studio compatibility work that Robert Ammon initiated during the ns-3.28 release cycle, and continues towards ns-3.29.

Some previous ports for older versions of Visual Studio (2010, 2012) can be found by searching the wiki, but are no longer maintained.

The ns-3 tracker issue is https://www.nsnam.org/bugzilla/show_bug.cgi?id=2726. A per-module status table can be found at https://www.nsnam.org/bugzilla/attachment.cgi?id=3088. As of ns-3.28 release (March 2018), the project is still working through the Phase 1 patches.

Summary of changes

The following provides a summary of the changes for the Visual Studio Development environment. It highlights the changes necessary to the existing NS-3 files to support development for Windows using Visual Studio.

To support integration of the changes in a more manageable fashion, the changes necessary for the VS development environment are segregated into four phases. The four phases are defined as

  • Phase 1 – Visual Studio Compiler Warning Resolution
  • Phase 2 – Visual Studio Windows Conditional Compilation
  • Phase 3 – Visual Studio Class Declaration Changes
  • Phase 4 – NS-3 Implementation Changes for Visual Studio

Phase 1 – Visual Studio Compiler Warning Resolution

The changes in this phase are changes to the existing NS-3 source code files to eliminate compiler warnings under Visual Studio. Under the Visual Studio development environment, all compiler warnings are treated s errors. The changes for this phase eliminate the compiler warnings under Visual Studio. The changes mostly fall into the following categories:

  • Elimination of automatic type casts to lower resolution data types (for example uint16_t to uint8_t)
These changes either add static cast declarations or modify the code (if possible) to eliminate the need for a type case
  • Elimination of unused function parameters
These changes either eliminate the unused parameters (if possible) or add NS_UNUSED references to the parameter.
  • Elimination of hidden variables (for example, a for loop using index i inside of a for loop using index i)
These changes rename the inner variable that is hiding the outer variable.

The Phase 1 changes will be applied in first before the Phase 2, Phase 3 and Phase 4 changes. The Phase 1 changes apply to the majority of the NS-3 modules but not all modules.

Phase 2 – Visual Studio Windows Conditional Compilation

The changes in this phase are changes to the existing NS-3 source code files to add conditional code for the Visual Studio development environment. These changes add code that is executed under the Windows configuration only. The changes mostly fall into the following categories:

Code to the example programs to produce crashdump files under the Release configuration (similar to core files produced under the Unix variant operating systems).

Additional CrashHandler header

This includes adding an additional header file

#ifdef _WIN32
#include "CrashHandler.h"
#endif
  • Suggest adding this to src/core/model/command-line.h, since all executables should (at least in the main tree) have a CommandLine instance. Pdbarnes (talk)

Instantiating the CrashHandler

And an additional installation function

#ifdef _WIN32
#ifndef _DEBUG
	CCrashHandler ch;
	ch.SetProcessExceptionHandlers();
	ch.SetThreadExceptionHandlers(); 
#endif
#endif

to each main program.

  • What scope and lifetime does the CCrashHandler instance require? Can it be a data member of CommandLine ? Or a global declared in src/core/model/command-line.cc? Pdbarnes (talk)

Loading DLLs

Modification of existing code or addition of new code for the Windows configuration. For example

// Force DLLs to be loaded for modules loaded dynamically
#ifdef _WIN32
  LoadLibraryA("wimax.dll");
  LoadLibraryA("uan.dll");
  LoadLibraryA("wave.dll");
#endif
  • Where does this stanza have to occur? In the main program? Can it occur in code in a dll itself (building dll A, which depends on dll B)? How can we leverage the module dependencies already captured in wscript files? Pdbarnes (talk)

The modifications in this phase affect a minority of the NS-3 source code files.

Phase 3 – Visual Studio Class Declaration Changes

While the Windows DLLs are similar to the Unix shared libraries, there are a couple of significant differences between them. One of the differences which cause changes in the NS-3 source code is items in a Windows DLL are hidden from consumers of the DLL unless specifically identified as exported items. This means that the classes in the NS-3 modules that are accessible by other NS-3 modules or user programs. This change adds a new DLL to the core module and an additional conditional declaration to each class declaration.

NS3DLL.H code fragment
#ifndef NS3DLL_H
#define NS3DLL_H

#ifdef _WIN32
#ifdef _ANT
#define NS3ANTLIB __declspec(dllexport)
#else
#define NS3ANTLIB __declspec(dllimport)
#endif
...
#else
#define NS3ANTLIB
...
#endif

#endif /* NS3DLL_H */

Example class declaration

class NS3ANTLIB AntennaModel : public Object

The modifications in this phase affect almost every header file in the NS-3 source code.

Phase 4 – NS-3 Implementation Changes for Visual Studio

In a few of the NS-3 implementations, there are differences in the implementation between Linux and Windows. These are cases where the same source code does not produce the exact same results, either to differences in the OS, third party libraries of compiler code generation. For these changes, the source code has been modified to produce equivalent behavior on all platforms that matches the original implementation.

The number of changes in this phase are limited to a few examples.