Added parameter to ipolite that specifies how many dups that are acceptable, before suppressing one's own packet

This commit is contained in:
adamdunkels 2010-01-25 13:54:06 +00:00
parent 0b58ca3b22
commit 423e37f426
4 changed files with 25 additions and 16 deletions

View File

@ -33,7 +33,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: ipolite.c,v 1.15 2009/11/08 19:40:17 adamdunkels Exp $
* $Id: ipolite.c,v 1.16 2010/01/25 13:54:06 adamdunkels Exp $
*/
/**
@ -74,13 +74,17 @@ recv(struct broadcast_conn *broadcast, const rimeaddr_t *from)
packetbuf_datalen() == queuebuf_datalen(c->q) &&
memcmp(packetbuf_dataptr(), queuebuf_dataptr(c->q),
MIN(c->hdrsize, packetbuf_datalen())) == 0) {
/* We received a copy of our own packet, so we do not send out
packet. */
queuebuf_free(c->q);
c->q = NULL;
ctimer_stop(&c->t);
if(c->cb->dropped) {
c->cb->dropped(c);
/* We received a copy of our own packet, so we increase the
duplicate counter. If it reaches its maximum, do not send out
our packet. */
c->dups++;
if(c->dups == c->maxdups) {
queuebuf_free(c->q);
c->q = NULL;
ctimer_stop(&c->t);
if(c->cb->dropped) {
c->cb->dropped(c);
}
}
}
if(c->cb->recv) {
@ -111,11 +115,12 @@ send(void *ptr)
static const struct broadcast_callbacks broadcast = { recv };
/*---------------------------------------------------------------------------*/
void
ipolite_open(struct ipolite_conn *c, uint16_t channel,
ipolite_open(struct ipolite_conn *c, uint16_t channel, uint8_t dups,
const struct ipolite_callbacks *cb)
{
broadcast_open(&c->c, channel, &broadcast);
c->cb = cb;
c->maxdups = dups;
PRINTF("ipolite open channel %d\n", channel);
}
/*---------------------------------------------------------------------------*/
@ -139,11 +144,12 @@ ipolite_send(struct ipolite_conn *c, clock_time_t interval, uint8_t hdrsize)
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
queuebuf_free(c->q);
}
c->dups = 0;
c->hdrsize = hdrsize;
if(interval == 0) {
PRINTF("%d.%d: ipolite_send: interval 0\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
if (broadcast_send(&c->c)) {
if(broadcast_send(&c->c)) {
if(c->cb->sent) {
c->cb->sent(c);
}

View File

@ -81,7 +81,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: ipolite.h,v 1.9 2009/11/08 19:40:17 adamdunkels Exp $
* $Id: ipolite.h,v 1.10 2010/01/25 13:54:06 adamdunkels Exp $
*/
/**
@ -138,6 +138,8 @@ struct ipolite_conn {
struct ctimer t;
struct queuebuf *q;
uint8_t hdrsize;
uint8_t maxdups;
uint8_t dups;
};
@ -145,6 +147,7 @@ struct ipolite_conn {
* \brief Open an ipolite connection
* \param c A pointer to a struct ipolite_conn.
* \param channel The channel number to be used for this connection
* \param maxdups The number of duplicates that are allowed to be heard before suppressing
* \param cb A pointer to the callbacks used for this connection
*
* This function opens an ipolite connection on the
@ -152,7 +155,7 @@ struct ipolite_conn {
* packet is received, or when another event occurs on the
* connection (see \ref "struct ipolite_callbacks").
*/
void ipolite_open(struct ipolite_conn *c, uint16_t channel,
void ipolite_open(struct ipolite_conn *c, uint16_t channel, uint8_t maxdups,
const struct ipolite_callbacks *cb);
/**

View File

@ -33,7 +33,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: netflood.c,v 1.5 2009/11/09 08:22:40 adamdunkels Exp $
* $Id: netflood.c,v 1.6 2010/01/25 13:54:06 adamdunkels Exp $
*/
/**
@ -148,7 +148,7 @@ void
netflood_open(struct netflood_conn *c, clock_time_t queue_time,
uint16_t channel, const struct netflood_callbacks *u)
{
ipolite_open(&c->c, channel, &netflood);
ipolite_open(&c->c, channel, 1, &netflood);
c->u = u;
c->queue_time = queue_time;
}

View File

@ -33,7 +33,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: rudolph1.c,v 1.13 2009/11/08 19:40:18 adamdunkels Exp $
* $Id: rudolph1.c,v 1.14 2010/01/25 13:54:06 adamdunkels Exp $
*/
/**
@ -304,7 +304,7 @@ rudolph1_open(struct rudolph1_conn *c, uint16_t channel,
const struct rudolph1_callbacks *cb)
{
trickle_open(&c->trickle, TRICKLE_INTERVAL, channel, &trickle);
ipolite_open(&c->ipolite, channel + 1, &ipolite);
ipolite_open(&c->ipolite, channel + 1, 1, &ipolite);
c->cb = cb;
c->version = 0;
c->send_interval = DEFAULT_SEND_INTERVAL;