【问题标题】:How to implement CCA in OMNet++ 4.5如何在 OMNet++ 4.5 中实现 CCA
【发布时间】:2016-05-20 03:39:43
【问题描述】:

我正在编写代码以使用 OMNeT++ 4.5 模拟无线传感器网络 MAC 协议。但我不知道如何实施 CCA(运营商渠道评估)。你能帮我提供任何示例代码吗?

【问题讨论】:

    标签: omnet++


    【解决方案1】:

    我建议阅读 INET 中的 BMacLayer.cc 文件

    case CCA:
                if (msg->getKind() == BMAC_CCA_TIMEOUT) {
                    // channel is clear
                    // something waiting in eth queue?
                    if (macQueue.size() > 0) {
                        EV_DETAIL << "State CCA, message CCA_TIMEOUT, new state"
                                     " SEND_PREAMBLE" << endl;
                        macState = SEND_PREAMBLE;
                        radio->setRadioMode(IRadio::RADIO_MODE_TRANSMITTER);
                        changeDisplayColor(YELLOW);
                        scheduleAt(simTime() + slotDuration, stop_preambles);
                        return;
                    }
                    // if not, go back to sleep and wake up after a full period
                    else {
                        EV_DETAIL << "State CCA, message CCA_TIMEOUT, new state SLEEP"
                                  << endl;
                        scheduleAt(simTime() + slotDuration, wakeup);
                        macState = SLEEP;
                        radio->setRadioMode(IRadio::RADIO_MODE_SLEEP);
                        changeDisplayColor(BLACK);
                        return;
                    }
                }
                // during CCA, we received a preamble. Go to state WAIT_DATA and
                // schedule the timeout.
                if (msg->getKind() == BMAC_PREAMBLE) {
                    nbRxPreambles++;
                    EV_DETAIL << "State CCA, message BMAC_PREAMBLE received, new state"
                                 " WAIT_DATA" << endl;
                    macState = WAIT_DATA;
                    cancelEvent(cca_timeout);
                    scheduleAt(simTime() + slotDuration + checkInterval, data_timeout);
                    delete msg;
                    return;
                }
                // this case is very, very, very improbable, but let's do it.
                // if in CCA and the node receives directly the data packet, switch to
                // state WAIT_DATA and re-send the message
                if (msg->getKind() == BMAC_DATA) {
                    nbRxDataPackets++;
                    EV_DETAIL << "State CCA, message BMAC_DATA, new state WAIT_DATA"
                              << endl;
                    macState = WAIT_DATA;
                    cancelEvent(cca_timeout);
                    scheduleAt(simTime() + slotDuration + checkInterval, data_timeout);
                    scheduleAt(simTime(), msg);
                    return;
                }
                //in case we get an ACK, we simply dicard it, because it means the end
                //of another communication
                if (msg->getKind() == BMAC_ACK) {
                    EV_DETAIL << "State CCA, message BMAC_ACK, new state CCA" << endl;
                    delete msg;
                    return;
                }
                break;
    

    有关更多详细信息,您可以参考 在 MiXiM 中实现 WSN 的 B-MAC 协议,作者是 Anna Förster

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-13
      • 1970-01-01
      • 1970-01-01
      • 2015-07-23
      相关资源
      最近更新 更多