Writing your own code

NetSim allows the user to write the custom code for all the protocols by creating a DLL (Dynamic Link Library) for their custom code and replacing NetSim’s default DLL with the user’s custom DLL.

There are various important steps in this process, and each of these steps has various options as explained in the subsequent pages:

Modifying code

DLL is the shared library concept, implemented by Microsoft. All DLL files have a .dll file extension. DLLs provide a mechanism for sharing code and data to upgrade functionality without requiring applications to be re-linked or re-compiled. It is not possible to directly execute a DLL, since it requires an EXE for the operating system to load it through an entry point.

Dynamic link libraries (DLLs) can be built using different compilers:

  1. Using Microsoft Visual Studio Compiler
  2. Compiler: Microsoft Visual Studio

To create the DLL follow the steps given below.

Note: Make sure that Visual Studio 2010 is installed in your computer

Step 1: Go to “../NetSim Standard/src/Simulation” folder and double click on “NetSim.sln” file to open the solution in visual studio.

Note: It is recommended to keep a separate copy of the “../NetSim Standard/src/Simulation” folder to have the backup of the original source code.

Note: Sometimes you may get the following warning message. Then click on ok and proceed.

Step 2: Inside Solution Explorer pane in Visual Studio 2010, double click on DSR. Then open DSR.C file by double clicking on it.

Step 3: Add fprintf (stderr, “Source is modified\n”); statement inside the source code of DSR as shown below to print “Source is modified”.

Note: - Use fprintf (stderr,”Hello World”) instead of printf ( ) to write to standard out. stdout is redirected to LogFile.txt which is present in <iopath>. So you can see “Hello World” Statement (or whatever you write inside the printf) inside the LogFile.txt.

Once this is done click to save the changes and overwrite the file (in case of write protection).

Building Dlls

Step 1: Right Click on the Project (in this case DSR) inside the Solution Explorer pane and select Build to create DLL file of that specific protocol only

NOTE: To create DLL file of all the protocols actively displayed inside solution pane, click on “BuildBuild Solution”

Check that the build is successful and necessary DLL files have been built.

Step 2: Inside the simulation folder (present on the desktop) a Dll folder will be created and inside, the DLL’s are built.

It will contain custom DLL’s which have been built per the modifications done.

Linking Dlls

The procedure to link custom dynamic link libraries (DLLs) is explained below. This procedure is common for any linking of any custom DLL to NetSim.

Now we will link the customized libDSR.dll to the NetSim.

Step 1: Copy the newly created DLL file of customized DSR from “../NetSim Standard/src/Simulation” folder

Step 2: Go to “NetSim Standardbin” folder. Here one would find default DLLs for respective protocols as shown in next figure.

Step 3: Rename the default DLL:It is recommended to rename the default DLL thereby saving a copy of original DLL. For example libCognitiveRadio.dll has been renamed as libCognitiveRadio_default.dll as shown below.

Step 4: Place the custom DLL obtained from Step 1 inside the “NetSim Standard bin” folder.

Running Simulation

User can run the simulation via GUI (Please refer section 3). In this case, user can create a scenario in any network which involves DSR protocol. Running the simulation with the custom DLL will give desired output to the user as shown below.

Press enter then simulation will continue.

results matching ""

    No results matching ""