NS2:RTS阈值(RTSThreshold)的意义

来源:互联网 发布:网络语氮素是什么意思 编辑:程序博客网 时间:2024/06/05 14:38

一个无线帧的大小如果超过设置的RTS阈值,才发送RTS;否则,为保证吞吐量和空口环境的平衡,不发送RTS。

voidMac802_11::sendRTS(int dst)    //creact a RTS packet and store it in the buffer pktRTS_{Packet *p = Packet::alloc();hdr_cmn* ch = HDR_CMN(p);struct rts_frame *rf = (struct rts_frame*)p->access(hdr_mac::offset_);assert(pktTx_);assert(pktRTS_ == 0);/* *  If the size of the packet is larger than the *  RTSThreshold, then perform the RTS/CTS exchange. */if( (u_int32_t) HDR_CMN(pktTx_)->size() < macmib_.getRTSThreshold() ||            (u_int32_t) dst == MAC_BROADCAST) {Packet::free(p);return;}ch->uid() = 0;ch->ptype() = PT_MAC;ch->size() = phymib_.getRTSlen();ch->iface() = -2;ch->error() = 0;bzero(rf, MAC_HDR_LEN);rf->rf_fc.fc_protocol_version = MAC_ProtocolVersion; rf->rf_fc.fc_type= MAC_Type_Control; rf->rf_fc.fc_subtype= MAC_Subtype_RTS; rf->rf_fc.fc_to_ds= 0; rf->rf_fc.fc_from_ds= 0; rf->rf_fc.fc_more_frag= 0; rf->rf_fc.fc_retry= 0; rf->rf_fc.fc_pwr_mgt= 0; rf->rf_fc.fc_more_data= 0; rf->rf_fc.fc_wep= 0; rf->rf_fc.fc_order= 0;//rf->rf_duration = RTS_DURATION(pktTx_);STORE4BYTE(&dst, (rf->rf_ra));/* store rts tx time */ ch->txtime() = txtime(ch->size(), basicRate_);STORE4BYTE(&index_, (rf->rf_ta));/* calculate rts duration field */rf->rf_duration = usec(phymib_.getSIFS()                             //duration time (rf_duration) =       + txtime(phymib_.getCTSlen(), basicRate_)      // 1.(txtime of a CTS packet + a SIFS time)       + phymib_.getSIFS()                                                   + txtime(pktTx_)                                      // 2. +(txtime of a DATA packet + a SIFS time)       + phymib_.getSIFS()       + txtime(phymib_.getACKlen(), basicRate_));  // 3. +(txtime of a ACK packet + a SIFS time)    pktRTS_ = p;}

上面的sendRTS() 函数:在创建RTS包的时候,需要判断帧的大小是否大于RTS阈值:即HDR_CMN(pktTx_)->size() 与macmib_.getRTSThreshold()值进行比较。代码如下:

if( (u_int32_t) HDR_CMN(pktTx_)->size() < macmib_.getRTSThreshold() ||            (u_int32_t) dst == MAC_BROADCAST) {Packet::free(p);return;}

(1)、如果帧的大小 < RTS阈值或帧为广播包(广播包不需要握手):则释放创建的RTS包,不需要进行接下来RTS包的设置,返回send()函数;

(2)、如果帧的大小 > RTS阈值且帧不是广播包:则继续RTS包的创建,继续接下来的一些参数的设置。

原创粉丝点击