Rewrote the collect module so that it uses the announcement module rather than the neighbor-discovery module. This makes it possible to implement other annoumcement back-ends than the traditional broadcast-based neighbor discovery
This commit is contained in:
parent
37e15ab537
commit
3670ef2f44
|
@ -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.15 2008/11/17 22:52:10 oliverschmidt Exp $
|
* $Id: collect.c,v 1.16 2009/02/09 20:58:25 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +68,7 @@ static const struct rimebuf_attrlist attributes[] =
|
||||||
RIMEBUF_ATTR_LAST
|
RIMEBUF_ATTR_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NUM_RECENT_PACKETS 2
|
#define NUM_RECENT_PACKETS 4
|
||||||
|
|
||||||
struct recent_packet {
|
struct recent_packet {
|
||||||
rimeaddr_t originator;
|
rimeaddr_t originator;
|
||||||
|
@ -115,18 +115,13 @@ 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) {
|
||||||
uint16_t new_rtmetric = n->rtmetric + neighbor_etx(n);
|
tc->rtmetric = n->rtmetric + neighbor_etx(n);
|
||||||
|
/* neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric);*/
|
||||||
if(tc->rtmetric == RTMETRIC_MAX) {
|
announcement_set_value(&tc->announcement, tc->rtmetric);
|
||||||
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);
|
||||||
|
@ -164,11 +159,6 @@ node_packet_received(struct runicast_conn *c, rimeaddr_t *from, uint8_t seqno)
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -231,8 +221,7 @@ node_packet_received(struct runicast_conn *c, rimeaddr_t *from, uint8_t seqno)
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
node_packet_sent(struct runicast_conn *c, rimeaddr_t *to,
|
node_packet_sent(struct runicast_conn *c, rimeaddr_t *to, uint8_t retransmissions)
|
||||||
uint8_t retransmissions)
|
|
||||||
{
|
{
|
||||||
struct collect_conn *tc = (struct collect_conn *)
|
struct collect_conn *tc = (struct collect_conn *)
|
||||||
((char *)c - offsetof(struct collect_conn, runicast_conn));
|
((char *)c - offsetof(struct collect_conn, runicast_conn));
|
||||||
|
@ -243,8 +232,7 @@ node_packet_sent(struct runicast_conn *c, rimeaddr_t *to,
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
node_packet_timedout(struct runicast_conn *c, rimeaddr_t *to,
|
node_packet_timedout(struct runicast_conn *c, rimeaddr_t *to, uint8_t retransmissions)
|
||||||
uint8_t retransmissions)
|
|
||||||
{
|
{
|
||||||
struct collect_conn *tc = (struct collect_conn *)
|
struct collect_conn *tc = (struct collect_conn *)
|
||||||
((char *)c - offsetof(struct collect_conn, runicast_conn));
|
((char *)c - offsetof(struct collect_conn, runicast_conn));
|
||||||
|
@ -254,7 +242,7 @@ node_packet_timedout(struct runicast_conn *c, rimeaddr_t *to,
|
||||||
update_rtmetric(tc);
|
update_rtmetric(tc);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
/*static void
|
||||||
adv_received(struct neighbor_discovery_conn *c, rimeaddr_t *from, uint16_t rtmetric)
|
adv_received(struct neighbor_discovery_conn *c, rimeaddr_t *from, uint16_t rtmetric)
|
||||||
{
|
{
|
||||||
struct collect_conn *tc = (struct collect_conn *)
|
struct collect_conn *tc = (struct collect_conn *)
|
||||||
|
@ -273,35 +261,61 @@ adv_received(struct neighbor_discovery_conn *c, rimeaddr_t *from, uint16_t rtmet
|
||||||
1, rtmetric);
|
1, rtmetric);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_rtmetric(tc);
|
||||||
|
}*/
|
||||||
|
static void
|
||||||
|
received_announcement(struct announcement *a, rimeaddr_t *from,
|
||||||
|
uint16_t id, uint16_t value)
|
||||||
|
{
|
||||||
|
struct collect_conn *tc = (struct collect_conn *)
|
||||||
|
((char *)a - offsetof(struct collect_conn, announcement));
|
||||||
|
struct neighbor *n;
|
||||||
|
|
||||||
|
n = neighbor_find(from);
|
||||||
|
|
||||||
|
if(n == NULL) {
|
||||||
|
neighbor_add(from, value, 1);
|
||||||
|
} else {
|
||||||
|
neighbor_update(n, value);
|
||||||
|
PRINTF("%d.%d: updating neighbor %d.%d, etx %d, hops %d\n",
|
||||||
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||||
|
n->addr.u8[0], n->addr.u8[1],
|
||||||
|
1, value);
|
||||||
|
}
|
||||||
|
|
||||||
update_rtmetric(tc);
|
update_rtmetric(tc);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static const struct runicast_callbacks runicast_callbacks = {node_packet_received,
|
static const struct runicast_callbacks runicast_callbacks = {node_packet_received,
|
||||||
node_packet_sent,
|
node_packet_sent,
|
||||||
node_packet_timedout};
|
node_packet_timedout};
|
||||||
static const struct neighbor_discovery_callbacks neighbor_discovery_callbacks =
|
/*static const struct neighbor_discovery_callbacks neighbor_discovery_callbacks =
|
||||||
{ adv_received, NULL};
|
{ adv_received, NULL};*/
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
collect_open(struct collect_conn *tc, uint16_t channels,
|
collect_open(struct collect_conn *tc, uint16_t channels,
|
||||||
const struct collect_callbacks *cb)
|
const struct collect_callbacks *cb)
|
||||||
{
|
{
|
||||||
neighbor_discovery_open(&tc->neighbor_discovery_conn, channels,
|
/* neighbor_discovery_open(&tc->neighbor_discovery_conn, channels,
|
||||||
CLOCK_SECOND * 2,
|
CLOCK_SECOND * 2,
|
||||||
CLOCK_SECOND * 10,
|
CLOCK_SECOND * 10,
|
||||||
CLOCK_SECOND * 60,
|
CLOCK_SECOND * 60,
|
||||||
&neighbor_discovery_callbacks);
|
&neighbor_discovery_callbacks);*/
|
||||||
runicast_open(&tc->runicast_conn, channels + 1, &runicast_callbacks);
|
runicast_open(&tc->runicast_conn, channels + 1, &runicast_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;
|
||||||
neighbor_discovery_set_val(&tc->neighbor_discovery_conn, tc->rtmetric);
|
/* neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric);*/
|
||||||
|
announcement_register(&tc->announcement, channels, tc->rtmetric,
|
||||||
|
received_announcement);
|
||||||
|
announcement_listen(2);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
collect_close(struct collect_conn *tc)
|
collect_close(struct collect_conn *tc)
|
||||||
{
|
{
|
||||||
neighbor_discovery_close(&tc->neighbor_discovery_conn);
|
/* neighbor_discovery_close(&tc->neighbor_discovery_conn);*/
|
||||||
|
announcement_remove(&tc->announcement);
|
||||||
runicast_close(&tc->runicast_conn);
|
runicast_close(&tc->runicast_conn);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
@ -310,10 +324,12 @@ collect_set_sink(struct collect_conn *tc, int should_be_sink)
|
||||||
{
|
{
|
||||||
if(should_be_sink) {
|
if(should_be_sink) {
|
||||||
tc->rtmetric = SINK;
|
tc->rtmetric = SINK;
|
||||||
neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric);
|
/* neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric);*/
|
||||||
|
announcement_set_value(&tc->announcement, tc->rtmetric);
|
||||||
} else {
|
} else {
|
||||||
tc->rtmetric = RTMETRIC_MAX;
|
tc->rtmetric = RTMETRIC_MAX;
|
||||||
}
|
}
|
||||||
|
announcement_set_value(&tc->announcement, tc->rtmetric);
|
||||||
update_rtmetric(tc);
|
update_rtmetric(tc);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -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.8 2008/07/03 21:52:25 adamdunkels Exp $
|
* $Id: collect.h,v 1.9 2009/02/09 20:58:25 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,9 +60,8 @@
|
||||||
#ifndef __COLLECT_H__
|
#ifndef __COLLECT_H__
|
||||||
#define __COLLECT_H__
|
#define __COLLECT_H__
|
||||||
|
|
||||||
#include "net/rime/ipolite.h"
|
#include "net/rime/announcement.h"
|
||||||
#include "net/rime/runicast.h"
|
#include "net/rime/runicast.h"
|
||||||
#include "net/rime/neighbor-discovery.h"
|
|
||||||
|
|
||||||
#define COLLECT_ATTRIBUTES { RIMEBUF_ADDR_ESENDER, RIMEBUF_ADDRSIZE }, \
|
#define COLLECT_ATTRIBUTES { RIMEBUF_ADDR_ESENDER, RIMEBUF_ADDRSIZE }, \
|
||||||
{ RIMEBUF_ATTR_EPACKET_ID, RIMEBUF_ATTR_BIT * 2 }, \
|
{ RIMEBUF_ATTR_EPACKET_ID, RIMEBUF_ATTR_BIT * 2 }, \
|
||||||
|
@ -77,8 +76,8 @@ struct collect_callbacks {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct collect_conn {
|
struct collect_conn {
|
||||||
struct neighbor_discovery_conn neighbor_discovery_conn;
|
|
||||||
struct runicast_conn runicast_conn;
|
struct runicast_conn runicast_conn;
|
||||||
|
struct announcement announcement;
|
||||||
const struct collect_callbacks *cb;
|
const struct collect_callbacks *cb;
|
||||||
struct ctimer t;
|
struct ctimer t;
|
||||||
uint16_t rtmetric;
|
uint16_t rtmetric;
|
||||||
|
|
Loading…
Reference in a new issue