如何计算Cooja模拟器中的吞吐量

How to calculate the throughput in Cooja simulator


大家好,

我在 cooja 模拟器中使用 example/ipv6/rpl-udp 文件。如何测量网络中的吞吐量?

使用 client.c 代码中的命令 "powertrace_start(CLOCK_SECOND * 60); ",我得到了 Powertrace 输出。

我可以用这个方法吗?

吞吐量=接收到的数据包/模拟时间

模拟时间= (ENERGEST_TYPE_TRANSMIT + ENERGEST_TYPE_LISTEN) / 32768

方法是否正确?

提前致谢,

纳斯林

不,这是不正确的,因为 ENERGEST_TYPE_* 是常量。

一种方法是使用 Cooja simulator scripts

例如,假设您有一个 C 程序,每次节点向另一个节点发送消息时打印“消息已传输”,每次接收消息时打印“消息已接收”。

Cooja 脚本可以自动运行 模拟特定时间并计算消息数。此代码对我有用:

TIMEOUT(100000); // simulation duration in milliseconds

num_messages_tx = 0;
num_messages_rx = 0;

timeout_function = function () {
    log.log("Script timed out.\n");
    log.log("Messages transmitted: " + num_messages_tx + " \n");
    log.log("Messages received:    " + num_messages_rx + " \n");
    log.testOK();
}

while (true) {
    if (msg) {
        if(msg.startsWith("Message transmitted")) {
            num_messages_tx += 1;
        }
        if(msg.startsWith("Message received")) {
            num_messages_rx += 1;
        }
    }

    YIELD();
}

要开始使用它,请将代码(它的 JavaScript)保存在文件 test.js 中并将其添加到您的 .csc Cooja 配置文件中:

<plugin>
  org.contikios.cooja.plugins.ScriptRunner
  <plugin_config>
    <scriptfile>[CONFIG_DIR]/test.js</scriptfile>
    <active>true</active>
  </plugin_config>
  <width>457</width>
  <z>4</z>
  <height>427</height>
 <location_x>3</location_x>
 <location_y>404</location_y>
</plugin>