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

📄 wlan_mac_tmac_nav_rpm_31jan06_ver2.header block

📁 opnet无线网络编程
💻 HEADER BLOCK
📖 第 1 页 / 共 2 页
字号:
/** Include files **/

#include <math.h>
#include <string.h>
#include "oms_pr.h"
#include "oms_tan.h"
#include "oms_bgutil.h"
#include "wsn_support.h" 
#include "oms_auto_addr_support.h"
#include "oms_dist_support.h"
#include "bridge_header.h"	
#include "prg_mapping.h"
#include <prg_geo.h>
#include <oms_rr.h>  

/** Constants **/

/* Incoming statistics and stream wires.							*/
#define 	TRANSMITTER_BUSY_INSTAT		1
#define		LOW_LAYER_INPUT_STREAM		0
#define		LOW_LAYER_OUTPUT_STREAM		0

/* Flags to load different variables based on attribute settings.	*/
#define		WLAN_AP						1
#define		WLAN_STA					0

/* Flags to indicate the medium access mode (PCF/DCF).				*/
#define		PCF_ACTIVE					1
#define		PCF_INACTIVE				0

/* Special value indicating BSS identification is not used.			*/
#define		WLAN_BSSID_NOT_USED			-1

/* Special value indicating radio transceiver frequencies are set	*/
/* based on the BSS identification.									*/
#define 	BSS_BASED_FREQ_USED			-1.0

/* Special value indicating that the bandwidth of the transceiver	*/
/* channels are configured to use the standard value of the			*/
/* specified physical layer technology.								*/
#define		PHY_TECH_BASED_BW_USED		-1.0

/* Special value indicating that the number of back-off slots are	*/
/* not determined yet.												*/
#define		BACKOFF_SLOTS_UNSET			-1.0

/* Special value for nav_reset_time when NAV is not set based on a	*/
/* received RTS.													*/
#define		NAV_RESET_TIME_UNSET		-1.0
	
/* Define a small value (= 1 psec), which will be used to recover	*/
/* from double arithmetic precision losts while doing time related	*/
/* precision sensitive computations.								*/
#define		PRECISION_RECOVERY			0.000000000001

/* Special value indicating BSS identification is currently unset.	*/
#define 	WLANC_BSS_ID_UNKNOWN		-2

/* Speed of light (m/s). 											*/
#define 	C							3.0E+08		

/* 16 times pi-squared. 											*/
#define 	SIXTEEN_PI_SQ				(16.0 * VOSC_NA_PI * VOSC_NA_PI)	

/* A small delay (= 10 nsec) between the transmission and reception	*/
/* of a CTS-to-self message to guarantee that the packet isn't		*/
/* delivered before the transmitter completes the transmission.		*/
#define		CTS_TO_SELF_RX_DELAY		0.00000001

/* In the idle state, number of beacon intervals after which the STA will wake	*/
/* up to check if it is still connected, if scanning is based on beacon			*/
/* reliability. There are no interrupts pending in the idle state, therefore,	*/
/* it is possible that the STA's state may be set to "scan" from a pipeline		*/
/* state without the MAC becoming aware of the state change till a packet		*/
/* arrives from the higher layer. Hence, there is a need to schedule periodic	*/
/* interrupts when in IDLE.    													*/
#define WLANC_CONN_CHK_BEACON_MULT		5.0  

/* Period after which the STA will check for connectivity if scanning is		*/
/* distance based. 																*/
#define WLANC_CONN_CHK_DIST_INTERVAL	10.0

/* When in the SCAN state, the period that an STA will wait before trying a new	*/
/* channel. 																	*/
#define WLANC_NEW_SCAN_BEACON_MULT		2.5


/** Enumerated Types **/

/* Define the three possible values that a global variable takes				*/
/* to check and ensure that all the MAC modules are either BSS ID				*/
/* based or purely subnet based. The variable is initialized to					*/
/* Not_Set and the first wireless MAC process sets it to either					*/
/* Entire_Subnet (if BSS_Identifier is Not Used) or Bssid_Subnet				*/
/* (if the BSS_Identifier is set to some value other than Not					*/
/* Used).																		*/						  
typedef enum WlanT_Bssid_Approach
	{
	WlanC_Not_Set,						/* Type of network not set				*/
	WlanC_Entire_Subnet,				/* The network is a pure subnet			*/
	WlanC_Bss_Divided_Subnet			/* The network is a BSS based subnet	*/
	} WlanT_Bss_Identification_Approach;
 
