| Applicable Versions | NetSim Standard | NetSim Pro |
Rebroadcasting in NetSim:
To implement this project in NetSim, we have created Rebroadcast.c file inside the Application project. The file contains the following functions:
This function is used to rebroadcast the packet
This function is used to check whether rebroadcasting is allowed or not
This function is used to add the packet to the rebroadcast list
This function is used to clean the broadcast information
Note: scroll down to see code changes for appropriate releases
| Applicable Releases | v13.0 |
/*This is used to generate next broadcast packet if the current device is present in the source list*/
_declspec (dllexport) int fn_NetSim_Application_Run() { switch(pstruEventDetails->nEventType)
{
case APPLICATION_OUT_EVENT:
handle_app_out();
break;
{
NetSim_PACKET* pstruPacket=pstruEventDetails->pPacket;
if(pstruPacket->nPacketType != PacketType_Control && pstruPacket->pstruAppData- >nApplicationId && pstruPacket->nControlDataType/100 != PROTOCOL_APPLICATION)
{
ptrAPPLICATION_INFO pstruappinfo;
fnValidatePacket(pstruPacket);
pstruappinfo=applicationInfo[pstruPacket->pstruAppData->nApplicationId-1];
pstruPacket->pstruAppData->dEndTime = pstruEventDetails->dEventTime;
fn_NetSim_Application_Plot(pstruPacket);
#ifdef REBROADCAST
if (pstruappinfo->sourceList[0] == pstruPacket->nSourceId)
#endif
appmetrics_dest_add(pstruappinfo, pstruPacket, pstruEventDetails->nDeviceId);
if(pstruappinfo->nAppType==TRAFFIC_PEER_TO_PEER && pstruPacket->pstruAppData- >nAppEndFlag==1)
{
fn_NetSim_Application_P2P_MarkReceivedPacket(pstruappinfo,pstruPacket); fn_NetSim_Application_P2P_SendNextPiece(pstruappinfo,get_first_dest_from_packet(pstruPacket ),pstruEventDetails->dEventTime);
}
/*The code checks if the destination is ‘0’ i.e., Broadcast packet, then it adds the packet to rebroadcast list*/
//Fragment the packet
int nSegmentCount = 0;
double segmentsize = fn_NetSim_Stack_GetMSS(pstruPacket);
nSegmentCount = fn_NetSim_Stack_FragmentPacket(pstruPacket, (int)fn_NetSim_Stack_GetMSS(pstruPacket));
//add rebroadcast
#ifdef REBROADCAST
if (appInfo->sourceList[0] == pstruEventDetails->nDeviceId)
#endif
set_app_end_and_generate_next_packet(pstruPacket, otherDetails, destCount, dest);
//Add the dummy payload to packet
fn_NetSim_Add_DummyPayload(pstruPacket, appInfo);
#ifdef REBROADCAST
if (appInfo->sourceList[0] == pstruEventDetails->nDeviceId)
#endif
appmetrics_src_add(appInfo, pstruPacket);
appout_send_packet(s, appInfo, pstruPacket, nDeviceId);
#ifdef REBROADCAST
if (!dest[0])
rebroadcast_add_packet_to_info(pstruPacket, pstruEventDetails->dEventTime);
#endif
// REBROADCAST
}
/* It checks whether the destination is ‘0’ or not. If it is ‘0’, then it rebroadcasts the packet or else deletes the packet.*/
#ifdef REBROADCAST
if (pstruappinfo->sourceList[0] == pstruPacket->nSourceId)
#endif
appmetrics_dest_add(pstruappinfo, pstruPacket, pstruEventDetails->nDeviceId);
if(pstruappinfo->nAppType==TRAFFIC_PEER_TO_PEER && pstruPacket->pstruAppData- >nAppEndFlag==1)
{
fn_NetSim_Application_P2P_MarkReceivedPacket(pstruappinfo,pstruPacket); fn_NetSim_Application_P2P_SendNextPiece(pstruappinfo,get_first_dest_from_packet(pstruPacke t),pstruEventDetails->dEventTime);
}
if(pstruappinfo->nAppType == TRAFFIC_EMULATION && pstruPacket->szPayload)
{
fn_NetSim_Dispatch_to_emulator(pstruPacket);
}
if (pstruappinfo->nAppType == TRAFFIC_BSM_APP)
{
process_saej2735_packet(pstruPacket);
}
#ifdef REBROADCAST
UINT destCount;
NETSIM_ID* dest = get_dest_from_packet(pstruPacket, &destCount);
if (!dest[0])
{
rebroadcast_packet(pstruPacket, pstruEventDetails->nDeviceId, pstruEventDetails->dEventTime);
}
else
{
#elif
//Delete the packet
fn_NetSim_Packet_FreePacket(pstruPacket);
//add
#endif
// REBROADCAST
#ifdef REBROADCAST
}
#endif
}
int fn_NetSim_Add_DummyPayload(NetSim_PACKET* packet, ptrAPPLICATION_INFO);
//Encryption char xor_encrypt(char ch, long key);
int aes256(char* str, int* len);
int des(char* buf, int* len);
//Application event handler
void handle_app_out();
#define REBROADCAST
void rebroadcast_add_packet_to_info(NetSim_PACKET* packet, double time);
void rebroadcast_packet(NetSim_PACKET* packet, NETSIM_ID devId, double time);
#endif
Also refer: MANET_VANET-Rebroadcast _V13.0.pdf (tetcos.com)
Applicable Releases | v11.1 | v12 |
Code modifications done in NetSim:
pstruPacket->pstruTransportData->nTransportProtocol = appInfo->trxProtocol;
//Fragment the packet
int nSegmentCount = 0;
double segmentsize = fn_NetSim_Stack_GetMSS(pstruPacket);
nSegmentCount = fn_NetSim_Stack_FragmentPacket(pstruPacket, (int)fn_NetSim_Stack_GetMSS(pstruPacket));
set_app_end_and_generate_next_packet(pstruPacket, otherDetails, destCount, dest);
//Add the dummy payload to packet
fn_NetSim_Add_DummyPayload(pstruPacket, appInfo);
#ifdef REBROADCAST
if(appInfo->sourceList[0]== pstruEventDetails->nDeviceId)
#endif
appmetrics_src_add(appInfo, pstruPacket);

//Fragment the packet
int nSegmentCount = 0;
double segmentsize = fn_NetSim_Stack_GetMSS(pstruPacket);
nSegmentCount = fn_NetSim_Stack_FragmentPacket(pstruPacket, (int)fn_NetSim_Stack_GetMSS(pstruPacket));
set_app_end_and_generate_next_packet(pstruPacket, otherDetails, destCount, dest);
//Add the dummy payload to packet
fn_NetSim_Add_DummyPayload(pstruPacket, appInfo);
#ifdef REBROADCAST
if(appInfo->sourceList[0]== pstruEventDetails->nDeviceId)
#endif
appmetrics_src_add(appInfo, pstruPacket);
#ifdef REBROADCAST
if (!dest[0])
rebroadcast_add_packet_to_info(pstruPacket, pstruEventDetails->dEventTime);
#endif //REBROADCAST
appout_send_packet(s, appInfo, pstruPacket, nDeviceId);
}

if (pstruappinfo->nAppType == TRAFFIC_EMULATION && pstruPacket->szPayload)
{
fn_NetSim_Dispatch_to_emulator(pstruPacket);
}
if (pstruappinfo->nAppType == TRAFFIC_BSM_APP)
{
process_saej2735_packet(pstruPacket);
}
#ifdef REBROADCAST
UINT destCount;
NETSIM_ID* dest = get_dest_from_packet(pstruPacket, &destCount);
if (!dest[0])
{
rebroadcast_packet(pstruPacket, pstruEventDetails->nDeviceId, pstruEventDetails->dEventTime);
}
else
{
#elif
//Delete the packet
fn_NetSim_Packet_FreePacket(pstruPacket);
#endif //rebroadcast
#ifdef REBROADCAST
}
#endif
}
// Here which type is placed is only getting processed next one is not getting processed
else if (pstruPacket->nControlDataType == packet_COAP_REQUEST)
{
ptrAPPLICATION_INFO pstruappinfo;

//Encryption
char xor_encrypt(char ch, long key);
int aes256(char* str, int* len);
int des(char* buf, int* len);
/****REBROADCAST****/
#define REBROADCAST
void rebroadcast_add_packet_to_info(NetSim_PACKET* packet, double time);
void rebroadcast_packet(NetSim_PACKET* packet, NETSIM_ID devId, double time);
#endif
//Application event handler
void handle_app_out();


#include "main.h"
#include "Application.h"
#define REBROADCAST_PROBABILITY 1
#define MAX_WAIT_FOR_REBROADCAST (10*SECOND)
static bool isRebroadcast()
{
double d = NETSIM_RAND_01();
if (d <= REBROADCAST_PROBABILITY)
return true;
else
return false;
}
typedef struct stru_broadcast_info
{
NETSIM_ID appId;
NETSIM_ID srcId;
UINT64 packetId;
double dBroadcastTime;
struct stru_broadcast_info* next;
}BROADCASTINFO, * ptrBROADCASTINFO;
static ptrBROADCASTINFO headInfo = NULL;
static ptrBROADCASTINFO tailInfo = NULL;
static void cleanup_broadcast_info(double time)
{
ptrBROADCASTINFO b = headInfo;
while (b)
{
if (time - b->dBroadcastTime > MAX_WAIT_FOR_REBROADCAST)
{
headInfo = b->next;
if (!headInfo)
tailInfo = NULL;
free(b);
b = headInfo;
}
else
{
break;
}
}
}
void rebroadcast_add_packet_to_info(NetSim_PACKET* packet,
double time)
{
cleanup_broadcast_info(time);
ptrBROADCASTINFO b = calloc(1, sizeof * b);
b->appId = packet->pstruAppData->nApplicationId;
b->dBroadcastTime = time;
b->packetId = packet->nPacketId;
b->srcId = packet->nSourceId;
if (headInfo)
{
tailInfo->next = b;
tailInfo = b;
}
else
{
headInfo = b;
tailInfo = b;
}
}
static bool isRebroadcastAllowed(NetSim_PACKET* packet,
NETSIM_ID devId)
{
if (!isRebroadcast())
return false;
ptrBROADCASTINFO t = headInfo;
while (t)
{
if (t->appId == packet->pstruAppData->nApplicationId &&
t->packetId == packet->nPacketId &&
t->srcId == devId)
return false;
t = t->next;
}
return true;
}
static NetSim_PACKET* reset_packet(NetSim_PACKET* packet,
NETSIM_ID newSrc,
double time)
{
NetSim_PACKET* newPacket = fn_NetSim_Packet_CreatePacket(APPLICATION_LAYER);
newPacket->dEventTime = time;
newPacket->nSourceId = newSrc;
newPacket->pstruNetworkData->szSourceIP = DEVICE_NWADDRESS(newSrc, 1);
add_dest_to_packet(newPacket, 0);
newPacket->pstruNetworkData->szDestIP = IP_COPY(packet->pstruNetworkData->szDestIP);
newPacket->nControlDataType = packet->nControlDataType;
newPacket->nPacketId = packet->nPacketId;
newPacket->nPacketPriority = packet->nPacketPriority;
newPacket->nPacketType = packet->nPacketType;
newPacket->nQOS = packet->nQOS;
newPacket->nServiceType = packet->nServiceType;
strcpy(newPacket->szPacketType, packet->szPacketType);
newPacket->pstruAppData->dPayload = packet->pstruAppData->dPayload;
newPacket->pstruAppData->nApplicationId = packet->pstruAppData->nApplicationId;
newPacket->pstruAppData->nAppType = packet->pstruAppData->nAppType;
newPacket->pstruTransportData->nDestinationPort = packet->pstruTransportData->nDestinationPort;
newPacket->pstruTransportData->nSourcePort = packet->pstruTransportData->nSourcePort;
newPacket->pstruNetworkData->nTTL = MAX_TTL;
return newPacket;
}
void rebroadcast_packet(NetSim_PACKET* packet,
NETSIM_ID devId,
double time)
{
if (!isRebroadcastAllowed(packet, devId))
{
fn_NetSim_Packet_FreePacket(packet);
return;
}
NetSim_PACKET* newPacket = reset_packet(packet, devId, time);
fn_NetSim_Packet_FreePacket(packet);
pstruEventDetails->nEventType = APPLICATION_OUT_EVENT;
pstruEventDetails->dPacketSize = newPacket->pstruAppData->dPayload;
pstruEventDetails->szOtherDetails = applicationInfo[newPacket->pstruAppData->nApplicationId - 1];
pstruEventDetails->pPacket = newPacket;
pstruEventDetails->nProtocolId = PROTOCOL_APPLICATION;
pstruEventDetails->nApplicationId = NETWORK->nApplicationCount + 1;
NETWORK->nApplicationCount += 1;
fnpAddEvent(pstruEventDetails);
}




| Applicable Releases | v10.2 |
Broadcasting:
Broadcasting is the process of sending a message from one node to all other nodes in an ad hoc network. It is a fundamental operation for communication in ad hoc networks as it allows for the update of network information and route discovery.

Attached herewith is a Rebroadcasting.zip folder which contains Code and Configuration file folders. The source codes present in Code folder can be loaded in Visual Studio using the NetSim.sln file. Users can then browse through the various associated files that are part of the Application project.
Rebroadcasting:
Wireless Node A initiates a broadcast of a message and the message is received by nodes B, C and D. B, C and D rebroadcast the message if they have not broadcasted that before. Furthermore, this implementation involves a Rebroadcast_probability based on which the nodes resend the packets.
Probability based rebroadcasting - the decision of rebroadcast is based upon a random probability. This probability may be as simple as flipping a coin or it may be more complex involving probabilities which include parameters such as node density, duplicate packets received, battery power or a nodes participation within the network etc. Users can change the Rebroadcast probability macro present in Rebroadcast.c file shown below 
Rebroadcasting in NetSim:
To implement this project in NetSim, we have created Rebroadcast.c file inside Application project. The file contains the following functions:
This function is used to rebroadcast the packet
This function is used to check whether rebroadcasting is allowed or not
This function is used to add the packet to rebroadcast rebroadcast list
This function is used to clean the broadcast information
Code modifications done in NetSim:




Steps:




