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

📄 aodv_wlan_mac.pr.c

📁 opnet环境中实现aodv路由协议建模
💻 C
📖 第 1 页 / 共 5 页
字号:
			    " 2. User higher speed wireless lan. \n"
			    " 3. Increase buffer capacity\n");
				if(DEBUG) printf("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"
			    " 2. User higher speed wireless lan. \n"
			    " 3. Increase buffer capacity\n");
				}
			
			if (pk_size > WLAN_MAXMSDU_LENGTH)
				{
				/* Writing log message for dropped packets due to packet size.	*/
				op_prg_log_entry_write (drop_pkt_log_handle, 
				"SYMPTOMS(S):\n"
			    " Wireless LAN MAC layer discarded some packets due to\n "
			    " large packet size. \n"
				"\n"
			    " This may lead to: \n"
  			    " - application data loss.\n"
			    " - higher layer packet retransmission.\n"
			    "\n"
			    " REMDEDIAL ACTION (S): \n"
			    " 1. Enable fragmentation threshold. \n"
			    " 2. Set the higher layer packet size to \n"
				   " be smaller than max MSDU size \n");
				if(DEBUG) ("SYMPTOMS(S):\n"
			    " Wireless LAN MAC layer discarded some packets due to\n "
			    " large packet size. \n"
				"\n"
			    " This may lead to: \n"
  			    " - application data loss.\n"
			    " - higher layer packet retransmission.\n"
			    "\n"
			    " REMDEDIAL ACTION (S): \n"
			    " 1. Enable fragmentation threshold. \n"
			    " 2. Set the higher layer packet size to \n"
				   " be smaller than max MSDU size \n");
				 }
			drop_pkt_entry_log_flag = OPC_TRUE;
			}

	/* Limit the sum of the sizes of all the packets in the queue to be 	*/
	/* the maximum buffer size.												*/
	if (total_hlpk_size >= hld_max_size)
		{
		total_hlpk_size = hld_max_size;
		}
 
		/* Report stat when data packet is dropped due to overflow buffer.	*/
		op_stat_write (drop_packet_handle, 1.0);
	    op_stat_write (drop_packet_handle, 0.0);

		/* Report stat when data packet is dropped due to overflow buffer.	*/
		op_stat_write (drop_packet_handle_inbits, (double) (pk_size));
	    op_stat_write (drop_packet_handle_inbits, 0.0);
		op_stat_write (global_dropped_data_handle, (double) (pk_size));
		op_stat_write (global_dropped_data_handle, 0.0);
		
		FOUT;   
		}
		
	/* Read ICI parameters at the stream interrupt.	*/
	ici_ptr = op_intrpt_ici ();
	if (DEBUG) printf("--- MAC Msg @ node %d --- receiving ICI.", my_address);
	/* Retrieve destination address from the ici set by the interface layer.	*/
	if (ici_ptr == OPC_NIL || op_ici_attr_get (ici_ptr, "dest_addr", &dest_addr) == OPC_COMPCODE_FAILURE)
		{
		/* Generate error message.	*/
		if (DEBUG) printf("--- MAC Msg @ node %d --- Destination address is not valid.", my_address);
		wlan_mac_error ("Destination address in not valid.", OPC_NIL, OPC_NIL);
		}
	if(DEBUG) printf("  Destination is %d\n", dest_addr);
	/* If it is a broadcast packet or the station doesn't exist in the subnet	*/  
	/*if ((dest_addr < 0) || (oms_aa_address_find (oms_aa_wlan_handle, dest_addr) < 0))*/
	// ############ DEBUG: need broadcasting thus <-1 instead <0
	if (dest_addr < -1)
	   {
	   if(DEBUG) printf("--- MAC Msg @ node %d --- Destination address is < 0 (dest addr = %d.", my_address,dest_addr);
	   /* 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;
	   op_pk_destroy (hld_pkptr);
	   FOUT;		
	   }
		
	   
	/* Check for an AP bridge that whether the destined stations exist in the BSS or not	*/
	/* if not then no need to broadcast the packet.											*/
	if (wlan_flags->bridge_flag == OPC_BOOLINT_ENABLED && ap_flag == OPC_BOOLINT_ENABLED)
		{
		stn_det_flag = OPC_FALSE;
		for (i = 0; i < bss_stn_count; i++)
			{
			if (dest_addr == bss_stn_list [i])
				{
				if (DEBUG) printf("--- MAC Msg @ node %d --- Destination address was found within BSS list (dest addr = %d.", my_address,dest_addr);
				stn_det_flag = OPC_TRUE;
				}
			}
		
		/* If the destination station doesn't exist in the BSS then */
		/* no need to broadcast the packet.							*/
		if (stn_det_flag == OPC_FALSE)
			{
			if (DEBUG) printf("--- MAC Msg @ node %d --- ERROR: Destination address was NOT found within BSS list (dest addr = %d.", my_address,dest_addr);			
			/* 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;
			op_pk_destroy (hld_pkptr);
			FOUT;	
			}
		}

	/* Stamp the packet with the current time. This information will remain		*/
	/* unchanged even if the packet is copied for retransmissions, and			*/
	/* eventually it will be used by the destination MAC to compute the end-to-	*/
	/* end delay.																*/
	op_pk_stamp (hld_pkptr);
	
	/* Insert the arrived packet in higher layer queue.	*/	
	wlan_hlpk_enqueue (hld_pkptr, dest_addr);
	if (DEBUG) printf("--- MAC Msg @ node %d --- packet queued @ Mac Layer\n",my_address);
	FOUT;
	}

static void
wlan_hlpk_enqueue (Packet* hld_pkptr, int dest_addr)
	{
	int						list_index;
	char					msg_string [120];
	char					msg_string1 [120];
	WlanT_Hld_List_Elem*	hld_ptr;
	double					data_size;
	
	/* Enqueuing data packet for transmission.	*/
	FIN (wlan_hlpk_enqueue (Packet* hld_pkptr, int dest_addr));

	/* Allocating pool memory to the higher layer data structure type. */	
	hld_ptr = (WlanT_Hld_List_Elem *) op_prg_pmo_alloc (hld_pmh);

	/* Generate error message and abort simulation if no memory left for data received from higher layer.	*/
	if (hld_ptr == OPC_NIL)
		{
		wlan_mac_error ("No more memory left to assign for data received from higher layer", OPC_NIL, OPC_NIL);
		}

	/* Updating higher layer data structure fields.	*/
	hld_ptr->time_rcvd           = current_time;
	hld_ptr->destination_address = dest_addr;
	hld_ptr->pkptr               = hld_pkptr;

	/* Insert a packet to the list.*/
	op_prg_list_insert (hld_list_ptr, hld_ptr, OPC_LISTPOS_TAIL);	
	
	/* Enable the flag indicating that there is a data frame to transmit.	*/
	wlan_flags->data_frame_to_send = OPC_BOOLINT_ENABLED;

	/* Printing out information to ODB.	*/
	if (wlan_trace_active == OPC_TRUE)
		{
		sprintf (msg_string, "Just arrived outbound Data packet id %d ", op_pk_id (hld_ptr->pkptr));
		sprintf	(msg_string1, "The outbound Data queue size is %d", 	op_prg_list_size (hld_list_ptr));	
		op_prg_odb_print_major (msg_string, msg_string1, OPC_NIL);
		}

	/* Report stat when outbound data packet is received.	*/
	op_stat_write (packet_load_handle, 1.0);
    op_stat_write (packet_load_handle, 0.0);

	/* Report stat in bits when outbound data packet is received.	*/
	data_size = (double) op_pk_total_size_get (hld_pkptr);
	op_stat_write (bits_load_handle, data_size);
    op_stat_write (bits_load_handle, 0.0);
	
	/* Update the global statistics as well.						*/
	op_stat_write (global_load_handle, data_size);
    op_stat_write (global_load_handle, 0.0);
	
	/* Report outbound data packets queue size at the arrival of every packet.	*/
	op_stat_write (hl_packets_rcvd, (double) (op_prg_list_size (hld_list_ptr)));

	FOUT;
	}

static void 
wlan_frame_transmit ()
	{
	char						msg_string  [120];
	char						msg_string1 [120];
	WlanT_Hld_List_Elem*		hld_ptr;
	int 						frag_list_size;
	int							type;
	double						pkt_tx_time;

	/** Main procedure to call functions for preparing frames.   **/
	/** The procedure to prepare frame is called in this routine **/
	FIN (wlan_frame_transmit());

	if(DEBUG) printf("WLAN FRAME Transmit\n");
	/* If Ack and Cts needs to be sent then prepare the appropriate	*/
	/* frame type for transmission									*/
	if ((fresp_to_send == WlanC_Cts) || (fresp_to_send == WlanC_Ack))
		{
		wlan_prepare_frame_to_send (fresp_to_send);

		/* Break the routine if Cts or Ack is already prepared to tranmsit */
		FOUT;
		}
	
	/* If it is a retransmission then check which type of frame needs to be	*/
	/* retransmitted and then prepare and transmit that frame				*/
	else if (retry_count != 0)
		{
		/* If the last frame unsuccessfully transmitted was Rts then transmit it again.	*/
		if ((last_frametx_type == WlanC_Rts) && (wlan_flags->rts_sent == OPC_BOOLINT_DISABLED))
			{
			/* Retransmit the Rts frame.	*/
			wlan_prepare_frame_to_send (WlanC_Rts);
			}

		/* For the retransmission of data frame first check whether Rts needs to be sent or not.	*/
		/* If it Rts needs to be sent and it is not already sent then first transmit Rts and then	*/
		/* transmit data frame.																		*/
		else if (last_frametx_type == WlanC_Data)
			{
			if ((op_pk_total_size_get (wlan_transmit_frame_copy_ptr) > (8 * rts_threshold + WLANC_MSDU_HEADER_SIZE)) && 
				(rts_threshold != -1) && (wlan_flags->rts_sent == OPC_BOOLINT_DISABLED))
				{
				/* Retransmit the Rts frame to again contend for the data .	*/
				wlan_prepare_frame_to_send (WlanC_Rts);				 
				}
			else
				{
				if(DEBUG) printf("wlan prepare frame to send: type DATA\n");
				wlan_prepare_frame_to_send (WlanC_Data);
				}
			}
		else
			{ 
			/* We continue with the retransmission process. We	*/
			/* received the expected Cts for our last Rts.		*/
			/* Hence, now we can retransmit our data frame.		*/
			if(DEBUG) printf("wlan prepare frame to send: type DATA\n");
			wlan_prepare_frame_to_send (WlanC_Data);
			}
			
		FOUT;
		}

	/* If higher layer queue is not empty then dequeue a packet	*/
	/* from the higher layer and insert it into fragmentation 	*/
	/* buffer check whether fragmentation and Rts-Cts exchange 	*/
	/* is needed  based on thresholds							*/
	/* Check if fragmenetation buffer is empty. If it is empty  */
   	/* then dequeue a packet from the higher layer queue.		*/ 
	else if ((op_prg_list_size (hld_list_ptr) != 0) && (op_sar_buf_size (fragmentation_buffer_ptr) == 0))
		{
		/* If rts is already sent then transmit data otherwise	*/
		/* check if rts needs to be sent or not.				*/
		if (wlan_flags->rts_sent == OPC_BOOLINT_DISABLED)
			{
			/* Remove packet from higher layer queue. */
			hld_ptr = (WlanT_Hld_List_Elem*) op_prg_list_remove (hld_list_ptr, 0);
			
			//$$$$$$$$$$$$$$$$$$ DSR $$$$$$$$$$$$$$$$$$$$$$$$
			op_pk_nfd_get((Packet*)(hld_ptr->pkptr),"Type",&data_packet_type);
			if (data_packet_type == DATA_PACKET_TYPE)
				 {
				 op_pk_nfd_get((Packet*)(hld_ptr->pkptr),"NextHop",&data_packet_dest);
			  	 op_pk_nfd_get((Packet*)(hld_ptr->pkptr),"DEST",&data_packet_final_dest);
				 }
			else
				 {
				 data_packet_dest=-1;
				 data_packet_final_dest=-1;
				 }
			//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
			
			/* Update the higher layer queue size statistic.				*/
			op_stat_write (hl_packets_rcvd, (double) (op_prg_list_size (hld_list_ptr)));
			
			/* Determine packet size to determine later wether fragmentation	*/
			/* and/or rts-cts exchange is needed.								*/
			packet_size = op_pk_total_size_get (hld_ptr->pkptr);

			/* Updating the total packet size of the higher layer buffer.	*/
			total_hlpk_size = total_hlpk_size - packet_size;

⌨️ 快捷键说明

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