Skip to content

Commit a152f45

Browse files
author
Jarkko Paso
committed
Merge branch 'koli' into IOTTHD-2442
* koli: Select correct parent based on network size and route cost Fixed Code style warning. Fixed WS_NESTED_IE information discover return length check.
2 parents ea583c6 + c3aa7d1 commit a152f45

File tree

9 files changed

+76
-30
lines changed

9 files changed

+76
-30
lines changed

source/6LoWPAN/ws/ws_bbr_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static void ws_bbr_rpl_root_activate(uint8_t *dodag_prefix, uint8_t *dodag_id)
4848
// Lifetime values
4949
new_conf.default_lifetime = 120;
5050
new_conf.lifetime_unit = 60;
51-
new_conf.objective_code_point = 1;
51+
new_conf.objective_code_point = 1; // MRHOF algorithm used
5252
new_conf.authentication = 0;
5353
new_conf.path_control_size = 0;
5454

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static void ws_bootstrap_pan_advertisement_analyse_active(struct protocol_interf
319319
*
320320
*/
321321

322-
if (pan_information->routing_cost <= cur->ws_info->pan_configuration.routing_cost) {
322+
if (pan_information->routing_cost <= cur->ws_info->pan_information.routing_cost) {
323323
trickle_consistent_heard(&cur->ws_info->trickle_pan_advertisement);
324324
} else {
325325
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement,&trickle_params_pan_advertisement);
@@ -372,16 +372,25 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
372372
if (memcmp(cur->ws_info->parent_info.addr, ADDR_UNSPECIFIED,8) != 0) {
373373
//Decide which is better parent for authentication
374374
if(cur->ws_info->parent_info.link_quality > data->mpduLinkQuality) {
375+
tr_info("EAPOL target dropped Lower link quality");
375376
return;
376377
}
378+
379+
uint16_t pan_cost = (pan_information.routing_cost / PRC_WEIGHT_FACTOR) + (pan_information.pan_size / PS_WEIGHT_FACTOR);
380+
uint16_t current_pan_cost = (cur->ws_info->parent_info.pan_information.routing_cost / PRC_WEIGHT_FACTOR) + (cur->ws_info->parent_info.pan_information.pan_size / PS_WEIGHT_FACTOR);
381+
if (current_pan_cost < pan_cost) {
382+
tr_info("EAPOL target dropped Higher Pan cost");
383+
return;
384+
}
385+
377386
}
378387
// Parent valid store information
379388
cur->ws_info->parent_info.ws_utt = *ws_utt;
380389
// Saved from unicast IE
381390
cur->ws_info->parent_info.ws_us = *ws_us;
382391

383392
// Saved from Pan information
384-
cur->ws_info->parent_info.pan_configuration = pan_information;
393+
cur->ws_info->parent_info.pan_information = pan_information;
385394

386395
// Saved from message
387396
cur->ws_info->parent_info.timestamp = data->timestamp;
@@ -399,11 +408,13 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
399408
// Active state processing
400409
ws_bootstrap_pan_advertisement_analyse_active(cur, &pan_information);
401410

402-
// TODO Learn routing cost per neighbour
403-
404411
// Learn latest network information
405412
if (cur->bootsrap_mode != ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
406-
cur->ws_info->pan_configuration = pan_information;
413+
cur->ws_info->pan_information.pan_size = pan_information.pan_size;
414+
cur->ws_info->pan_information.routing_cost = pan_information.routing_cost;
415+
cur->ws_info->pan_information.rpl_routing_method = pan_information.rpl_routing_method;
416+
cur->ws_info->pan_information.use_parent_bs = pan_information.use_parent_bs;
417+
cur->ws_info->pan_information.version = pan_information.version;
407418
}
408419
}
409420

@@ -489,7 +500,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
489500
ws_neighbor_class_neighbor_broadcast_schedule_set(neighbor_info.ws_neighbor, &ws_bs_ie);
490501

491502
if (cur->ws_info->configuration_learned &&
492-
common_serial_number_greater_16(cur->ws_info->pan_configuration.pan_version, pan_version)) {
503+
common_serial_number_greater_16(cur->ws_info->pan_information.pan_version, pan_version)) {
493504
// received version is lower se we need to reset the trickle
494505
tr_info("older pan version heard");
495506
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config,&trickle_params_pan_configuration);
@@ -504,7 +515,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
504515
return;
505516
}
506517
if (cur->ws_info->configuration_learned &&
507-
cur->ws_info->pan_configuration.pan_version == pan_version) {
518+
cur->ws_info->pan_information.pan_version == pan_version) {
508519
// No new information
509520
return;
510521
}
@@ -515,7 +526,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
515526
tr_info("Updated PAN configuration heard");
516527

