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

📄 dsr_wlan_mac.pr.c

📁 afit的ad hoc路由协议源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	/* subnet where for every node the attribute BSS_Id is set to indicate to which */
	/* BSS a node belongs. If the global is set to traditional subnet and the this	*/
	/* node has its BSS_Id attribute set then log a warning message and recover		*/
	/* by considering the BSS_Id attribute setting as not used.If the global is		*/
	/* set to BSS based subnet and this node is not using its BSS_Id attribute 		*/
	/* then log an error message and stop the simulation.					 		*/
	if (bss_id_type == WlanC_Not_Set )
		{
		if (bss_id ==  WLAN_BSSID_NOT_USED )
			{
			bss_id_type = WlanC_Entire_Subnet ;
			}
		else
			{
			bss_id_type = WlanC_Bss_Divided_Subnet ;
			}
		}
	else
		{
		if (bss_id_type == WlanC_Entire_Subnet && bss_id != WLAN_BSSID_NOT_USED)
			{
			/* Recoverable mismatch, log warning and continue by enforcing			*/
			/* traditional subnet, i.e. force the bss_id variable to not used.		*/

			/* Register the log handle. 											*/
			bssid_changed_log_handle = op_prg_log_handle_create (OpC_Log_Category_Configuration, "Wireless Lan", "BSS ID Changed", 128);

			/* Write the warning message.											*/
			op_prg_log_entry_write(bssid_changed_log_handle,
				"WARNING:\n"
				" A node with an explicit BSS \n"
				" assigment was found in a pure \n"
				" subnet.\n"
				"ACTION:\n"
				" The BSS identifier is set to\n"
				" the default value.\n"
				"CAUSE:\n"
				" There are some nodes in the\n"
				" network which have their BSS\n"
				" identifiers set to the default\n"
				" while the others have the\n"
				" default setting.\n"
				"SUGGESTION:\n"
				" Ensure that all nodes have the\n"
				" BSS identifier set to the default\n"
				" value or all of them are explicitly\n"
				" assigned.\n"
				);
		    }
		}
	
	/* Create the pool of station addresses of the same BSS using BSS ID if this 	*/
	/* attribute is set.															*/
	if (bss_id_type == WlanC_Bss_Divided_Subnet )
		{
		/* Get a string based on the BSS id and generate pool of station addresses	*/
		/* using this string register with this new string bss name.				*/
		sprintf ( bss_name , "bss_%d", bss_id);
		oms_aa_wlan_handle = oms_aa_address_handle_get (bss_name, "station_address");
		}
	else
		{
		/* If traditional subnet create a pool of station addresses for each		*/
		/* subnet based on subnet name.												*/
		op_ima_obj_attr_get (my_subnet_objid, "name", &subnet_name);
	    oms_aa_wlan_handle = oms_aa_address_handle_get (subnet_name, "station_address");
		}
	
   	/* Get model attributes.	*/
	op_ima_obj_attr_get (params_attr_objid, "Data Rate", &operational_speed);
	op_ima_obj_attr_get (params_attr_objid, "Fragmentation Threshold", &frag_threshold);
	op_ima_obj_attr_get (params_attr_objid, "Rts Threshold", &rts_threshold);
	op_ima_obj_attr_get (params_attr_objid, "Short Retry Limit", &short_retry_limit);
	op_ima_obj_attr_get (params_attr_objid, "Long Retry Limit", &long_retry_limit);
	op_ima_obj_attr_get (params_attr_objid, "Access Point Functionality", &ap_flag);	
	op_ima_obj_attr_get (params_attr_objid, "Buffer Size", &hld_max_size);
	op_ima_obj_attr_get (params_attr_objid, "Max Receive Lifetime", &max_receive_lifetime);
	op_ima_obj_attr_get (params_attr_objid, "Large Packet Processing", &accept_large_packets);

	/* Initialize the retry limit for the current frame to long retry limit.	*/
	retry_limit = long_retry_limit;
	
	/* Get the Channel Settings.										*/
	/* Extracting Channel 0,1,2,3 (i.e. 1,2,5.5 and 11Mbps) Settings	*/
	op_ima_obj_attr_get (params_attr_objid, "Channel Settings", &chann_params_comp_attr_objid);
	subchann_params_attr_objid = op_topo_child (chann_params_comp_attr_objid, OPC_OBJTYPE_GENERIC, 0);
	op_ima_obj_attr_get (subchann_params_attr_objid, "Bandwidth", &bandwidth);	
	op_ima_obj_attr_get (subchann_params_attr_objid, "Min Frequency", &frequency);	

	/* If the frequency is BSS based then assign frequency as a			*/
	/* function of the BSS Identifier.								 	*/
	if (frequency == WLAN_BSS_BASED_FREQ_USED)
		{
		/* Frequency in KHz as a funtion of the BSS identifier.		 	*/		
		frequency = (bss_id + 2) * 30 ;
		}
	
	/* Load the appropriate physical layer characteristics.	*/	
	op_ima_obj_attr_get (params_attr_objid, "Physical Characteristics", &phy_char_flag);

	/* Based on physical charateristics settings set appropriate values to the variables.	*/
	switch (phy_char_flag)
		{
		case WlanC_Frequency_Hopping:
			{
			/* Slot duration in terms of sec.	*/
			slot_time = 5E-05;

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

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

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

		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 + 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 and flags.	*/
	drop_pkt_log_handle	= op_prg_log_handle_create (OpC_Log_Category_Configuration, "Wireless Lan", "Data packet Drop", 128);
    drop_pkt_entry_log_flag = 0;

	/* 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->perform_cw			= OPC_BOOLINT_DISABLED;
	wlan_flags->nav_updated			= OPC_BOOLINT_DISABLED;
	wlan_flags->collision			= OPC_BOOLINT_DISABLED;
	wlan_flags->collided_packet		= 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 timer. 							*/
	rcv_idle_time = -2.0 * difs_time;

	/* 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;
	
	/* Initialize the receiver channel status.					*/
	rcv_channel_status = 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)
		{

⌨️ 快捷键说明

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