/*---------------------------------------------------------------------------*/ static void handle_dio_timer(struct net_buf *not_used, void *ptr) { rpl_instance_t *instance; instance = (rpl_instance_t *)ptr; PRINTF("RPL: DIO Timer triggered\n"); if(!dio_send_ok) { if(uip_ds6_get_link_local(ADDR_PREFERRED) != NULL) { dio_send_ok = 1; } else { PRINTF("RPL: Postponing DIO transmission since link local address is not ok\n"); ctimer_set(NULL, &instance->dio_timer, CLOCK_SECOND, &handle_dio_timer, instance); return; } } if(instance->dio_send) { /* send DIO if counter is less than desired redundancy */ if(instance->dio_redundancy != 0 && instance->dio_counter < instance->dio_redundancy) { #if RPL_CONF_STATS instance->dio_totsend++; #endif /* RPL_CONF_STATS */ dio_output(instance, NULL); } else { PRINTF("RPL: Supressing DIO transmission (%d >= %d)\n", instance->dio_counter, instance->dio_redundancy); } instance->dio_send = 0; PRINTF("RPL: Scheduling DIO timer %lu ticks in future (sent)\n", instance->dio_next_delay); ctimer_set(NULL, &instance->dio_timer, instance->dio_next_delay, handle_dio_timer, instance); } else { /* check if we need to double interval */ if(instance->dio_intcurrent < instance->dio_intmin + instance->dio_intdoubl) { instance->dio_intcurrent++; PRINTF("RPL: DIO Timer interval doubled %d\n", instance->dio_intcurrent); } new_dio_interval(instance); } #if DEBUG rpl_print_neighbor_list(); #endif }
/*---------------------------------------------------------------------------*/ static void handle_probing_timer(void *ptr) { rpl_instance_t *instance = (rpl_instance_t *)ptr; rpl_parent_t *probing_target = RPL_PROBING_SELECT_FUNC(instance->current_dag); /* Perform probing */ if(probing_target != NULL && rpl_get_parent_ipaddr(probing_target) != NULL) { PRINTF("RPL: probing %3u\n", nbr_table_get_lladdr(rpl_parents, probing_target)->u8[7]); /* Send probe, e.g. unicast DIO or DIS */ RPL_PROBING_SEND_FUNC(instance, rpl_get_parent_ipaddr(probing_target)); } /* Schedule next probing */ rpl_schedule_probing(instance); #if DEBUG rpl_print_neighbor_list(); #endif }
/*---------------------------------------------------------------------------*/ rpl_dag_t * rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p) { rpl_parent_t *last_parent; rpl_dag_t *dag, *end, *best_dag; rpl_rank_t old_rank; old_rank = instance->current_dag->rank; last_parent = instance->current_dag->preferred_parent; if(instance->current_dag->rank != ROOT_RANK(instance)) { rpl_select_parent(p->dag); } best_dag = NULL; for(dag = &instance->dag_table[0], end = dag + RPL_MAX_DAG_PER_INSTANCE; dag < end; ++dag) { if(dag->used && dag->preferred_parent != NULL && dag->preferred_parent->rank != INFINITE_RANK) { if(best_dag == NULL) { best_dag = dag; } else { best_dag = instance->of->best_dag(best_dag, dag); } } } if(best_dag == NULL) { /* No parent found: the calling function handle this problem. */ return NULL; } if(instance->current_dag != best_dag) { /* Remove routes installed by DAOs. */ rpl_remove_routes(instance->current_dag); PRINTF("RPL: New preferred DAG: "); PRINT6ADDR(&best_dag->dag_id); PRINTF("\n"); if(best_dag->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) { check_prefix(&instance->current_dag->prefix_info, &best_dag->prefix_info); } else if(instance->current_dag->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) { check_prefix(&instance->current_dag->prefix_info, NULL); } best_dag->joined = 1; instance->current_dag->joined = 0; instance->current_dag = best_dag; } instance->of->update_metric_container(instance); /* Update the DAG rank. */ best_dag->rank = instance->of->calculate_rank(best_dag->preferred_parent, 0); if(last_parent == NULL || best_dag->rank < best_dag->min_rank) { best_dag->min_rank = best_dag->rank; } else if(!acceptable_rank(best_dag, best_dag->rank)) { PRINTF("RPL: New rank unacceptable!\n"); rpl_set_preferred_parent(instance->current_dag, NULL); if(instance->mop != RPL_MOP_NO_DOWNWARD_ROUTES && last_parent != NULL) { /* Send a No-Path DAO to the removed preferred parent. */ dao_output(last_parent, RPL_ZERO_LIFETIME); } return NULL; } if(best_dag->preferred_parent != last_parent) { rpl_set_default_route(instance, rpl_get_parent_ipaddr(best_dag->preferred_parent)); PRINTF("RPL: Changed preferred parent, rank changed from %u to %u\n", (unsigned)old_rank, best_dag->rank); RPL_STAT(rpl_stats.parent_switch++); if(instance->mop != RPL_MOP_NO_DOWNWARD_ROUTES) { if(last_parent != NULL) { /* Send a No-Path DAO to the removed preferred parent. */ dao_output(last_parent, RPL_ZERO_LIFETIME); } /* The DAO parent set changed - schedule a DAO transmission. */ RPL_LOLLIPOP_INCREMENT(instance->dtsn_out); rpl_schedule_dao(instance); } rpl_reset_dio_timer(instance); #if DEBUG rpl_print_neighbor_list(); #endif } else if(best_dag->rank != old_rank) { PRINTF("RPL: Preferred parent update, rank changed from %u to %u\n", (unsigned)old_rank, best_dag->rank); } return best_dag; }