517528
cur->ws_info->pan_version_timeout_timer = PAN_VERSION_TIMEOUT;
518-
cur->ws_info->pan_configuration.pan_version = pan_version;
529+
cur->ws_info->pan_information.pan_version = pan_version;
519530
memcpy(cur->ws_info->gtkhash,gtkhash_ptr,32);
520531

521532
//Broadcast schedule
@@ -866,8 +877,8 @@ static void ws_bootstrap_network_information_learn(protocol_interface_info_entry
866877

867878
// Save network information
868879
cur->ws_info->network_pan_id = cur->ws_info->parent_info.pan_id;
869-
cur->ws_info->pan_configuration = cur->ws_info->parent_info.pan_configuration;
870-
cur->ws_info->pan_configuration.pan_version = 0; // This is learned from actual configuration
880+
cur->ws_info->pan_information = cur->ws_info->parent_info.pan_information;
881+
cur->ws_info->pan_information.pan_version = 0; // This is learned from actual configuration
871882

872883
// TODO create parent neighbour table entry for unicast schedule to enable authentication
873884

@@ -878,7 +889,7 @@ static void ws_bootstrap_network_configuration_learn(protocol_interface_info_ent
878889
tr_debug("Start using PAN configuration");
879890

880891
// Timing information can be modified here
881-
ws_llc_set_pan_information_pointer(cur, &cur->ws_info->pan_configuration);
892+
ws_llc_set_pan_information_pointer(cur, &cur->ws_info->pan_information);
882893
ws_llc_set_gtkhash(cur, cur->ws_info->gtkhash);
883894
// TODO update own fhss schedules we are starting to follow first parent
884895

@@ -952,7 +963,7 @@ static void ws_bootstrap_rpl_activate(protocol_interface_info_entry_t *cur)
952963

953964
cur->ws_info->rpl_state = 0xff; // Set invalid state and learn from event
954965
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_ROUTER) {
955-
// TODO RPL should have function to reset DIS trickle and it should be called here
966+
// TODO Multicast DIS should be sent only if no DIO heard for some time
956967
rpl_control_transmit_dis(cur->rpl_domain, cur, 0, 0, NULL, 0, ADDR_LINK_LOCAL_ALL_RPL_NODES);
957968
}
958969
}
@@ -961,7 +972,7 @@ static void ws_bootstrap_network_start(protocol_interface_info_entry_t *cur)
961972
{
962973
//Set Network names, Pan information configure, hopping schedule & GTKHash
963974
ws_llc_set_network_name(cur, (uint8_t*)cur->ws_info->network_name, strlen(cur->ws_info->network_name));
964-
ws_llc_set_pan_information_pointer(cur, &cur->ws_info->pan_configuration);
975+
ws_llc_set_pan_information_pointer(cur, &cur->ws_info->pan_information);
965976
}
966977

967978
static void ws_bootstrap_network_discovery_configure(protocol_interface_info_entry_t *cur)
@@ -1085,6 +1096,21 @@ static void ws_bootstrap_pan_config_solicit(protocol_interface_info_entry_t *cur
10851096

10861097
ws_llc_asynch_request(cur, &async_req);
10871098
}
1099+
static uint16_t ws_bootstrap_route_cost_calculate(protocol_interface_info_entry_t *cur)
1100+
{
1101+
// Find selected parent from RPL
1102+
1103+
struct rpl_instance *best_instance = NULL;
1104+
1105+
ns_list_foreach(struct rpl_instance, instance, &cur->rpl_domain->instances) {
1106+
best_instance = instance;
1107+
// Select best grounded and lowest rank? But there should be only one really
1108+
}
1109+
if (!best_instance) {
1110+
return 0xffff;
1111+
}
1112+
return rpl_control_current_rank(best_instance);
1113+
}
10881114

