Fixed a bunch of bugs in the collection neighbor announcement/discovery code: neighbor announcments were not repeated unless there was a change in the ETX val. Neighbor announcements happened to often when there were changes in the ETX.

This commit is contained in:
adamdunkels 2008-08-15 19:00:38 +00:00
parent 210782d9c6
commit 31509ad726
3 changed files with 39 additions and 18 deletions

View file

@ -36,7 +36,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: collect.c,v 1.13 2008/07/03 22:02:10 adamdunkels Exp $
* $Id: collect.c,v 1.14 2008/08/15 19:00:38 adamdunkels Exp $
*/
/**
@ -68,7 +68,7 @@ static const struct rimebuf_attrlist attributes[] =
RIMEBUF_ATTR_LAST
};
#define NUM_RECENT_PACKETS 4
#define NUM_RECENT_PACKETS 2
struct recent_packet {
rimeaddr_t originator;
@ -115,12 +115,18 @@ update_rtmetric(struct collect_conn *tc)
}
tc->rtmetric = RTMETRIC_MAX;
} else {
/* We set our rtmetric to the rtmetric of our best neighbor plus
the expected transmissions to reach that neighbor. */
if(n->rtmetric + neighbor_etx(n) != tc->rtmetric) {
tc->rtmetric = n->rtmetric + neighbor_etx(n);
neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric);
uint16_t new_rtmetric = n->rtmetric + neighbor_etx(n);
if(tc->rtmetric == RTMETRIC_MAX) {
neighbor_discovery_start(&tc->neighbor_discovery_conn, new_rtmetric);
} else {
neighbor_discovery_set_val(&tc->neighbor_discovery_conn, new_rtmetric);
}
tc->rtmetric = new_rtmetric;
PRINTF("%d.%d: new rtmetric %d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
tc->rtmetric);
@ -158,6 +164,11 @@ node_packet_received(struct runicast_conn *c, rimeaddr_t *from, uint8_t seqno)
if(recent_packets[i].seqno == rimebuf_attr(RIMEBUF_ATTR_EPACKET_ID)&&
rimeaddr_cmp(&recent_packets[i].originator,
rimebuf_addr(RIMEBUF_ADDR_ESENDER))) {
PRINTF("%d.%d: collect: dropping duplicate packet %d from %d.%d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
rimebuf_attr(RIMEBUF_ATTR_EPACKET_ID),
rimebuf_addr(RIMEBUF_ADDR_ESENDER)->u8[0],
rimebuf_addr(RIMEBUF_ADDR_ESENDER)->u8[1]);
/* Drop the packet. */
return;
}
@ -284,7 +295,7 @@ collect_open(struct collect_conn *tc, uint16_t channels,
channel_set_attributes(channels + 1, attributes);
tc->rtmetric = RTMETRIC_MAX;
tc->cb = cb;
neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric);
neighbor_discovery_set_val(&tc->neighbor_discovery_conn, tc->rtmetric);
}
/*---------------------------------------------------------------------------*/
void
@ -331,6 +342,9 @@ collect_send(struct collect_conn *tc, int rexmits)
#if NETSIM
ether_set_line(n->addr.u8[0], n->addr.u8[1]);
#endif /* NETSIM */
PRINTF("%d.%d: sending to %d.%d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
n->addr.u8[0], n->addr.u8[1]);
return runicast_send(&tc->runicast_conn, &n->addr, rexmits);
} else {
/* printf("Didn't find any neighbor\n");*/

View file

@ -33,7 +33,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: neighbor-discovery.c,v 1.9 2008/07/09 09:33:58 adamdunkels Exp $
* $Id: neighbor-discovery.c,v 1.10 2008/08/15 19:00:38 adamdunkels Exp $
*/
/**
@ -115,7 +115,7 @@ adv_packet_received(struct broadcast_conn *ibc, rimeaddr_t *from)
/* If we receive an announcement with a lower value than ours, we
cancel our own announcement. */
if(msg->val < c->val) {
ctimer_stop(&c->t);
ctimer_stop(&c->send_timer);
}
if(c->u->recv) {
@ -128,10 +128,9 @@ send_timer(void *ptr)
{
struct neighbor_discovery_conn *tc = ptr;
/* send_adv(tc, tc->max_interval);*/
ctimer_set(&tc->t,
ctimer_set(&tc->send_timer,
tc->max_interval / 2 + random_rand() % (tc->max_interval / 2),
send_timer, tc);
send_adv, tc);
ctimer_set(&tc->interval_timer,
tc->max_interval,
send_timer, tc);
@ -152,14 +151,20 @@ neighbor_discovery_open(struct neighbor_discovery_conn *c, uint16_t channel,
c->initial_interval = initial;
c->min_interval = min;
c->max_interval = max;
ctimer_set(&c->interval_timer, max, send_timer, c);
}
/*---------------------------------------------------------------------------*/
void
neighbor_discovery_close(struct neighbor_discovery_conn *c)
{
broadcast_close(&c->c);
ctimer_stop(&c->t);
ctimer_stop(&c->send_timer);
ctimer_stop(&c->interval_timer);
}
/*---------------------------------------------------------------------------*/
void
neighbor_discovery_set_val(struct neighbor_discovery_conn *c, uint16_t val)
{
c->val = val;
}
/*---------------------------------------------------------------------------*/
void
@ -173,7 +178,8 @@ neighbor_discovery_start(struct neighbor_discovery_conn *c, uint16_t val)
interval = c->min_interval;
}
c->val = val;
ctimer_set(&c->t, interval / 2 + random_rand() % (interval / 2),
ctimer_set(&c->interval_timer, interval, send_timer, 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.
*
* $Id: neighbor-discovery.h,v 1.6 2008/07/09 09:33:58 adamdunkels Exp $
* $Id: neighbor-discovery.h,v 1.7 2008/08/15 19:00:38 adamdunkels Exp $
*/
/**
@ -73,7 +73,7 @@ struct neighbor_discovery_callbacks {
struct neighbor_discovery_conn {
struct broadcast_conn c;
const struct neighbor_discovery_callbacks *u;
struct ctimer t, interval_timer;
struct ctimer send_timer, interval_timer;
clock_time_t initial_interval, min_interval, max_interval;
uint16_t val;
};
@ -85,6 +85,7 @@ void neighbor_discovery_open(struct neighbor_discovery_conn *c,
clock_time_t max,
const struct neighbor_discovery_callbacks *u);
void neighbor_discovery_close(struct neighbor_discovery_conn *c);
void neighbor_discovery_set_val(struct neighbor_discovery_conn *c, uint16_t val);
void neighbor_discovery_start(struct neighbor_discovery_conn *c, uint16_t val);