Chinaunix首页 | 论坛 | 博客
  • 博客访问: 162778
  • 博文数量: 16
  • 博客积分: 1456
  • 博客等级: 上尉
  • 技术积分: 214
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-14 18:30
文章分类
文章存档

2012年(1)

2011年(1)

2010年(2)

2009年(1)

2007年(11)

我的朋友

分类: 系统运维

2007-04-07 22:31:54

主要方法是把信息放在hdr_cmn结构体中来传递,主要信息是一个回调函数的指针及一个出来该事件的对象的指针.

struct hdr_cmn {
    ......

    /*关键在这里两行*/
    // called if pkt can't obtain media or isn't ack'd. not called if droped by a queue

    FailureCallback xmit_failure_;
    void *xmit_failure_data_;
    /*关键在上面这里两行*/

    /*
     * MONARCH wants to know if the MAC layer is passing this back because
     * it could not get the RTS through or because it did not receive
     * an ACK.
     */

    int xmit_reason_;
#define XMIT_REASON_RTS 0x01
#define XMIT_REASON_ACK 0x02

    // Monarch extn ends;


    ......
};


对于DSR来说,主要是下面两个定义在~/dsr/dsragent.cc文件里的两个全局函数:

void XmitFailureCallback(Packet *pkt, void *data) {
  DSRAgent *agent = (DSRAgent *)data; // cast of trust
  agent->xmitFailed(pkt);
}

void XmitFlowFailureCallback(Packet *pkt, void *data) {
  DSRAgent *agent = (DSRAgent *)data;
  agent->xmitFlowFailed(pkt);
}


当DSR向下发送pkt时,在即将出口之前,将pkt里的hdr_cmn结构中的那两个指针初始化:

void DSRAgent::sendOutPacketWithRoute(SRPacket& p, bool fresh, Time delay) {
    if (dsragent_enable_flowstate && p.src == net_id && !srh->route_request() && !srh->cur_addr() &&
        !srh->route_error() && !srh->route_reply()) {
        ......
        cmnh->xmit_failure_ = srh->num_addrs() ? XmitFailureCallback : XmitFlowFailureCallback;
        cmnh->xmit_failure_data_ = (void *) this;
    }
    else {
        if (srh->route_request()) { // broadcast forward

            cmnh->xmit_failure_ = 0;
            cmnh->next_hop() = MAC_BROADCAST;
            cmnh->addr_type() = NS_AF_ILINK;
        }
        else { // forward according to source route

            cmnh->xmit_failure_ = XmitFailureCallback;
            cmnh->xmit_failure_data_ = (void *) this;
            ......
        }
    }
}


在mac-802.11.cc文件中的Mac802_11类中,每当重传RTS达到7次或重传DATA达到4次,认为传送失败,用回调函数向上层反馈:

void Mac802_11::RetransmitRTS() {
    .......
    macmib_.RTSFailureCount++;
    ssrc_ += 1; // STA Short Retry Count

    if(ssrc_ >= macmib_.getShortRetryLimit()) {
        discard(pktRTS_, DROP_MAC_RETRY_COUNT_EXCEEDED); pktRTS_ = 0;
        /* tell the callback the send operation failed before discarding the packet */
        hdr_cmn *ch = HDR_CMN(pktTx_);
        if (ch->xmit_failure_) {
            /* Need to remove the MAC header so that re-cycled packets don't keep getting bigger. */
            ch->size() -= phymib_.getHdrLen11();
            ch->xmit_reason_ = XMIT_REASON_RTS;
            ch->xmit_failure_(pktTx_->copy(),->xmit_failure_data_);
        }
        discard(pktTx_, DROP_MAC_RETRY_COUNT_EXCEEDED);
        pktTx_ = 0;
        ssrc_ = 0;
        rst_cw();
    } else {
        ......
    }
}

void Mac802_11::RetransmitDATA() {
    ......

    (*rcount)++;
    if(*rcount >= thresh) {
        /* IEEE Spec section 9.2.3.5 says this should be greater than or equal */
        macmib_.FailedCount++;
        /* tell the callback the send operation failed before discarding the packet */
        hdr_cmn *ch = HDR_CMN(pktTx_);
        if (ch->xmit_failure_) {
            ch->size() -= phymib_.getHdrLen11();
            ch->xmit_reason_ = XMIT_REASON_ACK;
            ch->xmit_failure_(pktTx_->copy(),->xmit_failure_data_);
        }
        .......
    }
    else {
        .......
    }
}



阅读(1870) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~