【问题标题】:Omnet++: Set total message length to be transferred from one node to anotherOmnet++:设置从一个节点传输到另一个节点的总消息长度
【发布时间】:2016-02-03 14:04:42
【问题描述】:

我的网络中有 2 个节点,它们有 UDPBaiscApp 用于它们之间的通信。节点 1 定期向节点 2 发送长度为 10kb 的消息。现在我想限制节点 1 的数据大小。例如,如果节点 1 有 100kB 数据并且它一次发送 10kB,则通信应该在发送消息 10 次后结束。那么如何分配节点 1 可以拥有的最大数据呢?

【问题讨论】:

    标签: omnet++


    【解决方案1】:

    您可以通过多种方式做到这一点,例如:

    1) 在类UDPBasicApp定义中添加两个变量:

    long alreadySentBytes;
    long limitBytes;
    

    2) 在UDPBasicApp::initialise() 中填写初始值:

    alreadySentBytes = 0;
    limitBytes = 100 * 1024; // 100KB
    

    3) 在UDPBasicApp::sendPacket() 中进行如下修改:

    void UDPBasicApp::sendPacket()
    {
      if (alreadySentBytes < limitBytes) {
        std::ostringstream str;
        str << packetName << "-" << numSent;
        cPacket *payload = new cPacket(str.str().c_str());
        payload->setByteLength(par("messageLength").longValue());
        alreadySentBytes += par("messageLength").longValue();
        L3Address destAddr = chooseDestAddr();
    
        emit(sentPkSignal, payload);
        socket.sendTo(payload, destAddr, destPort);
        numSent++;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2022-01-02
      • 1970-01-01
      • 2023-03-24
      • 2012-04-10
      • 2019-03-09
      • 2011-08-26
      • 1970-01-01
      • 1970-01-01
      • 2015-03-21
      相关资源
      最近更新 更多