Add method to get the first neighbour which is about to expire

This commit is contained in:
lebrush 2013-05-15 12:16:15 +02:00
parent 8451a4198d
commit 9158ff4bf1
2 changed files with 32 additions and 2 deletions

View File

@ -875,7 +875,26 @@ uip_ds6_compute_reachable_time(void)
(uint32_t) (UIP_ND6_MAX_RANDOM_FACTOR(uip_ds6_if.base_reachable_time) -
UIP_ND6_MIN_RANDOM_FACTOR(uip_ds6_if.base_reachable_time));
}
/*---------------------------------------------------------------------------*/
uip_ds6_nbr_t*
uip_ds6_get_least_lifetime_neighbor()
{
uip_ds6_nbr_t *nbr_expiring = NULL;
uint8_t i;
for(i = 0; i < UIP_DS6_NBR_NB; i++) {
if(uip_ds6_nbr_cache[i].isused) {
if(nbr_expiring != NULL) {
clock_time_t curr = stimer_remaining(&uip_ds6_nbr_cache[i].reachable);
if(curr < stimer_remaining(&nbr_expiring->reachable)) {
nbr_expiring = &uip_ds6_nbr_cache[i];
}
} else {
nbr_expiring = &uip_ds6_nbr_cache[i];
}
}
}
return nbr_expiring;
}
/*---------------------------------------------------------------------------*/
/** @} */
#endif /* UIP_CONF_IPV6 */

View File

@ -371,4 +371,15 @@ uint32_t uip_ds6_compute_reachable_time(void); /** \brief compute random reachab
/** @} */
/** @} */
/**
* \brief
* This searches inside the neighbor table for the neighbor that is about to
* expire the next.
*
* \return
* A reference to the neighbor about to expire the next or NULL if
* table is empty.
*/
uip_ds6_nbr_t *uip_ds6_get_least_lifetime_neighbor();
#endif /* __UIP_DS6_H__ */