NetSim Cognitive Radio library detects spectrum usage based on whether the primary user (incumbent) is inside / outside the keep out distance from the secondary user.  


This means that the SU will detect the PU if the PU is inside the keep-out distance from either the SU.


Now, the secondary user (CR CPE) actively senses for the presence of the incumbent. If the CR_CPE detects the primary user then UCS Notifications will be sent by the secondary user to the base station.  UCS notifications are generated at the end of the quiet period.


The Keep-out distance used in NetSim is an abstract model for simulation purposes. A user can modify keep-out distance as per their sensing technique/algorithm. Since the keep-out distance is a user input, and hence the assumption is that the user has arrived at this value based on their sensing technique.


Please see the below link to understand how spectrum sensing is done.
http://www.ieee802.org/22/Meeting_documents/2006_Mar/22-06-0028-05-0000-Spectrum-Sensing-Simulation-Model.doc

The definition of the Spectrum Sensing Function can be found in the SpectrumManager.c file.

Now, if user wants to modify this at run time, then they can write a new sensing algorithm function and change keep-out distance used in below function.

struct stru_802_22_SSFOutput* fn_NetSim_CR_CPE_SSF(struct stru_802_22_SSFInput* input,NETSIM_ID nDevId,NETSIM_ID nInterfaceId)

This function is present in spectrummanager.c and it checks if the Incumbent signal is present or not. 

Additional info for Advanced users
---------------------------------------

The quiet period is scheduled whenever FCH is received from the BS during which Secondary Users perform Spectrum Sensing.


Quiet Period is scheduled as shown below:

pstruEventDetails->dEventTime =

pstruBSMAC->dFrameStartTime +

(pstruFCH->n_Length_of_the_frame - pstruCPEPhy->nIntraFrameQuietPeriodDuration)*

pstruSymbol->dSymbolDuration+

pstruBSPHY->dTTG;
Where,

pstruBSMAC->dFrameStartTime

pstruFCH->n_Length_of_the_frame is 6 bits which Indicates the length of the frame in number of OFDM symbols from the start of the frame including all preambles

pstruCPEPhy->nIntraFrameQuietPeriodDuration Default is one symbol and has range 1-16

pstruSymbol->dSymbolDuration SCH packet is one symbol long

pstruBSPHY->dTTG is Transmit Transition Gap. 105-333 micro sec. default 210 micro sec


During Quiet Period Spectrum Sensing is done by the Secondary users and the possibility of interference is checked in the function fn_NetSim_CR_CPE_SSF(). Interference in the operating or adjacent channels is checked and UCS Notifications are initiated from the SU's to the BS.


The Quiet period is scheduled in FCH.c file in the function fn_NetSim_CR_CPE_ProcessFCH().  The Quiet period is handled in SpectrumManager.c file in the function fn_NetSim_CR_QuietPeriod().


The UCS Notifications are processed by the BS in SpectrumManager.c file in the function fn_NetSim_CR_BS_UCS() and channel switch message is broadcasted if interference is identified.


The 802.22 MAC Header has a variable n_UCS which is 1-bit Urgent Coexistence Situation used by the CPE to alert the BS about a UCS with incumbents in the channel currently being used by the BS or either of its adjacent channels:
 0: no incumbent (default)
 1: incumbent detected


During the Quiet Period upon sensing the spectrum, if interference is detected, n_UCSvariable is set to 1 in the UCS notification. 


Following are the channel states in 802.22:

ChannelState_DISALLOWED,
ChannelState_OPERATING,
ChannelState_BACKUP,
ChannelState_CANDIDATE,
ChannelState_PROTECTED,
ChannelState_UNCLASSIFIED


Upon receiving the UCS notification BS sets the current operating channel state to ChannelState_PROTECTED if n_UCS variable is set to 1. This happens in the function fn_NetSim_CR_BS_UCS()  which is part of the SpectrumManager.c file.  BS checks for any channels in ChannelState_BACKUP state. If found, it is set as the operating channel.
BS then broadcasts CHS_REQ Channel switch request in order to switch the entire cell operation to a new channel.


CRCPE's upon receiving the CHS_REQ switches their operating channel to the new channel. Channel Switching happens in the function fn_NetSim_CR_CPE_SwitchChannel()which is part of the SpectrumManager.c file.  In the results window, UCS Notification and CHS_REQ count can be found under CRCPE metrics. Packet Trace and Event Trace logs the details of these packets and can be used for the purpose of analysis.