您的位置:首页 > 其它

NS2中Mac802_11::recv(Packet *p, Handler *h )函数解析

2017-06-30 13:53 801 查看
void
Mac802_11::recv(Packet *p, Handler *h)
{
struct hdr_cmn *hdr = HDR_CMN(p);
/*
* Sanity Check
*/
assert(initialized());

/*
*  Handle outgoing packets.
*/
if(hdr->direction() == hdr_cmn::DOWN) {    //1、先判断数据是从MAC层发送出去的海试要接收的数据,如果是要发送给下层的数据,那么直接调用send()函数
send(p, h);
return;
}
/*
*  Handle incoming packets.
*
*  We just received the 1st bit of a packet on the network
*  interface.
*
*/

/*
*  If the interface is currently in transmit mode, then
*  it probably won't even see this packet.  However, the
*  "air" around me is BUSY so I need to let the packet
*  proceed.  Just set the error flag in the common header
*  to that the packet gets thrown away.
*/
if(tx_active_ && hdr->error() == 0) {   //tx_active_=1:represent the MAC currently being sending.MAC层正在发送数据
hdr->error() = 1;    //then, mark the packet error.那么,在包头标记错误
}

if(rx_state_ == MAC_IDLE) {   //if currently being idle, then, the state being set: recv ,2、判断MAC层的状态,如果MAC层空闲,则将信道状态改变成接收状态
setRxState(MAC_RECV);
pktRx_ = p;
/*
* Schedule the reception of this packet, in
* txtime seconds.
*/
mhRecv_.start(txtime(p));
} else {
/*
*  If the power of the incoming packet is smaller than the
*  power of the packet currently being received by at least
*  the capture threshold, then we ignore the new packet.
*/
if(pktRx_->txinfo_.RxPr / p->txinfo_.RxPr >= p->txinfo_.CPThresh) {    //there exits collision. //pktRx_: is the previes received packets(先前接收到的分组),  packet p: is the newly received packet(新接收到的分组).
capture(p);
} else {
collision(p);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  NS2 recv