From c3ea1f9fc6689992a8b833cd80b2eb1bf181fce2 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 29 Apr 2016 22:12:06 +0200 Subject: [PATCH] Orchestra: added support for RPL non-storing mode --- apps/orchestra/Makefile.orchestra | 2 +- apps/orchestra/orchestra-conf.h | 8 +- ...chestra-rule-unicast-per-neighbor-rpl-ns.c | 119 ++++++++++++++++++ ...a-rule-unicast-per-neighbor-rpl-storing.c} | 10 +- apps/orchestra/orchestra.h | 3 +- 5 files changed, 132 insertions(+), 10 deletions(-) create mode 100644 apps/orchestra/orchestra-rule-unicast-per-neighbor-rpl-ns.c rename apps/orchestra/{orchestra-rule-unicast-per-neighbor.c => orchestra-rule-unicast-per-neighbor-rpl-storing.c} (96%) diff --git a/apps/orchestra/Makefile.orchestra b/apps/orchestra/Makefile.orchestra index 314fdac23..8c30a816e 100644 --- a/apps/orchestra/Makefile.orchestra +++ b/apps/orchestra/Makefile.orchestra @@ -1 +1 @@ -orchestra_src = orchestra.c orchestra-rule-default-common.c orchestra-rule-eb-per-time-source.c orchestra-rule-unicast-per-neighbor.c +orchestra_src = orchestra.c orchestra-rule-default-common.c orchestra-rule-eb-per-time-source.c orchestra-rule-unicast-per-neighbor-rpl-storing.c orchestra-rule-unicast-per-neighbor-rpl-ns.c diff --git a/apps/orchestra/orchestra-conf.h b/apps/orchestra/orchestra-conf.h index 910917620..d8116ff16 100644 --- a/apps/orchestra/orchestra-conf.h +++ b/apps/orchestra/orchestra-conf.h @@ -46,10 +46,10 @@ * - a sender-based or receiver-based slotframe for unicast to RPL parents and children * - a common shared slotframe for any other traffic (mostly broadcast) * */ -#define ORCHESTRA_RULES { &eb_per_time_source, \ - &unicast_per_neighbor, \ - &default_common, \ - } +#define ORCHESTRA_RULES { &eb_per_time_source, &unicast_per_neighbor_rpl_storing, &default_common } +/* Example configuration for RPL non-storing mode: */ +/* #define ORCHESTRA_RULES { &eb_per_time_source, &unicast_per_neighbor_rpl_ns, &default_common } */ + #endif /* ORCHESTRA_CONF_RULES */ /* Length of the various slotframes. Tune to balance network capacity, diff --git a/apps/orchestra/orchestra-rule-unicast-per-neighbor-rpl-ns.c b/apps/orchestra/orchestra-rule-unicast-per-neighbor-rpl-ns.c new file mode 100644 index 000000000..d72646e1d --- /dev/null +++ b/apps/orchestra/orchestra-rule-unicast-per-neighbor-rpl-ns.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2016, Inria. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ +/** + * \file + * Orchestra: a slotframe dedicated to unicast data transmission. Designed primarily + * for RPL non-storing mode but would work with any mode-of-operation. Does not require + * any knowledge of the children. Works only as received-base, and as follows: + * Nodes listen at a timeslot defined as hash(MAC) % ORCHESTRA_SB_UNICAST_PERIOD + * Nodes transmit at: for any neighbor, hash(nbr.MAC) % ORCHESTRA_SB_UNICAST_PERIOD + * + * \author Simon Duquennoy + */ + +#include "contiki.h" +#include "orchestra.h" +#include "net/ipv6/uip-ds6-route.h" +#include "net/packetbuf.h" + +static uint16_t slotframe_handle = 0; +static uint16_t channel_offset = 0; +static struct tsch_slotframe *sf_unicast; + +/*---------------------------------------------------------------------------*/ +static uint16_t +get_node_timeslot(const linkaddr_t *addr) +{ + if(addr != NULL && ORCHESTRA_UNICAST_PERIOD > 0) { + return ORCHESTRA_LINKADDR_HASH(addr) % ORCHESTRA_UNICAST_PERIOD; + } else { + return 0xffff; + } +} +/*---------------------------------------------------------------------------*/ +static void +child_added(const linkaddr_t *linkaddr) +{ +} +/*---------------------------------------------------------------------------*/ +static void +child_removed(const linkaddr_t *linkaddr) +{ +} +/*---------------------------------------------------------------------------*/ +static int +select_packet(uint16_t *slotframe, uint16_t *timeslot) +{ + /* Select data packets we have a unicast link to */ + const linkaddr_t *dest = packetbuf_addr(PACKETBUF_ADDR_RECEIVER); + if(packetbuf_attr(PACKETBUF_ATTR_FRAME_TYPE) == FRAME802154_DATAFRAME + && !linkaddr_cmp(dest, &linkaddr_null)) { + if(slotframe != NULL) { + *slotframe = slotframe_handle; + } + if(timeslot != NULL) { + *timeslot = get_node_timeslot(dest); + } + return 1; + } + return 0; +} +/*---------------------------------------------------------------------------*/ +static void +new_time_source(const struct tsch_neighbor *old, const struct tsch_neighbor *new) +{ +} +/*---------------------------------------------------------------------------*/ +static void +init(uint16_t sf_handle) +{ + int i; + uint16_t rx_timeslot; + slotframe_handle = sf_handle; + channel_offset = sf_handle; + /* Slotframe for unicast transmissions */ + sf_unicast = tsch_schedule_add_slotframe(slotframe_handle, ORCHESTRA_UNICAST_PERIOD); + rx_timeslot = get_node_timeslot(&linkaddr_node_addr); + /* Add a Tx link at each available timeslot. Make the link Rx at our own timeslot. */ + for(i = 0; i < ORCHESTRA_UNICAST_PERIOD; i++) { + tsch_schedule_add_link(sf_unicast, + LINK_OPTION_SHARED | LINK_OPTION_TX | ( i == rx_timeslot ? LINK_OPTION_RX : 0 ), + LINK_TYPE_NORMAL, &tsch_broadcast_address, + i, channel_offset); + } +} +/*---------------------------------------------------------------------------*/ +struct orchestra_rule unicast_per_neighbor_rpl_ns = { + init, + new_time_source, + select_packet, + child_added, + child_removed, +}; diff --git a/apps/orchestra/orchestra-rule-unicast-per-neighbor.c b/apps/orchestra/orchestra-rule-unicast-per-neighbor-rpl-storing.c similarity index 96% rename from apps/orchestra/orchestra-rule-unicast-per-neighbor.c rename to apps/orchestra/orchestra-rule-unicast-per-neighbor-rpl-storing.c index 58f5dcc42..76e039f09 100644 --- a/apps/orchestra/orchestra-rule-unicast-per-neighbor.c +++ b/apps/orchestra/orchestra-rule-unicast-per-neighbor-rpl-storing.c @@ -29,12 +29,13 @@ */ /** * \file - * Orchestra: a slotframe dedicated to unicast data transmission. - * If sender-based: + * Orchestra: a slotframe dedicated to unicast data transmission. Designed for + * RPL storing mode only, as this is based on the knowledge of the children (and parent). + * If receiver-based: * Nodes listen at a timeslot defined as hash(MAC) % ORCHESTRA_SB_UNICAST_PERIOD * Nodes transmit at: for each nbr in RPL children and RPL preferred parent, * hash(nbr.MAC) % ORCHESTRA_SB_UNICAST_PERIOD - * If receiver-based: the opposite + * If sender-based: the opposite * * \author Simon Duquennoy */ @@ -43,6 +44,7 @@ #include "orchestra.h" #include "net/ipv6/uip-ds6-route.h" #include "net/packetbuf.h" +#include "net/rpl/rpl-conf.h" #if ORCHESTRA_UNICAST_SENDER_BASED && ORCHESTRA_COLLISION_FREE_HASH #define UNICAST_SLOT_SHARED_FLAG ((ORCHESTRA_UNICAST_PERIOD < (ORCHESTRA_MAX_HASH + 1)) ? LINK_OPTION_SHARED : 0) @@ -202,7 +204,7 @@ init(uint16_t sf_handle) timeslot, channel_offset); } /*---------------------------------------------------------------------------*/ -struct orchestra_rule unicast_per_neighbor = { +struct orchestra_rule unicast_per_neighbor_rpl_storing = { init, new_time_source, select_packet, diff --git a/apps/orchestra/orchestra.h b/apps/orchestra/orchestra.h index a895335b5..b948a2985 100644 --- a/apps/orchestra/orchestra.h +++ b/apps/orchestra/orchestra.h @@ -53,7 +53,8 @@ struct orchestra_rule { }; struct orchestra_rule eb_per_time_source; -struct orchestra_rule unicast_per_neighbor; +struct orchestra_rule unicast_per_neighbor_rpl_storing; +struct orchestra_rule unicast_per_neighbor_rpl_ns; struct orchestra_rule default_common; extern linkaddr_t orchestra_parent_linkaddr;