Skip to content

Commit

Permalink
Select correct parent based on network size and route cost
Browse files Browse the repository at this point in the history
Changed pan_configuration to pan_information
Fixed valgrind error when learning PAN IE information which override version
from PAN configuration

Added function to get RPL rank from rpl_control
  • Loading branch information
Mika Tervonen committed Apr 19, 2018
1 parent 7bf3994 commit c3aa7d1
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 27 deletions.
2 changes: 1 addition & 1 deletion source/6LoWPAN/ws/ws_bbr_api.c
Expand Up @@ -48,7 +48,7 @@ static void ws_bbr_rpl_root_activate(uint8_t *dodag_prefix, uint8_t *dodag_id)
// Lifetime values
new_conf.default_lifetime = 120;
new_conf.lifetime_unit = 60;
new_conf.objective_code_point = 1;
new_conf.objective_code_point = 1; // MRHOF algorithm used
new_conf.authentication = 0;
new_conf.path_control_size = 0;

Expand Down
74 changes: 53 additions & 21 deletions source/6LoWPAN/ws/ws_bootstrap.c
Expand Up @@ -319,7 +319,7 @@ static void ws_bootstrap_pan_advertisement_analyse_active(struct protocol_interf
*
*/

if (pan_information->routing_cost <= cur->ws_info->pan_configuration.routing_cost) {
if (pan_information->routing_cost <= cur->ws_info->pan_information.routing_cost) {
trickle_consistent_heard(&cur->ws_info->trickle_pan_advertisement);
} else {
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement,&trickle_params_pan_advertisement);
Expand Down Expand Up @@ -372,16 +372,25 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
if (memcmp(cur->ws_info->parent_info.addr, ADDR_UNSPECIFIED,8) != 0) {
//Decide which is better parent for authentication
if(cur->ws_info->parent_info.link_quality > data->mpduLinkQuality) {
tr_info("EAPOL target dropped Lower link quality");
return;
}

uint16_t pan_cost = (pan_information.routing_cost / PRC_WEIGHT_FACTOR) + (pan_information.pan_size / PS_WEIGHT_FACTOR);
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);
if (current_pan_cost < pan_cost) {
tr_info("EAPOL target dropped Higher Pan cost");
return;
}

}
// Parent valid store information
cur->ws_info->parent_info.ws_utt = *ws_utt;
// Saved from unicast IE
cur->ws_info->parent_info.ws_us = *ws_us;

// Saved from Pan information
cur->ws_info->parent_info.pan_configuration = pan_information;
cur->ws_info->parent_info.pan_information = pan_information;

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

// TODO Learn routing cost per neighbour

// Learn latest network information
if (cur->bootsrap_mode != ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
cur->ws_info->pan_configuration = pan_information;
cur->ws_info->pan_information.pan_size = pan_information.pan_size;
cur->ws_info->pan_information.routing_cost = pan_information.routing_cost;
cur->ws_info->pan_information.rpl_routing_method = pan_information.rpl_routing_method;
cur->ws_info->pan_information.use_parent_bs = pan_information.use_parent_bs;
cur->ws_info->pan_information.version = pan_information.version;
}
}

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

if (cur->ws_info->configuration_learned &&
common_serial_number_greater_16(cur->ws_info->pan_configuration.pan_version, pan_version)) {
common_serial_number_greater_16(cur->ws_info->pan_information.pan_version, pan_version)) {
// received version is lower se we need to reset the trickle
tr_info("older pan version heard");
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config,&trickle_params_pan_configuration);
Expand All @@ -504,7 +515,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
return;
}
if (cur->ws_info->configuration_learned &&
cur->ws_info->pan_configuration.pan_version == pan_version) {
cur->ws_info->pan_information.pan_version == pan_version) {
// No new information
return;
}
Expand All @@ -515,7 +526,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
tr_info("Updated PAN configuration heard");

cur->ws_info->pan_version_timeout_timer = PAN_VERSION_TIMEOUT;
cur->ws_info->pan_configuration.pan_version = pan_version;
cur->ws_info->pan_information.pan_version = pan_version;
memcpy(cur->ws_info->gtkhash,gtkhash_ptr,32);

//Broadcast schedule
Expand Down Expand Up @@ -866,8 +877,8 @@ static void ws_bootstrap_network_information_learn(protocol_interface_info_entry

// Save network information
cur->ws_info->network_pan_id = cur->ws_info->parent_info.pan_id;
cur->ws_info->pan_configuration = cur->ws_info->parent_info.pan_configuration;
cur->ws_info->pan_configuration.pan_version = 0; // This is learned from actual configuration
cur->ws_info->pan_information = cur->ws_info->parent_info.pan_information;
cur->ws_info->pan_information.pan_version = 0; // This is learned from actual configuration

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

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

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

Expand Down Expand Up @@ -952,7 +963,7 @@ static void ws_bootstrap_rpl_activate(protocol_interface_info_entry_t *cur)

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

static void ws_bootstrap_network_discovery_configure(protocol_interface_info_entry_t *cur)
Expand Down Expand Up @@ -1085,6 +1096,21 @@ 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

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 0xffff;
}
return rpl_control_current_rank(best_instance);
}

static void ws_bootstrap_pan_advert(protocol_interface_info_entry_t *cur)
{
Expand All @@ -1104,9 +1130,15 @@ static void ws_bootstrap_pan_advert(protocol_interface_info_entry_t *cur)

if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
// Border routers write the NW size
cur->ws_info->pan_configuration.pan_size = ws_bbr_pan_size(cur);
cur->ws_info->pan_information.pan_size = ws_bbr_pan_size(cur);
cur->ws_info->pan_information.routing_cost = 0;
} 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);
}