/* Define interrupt codes for generating handling interrupts					*/
/* indicating changes in deference, frame timeout which infers         			*/
/* that the collision has occurred, random backoff and transmission 			*/
/* completion by the physical layer (self interrupts).							*/
typedef enum WlanT_Mac_Intrpt_Code
	{	
	WlanC_Deference_Off,  	/* Deference before frame transmission 				*/
	WlanC_Frame_Timeout,	/* No frame rcvd in set duration (infer collision)	*/
	WlanC_Backoff_Elapsed,  /* Backoff done before frame transmission			*/
	WlanC_CW_Elapsed,		/* Backoff done after successful frame transmission	*/	
	WlanC_Beacon_Tx_Time,	/* Time to transmit beacon frame                    */
	WlanC_Cfp_End,			/* End of the Contention free period 				*/
	WlanC_Scan_Timeout,		/* End of scan duration for given channel 			*/
	WlanC_AP_Check_Timeout,	/* Time to check the connectivity status with the	*/
							/* current AP.										*/
	WlanC_NAV_Reset_Time,	/* Time to reset NAV that is updated by an RTS.		*/
	
	// wsn
	WlanC_Sleep_Schedule_Cyclic,	// Time for node to go to sleep
	WlanC_Sleep_Schedule_NAV,	// Time for node to go to sleep
	WlanC_Wake_Schedule,		// Time for node to wake up
	WlanC_Update_Period
		
	} WlanT_Mac_Intrpt_Code;


/* Define the individual forced and unforced states to determine energy consumption costs  */
/* upon exiting the state									        			*/
typedef enum WsnT_State
	{	
	
	// Unforced States
	WSN_IDLE,  	
	WSN_DEFER,	
	WSN_BACKOFF,
	WSN_SLEEP_LPM3,	
	WSN_SLEEP_LPM2,		
	WSN_SLEEP_LPM1,		
	WSN_WAIT_FOR_RESPONSE,	
	WSN_SCAN,	
	WSN_TRANSMIT,
	
	// Forced States
	
	WSN_BKOFF_NEEDED,
	WSN_WAKE_TRANSIT,
	WSN_FRM_END
		
	} WsnT_State;


/** Data Structures **/

/* Define a structure to maintain data fragments received by each 	  */
/* station for the purpose of reassembly (or defragmentation)		  */
typedef struct WlanT_Mac_Defragmentation_Buffer_Entry
	{		
	int			tx_station_address    ;/* Store the station address of transmitting station  		*/	 
	double		time_rcvd		      ;/* Store time the last fragment for this frame was received	*/ 
	Sbhandle	reassembly_buffer_ptr ;/* Store data fragments for a particular packet       		*/  		 
	} WlanT_Mac_Defragmentation_Buffer_Entry;

/* Define a structure to maintain a copy of each unique data frame      */
/* received by the station. This is done so that the station can    	*/
/* discard any additional copies of the frame received by it. 	   		*/
typedef struct WlanT_Mac_Duplicate_Buffer_Entry
	{	
	int         tx_station_address;  /* store the station address of transmitting station	*/
	int 		sequence_id		  ;  /* rcvd packet sequence id 						 	*/	
	int		    fragment_number	  ;  /* rcvd packet fragment number                      	*/	 
	} WlanT_Mac_Duplicate_Buffer_Entry;

