Search code examples
iotcontiki

How to access data packet details in rpl's objective function MRHOF in contikiRPL?


I wants to implement DAG Metric Container objective types such as energy, throughput, latency, hop count in mrhrof objective function in contikirpl. I am trying to get data packet details packet like timestamp of packet send/receive, packets received by immediate parent mote etc.

Experimental setup: one sink (mote1) (udp-server.c), three source (mote2,3 & 4) (udp-slient.c) (..../contiki-3.0/examples/ipv6/rpl-udp).

mote1<---->mote2<---->mote3<---->mote4

(1) For counting packets received, i tried very simple code in neighbor_link_callback() because this function receives link-layer neighbor information. (..contiki-3.0/core/net/rpl/rpl-mrhof.c)

#include "sys/node-id.h" (included in file to access node-id)


 static uint16_t pkt1=0,pkt2=0,pkt3=0;   /* pkt1,2 and 3 store incoming packets for mote2,3 and 4 respectively */  

if(status == MAC_TX_OK)      // pkts transmission successfully 
    {
      switch (node_id) {
      case 2:
         pkt1++;
        break;
      case 3:
        pkt2++;
        break;
      case 4:
        pkt3++;
        break;
      default:
         PRINTF("Other::error outside of three mote  \n"); 
        break;
      }
     }

The problem with this code is i am getting more number of packets in these variable. i think because of it is storing all types of packets (control and data packets). How to get only data packets in these variable (pkt1,pkt2,pkt3).

(2) For calculating latency, i want to get send/receiving packet timestamp in mrhrof.c mote wise, but i am only able to get time in udp-server.c and udp-client.c
(..../contiki-3.0/examples/ipv6/rpl-udp)

For this i wrote following code: udp-client.c

static uint16_t pkt1_s=0,pkt2_s=0,pkt3_s=0;

Inside "static void send_packet(void *ptr)"

 pkt_send_time = clock_seconds(); 

switch (node_id) {
      case 2:
        PRINTF("::No of pkt_send::  %u by \t mote %d at \t pkt_send_time:: %u  \n",++pkt1_s,node_id,pkt_send_time); 
        break;
      case 3:
        PRINTF("::#pkt_send::  %u  \t  by mote %d at \t pkt_send_time:: %u  \n",++pkt2_s,node_id,pkt_send_time); 
        break;
      case 4:
        PRINTF("::#pkt_send::  %u  \t by mote %d at \t pkt_send_time:: %u  \n",++pkt3_s,node_id,pkt_send_time); 
        break;
      default:
         PRINTF("::error send pkt outside range  \n"); 
        break;
      }

i wrote same type of code for udp-server.c.

Here, i am facing following problems:

  1. Function clock_seconds() is providing time in second, but i need time in miiliseconds.
  2. How to get exact timestamp of sending/receiving data packets in rpl-mhrof.c

Solution

    1. You can use the RTIMER_NOW() for better time granularity, but, be careful: for most of the node types, the clocks are not synchronized! Your only reliable solution is to send the time_send value to the node, and ask the node to reply with this. When you receive it, you can take the current_time and subtract them. Another bypass is to use cooja's times into the output (Log all output and work with this offline data).
    2. For detailed packets (data/icmp, send/received) use the following: uip_stat.udp.sent, uip_stat.udp.recv, uip_stat.icmp.sent, uip_stat.icmp.recv

    by using

    #include "net/ipv6/uip-ds6.h"
    #include "net/ip/uip-udp-packet.h"