ws_llc_asynch_request(cur, &async_req);
}

Expand Down Expand Up @@ -1166,12 +1198,12 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
tr_debug("Border router start network");
cur->ws_info->network_pan_id = randLIB_get_random_in_range(0,0xfffd);
cur->ws_info->pan_configuration.pan_size = 0;
cur->ws_info->pan_configuration.pan_version = randLIB_get_random_in_range(0,0xffff);
cur->ws_info->pan_configuration.routing_cost = 0;
cur->ws_info->pan_configuration.rpl_routing_method = true;
cur->ws_info->pan_configuration.use_parent_bs = true;
cur->ws_info->pan_configuration.version = WS_FAN_VERSION_1_0;
cur->ws_info->pan_information.pan_size = 0;
cur->ws_info->pan_information.pan_version = randLIB_get_random_in_range(0,0xffff);
cur->ws_info->pan_information.routing_cost = 0;
cur->ws_info->pan_information.rpl_routing_method = true;
cur->ws_info->pan_information.use_parent_bs = true;
cur->ws_info->pan_information.version = WS_FAN_VERSION_1_0;
cur->ws_info->hopping_schdule.channel_function = WS_FIXED_CHANNEL;
ws_llc_set_gtkhash(cur, cur->ws_info->gtkhash);
cur->ws_info->pan_version_timer = PAN_VERSION_LIFETIME;
Expand Down Expand Up @@ -1375,7 +1407,7 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s
// Border router has timed out
tr_debug("Border router version number update");
cur->ws_info->pan_version_timer = PAN_VERSION_LIFETIME;
cur->ws_info->pan_configuration.pan_version++;
cur->ws_info->pan_information.pan_version++;
// Inconsistent for border router to make information distribute faster
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config,&trickle_params_pan_configuration);
}
Expand Down
6 changes: 3 additions & 3 deletions source/6LoWPAN/ws/ws_common.c
Expand Up @@ -134,9 +134,9 @@ int8_t ws_common_allocate_and_init(protocol_interface_info_entry_t *cur)

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

cur->ws_info->pan_configuration.use_parent_bs = true;
cur->ws_info->pan_configuration.rpl_routing_method = true;
cur->ws_info->pan_configuration.version = WS_FAN_VERSION_1_0;
cur->ws_info->pan_information.use_parent_bs = true;
cur->ws_info->pan_information.rpl_routing_method = true;
cur->ws_info->pan_information.version = WS_FAN_VERSION_1_0;

cur->ws_info->hopping_schdule.regulatory_domain = REG_DOMAIN_KR;
cur->ws_info->hopping_schdule.operating_mode = OPERATING_MODE_1a;
Expand Down
4 changes: 2 additions & 2 deletions source/6LoWPAN/ws/ws_common.h
Expand Up @@ -33,7 +33,7 @@ typedef struct parent_info_s {
uint8_t addr[8]; /**< address */
uint8_t link_quality; /**< LQI value measured during reception of the MPDU */
int8_t signal_dbm; /**< This extension for normal IEEE 802.15.4 Data indication */
ws_pan_information_t pan_configuration;
ws_pan_information_t pan_information;
ws_utt_ie_t ws_utt;
ws_us_ie_t ws_us;
uint32_t timestamp; /**< Timestamp when packet was received */
Expand All @@ -54,7 +54,7 @@ typedef struct ws_info_s {
uint8_t gtkhash[32];
bool configuration_learned:1;

struct ws_pan_information_s pan_configuration;
struct ws_pan_information_s pan_information;
ws_hopping_schedule_t hopping_schdule;
struct ws_neighbor_class_s neighbor_storage;
struct fhss_timer *fhss_timer_ptr; // Platform adaptation for FHSS timers.
Expand Down
8 changes: 8 additions & 0 deletions source/6LoWPAN/ws/ws_config.h
Expand Up @@ -49,4 +49,12 @@

#define PAN_VERSION_TIMEOUT 1920

/* Routing Cost Weighting factor
*/
#define PRC_WEIGHT_FACTOR 256

/* Routing Cost Weighting factor
*/
#define PS_WEIGHT_FACTOR 64

#endif /* WS_CONFIG_H_ */
6 changes: 6 additions & 0 deletions source/RPL/rpl_control.c
Expand Up @@ -1657,6 +1657,12 @@ const uint8_t *rpl_control_preferred_parent_addr(const rpl_instance_t *instance,
}
}

uint16_t rpl_control_current_rank(const struct rpl_instance *instance)
{
return rpl_instance_current_rank(instance);
}


static void rpl_domain_print(const rpl_domain_t *domain, route_print_fn_t *print_fn)
{
print_fn("RPL Domain %p", (void *) domain);
Expand Down
1 change: 1 addition & 0 deletions source/RPL/rpl_control.h
Expand Up @@ -158,6 +158,7 @@ bool rpl_control_get_instance_dao_target_count(rpl_domain_t *domain, uint8_t ins
bool rpl_control_read_dodag_info(const struct rpl_instance *instance, struct rpl_dodag_info_t *dodag_info);
const rpl_dodag_conf_t *rpl_control_get_dodag_config(const struct rpl_instance *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);


#else /* HAVE_RPL */
Expand Down

0 comments on commit c3aa7d1

Please sign in to comment.