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:
parent
210782d9c6
commit
31509ad726
3 changed files with 39 additions and 18 deletions
|
@ -36,7 +36,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* 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
|
RIMEBUF_ATTR_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NUM_RECENT_PACKETS 4
|
#define NUM_RECENT_PACKETS 2
|
||||||
|
|
||||||
struct recent_packet {
|
struct recent_packet {
|
||||||
rimeaddr_t originator;
|
rimeaddr_t originator;
|
||||||
|
@ -115,12 +115,18 @@ update_rtmetric(struct collect_conn *tc)
|
||||||
}
|
}
|
||||||
tc->rtmetric = RTMETRIC_MAX;
|
tc->rtmetric = RTMETRIC_MAX;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* We set our rtmetric to the rtmetric of our best neighbor plus
|
/* We set our rtmetric to the rtmetric of our best neighbor plus
|
||||||
the expected transmissions to reach that neighbor. */
|
the expected transmissions to reach that neighbor. */
|
||||||
if(n->rtmetric + neighbor_etx(n) != tc->rtmetric) {
|
if(n->rtmetric + neighbor_etx(n) != tc->rtmetric) {
|
||||||
tc->rtmetric = n->rtmetric + neighbor_etx(n);
|
uint16_t new_rtmetric = n->rtmetric + neighbor_etx(n);
|
||||||
neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric);
|
|
||||||
|
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",
|
PRINTF("%d.%d: new rtmetric %d\n",
|
||||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||||
tc->rtmetric);
|
tc->rtmetric);
|
||||||
|
@ -156,8 +162,13 @@ node_packet_received(struct runicast_conn *c, rimeaddr_t *from, uint8_t seqno)
|
||||||
|
|
||||||
for(i = 0; i < NUM_RECENT_PACKETS; i++) {
|
for(i = 0; i < NUM_RECENT_PACKETS; i++) {
|
||||||
if(recent_packets[i].seqno == rimebuf_attr(RIMEBUF_ATTR_EPACKET_ID)&&
|
if(recent_packets[i].seqno == rimebuf_attr(RIMEBUF_ATTR_EPACKET_ID)&&
|
||||||
rimeaddr_cmp(&recent_packets[i].originator,
|
rimeaddr_cmp(&recent_packets[i].originator,
|
||||||
rimebuf_addr(RIMEBUF_ADDR_ESENDER))) {
|
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. */
|
/* Drop the packet. */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -284,7 +295,7 @@ collect_open(struct collect_conn *tc, uint16_t channels,
|
||||||
channel_set_attributes(channels + 1, attributes);
|
channel_set_attributes(channels + 1, attributes);
|
||||||
tc->rtmetric = RTMETRIC_MAX;
|
tc->rtmetric = RTMETRIC_MAX;
|
||||||
tc->cb = cb;
|
tc->cb = cb;
|
||||||
neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric);
|
neighbor_discovery_set_val(&tc->neighbor_discovery_conn, tc->rtmetric);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
|
@ -331,6 +342,9 @@ collect_send(struct collect_conn *tc, int rexmits)
|
||||||
#if NETSIM
|
#if NETSIM
|
||||||
ether_set_line(n->addr.u8[0], n->addr.u8[1]);
|
ether_set_line(n->addr.u8[0], n->addr.u8[1]);
|
||||||
#endif /* NETSIM */
|
#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);
|
return runicast_send(&tc->runicast_conn, &n->addr, rexmits);
|
||||||
} else {
|
} else {
|
||||||
/* printf("Didn't find any neighbor\n");*/
|
/* printf("Didn't find any neighbor\n");*/
|
||||||
|
|
|
@ -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.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
|
/* 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(msg->val < c->val) {
|
||||||
ctimer_stop(&c->t);
|
ctimer_stop(&c->send_timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(c->u->recv) {
|
if(c->u->recv) {
|
||||||
|
@ -128,10 +128,9 @@ send_timer(void *ptr)
|
||||||
{
|
{
|
||||||
struct neighbor_discovery_conn *tc = ptr;
|
struct neighbor_discovery_conn *tc = ptr;
|
||||||
|
|
||||||
/* send_adv(tc, tc->max_interval);*/
|
ctimer_set(&tc->send_timer,
|
||||||
ctimer_set(&tc->t,
|
|
||||||
tc->max_interval / 2 + random_rand() % (tc->max_interval / 2),
|
tc->max_interval / 2 + random_rand() % (tc->max_interval / 2),
|
||||||
send_timer, tc);
|
send_adv, tc);
|
||||||
ctimer_set(&tc->interval_timer,
|
ctimer_set(&tc->interval_timer,
|
||||||
tc->max_interval,
|
tc->max_interval,
|
||||||
send_timer, tc);
|
send_timer, tc);
|
||||||
|
@ -152,14 +151,20 @@ neighbor_discovery_open(struct neighbor_discovery_conn *c, uint16_t channel,
|
||||||
c->initial_interval = initial;
|
c->initial_interval = initial;
|
||||||
c->min_interval = min;
|
c->min_interval = min;
|
||||||
c->max_interval = max;
|
c->max_interval = max;
|
||||||
ctimer_set(&c->interval_timer, max, send_timer, c);
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
neighbor_discovery_close(struct neighbor_discovery_conn *c)
|
neighbor_discovery_close(struct neighbor_discovery_conn *c)
|
||||||
{
|
{
|
||||||
broadcast_close(&c->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
|
void
|
||||||
|
@ -173,7 +178,8 @@ neighbor_discovery_start(struct neighbor_discovery_conn *c, uint16_t val)
|
||||||
interval = c->min_interval;
|
interval = c->min_interval;
|
||||||
}
|
}
|
||||||
c->val = val;
|
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);
|
send_adv, c);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -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.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 neighbor_discovery_conn {
|
||||||
struct broadcast_conn c;
|
struct broadcast_conn c;
|
||||||
const struct neighbor_discovery_callbacks *u;
|
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;
|
clock_time_t initial_interval, min_interval, max_interval;
|
||||||
uint16_t val;
|
uint16_t val;
|
||||||
};
|
};
|
||||||
|
@ -85,6 +85,7 @@ void neighbor_discovery_open(struct neighbor_discovery_conn *c,
|
||||||
clock_time_t max,
|
clock_time_t max,
|
||||||
const struct neighbor_discovery_callbacks *u);
|
const struct neighbor_discovery_callbacks *u);
|
||||||
void neighbor_discovery_close(struct neighbor_discovery_conn *c);
|
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);
|
void neighbor_discovery_start(struct neighbor_discovery_conn *c, uint16_t val);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue