You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cooja模拟器中RPL-UDP场景下吞吐量计算方法正确性验证

Measuring Throughput in Cooja's RPL-UDP Example

Hey Nasrin,

Great question about measuring throughput in your Cooja RPL-UDP setup—let's break down what's wrong with your proposed method and walk through reliable approaches.

Your Current Calculation Has Two Key Issues

Let's clarify why your approach won't give you accurate standard throughput:

  1. Wrong time denominator: The formula (ENERGEST_TYPE_TRANSMIT + ENERGEST_TYPE_LISTEN)/32768 calculates your node's active time (time spent transmitting or listening for packets), not the total duration of your simulation. Since you started powertrace with powertrace_start(CLOCK_SECOND * 60);, your simulation runs for 60 full seconds—this is the correct time base for standard throughput measurements.
  2. Packet count ≠ throughput: Counting received packets gives you a packet rate (packets per second), not throughput. Throughput is almost always measured in bytes per second, so you need to track the total number of data bytes received, not just how many packets came in.

Correct Methods to Measure Throughput

Here are two straightforward, accurate ways to get your throughput numbers:

1. Add Custom Counters to the Code

This is the most precise method—just tweak the receiving node's code (usually server.c in the RPL-UDP example):

  • Add two global counters at the top of the file:
    static uint32_t total_received_bytes = 0;
    static uint16_t received_packet_count = 0;
    
  • Update these counters in the UDP receive callback whenever a packet arrives:
    static void
    udp_rx_callback(struct udp_socket *c,
                   const uip_ipaddr_t *sender_addr,
                   uint16_t sender_port,
                   const uip_ipaddr_t *receiver_addr,
                   uint16_t receiver_port,
                   const uint8_t *data,
                   uint16_t datalen)
    {
      total_received_bytes += datalen;
      received_packet_count++;
      // Keep the existing callback logic (like printing packet info) here
    }
    
  • After your 60-second simulation finishes, print these values (you can add a timer event to trigger a print at the end). Then calculate:
    • Throughput: total_received_bytes / 60 (bytes per second)
    • Packet rate: received_packet_count / 60 (packets per second)

2. Use Cooja's Simulation Logs

If you don't want to modify code, you can analyze Cooja's logs:

  • Right-click the receiving node in Cooja > select "Log to file" to save its output.
  • Run your 60-second simulation, then open the saved log file.
  • Manually (or with a simple script) count the number of received packets and sum their payload lengths (look for log lines mentioning the packet length).
  • Divide the total bytes by 60 to get your throughput.

Quick Note on Powertrace

Powertrace is built for energy consumption analysis, not throughput. While you can use its output to calculate active time, using that as your time base would give you an "active-only" throughput metric—this isn't the standard definition most people use. Stick to the total simulation duration for accurate, standard throughput numbers.

Hope this helps you get the data you need!

内容的提问来源于stack exchange,提问作者n.nobakht

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:34:48