contiki

How to calculate the throughput in Cooja simulator



Hi All,

I work with example/ipv6/rpl-udp files in cooja simulator. How do I measure the amount of throughput in the network?

With the command "powertrace_start(CLOCK_SECOND * 60); " in the client.c code, I get the Powertrace output.

Can I use this method?

throughput= packet received / Simulation time

Simulation time = (ENERGEST_TYPE_TRANSMIT + ENERGEST_TYPE_LISTEN) / 32768

Is the method correct?

Thanks in advance,

Nasrin


Solution

  • No, that is not correct as ENERGEST_TYPE_* are constants.

    One way to do it is with Cooja simulator scripts.

    For example, let's say you have a C program that prints "Message transmitted" every time the node sends a message to another node and "Message received" every time it receives as message.

    A Cooja script can automatically run the simulation for a specific time and count the messages. This code works for me:

    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();
    }
    

    To start using it, save the code (its JavaScript) in a file test.js and add this to your .csc Cooja configuration file:

    <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>