10891115
static void ws_bootstrap_pan_advert(protocol_interface_info_entry_t *cur)
10901116
{
@@ -1104,9 +1130,15 @@ static void ws_bootstrap_pan_advert(protocol_interface_info_entry_t *cur)
11041130

11051131
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
11061132
// Border routers write the NW size
1107-
cur->ws_info->pan_configuration.pan_size = ws_bbr_pan_size(cur);
1133+
cur->ws_info->pan_information.pan_size = ws_bbr_pan_size(cur);
1134+
cur->ws_info->pan_information.routing_cost = 0;
1135+
} else {
1136+
// Nodes need to calculate routing cost
1137+
// PAN size is saved from latest PAN advertisement
1138+
cur->ws_info->pan_information.routing_cost = ws_bootstrap_route_cost_calculate(cur);
11081139
}
11091140

1141+
11101142
ws_llc_asynch_request(cur, &async_req);
11111143
}
11121144

@@ -1166,12 +1198,12 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
11661198
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
11671199
tr_debug("Border router start network");
11681200
cur->ws_info->network_pan_id = randLIB_get_random_in_range(0,0xfffd);
1169-
cur->ws_info->pan_configuration.pan_size = 0;
1170-
cur->ws_info->pan_configuration.pan_version = randLIB_get_random_in_range(0,0xffff);
1171-
cur->ws_info->pan_configuration.routing_cost = 0;
1172-
cur->ws_info->pan_configuration.rpl_routing_method = true;
1173-
cur->ws_info->pan_configuration.use_parent_bs = true;
1174-
cur->ws_info->pan_configuration.version = WS_FAN_VERSION_1_0;
1201+
cur->ws_info->pan_information.pan_size = 0;
1202+
cur->ws_info->pan_information.pan_version = randLIB_get_random_in_range(0,0xffff);
1203+
cur->ws_info->pan_information.routing_cost = 0;
1204+
cur->ws_info->pan_information.rpl_routing_method = true;
1205+
cur->ws_info->pan_information.use_parent_bs = true;
1206+
cur->ws_info->pan_information.version = WS_FAN_VERSION_1_0;
11751207
cur->ws_info->hopping_schdule.channel_function = WS_FIXED_CHANNEL;
11761208
ws_llc_set_gtkhash(cur, cur->ws_info->gtkhash);
11771209
cur->ws_info->pan_version_timer = PAN_VERSION_LIFETIME;
@@ -1375,7 +1407,7 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s
13751407
// Border router has timed out
13761408
tr_debug("Border router version number update");
13771409
cur->ws_info->pan_version_timer = PAN_VERSION_LIFETIME;
1378-
cur->ws_info->pan_configuration.pan_version++;
1410+
cur->ws_info->pan_information.pan_version++;
13791411
// Inconsistent for border router to make information distribute faster
13801412
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config,&trickle_params_pan_configuration);
13811413
}

source/6LoWPAN/ws/ws_common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ int8_t ws_common_allocate_and_init(protocol_interface_info_entry_t *cur)
134134

135135
memset(cur->ws_info,0, sizeof(ws_info_t));
136136

137-
cur->ws_info->pan_configuration.use_parent_bs = true;
138-
cur->ws_info->pan_configuration.rpl_routing_method = true;
139-
cur->ws_info->pan_configuration.version = WS_FAN_VERSION_1_0;
137+
cur->ws_info->pan_information.use_parent_bs = true;
138+
cur->ws_info->pan_information.rpl_routing_method = true;
139+
cur->ws_info->pan_information.version = WS_FAN_VERSION_1_0;
140140

141141
cur->ws_info->hopping_schdule.regulatory_domain = REG_DOMAIN_KR;
142142
cur->ws_info->hopping_schdule.operating_mode = OPERATING_MODE_1a;

