Applicable Versions | NetSim Standard | NetSim Pro |
The payload of the packet is added to the application layer while generating the packet. NetSim adds its own payload to the packet as per the packet size specified in the application properties. However, the payload can be modified by the user by reading from a string, file, etc.
Note: In this example, the payload of a packet is modified by reading from a string. The steps involved may vary between different versions of NetSim. Choose the appropriate section of this article, as per the version of NetSim.
Applicable Releases | v11.1 | v12 | v12.2 | v13 |
Note: From v13.1 Open NetSim source code in Visual Studio 2019 by clicking on the Open Code option present in NetSim Home Screen via Your Work->Source Code->Open Code option.
1. Open NetSim source code in Visual Studio 2019 by clicking on the Open Code button present on NetSim Home Screen via Open Simulation->Workspace Options->Open Code. Go to the Application Project in the solution explorer. Open copy_payload() function present in Application.c file inside the Application project.
2. Inside the function copy_payload(), make the modifications as given below (highlighted in red) :
void copy_payload(UINT8 real[],NetSim_PACKET* packet,unsigned int* payload,APP_INFO* info)
{
u_short i;
uint32_t key = 16;
static int j = 0, k = 1, size = 1;
static long file_size, curr_pos;
char custom_data[1460], ch;
if (k)
{
open_file();
k = 0;
/* Get the number of bytes */
fseek(fp, 0L, SEEK_END);
file_size = ftell(fp);
fseek(fp, 0L, SEEK_SET);
}
if (file_size < *payload)
{
while ((ch = fgetc(fp)) != EOF)
{
custom_data[j] = ch;
j++;
}
j = 0;
fseek(fp, 0L, SEEK_SET);
}
else
{
while (size < file_size)
{
ch = fgetc(fp);
custom_data[j] = ch;
j++;
size++;
if (size == file_size)
{
/* reset the file position indicator to the beginning of the file */
fseek(fp, 0L, SEEK_SET);
size = 1;
}
if (j == *payload)
{
curr_pos = ftell(fp);
fseek(fp, curr_pos, SEEK_SET);
j = 0;
break;
}
}
}
if (payload)
{
for (i = 0; i < *payload; i++)
{
if (info->encryption == Encryption_XOR)
real[i] = xor_encrypt(custom_data[i%(*payload)], 16);
else
real[i] = custom_data[i%(*payload)];
}
if (info->encryption == Encryption_TEA)
encryptBlock(real, payload, &key);
else if (info->encryption == Encryption_AES)
aes256(real,payload);
else if(info->encryption==Encryption_DES)
des(real,payload);
}
}
3. In the same Application.c file make the modifications at the start of the file as given below (highlighted in red) :
#include "main.h"
#include "Application.h"
#include "CoAP.h"
static void open_file();
FILE *fp = NULL;
static void open_file()
{
fp = fopen("input_data.txt", "r");
}
/**
This function is used to initialize the parameter for all the application based on
the traffic type
*/
_declspec(dllexport) int fn_NetSim_Application_Init(struct stru_NetSim_Network *NETWORK_Formal,
NetSim_EVENTDETAILS *pstruEventDetails_Formal,
char *pszAppPath_Formal,
char *pszWritePath_Formal,
int nVersion_Type,
void **fnPointer)
{
4. Create a file input_data.txt with some content and save the txt file in NetSim binary folder in NetSim's installation directory (Eg: C:\Program Files (x86)\NetSim Standard\bin or C:\Program Files \NetSim\Standard_v13_1\bin).
For eg: Save the input_data.txt file with the following content and save ".
"This is to demonstrate how users can add their own payload to the packet. The payload will further be encrypted if encryption is enabled". The payload will further be encrypted if encryption is enabled
5. After the source code is modified, rebuild the Application module. Upon successful build, NetSim will automatically take care of linking your modified code with further simulations performed.
6. To view the payload of the packet, Wireshark can be set to online in the Node properties. For instance, the user can create a simple scenario in Internetworks with two Wired Nodes connected to a router. Set an application between the two nodes. In either of the Nodes right click and select properties. In the General properties set Wireshark to online and run the simulation.
Result and Analysis
During the simulation, Wireshark will automatically execute and will display the packets captured in the wired node. One can view the packet payload in the pane at the bottom, by clicking on the corresponding packet.
Users can also change the payload of the packet by reading content from a file.
Result and Analysis
During the simulation, Wireshark will automatically execute and will display the packets captured in the wired node. One can view the packet payload in the pane at the bottom, by clicking on the corresponding packet.
Applicable Releases | v10 | v11.0 |
1. Open copy_payload() function present in Application.c file inside the Application project
2. Inside the function copy_payload(), make the modifications as given below (highlighted in red) :
void copy_payload(UINT8 real[],NetSim_PACKET* packet,unsigned int* payload,APP_INFO* info)
{
u_short i;
uint32_t key = 16;
static int j = 0, k = 1, size = 1;
static long file_size, curr_pos;
char custom_data[1460], ch;
if (k)
{
open_file();
k = 0;
/* Get the number of bytes */
fseek(fp, 0L, SEEK_END);
file_size = ftell(fp);
fseek(fp, 0L, SEEK_SET);
}
if (file_size < *payload)
{
while ((ch = fgetc(fp)) != EOF)
{
custom_data[j] = ch;
j++;
}
j = 0;
fseek(fp, 0L, SEEK_SET);
}
else
{
while (size < file_size)
{
ch = fgetc(fp);
custom_data[j] = ch;
j++;
size++;
if (size == file_size)
{
/* reset the file position indicator to the beginning of the file */
fseek(fp, 0L, SEEK_SET);
size = 1;
}
if (j == *payload)
{
curr_pos = ftell(fp);
fseek(fp, curr_pos, SEEK_SET);
j = 0;
break;
}
}
}
if (payload)
{
for (i = 0; i < *payload; i++)
{
if (info->encryption == Encryption_XOR)
real[i] = xor_encrypt(custom_data[i%(*payload)], 16);
else
real[i] = custom_data[i%(*payload)];
}
if (info->encryption == Encryption_TEA)
encryptBlock(real, payload, &key);
else if (info->encryption == Encryption_AES)
aes256(real,payload);
else if(info->encryption==Encryption_DES)
des(real,payload);
}
}
3. In the same Application.c file perform the modifications at the start of the file as given below (highlighted in red) :
#include "main.h"
#include "Application.h"
#include "CoAP.h"
static void open_file();
FILE *fp = NULL;
static void open_file()
{
fp = fopen("input_data.txt", "r");
}
/**
This function is used to initialize the parameter for all the applications based on
the traffic type
*/
_declspec(dllexport) int fn_NetSim_Application_Init(struct stru_NetSim_Network *NETWORK_Formal,
NetSim_EVENTDETAILS *pstruEventDetails_Formal,
char *pszAppPath_Formal,
char *pszWritePath_Formal,
int nVersion_Type,
void **fnPointer)
{
4. Create a file input_data.txt in NetSim binary folder in NetSim's installation directory (Eg: C:\Program Files (x86)\NetSim Standard\bin)
5. After the source code is modified, rebuild the Application module and replace the newly built libApplication.dll file in the bin folder of NetSim after renaming the original libApplication.dll file to say, libApplication_original.dll as a backup.
Results and analysis:
To view the payload of the packet, Wireshark can be set to online in the Node properties. For instance, a user can create a simple scenario in Internetworks with two Wired Nodes connected to a router. Set an application between the two nodes. In either of the Nodes right click and select properties. In the global properties set Wireshark to online and run the simulation.
During the simulation, Wireshark will automatically execute and will display the packets captured in the wired node. One can view the packet payload in the pane at the bottom, by clicking on the corresponding packet.