Added a parameter to collect_open() that specifies whether or not the node should be a router for packets, or only an originator of packets. Updated the collect module to the new annoucement API.

This commit is contained in:
adamdunkels 2010-03-25 08:51:07 +00:00
parent 2559e27414
commit a4f9e62295
2 changed files with 57 additions and 9 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: collect.c,v 1.41 2010/03/19 13:17:00 adamdunkels Exp $ * $Id: collect.c,v 1.42 2010/03/25 08:51:07 adamdunkels Exp $
*/ */
/** /**
@ -101,7 +101,9 @@ PACKETQUEUE(sending_queue, MAX_SENDING_QUEUE);
#define COLLECT_ANNOUNCEMENTS COLLECT_CONF_ANNOUNCEMENTS #define COLLECT_ANNOUNCEMENTS COLLECT_CONF_ANNOUNCEMENTS
#endif /* COLLECT_CONF_ANNOUNCEMENTS */ #endif /* COLLECT_CONF_ANNOUNCEMENTS */
#define DEBUG 1 #define ANNOUNCEMENT_SCAN_TIME CLOCK_SECOND
#define DEBUG 0
#if DEBUG #if DEBUG
#include <stdio.h> #include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__) #define PRINTF(...) printf(__VA_ARGS__)
@ -141,7 +143,9 @@ update_rtmetric(struct collect_conn *tc)
} }
tc->rtmetric = RTMETRIC_MAX; tc->rtmetric = RTMETRIC_MAX;
#if COLLECT_ANNOUNCEMENTS #if COLLECT_ANNOUNCEMENTS
#if ! COLLECT_CONF_WITH_LISTEN
announcement_set_value(&tc->announcement, tc->rtmetric); announcement_set_value(&tc->announcement, tc->rtmetric);
#endif /* COLLECT_CONF_WITH_LISTEN */
#else /* COLLECT_ANNOUNCEMENTS */ #else /* COLLECT_ANNOUNCEMENTS */
neighbor_discovery_set_val(&tc->neighbor_discovery_conn, tc->rtmetric); neighbor_discovery_set_val(&tc->neighbor_discovery_conn, tc->rtmetric);
#endif /* COLLECT_ANNOUNCEMENTS */ #endif /* COLLECT_ANNOUNCEMENTS */
@ -159,15 +163,19 @@ update_rtmetric(struct collect_conn *tc)
before, we call neighbor_discovery_start to start a new before, we call neighbor_discovery_start to start a new
period. */ period. */
if(old_rtmetric >= tc->rtmetric + COLLECT_NEIGHBOR_ETX_SCALE + COLLECT_NEIGHBOR_ETX_SCALE / 2 || if(old_rtmetric >= tc->rtmetric + COLLECT_NEIGHBOR_ETX_SCALE + COLLECT_NEIGHBOR_ETX_SCALE / 2 ||
old_rtmetric == SINK) { old_rtmetric == RTMETRIC_MAX) {
neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric); neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric);
} else { } else {
neighbor_discovery_set_val(&tc->neighbor_discovery_conn, tc->rtmetric); neighbor_discovery_set_val(&tc->neighbor_discovery_conn, tc->rtmetric);
} }
#else /* ! COLLECT_ANNOUNCEMENTS */ #else /* ! COLLECT_ANNOUNCEMENTS */
announcement_set_value(&tc->announcement, tc->rtmetric); if(tc->is_router) {
announcement_set_value(&tc->announcement, tc->rtmetric);
} else {
announcement_remove_value(&tc->announcement);
}
if(old_rtmetric >= tc->rtmetric + COLLECT_NEIGHBOR_ETX_SCALE + COLLECT_NEIGHBOR_ETX_SCALE / 2 || if(old_rtmetric >= tc->rtmetric + COLLECT_NEIGHBOR_ETX_SCALE + COLLECT_NEIGHBOR_ETX_SCALE / 2 ||
old_rtmetric == SINK) { old_rtmetric == RTMETRIC_MAX) {
announcement_bump(&tc->announcement); announcement_bump(&tc->announcement);
} }
#endif /* ! COLLECT_ANNOUNCEMENTS */ #endif /* ! COLLECT_ANNOUNCEMENTS */
@ -175,11 +183,12 @@ update_rtmetric(struct collect_conn *tc)
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);
#if ! COLLECT_CONF_WITH_LISTEN
/* We got a new, working, route we send any queued packets we may have. */ /* We got a new, working, route we send any queued packets we may have. */
if(old_rtmetric == RTMETRIC_MAX) { if(old_rtmetric == RTMETRIC_MAX) {
send_queued_packet(); send_queued_packet();
} }
#endif /* COLLECT_CONF_WITH_LISTEN */
} }
} }
} }
@ -282,7 +291,15 @@ send_queued_packet(void)
retransmit_callback, c); retransmit_callback, c);
} else { } else {
#if COLLECT_ANNOUNCEMENTS #if COLLECT_ANNOUNCEMENTS
#if COLLECT_CONF_WITH_LISTEN
printf("listen\n");
announcement_listen(1); announcement_listen(1);
ctimer_set(&c->transmit_after_scan_timer, ANNOUNCEMENT_SCAN_TIME,
send_queued_packet, NULL);
#else /* COLLECT_CONF_WITH_LISTEN */
announcement_set_value(&c->announcement, RTMETRIC_MAX);
announcement_bump(&c->announcement);
#endif /* COLLECT_CONF_WITH_LISTEN */
#endif /* COLLECT_ANNOUNCEMENTS */ #endif /* COLLECT_ANNOUNCEMENTS */
} }
} }
@ -634,7 +651,14 @@ received_announcement(struct announcement *a, const rimeaddr_t *from,
n->addr.u8[0], n->addr.u8[1], value); n->addr.u8[0], n->addr.u8[1], value);
} }
update_rtmetric(tc); update_rtmetric(tc);
#if ! COLLECT_CONF_WITH_LISTEN
if(value == RTMETRIC_MAX &&
tc->rtmetric != RTMETRIC_MAX) {
announcement_bump(&tc->announcement);
}
#endif /* COLLECT_CONF_WITH_LISTEN */
} }
#endif /* !COLLECT_ANNOUNCEMENTS */ #endif /* !COLLECT_ANNOUNCEMENTS */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -647,12 +671,14 @@ static const struct neighbor_discovery_callbacks neighbor_discovery_callbacks =
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
collect_open(struct collect_conn *tc, uint16_t channels, collect_open(struct collect_conn *tc, uint16_t channels,
uint8_t is_router,
const struct collect_callbacks *cb) const struct collect_callbacks *cb)
{ {
unicast_open(&tc->unicast_conn, channels + 1, &unicast_callbacks); unicast_open(&tc->unicast_conn, channels + 1, &unicast_callbacks);
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;
tc->is_router = is_router;
collect_neighbor_init(); collect_neighbor_init();
packetqueue_init(&sending_queue); packetqueue_init(&sending_queue);
@ -664,8 +690,11 @@ collect_open(struct collect_conn *tc, uint16_t channels,
&neighbor_discovery_callbacks); &neighbor_discovery_callbacks);
neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric); neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric);
#else /* !COLLECT_ANNOUNCEMENTS */ #else /* !COLLECT_ANNOUNCEMENTS */
announcement_register(&tc->announcement, channels, tc->rtmetric, announcement_register(&tc->announcement, channels,
received_announcement); received_announcement);
#if ! COLLECT_CONF_WITH_LISTEN
announcement_set_value(&tc->announcement, RTMETRIC_MAX);
#endif /* COLLECT_CONF_WITH_LISTEN */
#endif /* !COLLECT_ANNOUNCEMENTS */ #endif /* !COLLECT_ANNOUNCEMENTS */
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -684,6 +713,7 @@ void
collect_set_sink(struct collect_conn *tc, int should_be_sink) collect_set_sink(struct collect_conn *tc, int should_be_sink)
{ {
if(should_be_sink) { if(should_be_sink) {
tc->is_router = 1;
tc->rtmetric = SINK; tc->rtmetric = SINK;
PRINTF("collect_set_sink: tc->rtmetric %d\n", tc->rtmetric); PRINTF("collect_set_sink: tc->rtmetric %d\n", tc->rtmetric);
#if !COLLECT_ANNOUNCEMENTS #if !COLLECT_ANNOUNCEMENTS
@ -749,8 +779,18 @@ collect_send(struct collect_conn *tc, int rexmits)
PRINTF("%d.%d: did not find any neighbor to send to\n", PRINTF("%d.%d: did not find any neighbor to send to\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]); rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
#if COLLECT_ANNOUNCEMENTS #if COLLECT_ANNOUNCEMENTS
#if COLLECT_CONF_WITH_LISTEN
printf("listen\n");
announcement_listen(1); announcement_listen(1);
ctimer_set(&tc->transmit_after_scan_timer, ANNOUNCEMENT_SCAN_TIME,
send_queued_packet, NULL);
#else /* COLLECT_CONF_WITH_LISTEN */
printf("bump neighbor value\n");
announcement_set_value(&tc->announcement, RTMETRIC_MAX);
announcement_bump(&tc->announcement);
#endif /* COLLECT_CONF_WITH_LISTEN */
#endif /* COLLECT_ANNOUNCEMENTS */ #endif /* COLLECT_ANNOUNCEMENTS */
if(packetqueue_enqueue_packetbuf(&sending_queue, FORWARD_PACKET_LIFETIME, if(packetqueue_enqueue_packetbuf(&sending_queue, FORWARD_PACKET_LIFETIME,
tc)) { tc)) {
return 1; return 1;

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: collect.h,v 1.14 2010/03/14 23:01:12 adamdunkels Exp $ * $Id: collect.h,v 1.15 2010/03/25 08:51:07 adamdunkels Exp $
*/ */
/** /**
@ -86,6 +86,7 @@ struct collect_conn {
struct neighbor_discovery_conn neighbor_discovery_conn; struct neighbor_discovery_conn neighbor_discovery_conn;
#else /* ! COLLECT_CONF_ANNOUNCEMENTS */ #else /* ! COLLECT_CONF_ANNOUNCEMENTS */
struct announcement announcement; struct announcement announcement;
struct ctimer transmit_after_scan_timer;
#endif /* COLLECT_CONF_ANNOUNCEMENTS */ #endif /* COLLECT_CONF_ANNOUNCEMENTS */
const struct collect_callbacks *cb; const struct collect_callbacks *cb;
struct ctimer t; struct ctimer t;
@ -96,9 +97,16 @@ struct collect_conn {
uint8_t eseqno; uint8_t eseqno;
struct ctimer retransmission_timer; struct ctimer retransmission_timer;
rimeaddr_t current_receiver; rimeaddr_t current_receiver;
uint8_t is_router;
};
enum {
COLLECT_NO_ROUTER,
COLLECT_ROUTER,
}; };
void collect_open(struct collect_conn *c, uint16_t channels, void collect_open(struct collect_conn *c, uint16_t channels,
uint8_t is_router,
const struct collect_callbacks *callbacks); const struct collect_callbacks *callbacks);
void collect_close(struct collect_conn *c); void collect_close(struct collect_conn *c);