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"
44#include "net/packetbuf.h"
45
46static uint16_t slotframe_handle = 0;
47static struct tsch_slotframe *sf_unicast;
48
49/*---------------------------------------------------------------------------*/
50static uint16_t
51get_node_timeslot(const linkaddr_t *addr)
52{
53 if(addr != NULL && ORCHESTRA_UNICAST_PERIOD > 0) {
54 return ORCHESTRA_LINKADDR_HASH(addr) % ORCHESTRA_UNICAST_PERIOD;
55 } else {
56 return 0xffff;
57 }
58}
59/*---------------------------------------------------------------------------*/
60static uint16_t
61get_node_channel_offset(const linkaddr_t *addr)
62{
63 if(addr != NULL && ORCHESTRA_UNICAST_MAX_CHANNEL_OFFSET >= ORCHESTRA_UNICAST_MIN_CHANNEL_OFFSET) {
64 return ORCHESTRA_LINKADDR_HASH(addr) % (ORCHESTRA_UNICAST_MAX_CHANNEL_OFFSET - ORCHESTRA_UNICAST_MIN_CHANNEL_OFFSET + 1)
65 + ORCHESTRA_UNICAST_MIN_CHANNEL_OFFSET;
66 } else {
67 return 0xffff;
68 }
69}
70/*---------------------------------------------------------------------------*/
71static void
72child_added(const linkaddr_t *linkaddr)
73{
74}
75/*---------------------------------------------------------------------------*/
76static void
77child_removed(const linkaddr_t *linkaddr)
78{
79}
80/*---------------------------------------------------------------------------*/
81static int
82select_packet(uint16_t *slotframe, uint16_t *timeslot, uint16_t *channel_offset)
83{
84 /* Select data packets we have a unicast link to */
85 const linkaddr_t *dest = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
86 if(packetbuf_attr(PACKETBUF_ATTR_FRAME_TYPE) == FRAME802154_DATAFRAME
87 && !orchestra_is_root_schedule_active(dest)
88 && !linkaddr_cmp(dest, &linkaddr_null)) {
89 if(slotframe != NULL) {
90 *slotframe = slotframe_handle;
91 }
92 if(timeslot != NULL) {
93 *timeslot = get_node_timeslot(dest);
94 }
95 /* set per-packet channel offset */
96 if(channel_offset != NULL) {
97 *channel_offset = get_node_channel_offset(dest);
98 }
99 return 1;
100 }
101 return 0;
102}
103/*---------------------------------------------------------------------------*/
104static void
105new_time_source(const struct tsch_neighbor *old, const struct tsch_neighbor *new)
106{
107}
108/*---------------------------------------------------------------------------*/
109static void
110init(uint16_t sf_handle)
111{
112 int i;
113 uint16_t rx_timeslot;
114 linkaddr_t *local_addr = &linkaddr_node_addr;
115
116 slotframe_handle = sf_handle;
117 /* Slotframe for unicast transmissions */
118 sf_unicast = tsch_schedule_add_slotframe(slotframe_handle, ORCHESTRA_UNICAST_PERIOD);
119 rx_timeslot = get_node_timeslot(local_addr);
120 /* Add a Tx link at each available timeslot. Make the link Rx at our own timeslot. */
121 for(i = 0; i < ORCHESTRA_UNICAST_PERIOD; i++) {
122 tsch_schedule_add_link(sf_unicast,
123 LINK_OPTION_SHARED | LINK_OPTION_TX | ( i == rx_timeslot ? LINK_OPTION_RX : 0 ),
124 LINK_TYPE_NORMAL, &tsch_broadcast_address,
125 i, get_node_channel_offset(local_addr), 1);
126 }
127}
128/*---------------------------------------------------------------------------*/
129struct orchestra_rule unicast_per_neighbor_rpl_ns = {
130 init,
131 new_time_source,
132 select_packet,
133 child_added,
134 child_removed,
135 NULL,
136 "unicast per neighbor non-storing",
137 ORCHESTRA_UNICAST_PERIOD,
138};
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
Definition: linkaddr.c:48
const linkaddr_t linkaddr_null
The null link-layer address.
int linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two link-layer addresses.
Definition: linkaddr.c:69
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, uint8_t do_remove)
Adds a link to a slotframe.
struct tsch_slotframe * tsch_schedule_add_slotframe(uint16_t handle, uint16_t size)
Creates and adds a new slotframe.
Definition: tsch-schedule.c:73
Orchestra header file.
Header file for the Packet buffer (packetbuf) management.
TSCH neighbor information.
Definition: tsch-types.h:109
802.15.4e slotframe (contains links)
Definition: tsch-types.h:84
Header file for routing table manipulation.
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition: uip-nd6.c:107