⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bkoff_nee enter execs

📁 opnet无线网络编程
💻
字号:
/** In this state we determine whether a back-off is necessary for the	**/
/** frame we are trying to transmit. It is needed when station			**/
/** preparing to transmit frame discovers that the medium is busy or	**/
/** when the the station infers collision. Backoff is not needed when	**/
/** the station is responding to the frame. Following a successful		**/
/** packet transmission, again a back-off procedure is performed for a	**/
/** contention window period as stated in 802.11 standard.				**/
/**																		**/
/** If backoff needed then check whether the station completed its 		**/
/** backoff in the last attempt. If not then resume the backoff 		**/
/** from the same point, otherwise generate a new random number 	 	**/
/** for the number of backoff slots. 									**/

// assigns the unique state number and writes the sleep staus to the sleep statistic handeler for graphing purposes
state = WSN_BKOFF_NEEDED;

// since the station progressed from deference to backoff needed it must have
// finished its deference and there should not be any pending deference
deference_pending = OPC_FALSE;

if (wlan_flags->backoff_flag == OPC_TRUE || wlan_flags->perform_cw == OPC_TRUE)
	{
	
	if ((backoff_slots == BACKOFF_SLOTS_UNSET))
		{                                                             
		/* Compute backoff interval using binary exponential process.	*/
		/* After a successful transmission we always use cw_min.		*/
		if (short_retry_count + long_retry_count == 0 || wlan_flags->perform_cw == OPC_TRUE)
			{			 
			/* If retry count is set to 0 then set the maximum backoff	*/
			/* slots to min window size.								*/	
			max_backoff = cw_min;
			}
		else
			{
			/* We are retransmitting. Increase the back-off window		*/
			/* size.													*/
				max_backoff = max_backoff * 2 + 1; 				
			}

		/* The number of possible slots grows exponentially until it	*/
		/* exceeds a fixed limit.										*/
		if (max_backoff > cw_max) 
			{
			max_backoff = cw_max;
			}
 
		/* Obtain a uniformly distributed random integer between 0 and	*/
		/* the minimum contention window size. Scale the number of		*/
		/* slots according to the number of retransmissions.			*/
		backoff_slots = floor (op_dist_uniform (max_backoff + 1));
		}

	/* Set a timer for the end of the backoff interval.					*/
	intrpt_time = (op_sim_time() + backoff_slots * slot_time);
	
	// wsn
	// the time the interrupt backoff is supposed to occur. this time is used to offset the backoff time
	// when the self-interrupt is rescheduled upon the node waking up
	intrpt_time_backoff  = intrpt_time;
	
	/* Scheduling self interrupt for backoff.							*/
	if (wlan_flags->perform_cw == OPC_TRUE)
		{
		backoff_elapsed_evh = op_intrpt_schedule_self (intrpt_time, WlanC_CW_Elapsed);
		
		// indicates a CW interrupt was scheduled, used when the interrupt is reshduled when the node wakes up after sleeping
		backoff_pending = OPC_TRUE;
		wsn_interrupt_cw = OPC_TRUE;
		}
	else
		{
		backoff_elapsed_evh = op_intrpt_schedule_self (intrpt_time, WlanC_Backoff_Elapsed);
		// indicates a Backoff interrupt was scheduled, used when the interrupt is reshduled when the node wakes up after sleeping
		backoff_pending = OPC_TRUE;
		wsn_interrupt_backoff = OPC_TRUE;
		}

	#ifndef OPD_NO_DEBUG
	if ((op_sim_time() > wsn_test_time) && (my_address == wsn_test_address || my_address == wsn_test_address_2) )
		printf("Node <%d> in BKOFF_NEEDED with %e SLOTS at time %e \n", my_address, backoff_slots, op_sim_time());
	#endif

	/* Reporting number of backoff slots as a statistic.				*/
	op_stat_write (backoff_slots_handle, backoff_slots);

	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -