📄 dsr_wlan_mac.pr.c
字号:
wlan_mac_error (" No channel is available for transmission", OPC_NIL, OPC_NIL);
}
/* Setting the Frequency and Bandwidth for the transmitting channels. */
for (i = 0; i < num_chann; i++)
{
/* Accessing channel to set the frequency and bandwidth. */
sub_chann_objid = op_topo_child (chann_objid, OPC_OBJTYPE_RATXCH, i);
/* Setting the operating freqeuncy and channel bandwidth for the transmitting channels. */
op_ima_obj_attr_set (sub_chann_objid, "bandwidth", bandwidth);
op_ima_obj_attr_set (sub_chann_objid, "min frequency", frequency);
}
/* 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);
/* Generate error message and terminate simulation if no channel is available for reception. */
if (num_chann == 0)
{
wlan_mac_error (" No channel is available for reception", OPC_NIL, OPC_NIL);
}
/* Setting the Frequency and Bandwidth for the transmitting channels. */
for (i = 0; i < num_chann; i++)
{
/* Accessing channel to set the frequency and bandwidth. */
sub_chann_objid = op_topo_child (chann_objid, OPC_OBJTYPE_RARXCH, i);
/* Setting the operating freqeuncy and channel bandwidth for the receiving channels. */
op_ima_obj_attr_set (sub_chann_objid, "bandwidth", bandwidth);
op_ima_obj_attr_set (sub_chann_objid, "min frequency", frequency);
}
llc_iciptr = op_ici_create ("wlan_mac_ind");
if (llc_iciptr == OPC_NIL)
{
wlan_mac_error ("Unable to create ICI for communication with LLC.", OPC_NIL, OPC_NIL);
}
FOUT;
}
static void
wlan_higher_layer_data_arrival ()
{
Packet* hld_pkptr;
int data_size, frag_size;
int i;
int dest_addr;
Ici* ici_ptr;
Boolean stn_det_flag;
int large_packet_bit = 0x1;
int full_buffer_bit = 0x2;
/** Queue the packet as it arrives from higher layer. **/
/** Also, store the destination address of the packet **/
/** in the queue and the arrival time. **/
FIN (wlan_higher_layer_data_arrival ());
/* Get packet from the incomming stream from higher layer and */
/* obtain the packet size */
hld_pkptr = op_pk_get (op_intrpt_strm ());
/* If we are in a bridge/switch node, then we don't accept any */
/* higher layer packet unless we are AP enabled. */
if ((wlan_flags->bridge_flag == OPC_BOOLINT_ENABLED) && (ap_flag == OPC_BOOLINT_DISABLED))
{
op_pk_destroy (hld_pkptr);
FOUT;
}
/* Get the size of the packet arrived from higher layer. */
data_size = op_pk_total_size_get (hld_pkptr);
/* maintaining total packet size of the packets in the higer layer queue. */
total_hlpk_size = total_hlpk_size + data_size;
/* If fragmentation is enabled and packet size is greater than the threshold */
/* then MSDU length will not be more than fragmentation threshold, hence */
/* the packet will be fragmented into the size less than or equal to fragmentaion */
/* threshold. */
if ((data_size > frag_threshold * 8) && (frag_threshold != -1))
frag_size = frag_threshold * 8;
else
frag_size = data_size;
/* Destroy packet if it is more than max msdu length or its */
/* size zero. Also, if the size of the higher layer queue */
/* will exceed its maximum after the insertion of this packet, */
/* then discard the arrived packet. */
/* The higher layer is reponsible for the retransmission of */
/* this packet. */
if ((data_size > WLAN_MAXMSDU_LENGTH && accept_large_packets == OPC_FALSE) ||
frag_size > WLAN_MAXMSDU_LENGTH ||
data_size == 0 ||
total_hlpk_size > hld_max_size)
{
/* Write an appropriate simulation log message unless the */
/* same message is written before. */
if (drop_pkt_entry_log_flag < full_buffer_bit + large_packet_bit)
{
if (total_hlpk_size > hld_max_size && !(drop_pkt_entry_log_flag & full_buffer_bit))
{
/* Writing log message for dropped packets. */
op_prg_log_entry_write (drop_pkt_log_handle,
"SYMPTOM(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"
" REMEDIAL ACTION(S): \n"
" 1. Reduce Network laod. \n"
" 2. User higher speed wireless lan. \n"
" 3. Increase buffer capacity\n");
drop_pkt_entry_log_flag += full_buffer_bit;
}
else if (total_hlpk_size <= hld_max_size && frag_size > 0 && !(drop_pkt_entry_log_flag & large_packet_bit))
{
/* Writing log message for dropped packets due to */
/* packet size. */
op_prg_log_entry_write (drop_pkt_log_handle,
"SYMPTOM(S):\n"
" Wireless LAN MAC layer discarded some packets due to \n"
" their large sizes. This is an expected protocol \n"
" behavior. \n"
"\n"
" This may lead to: \n"
" - application data loss.\n"
" - higher layer packet retransmission.\n"
"\n"
" REMEDIAL ACTION(S): \n"
" 1. Set the higher layer packet size to \n"
" be smaller than max MSDU size (2304 bystes). \n"
" 2. Enable fragmentation threshold and large packet \n"
" processing. \n");
drop_pkt_entry_log_flag += large_packet_bit;
}
}
/* 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 - data_size;
/* Destroy the dropped packet. */
op_pk_destroy (hld_pkptr);
/* 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) (data_size));
op_stat_write (drop_packet_handle_inbits, 0.0);
op_stat_write (global_dropped_data_handle, (double) (data_size));
op_stat_write (global_dropped_data_handle, 0.0);
FOUT;
}
/* Read ICI parameters at the stream interrupt. */
ici_ptr = op_intrpt_ici ();
/* 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. */
wlan_mac_error ("Destination address in not valid.", OPC_NIL, OPC_NIL);
}
/* 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])
{
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)
{
/* 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 - data_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);
FOUT;
}
static void
wlan_hlpk_enqueue (Packet* hld_pkptr, int dest_addr)
{
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);
/* 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;
double pkt_tx_time;
int seg_left, size_route;
char field [10];
/** Main procedure to call functions for preparing frames. **/
/** The procedure to prepare frame is called in this routine **/
FIN (wlan_frame_transmit());
/* 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))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -