0

I'm trying to build a TSCH Schedule that makes the RPL transmit into a timeslot and my application transmit in another timeslot, does someone know if is that possible?

I tried to use the following function to schedule my TSCH slotframe, but currently I can't figure out how to make TSCH identify RPL and application messages.

void my_tsch_scheduler(int advertising, int rx, int tx) {
  struct tsch_slotframe *sf_min;
  tsch_schedule_remove_all_slotframes();
  sf_min = tsch_schedule_add_slotframe(0, TSCH_SCHEDULE_DEFAULT_LENGTH);

  tsch_schedule_add_link(sf_min, LINK_OPTION_TX | LINK_OPTION_RX,
      LINK_TYPE_ADVERTISING, &tsch_broadcast_address, 0, 0);

  tsch_schedule_add_link(sf_min, LINK_OPTION_TX | LINK_OPTION_RX,
      LINK_TYPE_NORMAL, &tsch_broadcast_address, 3, 0);
}
kfx
  • 8,136
  • 3
  • 28
  • 52
j-r-mota
  • 23
  • 3

1 Answers1

0

Let's say you have two data slots scheduled at cells (3, 0) and (4, 0) and you want to use the first one for sending RPL messages and the second one for sending data:

void my_tsch_scheduler(int advertising, int rx, int tx) {
  struct tsch_slotframe *sf_min;
  tsch_schedule_remove_all_slotframes();
  sf_min = tsch_schedule_add_slotframe(0, TSCH_SCHEDULE_DEFAULT_LENGTH);

  tsch_schedule_add_link(sf_min, LINK_OPTION_TX | LINK_OPTION_RX,
      LINK_TYPE_ADVERTISING, &tsch_broadcast_address, 0, 0);

  tsch_schedule_add_link(sf_min, LINK_OPTION_TX | LINK_OPTION_RX,
      LINK_TYPE_NORMAL, &tsch_broadcast_address, 3, 0); /* RPL */
  tsch_schedule_add_link(sf_min, LINK_OPTION_TX | LINK_OPTION_RX,
      LINK_TYPE_NORMAL, &tsch_broadcast_address, 4, 0); /* data */
}

The idea is to use a packet selector - a callback function that will inspect th packet and tell TSCH which cell to use.

The selector needs to have specific declaration like:

int my_callback_packet_ready(void);

In the selector you can look at packetbuf attributes to figure out whether this is a RPL message, an EB message, or a regular data message:

int my_callback_packet_ready(void) {
  const uint16_t slotframe = 0;
  const uint16_t channel_offset = 0;
  uint16_t timeslot = 0xffff;

  if(packetbuf_attr(PACKETBUF_ATTR_FRAME_TYPE) == FRAME802154_BEACONFRAME) {
     /* EB packet */
     timeslot = 0;
  } else if (packetbuf_attr(PACKETBUF_ATTR_NETWORK_ID) == UIP_PROTO_ICMP6
     && (packetbuf_attr(PACKETBUF_ATTR_CHANNEL) >> 8) == ICMP6_RPL) {
     /* RPL packet */
     timeslot = 3;
  } else {
     /* data packet */
     timeslot = 4;
  }

#if TSCH_WITH_LINK_SELECTOR
  packetbuf_set_attr(PACKETBUF_ATTR_TSCH_SLOTFRAME, slotframe);
  packetbuf_set_attr(PACKETBUF_ATTR_TSCH_TIMESLOT, timeslot);
  packetbuf_set_attr(PACKETBUF_ATTR_TSCH_CHANNEL_OFFSET, channel_offset);
#endif

  return 1;
}

The you need to enable selector, and define the selector callback in application's configuration:

#define TSCH_CONF_WITH_LINK_SELECTOR 1
#define TSCH_CALLBACK_PACKET_READY my_callback_packet_ready
kfx
  • 8,136
  • 3
  • 28
  • 52
  • That's a great answer, but I still haven't been able to get it to work completely. I tested it on my main code, and on examples/6tisch/timesync-demo/node.c , and the results are the same: For some reason now only the first node on cooja (the root) is sending packets. Do you have any idea what may be happening? (Cooja print here: https://imgur.com/a/SucCMSD). Thank you very much, I appreciate your help. – j-r-mota Feb 13 '20 at 21:30
  • After some tests I realized that no timeslot other than 0 is sending packages. Besides that, printing packetbuf_attr(PACKETBUF_ATTR_NETWORK_ID), packetbuf_attr(PACKETBUF_ATTR_CHANNEL) with LOG_INFO() returns 0 on my Cooja. – j-r-mota Feb 14 '20 at 08:55
  • Is the callback actually called? Also, do you have `TSCH_WITH_LINK_SELECTOR` enabled? it's off by default, add `#define TSCH_CONF_WITH_LINK_SELECTOR 1` – kfx Feb 14 '20 at 10:28
  • The callback is being called, it is reading the LOG_INFO( ) commands, in fact, depending on the timeslot configuration, it generates different results in the simulation, if I use only timeslot=1, the nodes communicate normally as if no callback is being called, but with timeslots 3 and 4 nothing happens. I have already added #define TSCH_CONF_WITH_LINK_SELECTOR 1 on my project-conf.h. Maybe there are other TSCH settings missing? My application was running with TSCH_SCHEDULE_DEFAULT_LENGHT = 3 initially. I tried to change it to 7 but it is still using only timeslot 1. – j-r-mota Feb 18 '20 at 09:14