📄 wlan_mac_tmac_nav_rpm_31jan06_ver2.function block
字号:
/* Obtain the receiver valid packet power threshold value used by the */
/* statwires from the receiver into the MAC module. */
op_ima_obj_attr_get (params_attr_objid, "Packet Reception-Power Threshold", &rx_power_threshold_dbm);
/* Convert the power threshold (receiver sensitivity) value from dBm to */
/* Watts. */
rx_power_threshold = pow (10.0, rx_power_threshold_dbm / 10.0) / 1000.0;
/* Get the transmission power value in Watts. */
op_ima_obj_attr_get (params_attr_objid, "Transmit Power", &tx_power);
/* Set the data rate to the minimum data rate of the specified */
/* physical layer technology. */
data_tx_rate = wsn_data_rate;
/* Set the PHY standard as 11b for the technologies specified */
/* in 802.11 and 802.11b. */
phy_type = WlanC_11b_PHY;
/* The MAC is operating in either 802.11/802.11b */
/* Initialize the state variables related to channelization, which */
/* are mainly used during roaming (handover) procedures. */
channel_count = WLANC_11b_OPER_CHNL_COUNT;
first_chan_min_freq = WLANC_11b_FIRST_CHNL_MIN_FREQ;
channel_bandwidth = WLANC_11b_CHNL_BANDWIDTH;
channel_spacing = WLANC_11b_CHNL_SPACING;
/* Allocating memory for the flags used in this process model. */
wlan_flags = (WlanT_Mac_Flags *) op_prg_mem_alloc (sizeof (WlanT_Mac_Flags));
/* Initially resetting all the flags. */
wlan_flags->data_frame_to_send = OPC_FALSE;
wlan_flags->backoff_flag = OPC_FALSE;
wlan_flags->rts_sent = OPC_FALSE;
wlan_flags->rcvd_bad_packet = OPC_FALSE;
wlan_flags->receiver_busy = OPC_FALSE;
wlan_flags->transmitter_busy = OPC_FALSE;
wlan_flags->gateway_flag = OPC_FALSE;
wlan_flags->bridge_flag = OPC_FALSE;
wlan_flags->wait_eifs_dur = OPC_FALSE;
wlan_flags->immediate_xmt = OPC_FALSE;
wlan_flags->forced_bk_end = OPC_FALSE;
wlan_flags->cw_required = OPC_FALSE;
wlan_flags->perform_cw = OPC_FALSE;
wlan_flags->nav_updated = OPC_FALSE;
wlan_flags->collision = OPC_FALSE;
wlan_flags->collided_packet = OPC_FALSE;
wlan_flags->duration_zero = OPC_FALSE;
wlan_flags->ignore_busy = OPC_FALSE;
wlan_flags->tx_beacon = OPC_FALSE;
wlan_flags->tx_cf_end = OPC_FALSE;
wlan_flags->pcf_active = OPC_FALSE;
wlan_flags->polled = OPC_FALSE;
wlan_flags->more_data = OPC_FALSE;
wlan_flags->more_frag = OPC_FALSE;
wlan_flags->pcf_side_traf = OPC_FALSE;
wlan_flags->active_poll = OPC_FALSE;
wlan_flags->non_erp_present = OPC_FALSE;
wlan_flags->rcvd_bad_cts = OPC_FALSE;
wlan_flags->signal_extension = OPC_FALSE;
wlan_flags->pcf_lowered_drate = OPC_FALSE;
/* Set the flag corresponding to optional 802.11g protection mechanism */
/* "CTS-to-self" based on user's configuration. */
op_ima_obj_attr_get (params_attr_objid, "CTS-to-self Option", &cts_to_self_flag);
wlan_flags->cts_to_self = OPC_FALSE;
/* If the BSS IDs are auto-assigned then add the BSS ID into the */
/* physical layer technology specific BSS ID list, which is later going */
/* to be used while selecting channels for BSSs. */
if (bss_id_type == WlanC_Entire_Subnet)
{
wlan_bss_id_list_manage (bss_id, "add");
}
/* 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_FALSE;
/* Creating list to store data arrived from higher layer. */
hld_list_ptr = op_prg_list_create ();
/* If the station is an AP, and PCF supported, create separate PCF queue list for higher layer. */
if ((ap_flag == OPC_BOOLINT_ENABLED) && (pcf_flag == OPC_BOOLINT_ENABLED))
cfpd_list_ptr = op_prg_list_create ();
else
cfpd_list_ptr = OPC_NIL;
/* Initialize segmentation and reassembly buffers. */
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);
common_rsmbuf_ptr = op_sar_buf_create (OPC_SAR_BUF_TYPE_REASSEMBLY, OPC_SAR_BUF_OPT_DEFAULT);
mac_client_reassembly_buffer = op_sar_buf_create (OPC_SAR_BUF_TYPE_REASSEMBLY, OPC_SAR_BUF_OPT_DEFAULT);
/* Initialize PCF segmentation and reassembly buffer. (only used by AP) */
pcf_frag_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);
ap_conn_handle = op_stat_reg ("Wireless Lan.AP Connectivity", 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);
/* Initialize polling index. */
poll_index = -1;
/* Initialize pcf retry count. */
pcf_retry_count = 0;
/* Initialize pcf retry count. */
poll_fail_count = 0;
/* Initialize pcf queue offset. */
pcf_queue_offset = 0;
/* Initialize retry and back-off slot counts. */
short_retry_count = 0;
long_retry_count = 0;
backoff_slots = BACKOFF_SLOTS_UNSET;
/* Initialize the packet pointers that holds the last */
/* transmitted packets to be used for retransmissions when */
/* necessary. */
wlan_transmit_frame_copy_ptr = OPC_NIL;
wlan_pcf_transmit_frame_copy_ptr = OPC_NIL;
/* Initialize NAV duration and NAV reset event handle. */
nav_duration = 0;
nav_reset_evh = invalid_evh;
/* 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_dcf = 0;
packet_size_pcf = 0;
receive_time_dcf = 0.0;
receive_time_pcf = 0.0;
/* Initializing frame response to send to none. */
fresp_to_send = WlanC_None;
/* Determines if the ap is controlling the medium. This */
/* variable is used to determine when the NAV's can be */
/* updates. */
cfp_ap_medium_control = OPC_FALSE;
/* Initializing expected frame type to none. */
expected_frame_type = WlanC_None;
/* Set the variable that holds the current simulation time. */
current_time = op_sim_time ();
/* 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);
/* Check for error conditions. The transmitter is expected to have a single */
/* channel. */
if (num_chann > 1)
wlan_mac_error ("The transmitter of the surrounding node has too many channels. This MAC",
"is implemented to use a single channel for all supported data rates.",
"Possibly, the new MAC process model is deployed in an old node model.");
else if (num_chann == 0)
wlan_mac_error ("No channel is available for transmission.", OPC_NIL, OPC_NIL);
/* Set the transmitter's transmission power. */
txch_objid = op_topo_child (chann_objid, OPC_OBJTYPE_RATXCH, 0);
op_ima_obj_attr_set (txch_objid, "power", tx_power);
/* Free the transmitter channel state information set at the rxgroup */
/* pipeline stage. */
temp_ptr = (void *) op_ima_obj_state_get (txch_objid);
op_prg_mem_free (temp_ptr);
/* Reset the channel state. */
op_ima_obj_state_set (txch_objid, OPC_NIL);
/* 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);
/* Check for error conditions. The receiver is expected to have a single */
/* channel. */
if (num_chann > 1)
wlan_mac_error ("The receiver of the surrounding node has too many channels. This MAC",
"is implemented to use a single channel for all supported data rates.",
"Possibly, the new MAC process model is deployed in an old node model.");
else if (num_chann == 0)
wlan_mac_error (" No channel is available for reception", OPC_NIL, OPC_NIL);
/* Free the receiver channel state information set at the rxgroup stage. */
rxch_objid = op_topo_child (chann_objid, OPC_OBJTYPE_RARXCH, 0);
temp_ptr = (void *) op_ima_obj_state_get (rxch_objid);
op_prg_mem_free (temp_ptr);
/* Reset the channel state. */
op_ima_obj_state_set (rxch_objid, OPC_NIL);
/* Initialize the roaming related information. */
roam_state_ptr = (WlanT_Roam_State_Info *) op_prg_mem_alloc (sizeof (WlanT_Roam_State_Info));
roam_state_ptr->ap_reliability = 1.0;
roam_state_ptr->scan_mode = OPC_FALSE;
roam_state_ptr->current_bss_id = bss_id;
/* Initially, set roaming based on the attribute. In the next state, if it */
/* is determined that this is an ad-hoc network or if PCF is active in the */
/* BSS then roaming will be disabled. */
op_ima_obj_attr_get (params_attr_objid, "Roaming Capability", &roaming_cap_flag);
roam_state_ptr->enable_roaming = (roaming_cap_flag == OPC_BOOLINT_ENABLED) ? OPC_TRUE : OPC_FALSE;
/* Initialize the receiver channel state information. */
rx_state_info_ptr = (WlanT_Rx_State_Info *) op_prg_mem_alloc (sizeof (WlanT_Rx_State_Info));
rx_state_info_ptr->state_info_id = WLANC_RXCH_STATE_ID;
rx_state_info_ptr->rx_power_thresh = rx_power_threshold;
rx_state_info_ptr->rx_end_time = 0.0;
rx_state_info_ptr->roaming_info_ptr = roam_state_ptr;
rx_state_info_ptr->phy_tech = phy_type;
rx_state_info_ptr->routed_bgutil_state_ptr = OPC_NIL;
rx_state_info_ptr->port_name_ptr = OPC_NIL;
rx_state_info_ptr->node_name_ptr = OPC_NIL;
rx_state_info_ptr->data_rate = data_tx_rate;
rx_state_info_ptr->congestion_area = OPC_FALSE;
/* Find out the objid of the packet stream from the receiver into the MAC */
/* module, which is also stored in receiver channel state information. */
rx_state_info_ptr->mac_strm_objid = op_topo_assoc (rx_objid, OPC_TOPO_ASSOC_OUT, OPC_OBJTYPE_STRM, 0);
/* Set the new "state" information of the receiver channel. */
op_ima_obj_state_set (rxch_objid, rx_state_info_ptr);
/* Also overwrite the high threshold trigger attribute values of the */
/* statwires that come into the MAC from the radio receiver by using the */
/* reception power threshold. First determine the total count of incoming */
/* statwires. */
num_statwires = op_topo_assoc_count (my_objid, OPC_TOPO_ASSOC_IN, OPC_OBJTYPE_STATWIRE);
for (i = 0; i < num_statwires; i++)
{
/* Access the next statwire. Skip it if it is coming from the */
/* transmitter. */
statwire_objid = op_topo_assoc (my_objid, OPC_TOPO_ASSOC_IN, OPC_OBJTYPE_STATWIRE, i);
op_ima_obj_attr_get (statwire_objid, "high threshold trigger", &threshold);
/* If the trigger is not disabled then the statwire is from the */
/* receiver. Overwrite the attribute value unless they are already same.*/
if (threshold != OPC_BOOLDBL_DISABLED && threshold != rx_power_threshold)
op_ima_obj_attr_set (statwire_objid, "high threshold trigger", rx_power_threshold);
}
/* Create an ICI to be used during the communication with LLC. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -