factored out function for getting link local address in ds6 and made use of it in rpl for checking state of lladdress as DIOs should not be sent when tentative

This commit is contained in:
joxe 2010-05-09 17:52:37 +00:00
parent 1696e9f70f
commit adb00ed932
3 changed files with 34 additions and 10 deletions

View file

@ -32,7 +32,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: rpl-timers.c,v 1.2 2010/05/04 22:55:32 nvt-se Exp $
* $Id: rpl-timers.c,v 1.3 2010/05/09 17:52:37 joxe Exp $
*/
/**
* \file
@ -57,6 +57,10 @@ static void new_dio_interval(rpl_dag_t *dag);
static void handle_dio_timer(void *ptr);
static uint16_t next_dis;
/* dio_send_ok is true if the node is ready to send DIOs */
static uint8_t dio_send_ok;
/************************************************************************/
static void
handle_periodic_timer(void *ptr)
@ -118,6 +122,15 @@ handle_dio_timer(void *ptr)
dag = (rpl_dag_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 addres is not ok\n");
ctimer_set(&dag->dio_timer, CLOCK_SECOND, &handle_dio_timer, dag);
return;
}
}
if(dag->dio_send) {
/* send DIO if counter is less than desired redundancy */

View file

@ -586,6 +586,24 @@ uip_ds6_addr_lookup(uip_ipaddr_t * ipaddr)
return NULL;
}
/*---------------------------------------------------------------------------*/
/*
* get a link local address -
* state = -1 => any address is ok. Otherwise state = desired state of addr.
* (TENTATIVE, PREFERRED, DEPRECATED)
*/
uip_ds6_addr_t *
uip_ds6_get_link_local(int8_t state) {
for(locaddr = uip_ds6_if.addr_list;
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
if((locaddr->isused) && (state == - 1 || locaddr->state == state)
&& (uip_is_addr_link_local(&locaddr->ipaddr))) {
return locaddr;
}
}
return NULL;
}
/*---------------------------------------------------------------------------*/
uip_ds6_maddr_t *
uip_ds6_maddr_add(uip_ipaddr_t * ipaddr)
@ -763,15 +781,7 @@ uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
}
}
} else {
// use link local
for(locaddr = uip_ds6_if.addr_list;
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
if((locaddr->isused) && (locaddr->state == ADDR_PREFERRED)
&& (uip_is_addr_link_local(&locaddr->ipaddr))) {
matchaddr = locaddr;
break;
}
}
matchaddr = uip_ds6_get_link_local(ADDR_PREFERRED);
}
uip_ipaddr_copy(src, &matchaddr->ipaddr);

View file

@ -340,6 +340,7 @@ uip_ds6_addr_t *uip_ds6_addr_add(uip_ipaddr_t *ipaddr,
unsigned long vlifetime, uint8_t type);
void uip_ds6_addr_rm(uip_ds6_addr_t *addr);
uip_ds6_addr_t *uip_ds6_addr_lookup(uip_ipaddr_t *ipaddr);
uip_ds6_addr_t *uip_ds6_get_link_local(int8_t state);
/** @} */