Skip to content

Commit

Permalink
FHSS: Calculate hop count using RPL rank
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed May 2, 2018
1 parent 8f194f8 commit 4fdbc09
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ static bool ws_bootstrap_state_wait_rpl(struct protocol_interface_info_entry *cu
static int8_t ws_bootsrap_event_trig(ws_bootsrap_event_type_e event_type, int8_t interface_id, arm_library_event_priority_e priority, void *event_data);

static bool ws_bootstrap_neighbor_info_request(struct protocol_interface_info_entry *interface, const uint8_t *mac_64, llc_neighbour_req_t * neighbor_buffer, bool request_new);
static uint16_t ws_bootstrap_route_cost_calculate(protocol_interface_info_entry_t *cur);
static uint16_t ws_bootstrap_get_min_rank_inc(protocol_interface_info_entry_t *cur);

mac_neighbor_table_entry_t * ws_bootstrap_mac_neighbor_add(struct protocol_interface_info_entry *interface, const uint8_t *src64)
{
Expand Down Expand Up @@ -208,6 +210,9 @@ static int8_t ws_enable_fhss(protocol_interface_info_entry_t *cur)
if (ns_fhss_set_neighbor_info_fp(fhss_api, &ws_get_neighbor_info)) {
return -1;
}
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
ns_fhss_ws_set_hop_count(fhss_api, 0);
}
cur->ws_info->fhss_api = fhss_api;
return 0;
}
Expand Down Expand Up @@ -979,6 +984,15 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
if (event == RPL_EVENT_DAO_DONE) {
// Trigger statemachine check
cur->bootsrap_state_machine_cnt = 1;
uint16_t own_rank = ws_bootstrap_route_cost_calculate(cur);
uint16_t rank_inc = ws_bootstrap_get_min_rank_inc(cur);
if (own_rank == 0xffff || rank_inc == 0xffff) {
return;
}
// Calculate own hop count. This method gets inaccurate when hop count increases.
uint8_t own_hop = (own_rank - rank_inc) / rank_inc;
ns_fhss_ws_set_hop_count(cur->ws_info->fhss_api, own_hop);

} else if(event == RPL_EVENT_LOCAL_REPAIR_NO_MORE_DIS) {
/*
* RPL goes to passive mode, but does not require any extra changed
Expand Down Expand Up @@ -1158,20 +1172,40 @@ static void ws_bootstrap_pan_config_solicit(protocol_interface_info_entry_t *cur

ws_llc_asynch_request(cur, &async_req);
}
static uint16_t ws_bootstrap_route_cost_calculate(protocol_interface_info_entry_t *cur)
{
// Find selected parent from RPL

static struct rpl_instance *ws_get_rpl_instance(protocol_interface_info_entry_t *cur)
{
if (!cur || !cur->rpl_domain) {
return NULL;
}
struct rpl_instance *best_instance = NULL;

ns_list_foreach(struct rpl_instance, instance, &cur->rpl_domain->instances) {
best_instance = instance;
// Select best grounded and lowest rank? But there should be only one really
}
if (!best_instance) {
return best_instance;
}

static uint16_t ws_bootstrap_route_cost_calculate(protocol_interface_info_entry_t *cur)
{
struct rpl_instance *rpl_instance = ws_get_rpl_instance(cur);
if (!rpl_instance) {
return 0xffff;
}
return rpl_control_current_rank(rpl_instance);
}

static uint16_t ws_bootstrap_get_min_rank_inc(protocol_interface_info_entry_t *cur)
{
struct rpl_instance *rpl_instance = ws_get_rpl_instance(cur);
if (!rpl_instance) {
return 0xffff;
}
struct rpl_dodag_info_t dodag_info;
if (!rpl_control_read_dodag_info(rpl_instance, &dodag_info)) {
return 0xffff;
}
return rpl_control_current_rank(best_instance);
return dodag_info.dag_min_hop_rank_inc;
}

static void ws_bootstrap_pan_advert(protocol_interface_info_entry_t *cur)
Expand Down

0 comments on commit 4fdbc09

Please sign in to comment.