Improved backoff management: timer is now doubled on every transmission, until the using module calls the neighbor_discovery_start() function again. Don't cancel the transmission even if a lower value arrives (this fixes a problem with multi-hop ETX propagaion).

This commit is contained in:
adamdunkels 2010-02-23 18:36:50 +00:00
parent 0eade2886c
commit 2d13fecea7
2 changed files with 42 additions and 33 deletions

View File

@ -33,7 +33,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: neighbor-discovery.c,v 1.15 2009/11/08 19:40:17 adamdunkels Exp $ * $Id: neighbor-discovery.c,v 1.16 2010/02/23 18:36:50 adamdunkels Exp $
*/ */
/** /**
@ -65,15 +65,6 @@ struct adv_msg {
uint16_t val; uint16_t val;
}; };
#define SINK 0
#define HOPCOUNT_MAX TREE_MAX_DEPTH
#define MAX_HOPLIM 10
/*#define MAX_INTERVAL CLOCK_SECOND * 60
#define MIN_INTERVAL CLOCK_SECOND * 10
#define NEW_VAL_INTERVAL CLOCK_SECOND * 2*/
#define DEBUG 0 #define DEBUG 0
#if DEBUG #if DEBUG
#include <stdio.h> #include <stdio.h>
@ -107,37 +98,62 @@ adv_packet_received(struct broadcast_conn *ibc, const rimeaddr_t *from)
{ {
struct neighbor_discovery_conn *c = (struct neighbor_discovery_conn *)ibc; struct neighbor_discovery_conn *c = (struct neighbor_discovery_conn *)ibc;
struct adv_msg *msg = packetbuf_dataptr(); struct adv_msg *msg = packetbuf_dataptr();
uint16_t val;
PRINTF("%d.%d: adv_packet_received from %d.%d with val %d\n", PRINTF("%d.%d: adv_packet_received from %d.%d with val %d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
from->u8[0], from->u8[1], msg->val); from->u8[0], from->u8[1], msg->val);
memcpy(&val, &msg->val, sizeof(val));
/* If we receive an announcement with a lower value than ours, we /* If we receive an announcement with a lower value than ours, we
cancel our own announcement. */ cancel our own announcement. */
if(msg->val < c->val) { if(val < c->val) {
ctimer_stop(&c->send_timer); /* ctimer_stop(&c->send_timer);*/
} }
if(c->u->recv) { if(c->u->recv) {
c->u->recv(c, from, msg->val); c->u->recv(c, from, val);
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
adv_packet_sent(struct broadcast_conn *bc, int status, int num_tx)
{
}
/*---------------------------------------------------------------------------*/
static void send_timer(void *ptr);
static void
set_timers(struct neighbor_discovery_conn *c)
{
ctimer_set(&c->interval_timer, c->current_interval, send_timer, c);
ctimer_set(&c->send_timer, c->current_interval / 2 + random_rand() %
(c->current_interval / 2),
send_adv, c);
}
/*---------------------------------------------------------------------------*/
static void
send_timer(void *ptr) send_timer(void *ptr)
{ {
struct neighbor_discovery_conn *tc = ptr; struct neighbor_discovery_conn *c = ptr;
clock_time_t interval;
ctimer_set(&tc->send_timer, interval = c->current_interval * 2;
tc->max_interval / 2 + random_rand() % (tc->max_interval / 2),
send_adv, tc); if(interval > c->max_interval) {
ctimer_set(&tc->interval_timer, interval = c->max_interval;
tc->max_interval, }
send_timer, tc);
c->current_interval = interval;
printf("current_interval %lu\n", interval);
set_timers(c);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static CC_CONST_FUNCTION struct broadcast_callbacks broadcast_callbacks = static CC_CONST_FUNCTION struct broadcast_callbacks broadcast_callbacks =
{adv_packet_received}; {adv_packet_received, adv_packet_sent };
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
neighbor_discovery_open(struct neighbor_discovery_conn *c, uint16_t channel, neighbor_discovery_open(struct neighbor_discovery_conn *c, uint16_t channel,
@ -170,17 +186,9 @@ neighbor_discovery_set_val(struct neighbor_discovery_conn *c, uint16_t val)
void void
neighbor_discovery_start(struct neighbor_discovery_conn *c, uint16_t val) neighbor_discovery_start(struct neighbor_discovery_conn *c, uint16_t val)
{ {
clock_time_t interval; c->current_interval = c->initial_interval;
if(val < c->val) {
interval = c->initial_interval;
} else {
interval = c->min_interval;
}
c->val = val; c->val = val;
ctimer_set(&c->interval_timer, interval, send_timer, c); set_timers(c);
ctimer_set(&c->send_timer, interval / 2 + random_rand() % (interval / 2),
send_adv, c);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** @} */ /** @} */

View File

@ -47,7 +47,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: neighbor-discovery.h,v 1.9 2009/11/08 19:40:17 adamdunkels Exp $ * $Id: neighbor-discovery.h,v 1.10 2010/02/23 18:36:50 adamdunkels Exp $
*/ */
/** /**
@ -76,6 +76,7 @@ struct neighbor_discovery_conn {
const struct neighbor_discovery_callbacks *u; const struct neighbor_discovery_callbacks *u;
struct ctimer send_timer, interval_timer; struct ctimer send_timer, interval_timer;
clock_time_t initial_interval, min_interval, max_interval; clock_time_t initial_interval, min_interval, max_interval;
clock_time_t current_interval;
uint16_t val; uint16_t val;
}; };