Applicable versionsNetSim StandardNetsim Pro

 

Spectrum sensing is one of the most important components of cognitive radio (CR) technology. The delays in sensing idle channels for SU data will have a direct impact on how fast secondary user (SU) data transmissions happen. Sensing time or delay can be added via code modification to analyze the impact it has on the network performance.


Following changes are to be done to the code in order to add sensing time/delay for spectrum sensing:


Applicable Releasesv12
v13


1.Open Visual Studio 2019 through Netsim->open simulation->workspace options->Open Code

2.Go to Cognitive Radio project through the solution explorer and open the file SpectrumManager.c. Add the lines of code highlighted in red as shown below at the start of the file:


#include "main.h"

#include "802_22.h"

#include "SpectrumManager.h"

#define SENSING_DELAY 100000

/** This function is used to set the channel number and assign the channel characteristics for all channels */

int fn_NetSim_CR_FormChannelSet(BS_PHY* pstruBSPhy)


3. In the same file make the following changes highlighted in red inside the function fn_NetSim_CR_QuietPeriod() as shown below:


if (output->nSignalPresentVector == 0xFF)

{

//Generate the UCS notification packet

NetSim_PACKET* pstruPacket;

NetSim_PACKET* pstruTempPacket;

GMH* pstruGMH = (GMH*)fnpAllocateMemory(1, sizeof *pstruGMH);

pstruPacket = fn_NetSim_Packet_CreatePacket(MAC_LAYER);

pstruPacket->nControlDataType = CR_CONTROL_PACKET(MMM_UCS_NOTIFICATION);

add_dest_to_packet(pstruPacket, pstruCPEMAC->nBSID);

pstruPacket->nPacketPriority = Priority_High;

pstruPacket->nPacketType = PacketType_Control;

pstruPacket->nReceiverId = pstruCPEMAC->nBSID;

pstruPacket->nSourceId = pstruEventDetails->nDeviceId;

pstruPacket->nTransmitterId = pstruEventDetails->nDeviceId;

pstruPacket->pstruMacData->dArrivalTime = pstruEventDetails->dEventTime + SENSING_DELAY;

pstruPacket->pstruMacData->dOverhead = GMH_SIZE;


Delay is currently set to 100 ms (100000 microseconds). Users can modify the value of SENSING_DELAY as per the requirement to analyze the impact.


4. Open the file USFrame.c make the following changes highlighted in red inside the function fn_NetSim_CR_FormUSBurst() as shown below:


//Add an event to transmit US-Burst

pstruEventDetails->dEventTime = pstruCPEMAC->BWRequestInfo->dStartTime;

pstruEventDetails->dPacketSize = 0;

pstruEventDetails->nApplicationId = 0;

pstruEventDetails->nEventType = TIMER_EVENT;

pstruEventDetails->nPacketId = 0;

pstruEventDetails->nProtocolId = MAC_PROTOCOL_IEEE802_22;

pstruEventDetails->nSubEventType = TRANSMIT_US_BURST;

pstruEventDetails->pPacket = NULL;

fnpAddEvent(pstruEventDetails);

}


// Code modification for spectrum sensing delay starts here

NetSim_PACKET* p = NULL;

NetSim_PACKET* prev = NULL;

NetSim_PACKET* temp = pstruCPEMAC->pstruQueuedPacketList[0];


while (temp)

{

if (temp->pstruMacData->dArrivalTime > pstruEventDetails->dEventTime)

{

if (prev)

prev->pstruNextPacket = temp;

else

pstruCPEMAC->pstruQueuedPacketList[0] = temp;

prev = temp;

temp = temp->pstruNextPacket;

prev->pstruNextPacket = NULL;

p = NULL;

}

else

{

p = temp;

if (pstruCPEMAC->pstruQueuedPacketList[0] == temp)

pstruCPEMAC->pstruQueuedPacketList[0] = temp->pstruNextPacket;

temp = temp->pstruNextPacket;

p->pstruNextPacket = NULL;

}

if (p)

{

//Generate physical out event

pstruEventDetails->dEventTime = t;

pstruEventDetails->dPacketSize = p->pstruMacData->dPacketSize;

pstruEventDetails->nApplicationId = 0;

pstruEventDetails->nEventType = PHYSICAL_OUT_EVENT;

pstruEventDetails->nPacketId = 0;

pstruEventDetails->nProtocolId = MAC_PROTOCOL_IEEE802_22;

pstruEventDetails->nSubEventType = TRANSMIT_US_BURST_CONTROL;

pstruEventDetails->pPacket = p;

fnpAddEvent(pstruEventDetails);

}

// Code modification for spectrum sensing delay ends here

}

return 0;

}

}


5. Now choose the appropriate platform in Visual studio (win32 or x64) according to 32 bit or 64-bit Netsim installed and then right-click on the Cognitive Radio module in the solution explorer and select rebuild.

6. Upon a successful build, libCognitiveRadio.dll will automatically get updated in the bin directory of the current workspace.

8. Now on running any simulation in the Cognitive Radio network, whenever secondary users are performing spectrum sensing, an additional delay is added before UCS notification is sent to the BS.