source/6LoWPAN/ws/ws_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ typedef struct parent_info_s {
3333
uint8_t addr[8]; /**< address */
3434
uint8_t link_quality; /**< LQI value measured during reception of the MPDU */
3535
int8_t signal_dbm; /**< This extension for normal IEEE 802.15.4 Data indication */
36-
ws_pan_information_t pan_configuration;
36+
ws_pan_information_t pan_information;
3737
ws_utt_ie_t ws_utt;
3838
ws_us_ie_t ws_us;
3939
uint32_t timestamp; /**< Timestamp when packet was received */
@@ -54,7 +54,7 @@ typedef struct ws_info_s {
5454
uint8_t gtkhash[32];
5555
bool configuration_learned:1;
5656

57-
struct ws_pan_information_s pan_configuration;
57+
struct ws_pan_information_s pan_information;
5858
ws_hopping_schedule_t hopping_schdule;
5959
struct ws_neighbor_class_s neighbor_storage;
6060
struct fhss_timer *fhss_timer_ptr; // Platform adaptation for FHSS timers.

source/6LoWPAN/ws/ws_config.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,12 @@
4949

5050
#define PAN_VERSION_TIMEOUT 1920
5151

52+
/* Routing Cost Weighting factor
53+
*/
54+
#define PRC_WEIGHT_FACTOR 256
55+
56+
/* Routing Cost Weighting factor
57+
*/
58+
#define PS_WEIGHT_FACTOR 64
59+
5260
#endif /* WS_CONFIG_H_ */

source/6LoWPAN/ws/ws_llc_data_service.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ static void ws_llc_mac_indication_cb(const mac_api_t* api, const mcps_data_ind_t
465465
ws_us_ie_t us_ie;
466466
bool us_ie_inline = false;
467467
ws_wp_nested.id = WS_WP_NESTED_IE;
468-
if (mac_ie_payload_discover(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &ws_wp_nested) < 2) {
468+
if (mac_ie_payload_discover(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &ws_wp_nested) > 2) {
469469
us_ie_inline = ws_wp_nested_us_read(ws_wp_nested.content_ptr, ws_wp_nested.length, &us_ie);
470470
}
471471

source/MAC/IEEE802_15_4/mac_pd_sap.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ static int8_t mac_data_interface_tx_done_cb(protocol_interface_rf_mac_setup_s *r
315315

316316
if (status == PHY_LINK_CCA_PREPARE) {
317317
if (rf_ptr->fhss_api) {
318-
uint8_t *synch_info = NULL;
319318
mac_pre_build_frame_t *active_buf = rf_ptr->active_pd_data_request;
320319
if (!active_buf) {
321320
return -1;
@@ -324,7 +323,7 @@ static int8_t mac_data_interface_tx_done_cb(protocol_interface_rf_mac_setup_s *r
324323
if (active_buf->fcf_dsn.frametype == FC_BEACON_FRAME) {
325324
// FHSS synchronization info is written in the end of transmitted (Beacon) buffer
326325
dev_driver_tx_buffer_s *tx_buf = &rf_ptr->dev_driver_tx_buffer;
327-
synch_info = tx_buf->buf + rf_ptr->dev_driver->phy_driver->phy_header_length + tx_buf->len - FHSS_SYNCH_INFO_LENGTH;
326+
uint8_t *synch_info = tx_buf->buf + rf_ptr->dev_driver->phy_driver->phy_header_length + tx_buf->len - FHSS_SYNCH_INFO_LENGTH;
328327
rf_ptr->fhss_api->write_synch_info(rf_ptr->fhss_api, synch_info, 0, FHSS_SYNCH_FRAME, 0);
329328
}
330329
// Change to destination channel and write synchronization info to Beacon frames here

source/RPL/rpl_control.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,12 @@ const uint8_t *rpl_control_preferred_parent_addr(const rpl_instance_t *instance,
16571657
}
16581658
}
16591659

1660+
uint16_t rpl_control_current_rank(const struct rpl_instance *instance)
1661+
{
1662+
return rpl_instance_current_rank(instance);
1663+
}
1664+
1665+
16601666
static void rpl_domain_print(const rpl_domain_t *domain, route_print_fn_t *print_fn)
16611667
{
16621668
print_fn("RPL Domain %p", (void *) domain);

source/RPL/rpl_control.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ bool rpl_control_get_instance_dao_target_count(rpl_domain_t *domain, uint8_t ins
158158
bool rpl_control_read_dodag_info(const struct rpl_instance *instance, struct rpl_dodag_info_t *dodag_info);
159159
const rpl_dodag_conf_t *rpl_control_get_dodag_config(const struct rpl_instance *instance);
160160
const uint8_t *rpl_control_preferred_parent_addr(const struct rpl_instance *instance, bool global);
161+
uint16_t rpl_control_current_rank(const struct rpl_instance *instance);
161162

162163

163164
#else /* HAVE_RPL */

0 commit comments

Comments
 (0)