📄 aodv_wlan_mac.pr.c
字号:
/* Process model C form file: aodv_wlan_mac.pr.c */
/* Portions of this file copyright 1992-2003 by OPNET Technologies, Inc. */
/* This variable carries the header into the object file */
const char aodv_wlan_mac_pr_c [] = "MIL_3_Tfile_Hdr_ 100A 30A modeler 7 43C4D6AE 43C4D6AE 1 wind Administrator 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 8f3 1 ";
#include <string.h>
/* OPNET system definitions */
#include <opnet.h>
/* Header Block */
#include <math.h>
#include "oms_pr.h"
#include "oms_tan.h"
#include "oms_bgutil.h"
/* Definitions to all protocol specific parameters*/
#include "wlan_support.h"
/* Station address assignment definitions. */
#include "oms_auto_addr_support.h"
#include "oms_dist_support.h"
//$$$$$$$$$$$$$$$$$$ DSR $$$$$$$$$$$$$$$$$$$$$$$$
// define packet Types
#define DATA_PACKET_TYPE 5
#define REQUEST_PACKET_TYPE 7
#define REPLY_PACKET_TYPE 11
#define ERROR_PACKET_TYPE 13
// remote intrpt or self intrpt codes definition
#define ACK_CODE 10000
#define ERROR_CODE 20000
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#define WLANC_MSDU_HEADER_SIZE 272
#define WLAN_AIR_PROPAGATION_TIME 512
/* incoming statistics and stream wires */
#define TRANSMITTER_INSTAT 2
#define RECEIVER_BUSY_INSTAT 1
#define RECEIVER_COLL_INSTAT 0
#define LOW_LAYER_INPUT_STREAM_CH4 3
#define LOW_LAYER_OUT_STREAM_CH1 0
#define LOW_LAYER_OUT_STREAM_CH2 1
#define LOW_LAYER_OUT_STREAM_CH3 2
#define LOW_LAYER_OUT_STREAM_CH4 3
/* Flags to load different variables based on attribute settings. */
#define WLAN_AP 1
#define WLAN_STA 0
//$$$$$$$$$$$$$$$$$$ DSR $$$$$$$$$$$$$$$$$$$$$$$$
Stathandle stat_mac_failed_data;
int mac_failed_data;
Stathandle stat_mac_failed_reply;
int mac_failed_reply;
Stathandle stat_mac_failed_error;
int mac_failed_error=0;
Stathandle stat_mac_total_failed;
int mac_total_failed=0;
Stathandle stat_mac_retry_rts;
int mac_retry_rts;
Stathandle stat_mac_retry_data;
int mac_retry_data;
Stathandle stat_mac_retry_reply;
int mac_retry_reply;
Stathandle stat_mac_retry_error;
int mac_retry_error;
Stathandle stat_mac_total_retry;
int mac_total_retry;
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
/* 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 /* Bakcoff done after successful frame transmission */
} WlanT_Mac_Intrpt_Code;
/* Define codes for data and managment frames use in DCF */
/* The code defined is consistent with IEEE 802.11 format */
/* There are 6 bits used to define the code and in the following */
/* enumeration the first 6 bits are used in the type field of the frame.*/
//typedef enum WlanT_Mac_Frame_Type
//{
//WlanC_Rts = 0x6C, /* Rts code set into the Rts control frame */
//WlanC_Cts = 0x70, /* Cts code set into the Cts control frame */
//WlanC_Ack = 0x74, /* Ack code set into the Ack control frame */
//WlanC_Data = 0x80, /* Data code set into the Data frame */
//WlanC_None = 0x00 /* None type */
//} WlanT_Mac_Frame_Type;
/* Defining codes for the physical layer characteristics type */
typedef enum WlanT_Phy_Char_Code
{
WlanC_Frequency_Hopping,
WlanC_Direct_Sequence,
WlanC_Infra_Red
} WlanT_Phy_Char_Code;
/* 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 rts_sent; /* Flag to indicate that wether the Rts for this */
/* particular data frame is sent */
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 cw_required; /* Indicates the arrival of an ACK making the */
/* transmission successful, which requires a CW period. */
Boolean nav_updated; /* Indicates a new NAV value since the last time when */
/* self interrupt is scheduled for the end of deference.*/
} WlanT_Mac_Flags;
/* This structure contains the destination address to which the received */
/* data packet needs to be sent and the contents of the recieved 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;
/** Macros Definition **/
/** The data frame send flag is set whenever there is a data to be send by **/
/** the higher layer or the response frame needs to be sent. However,in **/
/** either case the flag will not be set if the receiver is busy **/
/** Frames cannot be transmitted until medium is idle. Once, the medium **/
/** is available then the station is eligible to transmit provided there **/
/** is a need for backoff. Once the transmission is complete then the **/
/** station will wait for the response provided the frame transmitted **/
/** requires a response (such as Rts and Data frames). If response **/
/** is not needed then the station will defer to transmit next packet **/
/* After receiving a stream interrupt, we need to switch states from */
/* idle to defer or transmit if there is a frame to transmit and the */
/* receiver is not busy */
#define READY_TO_TRANSMIT ((intrpt_type == OPC_INTRPT_STRM || (intrpt_type == OPC_INTRPT_SELF && intrpt_code == WlanC_CW_Elapsed)) && \
(wlan_flags->data_frame_to_send == OPC_BOOLINT_ENABLED || fresp_to_send != WlanC_None) && \
wlan_flags->receiver_busy == OPC_BOOLINT_DISABLED && \
(current_time >= cw_end || fresp_to_send != WlanC_None))
/* When we have a frame to transmit, we move to transmit state if the */
/* medium was idle for at least a DIFS time, otherwise we go to defer */
/* state. */
#define MEDIUM_IS_IDLE ((current_time - nav_duration >= difs_time) && \
(wlan_flags->receiver_busy == OPC_BOOLINT_DISABLED) && \
(current_time - rcv_idle_time >= difs_time))
/* Change state to Defer from Frm_End, if the input buffers are not empty or a frame needs */
/* to be retransmitted or the station has to respond to some frame. */
#define FRAME_TO_TRANSMIT ((wlan_flags->data_frame_to_send == OPC_BOOLINT_ENABLED && current_time >= cw_end) || \
fresp_to_send != WlanC_None || \
retry_count != 0)
/* After defering for either collision avoidance or interframe gap */
/* the channel will be available for transmission */
#define DEFERENCE_OFF (intrpt_type == OPC_INTRPT_SELF && \
intrpt_code == WlanC_Deference_Off && \
wlan_flags->receiver_busy == OPC_BOOLINT_DISABLED)
/* Isssue a transmission complete stat once the packet has successfully */
/* been transmitted from the source station */
#define TRANSMISSION_COMPLETE (intrpt_type == OPC_INTRPT_STAT && \
op_intrpt_stat () == TRANSMITTER_INSTAT)
/* Backoff is performed based on the value of the backoff flag. */
#define PERFORM_BACKOFF (wlan_flags->backoff_flag == OPC_BOOLINT_ENABLED)
/* Need to start transmitting frame once the backoff (self intrpt) */
/* completed */
#define BACKOFF_COMPLETED (intrpt_type == OPC_INTRPT_SELF && \
intrpt_code == WlanC_Backoff_Elapsed && \
wlan_flags->receiver_busy == OPC_BOOLINT_DISABLED)
/* After transmission the station will wait for a frame response for */
/* Data and Rts frames. */
#define WAIT_FOR_FRAME (expected_frame_type != WlanC_None)
/* Need to retransmit frame if there is a frame timeout and the */
/* required frame is not received */
#define FRAME_TIMEOUT (intrpt_type == OPC_INTRPT_SELF && intrpt_code == WlanC_Frame_Timeout)
/* If the frame is received appropriate response will be transmitted */
/* provided the medium is considered to be idle */
#define FRAME_RCVD (intrpt_type == OPC_INTRPT_STRM && wlan_flags->rcvd_bad_packet == OPC_BOOLINT_DISABLED && \
i_strm <= LOW_LAYER_INPUT_STREAM_CH4)
/* Skip backoff if no backoff is needed */
#define TRANSMIT_FRAME (wlan_flags->backoff_flag == OPC_BOOLINT_DISABLED)
/* Expecting frame response after data or Rts transmission */
#define EXPECTING_FRAME (expected_frame_type != WlanC_None)
/* Macros that check the change in the busy status of the receiver. */
#define RECEIVER_BUSY_HIGH (intrpt_type == OPC_INTRPT_STAT && intrpt_code == RECEIVER_BUSY_INSTAT && \
op_stat_local_read (RECEIVER_BUSY_INSTAT) == 1.0)
#define RECEIVER_BUSY_LOW (intrpt_type == OPC_INTRPT_STAT && intrpt_code == RECEIVER_BUSY_INSTAT && \
op_stat_local_read (RECEIVER_BUSY_INSTAT) == 0.0)
/* Function declarations. */
static void wlan_mac_sv_init ();
static void wlan_higher_layer_data_arrival ();
static void wlan_physical_layer_data_arrival ();
static void wlan_hlpk_enqueue (Packet* hld_pkptr, int dest_addr);
Boolean wlan_tuple_find (int sta_addr, int seq_id, int frag_num);
static void wlan_data_process (Packet* seg_pkptr, int sta_addr, int final_dest_addr, int frag_num, int more_frag, int pkt_id, int rcvd_sta_bssid);
static void wlan_accepted_frame_stats_update (Packet* seg_pkptr);
static void wlan_interrupts_process ();
static void wlan_prepare_frame_to_send (int frame_type);
static void wlan_frame_transmit ();
static void wlan_schedule_deference ();
static void wlan_frame_discard ();
static void wlan_mac_error (char* msg1, char* msg2, char* msg3);
/* End of Header Block */
#if !defined (VOSD_NO_FIN)
#undef BIN
#undef BOUT
#define BIN FIN_LOCAL_FIELD(_op_last_line_passed) = __LINE__ - _op_block_origin;
#define BOUT BIN
#define BINIT FIN_LOCAL_FIELD(_op_last_line_passed) = 0; _op_block_origin = __LINE__;
#else
#define BINIT
#endif /* #if !defined (VOSD_NO_FIN) */
/* State variable definitions */
typedef struct
{
/* Internal state tracking for FSM */
FSM_SYS_STATE
/* State Variables */
int retry_count;
int intrpt_type;
WlanT_Mac_Intrpt_Code intrpt_code;
int my_address;
List* hld_list_ptr;
double operational_speed;
int frag_threshold;
int packet_seq_number;
int packet_frag_number;
int destination_addr;
Sbhandle fragmentation_buffer_ptr;
WlanT_Mac_Frame_Type fresp_to_send;
double nav_duration;
int rts_threshold;
int duplicate_entry;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -