Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 4fdbc09

Browse files
author
Jarkko Paso
committed
FHSS: Calculate hop count using RPL rank
1 parent 8f194f8 commit 4fdbc09

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ static bool ws_bootstrap_state_wait_rpl(struct protocol_interface_info_entry *cu
7878
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);
7979

8080
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);
81+
static uint16_t ws_bootstrap_route_cost_calculate(protocol_interface_info_entry_t *cur);
82+
static uint16_t ws_bootstrap_get_min_rank_inc(protocol_interface_info_entry_t *cur);
8183

8284
mac_neighbor_table_entry_t * ws_bootstrap_mac_neighbor_add(struct protocol_interface_info_entry *interface, const uint8_t *src64)
8385
{
@@ -208,6 +210,9 @@ static int8_t ws_enable_fhss(protocol_interface_info_entry_t *cur)
208210
if (ns_fhss_set_neighbor_info_fp(fhss_api, &ws_get_neighbor_info)) {
209211
return -1;
210212
}
213+
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
214+
ns_fhss_ws_set_hop_count(fhss_api, 0);
215+
}
211216
cur->ws_info->fhss_api = fhss_api;
212217
return 0;
213218
}
@@ -979,6 +984,15 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
979984
if (event == RPL_EVENT_DAO_DONE) {
980985
// Trigger statemachine check
981986
cur->bootsrap_state_machine_cnt = 1;
987+
uint16_t own_rank = ws_bootstrap_route_cost_calculate(cur);
988+
uint16_t rank_inc = ws_bootstrap_get_min_rank_inc(cur);
989+
if (own_rank == 0xffff || rank_inc == 0xffff) {
990+
return;
991+
}
992+
// Calculate own hop count. This method gets inaccurate when hop count increases.
993+
uint8_t own_hop = (own_rank - rank_inc) / rank_inc;
994+
ns_fhss_ws_set_hop_count(cur->ws_info->fhss_api, own_hop);
995+
982996
} else if(event == RPL_EVENT_LOCAL_REPAIR_NO_MORE_DIS) {
983997
/*
984998
* RPL goes to passive mode, but does not require any extra changed
@@ -1158,20 +1172,40 @@ static void ws_bootstrap_pan_config_solicit(protocol_interface_info_entry_t *cur
11581172

11591173
ws_llc_asynch_request(cur, &async_req);
11601174
}
1161-
static uint16_t ws_bootstrap_route_cost_calculate(protocol_interface_info_entry_t *cur)
1162-
{
1163-
// Find selected parent from RPL
11641175

1176+
static struct rpl_instance *ws_get_rpl_instance(protocol_interface_info_entry_t *cur)
1177+
{
1178+
if (!cur || !cur->rpl_domain) {
1179+
return NULL;
1180+
}
11651181
struct rpl_instance *best_instance = NULL;
1166-
11671182
ns_list_foreach(struct rpl_instance, instance, &cur->rpl_domain->instances) {
11681183
best_instance = instance;
11691184
// Select best grounded and lowest rank? But there should be only one really
11701185
}
1171-
if (!best_instance) {
1186+
return best_instance;
1187+
}
1188+
1189+
static uint16_t ws_bootstrap_route_cost_calculate(protocol_interface_info_entry_t *cur)
1190+
{
1191+
struct rpl_instance *rpl_instance = ws_get_rpl_instance(cur);
1192+
if (!rpl_instance) {
1193+
return 0xffff;
1194+
}
1195+
return rpl_control_current_rank(rpl_instance);
1196+
}
1197+
1198+
static uint16_t ws_bootstrap_get_min_rank_inc(protocol_interface_info_entry_t *cur)
1199+
{
1200+
struct rpl_instance *rpl_instance = ws_get_rpl_instance(cur);
1201+
if (!rpl_instance) {
1202+
return 0xffff;
1203+
}
1204+
struct rpl_dodag_info_t dodag_info;
1205+
if (!rpl_control_read_dodag_info(rpl_instance, &dodag_info)) {
11721206
return 0xffff;
11731207
}
1174-
return rpl_control_current_rank(best_instance);
1208+
return dodag_info.dag_min_hop_rank_inc;
11751209
}
11761210

11771211
static void ws_bootstrap_pan_advert(protocol_interface_info_entry_t *cur)

0 commit comments

Comments
 (0)