Contiki-NG
orchestra-rule-unicast-per-neighbor-rpl-ns.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Inria.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  */
30 /**
31  * \file
32  * Orchestra: a slotframe dedicated to unicast data transmission. Designed primarily
33  * for RPL non-storing mode but would work with any mode-of-operation. Does not require
34  * any knowledge of the children. Works only as received-base, and as follows:
35  * Nodes listen at a timeslot defined as hash(MAC) % ORCHESTRA_SB_UNICAST_PERIOD
36  * Nodes transmit at: for any neighbor, hash(nbr.MAC) % ORCHESTRA_SB_UNICAST_PERIOD
37  *
38  * \author Simon Duquennoy <simon.duquennoy@inria.fr>
39  */
40 
41 #include "contiki.h"
42 #include "orchestra.h"
43 #include "net/ipv6/uip-ds6-route.h"
44 #include "net/packetbuf.h"
45 
46 static uint16_t slotframe_handle = 0;
47 static uint16_t channel_offset = 0;
48 static struct tsch_slotframe *sf_unicast;
49 
50 /*---------------------------------------------------------------------------*/
51 static uint16_t
52 get_node_timeslot(const linkaddr_t *addr)
53 {
54  if(addr != NULL && ORCHESTRA_UNICAST_PERIOD > 0) {
55  return ORCHESTRA_LINKADDR_HASH(addr) % ORCHESTRA_UNICAST_PERIOD;
56  } else {
57  return 0xffff;
58  }
59 }
60 /*---------------------------------------------------------------------------*/
61 static void
62 child_added(const linkaddr_t *linkaddr)
63 {
64 }
65 /*---------------------------------------------------------------------------*/
66 static void
67 child_removed(const linkaddr_t *linkaddr)
68 {
69 }
70 /*---------------------------------------------------------------------------*/
71 static int
72 select_packet(uint16_t *slotframe, uint16_t *timeslot)
73 {
74  /* Select data packets we have a unicast link to */
75  const linkaddr_t *dest = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
76  if(packetbuf_attr(PACKETBUF_ATTR_FRAME_TYPE) == FRAME802154_DATAFRAME
77  && !linkaddr_cmp(dest, &linkaddr_null)) {
78  if(slotframe != NULL) {
79  *slotframe = slotframe_handle;
80  }
81  if(timeslot != NULL) {
82  *timeslot = get_node_timeslot(dest);
83  }
84  return 1;
85  }
86  return 0;
87 }
88 /*---------------------------------------------------------------------------*/
89 static void
90 new_time_source(const struct tsch_neighbor *old, const struct tsch_neighbor *new)
91 {
92 }
93 /*---------------------------------------------------------------------------*/
94 static void
95 init(uint16_t sf_handle)
96 {
97  int i;
98  uint16_t rx_timeslot;
99  slotframe_handle = sf_handle;
100  channel_offset = sf_handle;
101  /* Slotframe for unicast transmissions */
102  sf_unicast = tsch_schedule_add_slotframe(slotframe_handle, ORCHESTRA_UNICAST_PERIOD);
103  rx_timeslot = get_node_timeslot(&linkaddr_node_addr);
104  /* Add a Tx link at each available timeslot. Make the link Rx at our own timeslot. */
105  for(i = 0; i < ORCHESTRA_UNICAST_PERIOD; i++) {
106  tsch_schedule_add_link(sf_unicast,
107  LINK_OPTION_SHARED | LINK_OPTION_TX | ( i == rx_timeslot ? LINK_OPTION_RX : 0 ),
108  LINK_TYPE_NORMAL, &tsch_broadcast_address,
109  i, channel_offset);
110  }
111 }
112 /*---------------------------------------------------------------------------*/
113 struct orchestra_rule unicast_per_neighbor_rpl_ns = {
114  init,
115  new_time_source,
116  select_packet,
117  child_added,
118  child_removed,
119 };
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition: uip-nd6.c:107
TSCH neighbor information.
Definition: tsch-types.h:109
802.15.4e slotframe (contains links)
Definition: tsch-types.h:84
Orchestra header file
struct tsch_slotframe * tsch_schedule_add_slotframe(uint16_t handle, uint16_t size)
Creates and adds a new slotframe.
Definition: tsch-schedule.c:72
const linkaddr_t linkaddr_null
The null link-layer address.
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
Definition: linkaddr.c:48
struct tsch_link * tsch_schedule_add_link(struct tsch_slotframe *slotframe, uint8_t link_options, enum link_type link_type, const linkaddr_t *address, uint16_t timeslot, uint16_t channel_offset)
Adds a link to a slotframe.
int linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two link-layer addresses.
Definition: linkaddr.c:69
Header file for routing table manipulation.
Header file for the Packet buffer (packetbuf) management