📄 gpr_wlan_mac.pr.c
字号:
/* Obtain the node's object identifier */
my_node_objid = op_topo_parent (my_objid);
/* Obtain subnet objid. */
my_subnet_objid = op_topo_parent (my_node_objid);
/* Obtain the values assigned to the various attributes */
op_ima_obj_attr_get (my_objid, "Wireless LAN Parameters", &mac_params_comp_attr_objid);
params_attr_objid = op_topo_child (mac_params_comp_attr_objid, OPC_OBJTYPE_GENERIC, 0);
/* Determine the assigned MAC address. */
op_ima_obj_attr_get (my_objid, "Address", &my_address);
/* Obtain an address handle for resolving WLAN MAC addresses. */
oms_aa_handle = oms_aa_address_handle_get ("MAC Addresses", "Address");
/* Obtain the BSS_Id attribute to determine if BSS based network is used */
op_ima_obj_attr_get (params_attr_objid, "BSS Identifier", &bss_id);
/* Register the log handles and related flags. */
config_log_handle = op_prg_log_handle_create (OpC_Log_Category_Configuration, "Wireless Lan", "MAC Configuration", 128);
drop_pkt_log_handle = op_prg_log_handle_create (OpC_Log_Category_Protocol, "Wireless Lan", "Data packet Drop", 128);
drop_pkt_entry_log_flag = 0;
/* Update the global variable if this is the first node to come up. If not the */
/* first node, then check for mismatches. A subnet can be a traditional subnet */
/* (i.e. a subnet with one BSS, this is the existing model) or a BSS based */
/* 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 ;
}
}
/* Configuration error checking */
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. */
/* Write the warning message. */
op_prg_log_entry_write (config_log_handle,
"WARNING:\n"
" A node with an explicit BSS \n"
" assignment 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"
);
}
else if (bss_id_type == WlanC_Bss_Divided_Subnet && bss_id == WLAN_BSSID_NOT_USED)
{
/* Unrecoverable error-- not all BSS IDs have been configured. Cannot */
/* what the BSS ID should be, hence terminate. */
wlan_mac_error ("BSS ID not set in a node which belongs to a network in which some BSS IDs are set",
"Please set a non-default BSS ID on all nodes in the network", OPC_NIL);
}
/* Use the subnet ID as the BSS ID if it is set to "NOT USED". */
if (bss_id_type == WlanC_Entire_Subnet)
{
bss_id = my_subnet_objid;
/* Add the BSS ID into the BSS ID list, which is later going to be used */
/* while selecting channels for BSSs. */
wlan_bss_id_list_manage (bss_id, "add");
}
/* 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);
/* Get simulation attributes. */
op_ima_sim_attr_get (OPC_IMA_TOGGLE, "WLAN Beacon Efficiency Mode", &beacon_eff_mode);
/* Initialize the retry limit for the current frame to long retry limit. */
retry_limit = long_retry_limit;
/* Extract beacon and PCF parameters. */
op_ima_obj_attr_get (params_attr_objid, "PCF Parameters", &pcf_params_comp_attr_objid);
subpcf_params_attr_objid = op_topo_child (pcf_params_comp_attr_objid, OPC_OBJTYPE_GENERIC, 0);
op_ima_obj_attr_get (subpcf_params_attr_objid, "PCF Functionality", &pcf_flag);
op_ima_obj_attr_get (subpcf_params_attr_objid, "CFP Beacon Multiple", &cfp_prd);
op_ima_obj_attr_get (subpcf_params_attr_objid, "CFP Offset", &cfp_offset);
op_ima_obj_attr_get (subpcf_params_attr_objid, "CFP Interval", &cfp_length);
op_ima_obj_attr_get (subpcf_params_attr_objid, "Max Failed Polls", &max_poll_fails);
op_ima_obj_attr_get (subpcf_params_attr_objid, "Beacon Interval", &beacon_int);
ap_relay = OPC_TRUE;
/* Check if there is an active AP controlling the medium during the CFP.*/
if ((ap_flag == OPC_BOOLINT_ENABLED) && (pcf_flag == OPC_BOOLINT_ENABLED))
active_pc= OPC_TRUE;
else
active_pc= OPC_FALSE;
/* Load the appropriate physical layer characteristics. */
op_ima_obj_attr_get (params_attr_objid, "Physical Characteristics", &phy_char_flag);
/* 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);
op_ima_obj_attr_get (params_attr_objid, "Transmit Power", &tx_power);
/* Based on physical characteristics settings set appropriate values to */
/* the variables. */
switch (phy_char_flag)
{
case WlanC_Frequency_Hopping:
{
/* Slot duration in terms of seconds. */
slot_time = 50E-06;
/* Short interframe gap in terms of seconds. */
sifs_time = 28E-06;
/* PLCP overheads, which include the preamble and header, in */
/* terms of seconds. */
plcp_overhead_control = 128E-06;
plcp_overhead_data = 128E-06;
/* 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 seconds. */
slot_time = 20E-06;
/* Short interframe gap in terms of seconds. */
sifs_time = 10E-06;
/* PLCP overheads, which include the preamble and header, in */
/* terms of seconds. */
plcp_overhead_control = 192E-06;
plcp_overhead_data = 192E-06;
/* 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 seconds. */
slot_time = 8E-06;
/* Short interframe gap in terms of seconds. */
sifs_time = 7E-06;
/* PLCP overheads, which include the preamble and header, in */
/* terms of seconds. Infra-red supports transmission of parts */
/* of the PLCP header at the regular data transmission rate, */
/* which can be higher than mandatory lowest data rate. */
plcp_overhead_control = 57E-06;
plcp_overhead_data = 25E-06 + (ceil (32000000.0 / operational_speed) / 1E6);
/* 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_FALSE;
/* 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 + plcp_overhead_control;
/** PIFS duration is used by the AP operating under PCF to gain **/
/** priority to access the medium **/
pifs_time = sifs_time + slot_time;
/* 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);
/* 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);
/* 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);
/* Allocating memory for the flags used in this process model. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -