首页 > 解决方案 > 更改 MAC 802_3 的 ns2 代码以关闭碰撞检测

问题描述

过去几周我一直在研究 ns2 模拟,需要更改 ns-2.35/mac/mac-802_3.cc 中的实现以关闭碰撞检测。

这是发生碰撞时运行的代码 -


void Mac802_3::collision(Packet *p) {

    PRNT_MAC_FUNCS(this);

    if (mhIFS_.busy()) mhIFS_.cancel();

    double ifstime= netif_->txtime(int((IEEE_8023_JAMSIZE+IEEE_8023_IFS_BITS)/8.0)); //jam time + ifs
    mhIFS_.schedule(ifstime);

    switch(state_) {
    case MAC_SEND:
      // If mac trace feature is on generate a collision trace for this packet. 
            if (trace_)
               drop(p);
            else
               Packet::free(p);
        if (mhSend_.busy()) mhSend_.cancel();
        if (!mhRetx_.busy()) {
            /* schedule retransmissions */
            if (!mhRetx_.schedule(ifstime)) {
                p= mhRetx_.packet();
                hdr_cmn *th = hdr_cmn::access(p);
                HDR_CMN(p)->size() -= (ETHER_HDR_LEN + HDR_MAC(p)->padding_);
                fprintf(stderr,"BEB limit exceeded:Dropping packet %d\n",th->uid());
                                fflush(stderr);
                drop(p); // drop if backed off far enough
                mhRetx_.reset();
            }
        }
        break;
    case MAC_RECV:
            Packet::free(p);
        // more than 2 packets collisions possible
        if (mhRecv_.busy()) mhRecv_.cancel();
        break;
    default:
        assert("SHOULD NEVER HAPPEN" == 0);
    }
}

我尝试评论 .cancel() 部分以避免在检测到碰撞时取消传输。但这并没有按预期工作,我在网络上的吞吐量为零。有人可以指导我如何实现这一目标吗?

标签: networkingnetwork-programmingnetwork-protocolsns2

解决方案


推荐阅读