/* This structure contains all the flags used in this process model to determine	*/
/* various conditions as mentioned in the comments for each flag					*/
typedef struct WlanT_Mac_Flags
	{
	Boolean 	data_frame_to_send; /* Flag to check when station needs to transmit.		*/ 
	Boolean     backoff_flag;  	    /* Backoff flag is set when either the collision is		*/
	                                /* inferred or the channel switched from busy to idle	*/
	Boolean		frame_size_req_rts;	/* Flag that is set when the current frame in process	*/
									/* of transmission is larger than the RTS threshold.	*/
	Boolean		rts_sent;   		/* Flag to indicate that whether the RTS for this		*/
								    /* particular data frame is sent and CTS is received.	*/
	Boolean		rcvd_bad_packet;	/* Flag to indicate that the received packet is bad		*/
    Boolean	    receiver_busy;		/* Set this flag if receiver busy stat is enabled		*/	
    Boolean	    transmitter_busy;	/* Set this flag if we are transmitting something.		*/	
	Boolean		wait_eifs_dur;		/* Set this flag if the station needs to wait for eifs	*/
									/* duration.											*/	
	Boolean		gateway_flag;		/* Set this flag if the station is a gateway.			*/
	Boolean		bridge_flag;		/* Set this flag if the station is a bridge				*/
	Boolean		immediate_xmt;		/* Set this flag if the new frame can be transmitted	*/
									/* without deferring.									*/
	Boolean		forced_bk_end;		/* Special case: resume with completion of back-off (or	*/
									/* CW) period regardless of receiver's status.			*/
	Boolean		cw_required;		/* Indicates that the MAC is in contention window		*/
									/* period following a successful transmission.			*/
	Boolean		perform_cw;			/* Flag that triggers backoff process for CW period.	*/
	Boolean		nav_updated;		/* Indicates a new NAV value since the last time when	*/
									/* self interrupt is scheduled for the end of deference.*/
	Boolean		collision;			/* Set this flag if a channel became busy while another	*/
									/* one busy.											*/
	Boolean		collided_packet;	/* Set this flag to drop the next received packet		*/
									/* because of collision.								*/
	Boolean		duration_zero;		/* Set this flag if duration should be zero in next ack	*/
	Boolean		ignore_busy;		/* Set this flag if the STA should ignore receiver busy	*/
	Boolean		tx_beacon;          /* Set this flag if time to send a beacon               */
	Boolean		tx_cf_end;          /* Set this flag if time to send a CF End frame         */
	Boolean		pcf_active;         /* Set this flag for AP if PCF is currently in effect	*/
	Boolean		polled;		        /* Set this flag if the station has received a poll     */
	Boolean		more_data;			/* Set this flag if must poll for more data (MSDU)		*/
	Boolean		more_frag;			/* Set this flag if must poll for more fragments		*/
	Boolean		pcf_side_traf;		/* Set this flag if the AP detects STA to STA traffic   */
	Boolean		active_poll;		/* Set this flag if an active poll is outstanding		*/
	Boolean		non_erp_present;	/* Set this flag if we are an ERP STA and our BSS has	*/
									/* at least one non-ERP STA.							*/
	Boolean		cts_to_self;		/* Set this flag if the optional 11g CTS-to-self		*/
									/* protection mechanism is enabled for this MAC.		*/
	Boolean		rcvd_bad_cts;		/* Set if a reception is detected during the last		*/
									/* CTS-to-self transmission.							*/
	Boolean		signal_extension;	/* Set this flag after an 11g transmission using		*/
									/* ERP-OFDM mode.										*/
	Boolean		pcf_lowered_drate;	/* Set by an 11g AP, if the data rate of current tx is	*/
									/* lowered due to a piggybacked ACK for a non-ERP STA.	*/
	} WlanT_Mac_Flags;

/* This structure contains the destination address to which the received */
/* data packet needs to be sent and the contents of the received packet  */
/* from the higher layer.												 */
typedef struct WlanT_Hld_List_Elem
	{
	double		time_rcvd;  			/* Time packet is received by the higher layer	*/
	int			destination_address; 	/* Station to which this packet needs to be sent*/
	Packet*     pkptr;				 	/* store packet contents  					  	*/
	} WlanT_Hld_List_Elem;

/* Information record for each BSS */
typedef struct bss_mapping_info
	{
	int 				bss_idx;
	int					ap_sta_addr;
	Objid				ap_objid;
	WlanT_Phy_Char_Code	ap_phy_char;
	int					non_erp_sta_count;
	PrgT_Mapping_Handle sta_mapping_hndl;
	} WlanT_Bss_Mapping_Info;

/* Information record for each STA */
typedef struct sta_mapping_info
	{
	int 				sta_addr;
	WlanT_Phy_Char_Code	sta_phy_char;
	PrgT_Mapping_Handle dup_mapping_hndl;
	} WlanT_Sta_Mapping_Info;

/* Information record for each STA */
typedef struct dup_mapping_info
	{
	int 								rem_sta_addr;
	WlanT_Mac_Duplicate_Buffer_Entry*	duplicate_ptr;
	}WlanT_Duplicate_Mapping_Info;

/* Information regarding the location of each APs */
typedef struct WlanT_AP_Position_Info
	{
	struct WlanT_AP_Position_Info * next_ptr;	/* next in chain */
	
	int		ap_bss_id;
	int		ap_channel_num;
	double  tx_power;
	double	lat;
	double  lon;
	double  alt;
	}
WlanT_AP_Position_Info;


/** Global Variables **/
int			wsn_live_nodes = 0;
int 		wsn_dead_nodes = 0;
double		wsn_throughput_global = 0;

⌨️ 快捷键说明

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