Improved handling of duplicate packets

This commit is contained in:
adamdunkels 2010-04-08 09:32:56 +00:00
parent 6d9f904627
commit 91ff8574ad
3 changed files with 40 additions and 19 deletions

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: contikimac.c,v 1.30 2010/04/06 11:57:43 adamdunkels Exp $
* $Id: contikimac.c,v 1.31 2010/04/08 09:32:56 adamdunkels Exp $
*/
/**
@ -192,8 +192,13 @@ static volatile rtimer_clock_t stream_until;
#define MIN(a, b) ((a) < (b)? (a) : (b))
#endif /* MIN */
static int last_received_seqno;
static rimeaddr_t last_received_sender;
struct seqno {
rimeaddr_t sender;
uint8_t seqno;
};
#define MAX_SEQNOS 8
static struct seqno received_seqnos[MAX_SEQNOS];
#if CONTIKIMAC_CONF_BROADCAST_RATE_LIMIT
static struct timer broadcast_rate_timer;
@ -896,18 +901,26 @@ input_packet(void)
#endif /* WITH_PHASE_OPTIMIZATION */
/* Check for duplicate packet by comparing the sequence number
of the incoming packet with the last one we saw. */
if(packetbuf_attr(PACKETBUF_ATTR_PACKET_ID) == last_received_seqno &&
of the incoming packet with the last few ones we saw. */
{
int i;
for(i = 0; i < MAX_SEQNOS; ++i) {
if(packetbuf_attr(PACKETBUF_ATTR_PACKET_ID) == received_seqnos[i].seqno &&
rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_SENDER),
&last_received_sender)) {
&received_seqnos[i].sender)) {
/* Drop the packet. */
/* printf("Drop duplicate ContikiMAC layer packet\n");*/
return;
}
last_received_seqno = packetbuf_attr(PACKETBUF_ATTR_PACKET_ID);
rimeaddr_copy(&last_received_sender, packetbuf_addr(PACKETBUF_ADDR_SENDER));
}
for(i = MAX_SEQNOS - 1; i > 0; --i) {
memcpy(&received_seqnos[i], &received_seqnos[i - 1],
sizeof(struct seqno));
}
received_seqnos[0].seqno = packetbuf_attr(PACKETBUF_ATTR_PACKET_ID);
rimeaddr_copy(&received_seqnos[0].sender,
packetbuf_addr(PACKETBUF_ADDR_SENDER));
}
#if CONTIKIMAC_CONF_COMPOWER
/* Accumulate the power consumption for the packet reception. */

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: csma.c,v 1.15 2010/03/26 12:29:29 nifi Exp $
* $Id: csma.c,v 1.16 2010/04/08 09:33:37 adamdunkels Exp $
*/
/**
@ -164,7 +164,7 @@ packet_sent(void *ptr, int status, int num_transmissions)
/* The retransmission time uses a linear backoff so that the
interval between the transmissions increase with each
retransmit. */
time = time + (random_rand() % ((q->collisions + q->transmissions) * 3 * time));
time = time + (random_rand() % ((q->transmissions + 1) * 3 * time));
if(q->transmissions < q->max_transmissions) {
PRINTF("csma: retransmitting with time %lu\n", time);
@ -186,6 +186,9 @@ static void
send_packet(mac_callback_t sent, void *ptr)
{
struct queued_packet *q;
static uint16_t seqno;
packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, seqno++);
/* Remember packet for later. */
q = memb_alloc(&packet_memb);

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: framer-802154.c,v 1.9 2010/04/05 19:28:07 adamdunkels Exp $
* $Id: framer-802154.c,v 1.10 2010/04/08 09:32:56 adamdunkels Exp $
*/
/**
@ -101,7 +101,12 @@ create(void)
params.fcf.frame_version = FRAME802154_IEEE802154_2003;
/* Increment and set the data sequence number. */
if(packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO)) {
params.seq = packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO);
} else {
params.seq = mac_dsn++;
packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, params.seq);
}
/* params.seq = packetbuf_attr(PACKETBUF_ATTR_PACKET_ID); */
/* Complete the addressing fields. */