Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release_internal' into release_e…
Browse files Browse the repository at this point in the history
…xternal

* origin/release_internal:
  Added support for handle RPL hop by Hop sender rank 0.
  Activated RPL force tunnel for wi-sun.
  RPL tunnel force functionality update
  RPL parent select timer random update from 1.0-1.2 to 1.0-1.5.
  MAC Ack wait fixed for OFDM (ARMmbed#2552)
  Fixed unused variable and function warnings.
  Wi-SUN bootstrap support RPL poison from Connected state to Discovery
  RPL Poison update
  • Loading branch information
Arto Kinnunen committed Jan 21, 2021
2 parents 3183d87 + 3275f83 commit f8ae0e9
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 47 deletions.
6 changes: 3 additions & 3 deletions source/6LoWPAN/Thread/thread_test_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int_fast8_t arm_nwk_6lowpan_thread_test_add_neighbour(
const uint8_t *id_mask,
const uint8_t *route_data)
{
#ifdef HAVE_THREAD
#ifdef HAVE_THREAD_ROUTER
protocol_interface_info_entry_t *cur;
cur = protocol_stack_interface_info_get_by_id(interface_id);
if (!cur) {
Expand All @@ -94,7 +94,7 @@ int_fast8_t arm_nwk_6lowpan_thread_test_remove_neighbour(
int8_t interface_id,
uint16_t neighbour_short_addr)
{
#ifdef HAVE_THREAD
#ifdef HAVE_THREAD_ROUTER
protocol_interface_info_entry_t *cur;
cur = protocol_stack_interface_info_get_by_id(interface_id);
if (!cur) {
Expand Down Expand Up @@ -1220,7 +1220,7 @@ int8_t thread_test_initial_slaac_iid_set(int8_t interface_id, uint8_t *iid)

int8_t thread_test_router_id_request_send(int8_t interface_id, uint8_t status)
{
#ifdef HAVE_THREAD
#ifdef HAVE_THREAD_ROUTER
protocol_interface_info_entry_t *cur;

cur = protocol_stack_interface_info_get_by_id(interface_id);
Expand Down
65 changes: 61 additions & 4 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,32 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
return ret_val;
}

void ws_bootstrap_disconnect(protocol_interface_info_entry_t *cur, ws_bootsrap_event_type_e event_type)
{
if (cur->nwk_bootstrap_state == ER_RPL_NETWORK_LEAVING) {
//Already moved to leaving state.
return;
}

if (cur->rpl_domain && cur->nwk_bootstrap_state == ER_BOOTSRAP_DONE) {
//Stop Asych Timer
ws_bootstrap_asynch_trickle_stop(cur);
tr_debug("Start Network soft leaving");
if (event_type == WS_FAST_DISCONNECT) {
rpl_control_instant_poison(cur, cur->rpl_domain);
cur->bootsrap_state_machine_cnt = 80; //Give 8 seconds time to send Poison
} else {
rpl_control_poison(cur->rpl_domain, 1);
cur->bootsrap_state_machine_cnt = 6000; //Give 10 minutes time for poison if RPL is not report
}

} else {
ws_bootstrap_event_discovery_start(cur);
}
cur->nwk_bootstrap_state = ER_RPL_NETWORK_LEAVING;
}


static void ws_bootstrap_asynch_trickle_stop(protocol_interface_info_entry_t *cur)
{
cur->ws_info->trickle_pas_running = false;
Expand Down Expand Up @@ -1638,7 +1664,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
tr_debug("NEW Brodcast Schedule %u...BR rebooted", ws_bs_ie.broadcast_schedule_identifier);
cur->ws_info->ws_bsi_block.block_time = cur->ws_info->cfg->timing.pan_timeout;
cur->ws_info->ws_bsi_block.old_bsi = cur->ws_info->hopping_schdule.fhss_bsi;
ws_bootstrap_event_discovery_start(cur);
ws_bootstrap_event_disconnect(cur, WS_NORMAL_DISCONNECT);
}
return;
}
Expand Down Expand Up @@ -2364,7 +2390,11 @@ int ws_bootstrap_set_rf_config(protocol_interface_info_entry_t *cur, phy_rf_chan
set_request.value_size = sizeof(phy_rf_channel_configuration_s);
cur->mac_api->mlme_req(cur->mac_api, MLME_SET, &set_request);
// Set Ack wait duration
uint16_t ack_wait_symbols = WS_ACK_WAIT_SYMBOLS + (WS_TACK_MAX_MS * (rf_configs.datarate / 1000));
uint8_t bits_per_symbol = 1;
if (rf_configs.modulation == M_OFDM) {
bits_per_symbol = 4;
}
uint16_t ack_wait_symbols = WS_ACK_WAIT_SYMBOLS + (WS_TACK_MAX_MS * (rf_configs.datarate / 1000) / bits_per_symbol);
set_request.attr = macAckWaitDuration;
set_request.value_pointer = &ack_wait_symbols;
set_request.value_size = sizeof(ack_wait_symbols);
Expand Down Expand Up @@ -2553,6 +2583,15 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
if (!cur->rpl_domain || cur->interface_mode != INTERFACE_UP) {
return;
}

if (event == RPL_EVENT_POISON_FINISHED) {
//If we are waiting poison we will trig Discovery after couple seconds
if (cur->nwk_bootstrap_state == ER_RPL_NETWORK_LEAVING) {
cur->bootsrap_state_machine_cnt = 80; //Give 8 seconds time to send Poison
}
return;
}

// if waiting for RPL and
if (event == RPL_EVENT_DAO_DONE) {
// Trigger statemachine check
Expand Down Expand Up @@ -2832,6 +2871,7 @@ static void ws_bootstrap_rpl_activate(protocol_interface_info_entry_t *cur)
rpl_control_set_dao_retry_count(WS_MAX_DAO_RETRIES);
rpl_control_set_initial_dao_ack_wait(WS_MAX_DAO_INITIAL_TIMEOUT);
rpl_control_set_mrhof_parent_set_size(WS_MAX_PARENT_SET_COUNT);
rpl_control_set_force_tunnel(true);
if (cur->bootsrap_mode != ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
rpl_control_set_memory_limits(WS_NODE_RPL_SOFT_MEM_LIMIT, WS_NODE_RPL_HARD_MEM_LIMIT);
}
Expand Down Expand Up @@ -3132,6 +3172,12 @@ void ws_bootstrap_event_routing_ready(protocol_interface_info_entry_t *cur)
{
ws_bootsrap_event_trig(WS_ROUTING_READY, cur->bootStrapId, ARM_LIB_LOW_PRIORITY_EVENT, NULL);
}

void ws_bootstrap_event_disconnect(protocol_interface_info_entry_t *cur, ws_bootsrap_event_type_e event_type)
{
ws_bootsrap_event_trig(event_type, cur->bootStrapId, ARM_LIB_LOW_PRIORITY_EVENT, NULL);
}

void ws_bootstrap_configuration_trickle_reset(protocol_interface_info_entry_t *cur)
{
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config, &cur->ws_info->trickle_params_pan_discovery);
Expand Down Expand Up @@ -3315,6 +3361,7 @@ static int8_t ws_bootstrap_backbone_ip_addr_get(protocol_interface_info_entry_t
return -1;
}


static void ws_bootstrap_event_handler(arm_event_s *event)
{
ws_bootsrap_event_type_e event_type;
Expand All @@ -3331,7 +3378,6 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
break;
case WS_DISCOVERY_START:
tr_info("Discovery start");

protocol_mac_reset(cur);
ws_llc_reset(cur);
lowpan_adaptation_interface_reset(cur->id);
Expand Down Expand Up @@ -3467,6 +3513,12 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
ws_bootstrap_advertise_start(cur);
ws_bootstrap_state_change(cur, ER_BOOTSRAP_DONE);
break;
case WS_FAST_DISCONNECT:
ws_bootstrap_disconnect(cur, WS_FAST_DISCONNECT);
break;
case WS_NORMAL_DISCONNECT:
ws_bootstrap_disconnect(cur, WS_NORMAL_DISCONNECT);
break;

default:
tr_err("Invalid event received");
Expand Down Expand Up @@ -3658,6 +3710,10 @@ void ws_bootstrap_state_machine(protocol_interface_info_entry_t *cur)
// Bootstrap_done event to application
nwk_bootsrap_state_update(ARM_NWK_BOOTSTRAP_READY, cur);
break;
case ER_RPL_NETWORK_LEAVING:
tr_debug("WS SM:RPL Leaving ready trigger discovery");
ws_bootstrap_event_discovery_start(cur);
break;
default:
tr_warn("WS SM:Invalid state %d", cur->nwk_bootstrap_state);
}
Expand Down Expand Up @@ -3743,9 +3799,10 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s
}
} else {
// Border router has timed out
//Clear Timeout timer
cur->ws_info->pan_timeout_timer = 0;
tr_warn("Border router has timed out");
ws_bootstrap_event_discovery_start(cur);
ws_bootstrap_event_disconnect(cur, WS_FAST_DISCONNECT);
}
}
if (cur->ws_info->aro_registration_timer) {
Expand Down
6 changes: 5 additions & 1 deletion source/6LoWPAN/ws/ws_bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ typedef enum {
WS_DISCOVERY_START, /**< discovery start*/
WS_CONFIGURATION_START, /**< configuration learn start*/
WS_OPERATION_START, /**< active operation start*/
WS_ROUTING_READY /**< RPL routing connected to BR*/
WS_ROUTING_READY, /**< RPL routing connected to BR*/
WS_FAST_DISCONNECT, /**< Do fast timeout after Border router timeout*/
WS_NORMAL_DISCONNECT /**< Border have been rebooted so Slow poison Process*/
} ws_bootsrap_event_type_e;

#ifdef HAVE_WS
Expand Down Expand Up @@ -60,6 +62,8 @@ void ws_bootstrap_event_operation_start(protocol_interface_info_entry_t *cur);

void ws_bootstrap_event_routing_ready(protocol_interface_info_entry_t *cur);

void ws_bootstrap_event_disconnect(protocol_interface_info_entry_t *cur, ws_bootsrap_event_type_e event_type);

void ws_bootstrap_configuration_trickle_reset(protocol_interface_info_entry_t *cur);

void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds);
Expand Down
2 changes: 1 addition & 1 deletion source/MAC/IEEE802_15_4/mac_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ typedef struct protocol_interface_rf_mac_setup {
int8_t bc_timer_id;
uint32_t mlme_tick_count;
uint32_t symbol_rate;
uint32_t symbol_time_us;
uint32_t symbol_time_ns;
uint32_t datarate;
uint8_t max_ED;
uint16_t mlme_ED_counter;
Expand Down
10 changes: 5 additions & 5 deletions source/MAC/IEEE802_15_4/mac_mlme.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,11 +652,11 @@ void mac_extended_mac_set(protocol_interface_rf_mac_setup_s *rf_mac_setup, const

static uint32_t mac_calc_ack_wait_duration(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint16_t symbols)
{
uint32_t AckWaitDuration = 0;
uint32_t AckWaitDuration_us = 0;
if (rf_mac_setup->rf_csma_extension_supported) {
AckWaitDuration = symbols * rf_mac_setup->symbol_time_us;
AckWaitDuration_us = (symbols * rf_mac_setup->symbol_time_ns) / 1000;
}
return AckWaitDuration;
return AckWaitDuration_us;
}

static int8_t mac_mlme_set_ack_wait_duration(protocol_interface_rf_mac_setup_s *rf_mac_setup, const mlme_set_t *set_req)
Expand Down Expand Up @@ -1107,8 +1107,8 @@ static int mac_mlme_set_symbol_rate(protocol_interface_rf_mac_setup_s *rf_mac_se
{
if (rf_mac_setup->rf_csma_extension_supported) {
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_GET_SYMBOLS_PER_SECOND, (uint8_t *) &rf_mac_setup->symbol_rate);
rf_mac_setup->symbol_time_us = 1000000 / rf_mac_setup->symbol_rate;
tr_debug("SW-MAC driver support rf extension %"PRIu32" symbol/seconds %"PRIu32" us symbol time length", rf_mac_setup->symbol_rate, rf_mac_setup->symbol_time_us);
rf_mac_setup->symbol_time_ns = 1000000000 / rf_mac_setup->symbol_rate;
tr_debug("SW-MAC driver support rf extension %"PRIu32" symbol/seconds %"PRIu32" ns symbol time length", rf_mac_setup->symbol_rate, rf_mac_setup->symbol_time_ns);
return 0;
}
return -1;
Expand Down
2 changes: 1 addition & 1 deletion source/MAC/IEEE802_15_4/mac_pd_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ uint32_t mac_csma_backoff_get(protocol_interface_rf_mac_setup_s *rf_mac_setup)
uint32_t backoff_in_us;
//Multiple aUnitBackoffPeriod symbol time
if (rf_mac_setup->rf_csma_extension_supported) {
backoff_in_us = backoff * rf_mac_setup->aUnitBackoffPeriod * rf_mac_setup->symbol_time_us;
backoff_in_us = backoff * rf_mac_setup->aUnitBackoffPeriod * (rf_mac_setup->symbol_time_ns / 1000);
} else {
backoff_in_us = backoff * rf_mac_setup->backoff_period_in_10us * 10;
}
Expand Down
1 change: 1 addition & 0 deletions source/NWK_INTERFACE/Include/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ typedef enum icmp_state {
ER_BOOTSTRAP_NEW_FRAGMENT_START,
ER_WAIT_RESTART,
ER_RPL_LOCAL_REPAIR,
ER_RPL_NETWORK_LEAVING,
} icmp_state_t;

typedef enum {
Expand Down
7 changes: 7 additions & 0 deletions source/RPL/rpl_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ void rpl_control_set_mrhof_parent_set_size(uint16_t parent_set_size)
rpl_policy_set_mrhof_parent_set_size(parent_set_size);
}

/* True Force RPL to use IPv6 tunneling when it send and forward data to Border router direction, This feature is disabled by default */
void rpl_control_set_force_tunnel(bool requested)
{
rpl_policy_force_tunnel_set(requested);
}

/* Send address registration to either specified address, or to non-registered address */
void rpl_control_register_address(protocol_interface_info_entry_t *interface, const uint8_t addr[16])
{
Expand Down Expand Up @@ -399,6 +405,7 @@ static void rpl_control_etx_change_callback(int8_t nwk_id, uint16_t previous_et
if (!cur || !cur->rpl_domain) {
return;
}
(void) attribute_index;
// ETX is "better" if now lower, or previous was "unknown" and new isn't infinite
bool better = current_etx < previous_etx || (previous_etx == 0 && current_etx != 0xffff);

Expand Down
4 changes: 4 additions & 0 deletions source/RPL/rpl_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef enum rpl_event {
RPL_EVENT_LOCAL_REPAIR_START, /* RPL start scanning new parent by multicast DIS user can disable beacon request responser here*/
RPL_EVENT_LOCAL_REPAIR_NO_MORE_DIS, /* RPL not sending DIS anymore user can report bootstrap error */
RPL_EVENT_DAO_PARENT_ADD, /* RPL indicate that DAO downward Parent has been added */
RPL_EVENT_POISON_FINISHED, /* RPL have finished Dodag Poison proces */
} rpl_event_t;

typedef void rpl_domain_callback_t(rpl_event_t event, void *handle);
Expand Down Expand Up @@ -176,6 +177,7 @@ bool rpl_control_find_worst_neighbor(struct protocol_interface_info_entry *inter

/* Parent link confirmation API extension */
void rpl_control_request_parent_link_confirmation(bool requested);
void rpl_control_set_force_tunnel(bool requested);
void rpl_control_set_dio_multicast_min_config_advertisment_count(uint8_t min_count);
void rpl_control_set_address_registration_timeout(uint16_t timeout_in_minutes);
void rpl_control_set_dao_retry_count(uint8_t count);
Expand All @@ -200,6 +202,7 @@ const rpl_dodag_conf_t *rpl_control_get_dodag_config(const struct rpl_instance *
const uint8_t *rpl_control_preferred_parent_addr(const struct rpl_instance *instance, bool global);
uint16_t rpl_control_current_rank(const struct rpl_instance *instance);
uint8_t rpl_policy_mrhof_parent_set_size_get(const rpl_domain_t *domain);
void rpl_control_instant_poison(struct protocol_interface_info_entry *cur, rpl_domain_t *domain);

#else /* HAVE_RPL */

Expand All @@ -211,6 +214,7 @@ uint8_t rpl_policy_mrhof_parent_set_size_get(const rpl_domain_t *domain);
#define rpl_control_address_register_done(interface, ll_addr, status) (false)
#define rpl_policy_mrhof_parent_set_size_get(domain) (0)
#define rpl_control_set_mrhof_parent_set_size(parent_set_size)
#define rpl_control_instant_poison(cur, domain) ((void) 0)
#endif /* HAVE_RPL */

#endif /* RPL_CONTROL_H_ */
56 changes: 38 additions & 18 deletions source/RPL/rpl_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,24 @@ static buffer_t *rpl_data_exthdr_provider_hbh_2(buffer_t *buf, rpl_instance_t *i

bool destination_in_instance = false;
uint16_t ext_size = 0;
if (addr_ipv6_equal(route_info->next_hop_addr, buf->dst_sa.address) ||
addr_ipv6_equal(buf->dst_sa.address, dodag->id)) {

// Limit creation of multi-hop RPL packets
// Previous code created multi-hop RPL packets as much as possible,
// sending direct to border router in particular.
// This has caused WiSUN interop problems, so limit this.
// a) When creating a basic packet, have a policy option that prevents
// direct RPL header insertion, forcing tunnelling. This means
// we never put a RPL header on the innermost packet. Option is
// off by default, except for WiSUN, as it increases packet size
// when talking to the border router (eg DAOs).
// b) When putting a packet into a tunnel, set the tunnel exit to the
// next hop always, rather than having a special case for exiting
// at the border router. This is probably a net benefit to packet
// size because of the LL addresses used on the outer header, so
// this is an unconditional change. Exception remains for local
// DODAGs, where the destination address must be the DODAGID.
if (addr_ipv6_equal(route_info->next_hop_addr, buf->dst_sa.address) || (!rpl_policy_force_tunnel() &&
addr_ipv6_equal(buf->dst_sa.address, dodag->id))) {
destination_in_instance = true;

if (buf->rpl_option) {
Expand Down Expand Up @@ -409,10 +425,12 @@ static buffer_t *rpl_data_exthdr_provider_hbh_2(buffer_t *buf, rpl_instance_t *i
rpl_data_locate_info(buf, &opt, NULL);
if (!opt) {
*result = IPV6_EXTHDR_MODIFY_TUNNEL;
// Tunnel to next hop in general case, but if going to DODAGID,
// it can tunnel all the way (and it HAS to if it is a local
// DODAG).
if (!addr_ipv6_equal(buf->dst_sa.address, dodag->id)) {
// Tunnel to next hop always, even if we could tunnel all
// the way to DODAG root (this may be better for
// packet compression, and it was found to be necessary for
// Wi-SUN interoperability). Except for local DODAGs the
// destination must be the DODAGID, so retain that in dst_sa.
if (!rpl_instance_id_is_local(instance->id)) {
memcpy(buf->dst_sa.address, route_info->next_hop_addr, 16);
}
buf->src_sa.addr_type = ADDR_NONE; // force auto-selection
Expand All @@ -427,18 +445,20 @@ static buffer_t *rpl_data_exthdr_provider_hbh_2(buffer_t *buf, rpl_instance_t *i
* strictly less for Down packets and strictly greater for Up.
*/
sender_rank = common_read_16_bit(opt + 4);
rpl_cmp_t cmp = rpl_rank_compare_dagrank_rank(dodag, sender_rank, instance->current_rank);
rpl_cmp_t expected_cmp = (opt[2] & RPL_OPT_DOWN) ? RPL_CMP_LESS : RPL_CMP_GREATER;
if (cmp != expected_cmp) {
/* Set the Rank-Error bit; if already set, drop */
if (opt[2] & RPL_OPT_RANK_ERROR) {
protocol_stats_update(STATS_RPL_ROUTELOOP, 1);
tr_info("Forwarding inconsistency R");
rpl_instance_inconsistency(instance);
*result = -1;
return buf;
} else {
opt[2] |= RPL_OPT_RANK_ERROR;
if (sender_rank != 0) {
rpl_cmp_t cmp = rpl_rank_compare_dagrank_rank(dodag, sender_rank, instance->current_rank);
rpl_cmp_t expected_cmp = (opt[2] & RPL_OPT_DOWN) ? RPL_CMP_LESS : RPL_CMP_GREATER;
if (cmp != expected_cmp) {
/* Set the Rank-Error bit; if already set, drop */
if (opt[2] & RPL_OPT_RANK_ERROR) {
protocol_stats_update(STATS_RPL_ROUTELOOP, 1);
tr_info("Forwarding inconsistency R");
rpl_instance_inconsistency(instance);
*result = -1;
return buf;
} else {
opt[2] |= RPL_OPT_RANK_ERROR;
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions source/RPL/rpl_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ static uint8_t rpl_policy_mrhof_parent_set_size_conf = 3; // default parent set
static uint16_t rpl_policy_minimum_dao_target_refresh_conf = 0; // by default follow the configuration
static uint16_t rpl_policy_address_registration_timeout_value = 0; // Address registration timeouts in minutes 0 use address lifetime

static bool rpl_policy_force_tunnel_to_BR = false;

bool rpl_policy_force_tunnel(void)
{
return rpl_policy_force_tunnel_to_BR;
}

void rpl_policy_force_tunnel_set(bool enable)
{
rpl_policy_force_tunnel_to_BR = enable;
}
/* TODO - application API to control when to join new instances / DODAGs
*
* Eg, allow application to ignore local DODAGs, or specify known instance IDs,
Expand Down
Loading

0 comments on commit f8ae0e9

Please sign in to comment.