From dae82f6b4f6e061034cc49c3debfea91a3962095 Mon Sep 17 00:00:00 2001 From: Mika Tervonen Date: Fri, 2 Nov 2018 15:14:10 +0200 Subject: [PATCH] implemented wisun routing cost calculation Changed min hop rank increase to 256 according to specification Save routing cost for all neighbours implemented the routing cost calculation function Added priority parent finder for mac neighbour table --- source/6LoWPAN/ws/ws_bbr_api.c | 2 +- source/6LoWPAN/ws/ws_bootstrap.c | 52 +++++++++++++++---- source/6LoWPAN/ws/ws_neighbor_class.h | 1 + .../mac_neighbor_table/mac_neighbor_table.c | 9 ++++ .../mac_neighbor_table/mac_neighbor_table.h | 2 + 5 files changed, 55 insertions(+), 11 deletions(-) diff --git a/source/6LoWPAN/ws/ws_bbr_api.c b/source/6LoWPAN/ws/ws_bbr_api.c index 2c21800247d6..42c8a3ca2778 100644 --- a/source/6LoWPAN/ws/ws_bbr_api.c +++ b/source/6LoWPAN/ws/ws_bbr_api.c @@ -67,7 +67,7 @@ static void ws_bbr_rpl_root_start(uint8_t *dodag_id) .authentication = 0, .path_control_size = 5, .dag_max_rank_increase = 2048, - .min_hop_rank_increase = 128, + .min_hop_rank_increase = 256, // DIO configuration .dio_interval_min = WS_RPL_DIO_IMIN, .dio_interval_doublings = WS_RPL_DIO_DOUBLING, diff --git a/source/6LoWPAN/ws/ws_bootstrap.c b/source/6LoWPAN/ws/ws_bootstrap.c index e0f1987e63f1..20a3a263c80c 100644 --- a/source/6LoWPAN/ws/ws_bootstrap.c +++ b/source/6LoWPAN/ws/ws_bootstrap.c @@ -83,8 +83,9 @@ static bool ws_bootstrap_state_discovery(struct protocol_interface_info_entry *c 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); +static uint16_t ws_bootstrap_routing_cost_calculate(protocol_interface_info_entry_t *cur); +static uint16_t ws_bootstrap_rank_get(protocol_interface_info_entry_t *cur); +static uint16_t ws_bootstrap_min_rank_inc_get(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) { @@ -783,6 +784,12 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf * */ + // Save route cost for all neighbours + llc_neighbour_req_t neighbor_info; + if (ws_bootstrap_neighbor_info_request(cur, data->SrcAddr, &neighbor_info, false) ) { + neighbor_info.ws_neighbor->routing_cost = pan_information.routing_cost; + } + // Save the best network parent if(ws_bootstrap_state_discovery(cur)) { @@ -1499,8 +1506,8 @@ static void ws_bootstrap_ip_stack_activate(protocol_interface_info_entry_t *cur) static void ws_set_fhss_hop(protocol_interface_info_entry_t *cur) { - uint16_t own_rank = ws_bootstrap_route_cost_calculate(cur); - uint16_t rank_inc = ws_bootstrap_get_min_rank_inc(cur); + uint16_t own_rank = ws_bootstrap_rank_get(cur); + uint16_t rank_inc = ws_bootstrap_min_rank_inc_get(cur); if (own_rank == 0xffff || rank_inc == 0xffff) { return; } @@ -1802,16 +1809,41 @@ static struct rpl_instance *ws_get_rpl_instance(protocol_interface_info_entry_t return best_instance; } -static uint16_t ws_bootstrap_route_cost_calculate(protocol_interface_info_entry_t *cur) +static uint16_t ws_bootstrap_routing_cost_calculate(protocol_interface_info_entry_t *cur) { - struct rpl_instance *rpl_instance = ws_get_rpl_instance(cur); - if (!rpl_instance) { + mac_neighbor_table_entry_t *mac_neighbor = mac_neighbor_entry_get_priority(mac_neighbor_info(cur)); + if (!mac_neighbor) { return 0xffff; } - return rpl_control_current_rank(rpl_instance); + ws_neighbor_class_entry_t *ws_neighbor = ws_neighbor_class_entry_get(&cur->ws_info->neighbor_storage, mac_neighbor->index); + if (!ws_neighbor) { + return 0xffff; + } + + uint16_t etx = etx_local_etx_read(cur->id,mac_neighbor->index); + if (etx == 0) { + etx = 0xffff; + } + if (etx > 0x800) { + // Wi-SUN section 6.2.3.1.6.1 says ETX can only be maximum of 1024 (8*128) in RPL units, ie 8.0. + etx = 0x800; + } + etx = etx >> 1; + + return ws_neighbor->routing_cost + etx; } -static uint16_t ws_bootstrap_get_min_rank_inc(protocol_interface_info_entry_t *cur) +static uint16_t ws_bootstrap_rank_get(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_min_rank_inc_get(protocol_interface_info_entry_t *cur) { struct rpl_instance *rpl_instance = ws_get_rpl_instance(cur); if (!rpl_instance) { @@ -1847,7 +1879,7 @@ static void ws_bootstrap_pan_advert(protocol_interface_info_entry_t *cur) } else { // Nodes need to calculate routing cost // PAN size is saved from latest PAN advertisement - cur->ws_info->pan_information.routing_cost = ws_bootstrap_route_cost_calculate(cur); + cur->ws_info->pan_information.routing_cost = ws_bootstrap_routing_cost_calculate(cur); } diff --git a/source/6LoWPAN/ws/ws_neighbor_class.h b/source/6LoWPAN/ws/ws_neighbor_class.h index 0f5bbd9110cb..5be662f3a45d 100644 --- a/source/6LoWPAN/ws/ws_neighbor_class.h +++ b/source/6LoWPAN/ws/ws_neighbor_class.h @@ -27,6 +27,7 @@ typedef struct ws_neighbor_class_entry { fhss_ws_neighbor_timing_info_t fhss_data; uint16_t rsl_in; /*!< RSL EWMA heard from neighbour*/ uint16_t rsl_out; /*!< RSL EWMA heard by neighbour*/ + uint16_t routing_cost; /*!< ETX to border Router. */ bool candidate_parent:1; bool broadcast_timing_info_stored:1; bool broadcast_shedule_info_stored:1; diff --git a/source/Service_Libs/mac_neighbor_table/mac_neighbor_table.c b/source/Service_Libs/mac_neighbor_table/mac_neighbor_table.c index 9e1d69000ec2..60352bec4fd0 100644 --- a/source/Service_Libs/mac_neighbor_table/mac_neighbor_table.c +++ b/source/Service_Libs/mac_neighbor_table/mac_neighbor_table.c @@ -274,4 +274,13 @@ mac_neighbor_table_entry_t *mac_neighbor_entry_get_by_mac64(mac_neighbor_table_t return mac_neighbor_table_entry_allocate(table_class, mac64); } +mac_neighbor_table_entry_t* mac_neighbor_entry_get_priority(mac_neighbor_table_t *table_class) +{ + ns_list_foreach(mac_neighbor_table_entry_t, entry, &table_class->neighbour_list) { + if (entry->link_role == PRIORITY_PARENT_NEIGHBOUR) { + return entry; + } + } + return NULL; +} diff --git a/source/Service_Libs/mac_neighbor_table/mac_neighbor_table.h b/source/Service_Libs/mac_neighbor_table/mac_neighbor_table.h index edd10a974d96..c2bd7ef4f7a9 100644 --- a/source/Service_Libs/mac_neighbor_table/mac_neighbor_table.h +++ b/source/Service_Libs/mac_neighbor_table/mac_neighbor_table.h @@ -202,4 +202,6 @@ mac_neighbor_table_entry_t *mac_neighbor_entry_get_by_ll64(mac_neighbor_table_t mac_neighbor_table_entry_t *mac_neighbor_entry_get_by_mac64(mac_neighbor_table_t *table_class, const uint8_t *mac64, bool allocateNew, bool *new_entry_allocated); +mac_neighbor_table_entry_t* mac_neighbor_entry_get_priority(mac_neighbor_table_t *table_class); + #endif /* MAC_NEIGHBOR_TABLE_H_ */