Applicable Releasesv10v11


1. Open NetSim source code in Visual Studio 2015/2017 by double-clicking on the NetSim.sln file present in “<NetSim_Install_Directory>/src/Simulation” folder.)


2.Go to Cognitive Radio project through the solution explorer and open the file SpectrumManager.c. Add the lines of code highlighted in red as shown below at the start of the file:


#include "main.h"

#include "802_22.h"

#include "SpectrumManager.h"

#define SENSING_DELAY 100000

/** This function is used to set the channel number and assign the channel characteristics for all channels */

int fn_NetSim_CR_FormChannelSet(BS_PHY* pstruBSPhy)


3. In the same file make the following changes highlighted in red inside the function fn_NetSim_CR_QuietPeriod() as shown below:


if (output->nSignalPresentVector == 0xFF)

{

//Generate the UCS notification packet

NetSim_PACKET* pstruPacket;

NetSim_PACKET* pstruTempPacket;

GMH* pstruGMH = (GMH*)fnpAllocateMemory(1, sizeof *pstruGMH);

pstruPacket = fn_NetSim_Packet_CreatePacket(MAC_LAYER);

pstruPacket->nControlDataType = CR_CONTROL_PACKET(MMM_UCS_NOTIFICATION);

add_dest_to_packet(pstruPacket, pstruCPEMAC->nBSID);

pstruPacket->nPacketPriority = Priority_High;

pstruPacket->nPacketType = PacketType_Control;

pstruPacket->nReceiverId = pstruCPEMAC->nBSID;

pstruPacket->nSourceId = pstruEventDetails->nDeviceId;

pstruPacket->nTransmitterId = pstruEventDetails->nDeviceId;

pstruPacket->pstruMacData->dArrivalTime = pstruEventDetails->dEventTime + SENSING_DELAY;

pstruPacket->pstruMacData->dOverhead = GMH_SIZE;


Delay is currently set to 100 ms (100000 microseconds). Users can modify the value of SENSING_DELAY as per the requirement to analyze the impact.


4. Open the file USFrame.c make the following changes highlighted in red inside the function fn_NetSim_CR_FormUSBurst() as shown below:


//Add an event to transmit US-Burst

pstruEventDetails->dEventTime = pstruCPEMAC->BWRequestInfo->dStartTime;

pstruEventDetails->dPacketSize = 0;

pstruEventDetails->nApplicationId = 0;

pstruEventDetails->nEventType = TIMER_EVENT;

pstruEventDetails->nPacketId = 0;

pstruEventDetails->nProtocolId = MAC_PROTOCOL_IEEE802_22;

pstruEventDetails->nSubEventType = TRANSMIT_US_BURST;

pstruEventDetails->pPacket = NULL;

fnpAddEvent(pstruEventDetails);

}


// Code modification for spectrum sensing delay starts here

NetSim_PACKET* p = NULL;

NetSim_PACKET* prev = NULL;

NetSim_PACKET* temp = pstruCPEMAC->pstruQueuedPacketList[0];


while (temp)

{

if (temp->pstruMacData->dArrivalTime > pstruEventDetails->dEventTime)

{

if (prev)

prev->pstruNextPacket = temp;

else

pstruCPEMAC->pstruQueuedPacketList[0] = temp;

prev = temp;

temp = temp->pstruNextPacket;

prev->pstruNextPacket = NULL;

p = NULL;

}

else

{

p = temp;

if (pstruCPEMAC->pstruQueuedPacketList[0] == temp)

pstruCPEMAC->pstruQueuedPacketList[0] = temp->pstruNextPacket;

temp = temp->pstruNextPacket;

p->pstruNextPacket = NULL;

}

if (p)

{

//Generate physical out event

pstruEventDetails->dEventTime = t;

pstruEventDetails->dPacketSize = p->pstruMacData->dPacketSize;

pstruEventDetails->nApplicationId = 0;

pstruEventDetails->nEventType = PHYSICAL_OUT_EVENT;

pstruEventDetails->nPacketId = 0;

pstruEventDetails->nProtocolId = MAC_PROTOCOL_IEEE802_22;

pstruEventDetails->nSubEventType = TRANSMIT_US_BURST_CONTROL;

pstruEventDetails->pPacket = p;

fnpAddEvent(pstruEventDetails);

}

// Code modification for spectrum sensing delay ends here

}

return 0;

}

}


5. Now choose the appropriate platform in Visual studio (win32 or x64) according to 32 bit or 64 bit of Netsim installed and then right-click on Cognitive Radio module in the solution explorer and select rebuild.

6. Upon a successful build, you will get a new libCognitiveRadio.dll file in the “<NetSim_Install_Directory>/src/Simulation/DLL” folder.

 Copy this newly-built DLL file and replace it in the bin folder of NetSim after you rename the original libCognitiveRadio.dll file which is already existing there(as a backup)).

8. Now on running any simulation in Cognitive Radio network, whenever secondary users are performing spectrum sensing, an additional delay is added before UCS notification is sent to the BS.


Related Articles:

how-is-spectrum-sensing-done-in-netsim-802-22-library-