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

📄 aodv_wlan_mac.pr.c

📁 opnet环境中实现aodv路由协议建模
💻 C
📖 第 1 页 / 共 5 页
字号:
		case WlanC_Direct_Sequence:
			{
			/* Slot duration in terms of sec.	*/
			slot_time = 2E-05;

			/* Short interframe gap in terms of sec.	*/
			sifs_time = 1E-05;

			/* Minimum contention window size for selecting backoff slots.	*/
			cw_min = 31;

			/* Maximum contention window size for selecting backoff slots.	*/
			cw_max = 1023;
			break;
			}

		case WlanC_Infra_Red:
			{
			/* Slot duration in terms of sec.	*/
			slot_time = 8E-06;

			/* Short interframe gap in terms of sec.	*/
			sifs_time = 1E-05;

			/* Minimum contention window size for selecting backoff slots.	*/
			cw_min = 63;

			/* Maximum contention window size for selecting backoff slots.	*/
			cw_max = 1023;
			break;
			}

		default:
			{
			wlan_mac_error ("Unexpected Physical Layer Characteristic encountered.", OPC_NIL, OPC_NIL);
			break;
			}
		}

	/* By default stations are configured for IBSS unless an Access Point is found,	*/
	/* then the network will have an infrastructure BSS configuration.				*/
	bss_flag = OPC_BOOLINT_DISABLED;

	/* Computing DIFS interval which is interframe gap between successive	*/
	/* frame transmissions.													*/
	difs_time = sifs_time + 2 * slot_time;

	/* If the receiver detects that the received frame is erroneous then it	*/
	/* will set the network allocation vector to EIFS duration. 			*/
	eifs_time = difs_time + sifs_time + (8 * WLAN_ACK_DURATION) ;
	
	/* Creating list to store data arrived from higher layer.	*/	
	hld_list_ptr = op_prg_list_create ();

	/* Initialize segmentation and reassembly buffer.	*/
	defragmentation_list_ptr = op_prg_list_create ();
	fragmentation_buffer_ptr = op_sar_buf_create (OPC_SAR_BUF_TYPE_SEGMENT, OPC_SAR_BUF_OPT_PK_BNDRY);

	/* Registering local statistics.	*/
	packet_load_handle				= op_stat_reg ("Wireless Lan.Load (packets)", 					  OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	bits_load_handle				= op_stat_reg ("Wireless Lan.Load (bits/sec)", 					  OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	hl_packets_rcvd					= op_stat_reg ("Wireless Lan.Hld Queue Size (packets)", 		  OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	backoff_slots_handle			= op_stat_reg ("Wireless Lan.Backoff Slots (slots)", 			  OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	data_traffic_sent_handle 		= op_stat_reg ("Wireless Lan.Data Traffic Sent (packets/sec)", 	  OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);	
	data_traffic_rcvd_handle		= op_stat_reg ("Wireless Lan.Data Traffic Rcvd (packets/sec)", 	  OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL); 
	data_traffic_sent_handle_inbits	= op_stat_reg ("Wireless Lan.Data Traffic Sent (bits/sec)", 	  OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	data_traffic_rcvd_handle_inbits	= op_stat_reg ("Wireless Lan.Data Traffic Rcvd (bits/sec)", 	  OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	ctrl_traffic_sent_handle	 	= op_stat_reg ("Wireless Lan.Control Traffic Sent (packets/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	ctrl_traffic_rcvd_handle		= op_stat_reg ("Wireless Lan.Control Traffic Rcvd (packets/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL); 
	ctrl_traffic_sent_handle_inbits	= op_stat_reg ("Wireless Lan.Control Traffic Sent (bits/sec)",    OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	ctrl_traffic_rcvd_handle_inbits	= op_stat_reg ("Wireless Lan.Control Traffic Rcvd (bits/sec)", 	  OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL); 
	drop_packet_handle       		= op_stat_reg ("Wireless Lan.Dropped Data Packets (packets/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL); 
	drop_packet_handle_inbits		= op_stat_reg ("Wireless Lan.Dropped Data Packets (bits/sec)", 	  OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL); 
	retrans_handle					= op_stat_reg ("Wireless Lan.Retransmission Attempts (packets)",  OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL); 
	media_access_delay				= op_stat_reg ("Wireless Lan.Media Access Delay (sec)", 		  OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	ete_delay_handle				= op_stat_reg ("Wireless Lan.Delay (sec)", 					 	  OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	channel_reserv_handle			= op_stat_reg ("Wireless Lan.Channel Reservation (sec)", 		  OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	throughput_handle				= op_stat_reg ("Wireless Lan.Throughput (bits/sec)", 			  OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);

	/* Registering global statistics.	*/
	global_ete_delay_handle 		= op_stat_reg ("Wireless LAN.Delay (sec)", 	  		    OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
	global_load_handle 				= op_stat_reg ("Wireless LAN.Load (bits/sec)", 		    OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
	global_throughput_handle 		= op_stat_reg ("Wireless LAN.Throughput (bits/sec)",    OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
	global_dropped_data_handle		= op_stat_reg ("Wireless LAN.Data Dropped (bits/sec)",  OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
	global_mac_delay_handle			= op_stat_reg ("Wireless LAN.Media Access Delay (sec)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
	
	//$$$$$$$$$$$$$$$$$$ DSR $$$$$$$$$$$$$$$$$$$$$$$$
	stat_mac_failed_data=op_stat_reg("Mac Failed Data",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL);
	op_stat_write(stat_mac_failed_data,mac_failed_data=0);
	stat_mac_failed_reply=op_stat_reg("Mac Failed Reply",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL);
	op_stat_write(stat_mac_failed_reply,mac_failed_reply=0);
	stat_mac_failed_error=op_stat_reg("Mac Failed Error",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL);
	op_stat_write(stat_mac_failed_error,mac_failed_error=0);
	stat_mac_total_failed=op_stat_reg("Mac Total Failed",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL);
	op_stat_write(stat_mac_total_failed,mac_total_failed=0);
	stat_mac_retry_rts=op_stat_reg("Mac Retry Rts",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL);
	op_stat_write(stat_mac_retry_rts,mac_retry_rts=0);
	stat_mac_retry_data=op_stat_reg("Mac Retry Data",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL);
	op_stat_write(stat_mac_retry_data,mac_retry_data=0);
	stat_mac_retry_reply=op_stat_reg("Mac Retry Reply",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL);
	op_stat_write(stat_mac_retry_reply,mac_retry_reply=0);
	stat_mac_retry_error=op_stat_reg("Mac Retry Error",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL);
	op_stat_write(stat_mac_retry_error,mac_retry_error=0);
	stat_mac_total_retry=op_stat_reg("Mac Total Retry",OPC_STAT_INDEX_NONE,OPC_STAT_GLOBAL);
	op_stat_write(stat_mac_total_retry,mac_total_retry=0);
	//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
	
	/* Registering log handles */
	drop_pkt_log_handle	= op_prg_log_handle_create (OpC_Log_Category_Configuration, "Wireless Lan", "Data packet Drop", 128);
    drop_pkt_entry_log_flag = OPC_FALSE;

	/* Allocating memory for the flags used in this process model. */
	wlan_flags = (WlanT_Mac_Flags *) op_prg_mem_alloc (sizeof (WlanT_Mac_Flags));

	/* Disabling all flags as a default.	*/
	wlan_flags->data_frame_to_send 	= OPC_BOOLINT_DISABLED;
	wlan_flags->backoff_flag       	= OPC_BOOLINT_DISABLED;
	wlan_flags->rts_sent		   	= OPC_BOOLINT_DISABLED;
	wlan_flags->rcvd_bad_packet		= OPC_BOOLINT_DISABLED;
	wlan_flags->receiver_busy		= OPC_BOOLINT_DISABLED;
	wlan_flags->transmitter_busy	= OPC_BOOLINT_DISABLED;
	wlan_flags->gateway_flag		= OPC_BOOLINT_DISABLED;
	wlan_flags->bridge_flag			= OPC_BOOLINT_DISABLED;
	wlan_flags->wait_eifs_dur		= OPC_BOOLINT_DISABLED;
	wlan_flags->immediate_xmt		= OPC_BOOLINT_DISABLED;
	wlan_flags->cw_required			= OPC_BOOLINT_DISABLED;
	wlan_flags->nav_updated			= OPC_BOOLINT_DISABLED;

	/* Intialize retry count. */
	retry_count = 0;

	/* Initialize the packet pointer that holds the last		*/
	/* transmitted packet to be used for retransmissions when	*/
	/* necessary.												*/
	wlan_transmit_frame_copy_ptr = OPC_NIL;
	
	/* Initialize nav duration	*/
	nav_duration = 0;
	
	/* Initialize receiver idle and conetion window timers.	*/
	rcv_idle_time = -2.0 * difs_time;
	cw_end =        0.0;

	/* Initializing the sum of sizes of the packets in the higher layer queue.	*/
	total_hlpk_size = 0;

	/* Initialize the state variables related with the current frame that is being handled.	*/
	packet_size  = 0;
	receive_time = 0.0;
	
	/* Data arrived from higher layer is queued in the buffer. Pool memory is used for		*/
	/* allocating data structure for the higher layer packet and the random destination		*/
	/* for the packet. This structure is then inserted in the higher layer arrival queue.	*/
	hld_pmh = op_prg_pmo_define ("WLAN hld list elements", sizeof (WlanT_Hld_List_Elem), 32);

	/* Obtaining transmitter objid for accessing channel data rate attribute.	*/
	tx_objid = op_topo_assoc (my_objid, OPC_TOPO_ASSOC_OUT, OPC_OBJTYPE_RATX, 0);

	/* If no receiver is attach then generate error message and abort the simulation.	*/
	if (tx_objid == OPC_OBJID_INVALID)
		{
		wlan_mac_error ("No transmitter attached to this MAC process", OPC_NIL, OPC_NIL);	
		}

	/* Obtaining number of channels available.	*/
	op_ima_obj_attr_get (tx_objid, "channel", &chann_objid);
	num_chann = op_topo_child_count (chann_objid, OPC_OBJTYPE_RATXCH);
	
	/* Generate error message and terminate simulation if no channel is available for transmission.	*/
	if (num_chann == 0)
		{
		wlan_mac_error (" No channel is available for transmission", OPC_NIL, OPC_NIL);
		}

	/* Setting the Frequency and Bandwidth for the transmitting channels.	*/
	for (i = 0; i < num_chann; i++)
		{ 
		/* Accessing channel to set the frequency and bandwidth.	*/
		sub_chann_objid = op_topo_child (chann_objid, OPC_OBJTYPE_RATXCH, i);

		/* Setting the operating freqeuncy and channel bandwidth for the transmitting channels.	*/	
		op_ima_obj_attr_set (sub_chann_objid, "bandwidth", bandwidth);
		op_ima_obj_attr_set (sub_chann_objid, "min frequency", frequency);
		}

	/* Obtaining receiver's objid for accessing channel data rate attribute.	*/
	rx_objid = op_topo_assoc (my_objid, OPC_TOPO_ASSOC_IN, OPC_OBJTYPE_RARX, 0);

	/* If no receiver is attach then generate error message and abort the simulation.	*/
	if (rx_objid == OPC_OBJID_INVALID)
		{
		wlan_mac_error ("No receiver attached to this MAC process", OPC_NIL, OPC_NIL);	
		}

	/* Obtaining number of channels available.	*/
	op_ima_obj_attr_get (rx_objid, "channel", &chann_objid);
	num_chann = op_topo_child_count (chann_objid, OPC_OBJTYPE_RARXCH);
	
	/* Generate error message and terminate simulation if no channel is available for reception.	*/
	if (num_chann == 0)
		{
		wlan_mac_error (" No channel is available for reception", OPC_NIL, OPC_NIL);
		}

	/* Setting the Frequency and Bandwidth for the transmitting channels.	*/
	for (i = 0; i < num_chann; i++)
		{ 	
		/* Accessing channel to set the frequency and bandwidth.	*/
		sub_chann_objid = op_topo_child (chann_objid, OPC_OBJTYPE_RARXCH, i);
	
		/* Setting the operating freqeuncy and channel bandwidth for the receiving channels.	*/
		op_ima_obj_attr_set (sub_chann_objid, "bandwidth", bandwidth);
		op_ima_obj_attr_set (sub_chann_objid, "min frequency", frequency);
		}
	
	llc_iciptr = op_ici_create ("wlan_mac_ind");

	if (llc_iciptr == OPC_NIL)
		{
		wlan_mac_error ("Unable to create ICI for communication with LLC.", OPC_NIL, OPC_NIL);
		}

	FOUT;
	}

static void
wlan_higher_layer_data_arrival ()
	{
	Packet*					hld_pkptr;
	int						pk_size,i;
	int						dest_addr;
	Ici*					ici_ptr;
	Boolean					stn_det_flag;

	/** Queue the packet as it arrives from higher layer.	**/
	/** Also, store the destination address of the packet	**/
	/** in the queue and the arrival time.					**/
	FIN (wlan_higher_layer_data_arrival ());

	/* Get packet from the incomming stream from higher layer and	*/
	/* obtain the packet size 										*/
	hld_pkptr = op_pk_get (op_intrpt_strm ());
	/* For bridge and gateway, only accept packet from the higher	*/
	/* layer if the access point functionality is enabled.			*/
	if (((wlan_flags->gateway_flag == OPC_BOOLINT_ENABLED) || 
		(wlan_flags->bridge_flag == OPC_BOOLINT_ENABLED)) &&
		(ap_flag == OPC_BOOLINT_DISABLED))
		{
		op_pk_destroy (hld_pkptr);
		FOUT;
		}

	pk_size   = op_pk_total_size_get (hld_pkptr);		

	/* maintaining total packet size of the packets in the higer layer queue.	*/
	total_hlpk_size = total_hlpk_size + pk_size;

	/* If fragmentation is enabled and packet size is greater than the threshold		*/
	/* then MSDU length will not be more than fragmentation threshold, hence			*/
	/* the packet will be fragmented into the size less than or equal to fragmentaion   */
	/* threshold.																		*/
	if ((pk_size > frag_threshold * 8) && (frag_threshold != -1))
		{
		 pk_size = frag_threshold * 8;
		}

	/* Destroy packet if it is more than max msdu length or its		*/
	/* size zero. Also, if the size of the higher layer queue  		*/
	/* will exceed its maximum after the insertion of this packet, 	*/
	/* then discard the arrived packet. 							*/
	/* The higher layer is reponsible for the retransmission of 	*/
	/* this packet.													*/ 
	if (pk_size > WLAN_MAXMSDU_LENGTH || pk_size == 0 ||
       total_hlpk_size > hld_max_size)
		{
		/* change the total hld queue size to original value	*/
		/* as this packet will not be added to the queue.		*/
		total_hlpk_size = total_hlpk_size - pk_size;
			
		if (drop_pkt_entry_log_flag == OPC_FALSE)
			{
			if (total_hlpk_size > hld_max_size)
				{
				/* Writing log message for dropped packets.	*/
				op_prg_log_entry_write (drop_pkt_log_handle, 
				"SYMPTOMS(S):\n"
			    " Wireless LAN MAC layer discarded some packets due to\n "
			    " insufficient buffer capacity. \n"
				"\n"
			    " This may lead to: \n"
  			    " - application data loss.\n"
			    " - higher layer packet retransmission.\n"
			    "\n"
			    " REMDEDIAL ACTION (S): \n"
			    " 1. Reduce Network laod. \n"

⌨️ 快捷键说明

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