From 287b4767e39b6aff45eb0c8f93a73059e7f5de43 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 20 May 2016 13:40:20 +0200 Subject: [PATCH 1/4] Orchestra: handle case where ORCHESTRA_UNICAST_PERIOD is smaller than the network size --- .../orchestra-rule-unicast-per-neighbor.c | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/apps/orchestra/orchestra-rule-unicast-per-neighbor.c b/apps/orchestra/orchestra-rule-unicast-per-neighbor.c index b70a907d0..acba8e7be 100644 --- a/apps/orchestra/orchestra-rule-unicast-per-neighbor.c +++ b/apps/orchestra/orchestra-rule-unicast-per-neighbor.c @@ -85,10 +85,16 @@ add_uc_link(const linkaddr_t *linkaddr) { if(linkaddr != NULL) { uint16_t timeslot = get_node_timeslot(linkaddr); - tsch_schedule_add_link(sf_unicast, - ORCHESTRA_UNICAST_SENDER_BASED ? LINK_OPTION_RX : LINK_OPTION_TX | UNICAST_SLOT_SHARED_FLAG, - LINK_TYPE_NORMAL, &tsch_broadcast_address, - timeslot, channel_offset); + uint8_t link_options = ORCHESTRA_UNICAST_SENDER_BASED ? LINK_OPTION_RX : LINK_OPTION_TX | UNICAST_SLOT_SHARED_FLAG; + + if(timeslot == get_node_timeslot(&linkaddr_node_addr)) { + /* This is also our timeslot, add necessary flags */ + link_options |= ORCHESTRA_UNICAST_SENDER_BASED ? LINK_OPTION_TX | UNICAST_SLOT_SHARED_FLAG: LINK_OPTION_RX; + } + + /* Add/update link */ + tsch_schedule_add_link(sf_unicast, link_options, LINK_TYPE_NORMAL, &tsch_broadcast_address, + timeslot, channel_offset); } } /*---------------------------------------------------------------------------*/ @@ -123,7 +129,17 @@ remove_uc_link(const linkaddr_t *linkaddr) } item = nbr_table_next(nbr_routes, item); } - tsch_schedule_remove_link(sf_unicast, l); + + /* Do we need this timeslot? */ + if(timeslot == get_node_timeslot(&linkaddr_node_addr)) { + /* This is our link, keep it but update the link options */ + uint8_t link_options = ORCHESTRA_UNICAST_SENDER_BASED ? LINK_OPTION_TX | UNICAST_SLOT_SHARED_FLAG: LINK_OPTION_RX; + tsch_schedule_add_link(sf_unicast, link_options, LINK_TYPE_NORMAL, &tsch_broadcast_address, + timeslot, channel_offset); + } else { + /* Remove link */ + tsch_schedule_remove_link(sf_unicast, l); + } } /*---------------------------------------------------------------------------*/ static void From 7e8d042609a65e45f64ce11c23ada80875ab7474 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 20 May 2016 13:40:50 +0200 Subject: [PATCH 2/4] Orchestra: fix bug in new_time_source --- apps/orchestra/orchestra-rule-unicast-per-neighbor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/orchestra/orchestra-rule-unicast-per-neighbor.c b/apps/orchestra/orchestra-rule-unicast-per-neighbor.c index acba8e7be..58f5dcc42 100644 --- a/apps/orchestra/orchestra-rule-unicast-per-neighbor.c +++ b/apps/orchestra/orchestra-rule-unicast-per-neighbor.c @@ -176,13 +176,14 @@ static void new_time_source(const struct tsch_neighbor *old, const struct tsch_neighbor *new) { if(new != old) { + const linkaddr_t *old_addr = old != NULL ? &old->addr : NULL; const linkaddr_t *new_addr = new != NULL ? &new->addr : NULL; if(new_addr != NULL) { linkaddr_copy(&orchestra_parent_linkaddr, new_addr); } else { linkaddr_copy(&orchestra_parent_linkaddr, &linkaddr_null); } - remove_uc_link(new_addr); + remove_uc_link(old_addr); add_uc_link(new_addr); } } From c7694e4dbdcfe831b29d8128f3845d9a9806ceac Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 20 May 2016 13:51:24 +0200 Subject: [PATCH 3/4] Orchestra: fix orchestra-rule-eb-per-time-source to handle hash collisions --- .../orchestra-rule-eb-per-time-source.c | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/orchestra/orchestra-rule-eb-per-time-source.c b/apps/orchestra/orchestra-rule-eb-per-time-source.c index 0f774f531..b18617f0a 100644 --- a/apps/orchestra/orchestra-rule-eb-per-time-source.c +++ b/apps/orchestra/orchestra-rule-eb-per-time-source.c @@ -83,14 +83,24 @@ new_time_source(const struct tsch_neighbor *old, const struct tsch_neighbor *new if(old_ts != 0xffff) { /* Stop listening to the old time source's EBs */ - tsch_schedule_remove_link_by_timeslot(sf_eb, old_ts); + if(old_ts == get_node_timeslot(&linkaddr_node_addr)) { + /* This was the same timeslot as slot. Reset original link options */ + tsch_schedule_add_link(sf_eb, LINK_OPTION_TX, LINK_TYPE_ADVERTISING_ONLY, + &tsch_broadcast_address, old_ts, 0); + } else { + /* Remove slot */ + tsch_schedule_remove_link_by_timeslot(sf_eb, old_ts); + } } if(new_ts != 0xffff) { + uint8_t link_options = LINK_OPTION_RX; + if(new_ts == get_node_timeslot(&linkaddr_node_addr)) { + /* This is also our timeslot, add necessary flags */ + link_options |= LINK_OPTION_TX; + } /* Listen to the time source's EBs */ - tsch_schedule_add_link(sf_eb, - LINK_OPTION_RX, - LINK_TYPE_ADVERTISING_ONLY, NULL, - new_ts, 0); + tsch_schedule_add_link(sf_eb, link_options, LINK_TYPE_ADVERTISING_ONLY, + &tsch_broadcast_address, new_ts, 0); } } /*---------------------------------------------------------------------------*/ From bc54f8bac36bd8e97d36824146b11d3c72e1f8a1 Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Sat, 21 May 2016 11:55:07 +0200 Subject: [PATCH 4/4] Orchestra: add NULL checks into new_time_source (eb-per-time-source) --- apps/orchestra/orchestra-rule-eb-per-time-source.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/orchestra/orchestra-rule-eb-per-time-source.c b/apps/orchestra/orchestra-rule-eb-per-time-source.c index b18617f0a..ed037291b 100644 --- a/apps/orchestra/orchestra-rule-eb-per-time-source.c +++ b/apps/orchestra/orchestra-rule-eb-per-time-source.c @@ -74,8 +74,8 @@ select_packet(uint16_t *slotframe, uint16_t *timeslot) static void new_time_source(const struct tsch_neighbor *old, const struct tsch_neighbor *new) { - uint16_t old_ts = get_node_timeslot(&old->addr); - uint16_t new_ts = get_node_timeslot(&new->addr); + uint16_t old_ts = old != NULL ? get_node_timeslot(&old->addr) : 0xffff; + uint16_t new_ts = new != NULL ? get_node_timeslot(&new->addr) : 0xffff; if(new_ts == old_ts) { return;