mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-09-04 21:29:00 +00:00
Made advertisments for new shorter routes quicker, and advertisements for longer routes slower
This commit is contained in:
parent
0650a014b5
commit
91aa54dc77
@ -1,3 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* \addtogroup rimetree
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@ -28,12 +33,12 @@
|
|||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* $Id: tree.c,v 1.9 2007/03/25 21:44:06 adamdunkels Exp $
|
* $Id: tree.c,v 1.10 2007/03/31 18:33:04 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* A brief description of what this file is.
|
* Tree-based hop-by-hop reliable data collection
|
||||||
* \author
|
* \author
|
||||||
* Adam Dunkels <adam@sics.se>
|
* Adam Dunkels <adam@sics.se>
|
||||||
*/
|
*/
|
||||||
@ -65,9 +70,6 @@ struct hdr {
|
|||||||
u8_t originator_seqno;
|
u8_t originator_seqno;
|
||||||
u8_t hopcount;
|
u8_t hopcount;
|
||||||
u8_t hoplim;
|
u8_t hoplim;
|
||||||
u8_t retransmissions;
|
|
||||||
u8_t datalen;
|
|
||||||
u8_t data[1];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SINK 0
|
#define SINK 0
|
||||||
@ -75,8 +77,31 @@ struct hdr {
|
|||||||
|
|
||||||
#define MAX_HOPLIM 10
|
#define MAX_HOPLIM 10
|
||||||
|
|
||||||
#define MAX_INTERVAL CLOCK_SECOND * 4
|
#define MAX_INTERVAL CLOCK_SECOND * 10
|
||||||
|
#define MIN_INTERVAL CLOCK_SECOND * 2
|
||||||
|
|
||||||
|
#define MAX_RETRANSMISSIONS 3
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
#if DEBUG
|
||||||
|
#include <stdio.h>
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define PRINTF(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
send_adv(struct tree_conn *tc, clock_time_t interval)
|
||||||
|
{
|
||||||
|
struct adv_msg *hdr;
|
||||||
|
|
||||||
|
rimebuf_clear();
|
||||||
|
rimebuf_set_datalen(sizeof(struct adv_msg));
|
||||||
|
hdr = rimebuf_dataptr();
|
||||||
|
hdr->hopcount = tc->hops_from_sink;
|
||||||
|
uibc_send(&tc->uibc_conn, interval);
|
||||||
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
update_hopcount(struct tree_conn *tc)
|
update_hopcount(struct tree_conn *tc)
|
||||||
@ -93,6 +118,7 @@ update_hopcount(struct tree_conn *tc)
|
|||||||
} else {
|
} else {
|
||||||
if(n->hopcount + 1 != tc->hops_from_sink) {
|
if(n->hopcount + 1 != tc->hops_from_sink) {
|
||||||
tc->hops_from_sink = n->hopcount + 1;
|
tc->hops_from_sink = n->hopcount + 1;
|
||||||
|
send_adv(tc, MIN_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,18 +138,6 @@ update_hopcount(struct tree_conn *tc)
|
|||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
send_adv(struct tree_conn *tc)
|
|
||||||
{
|
|
||||||
struct adv_msg *hdr;
|
|
||||||
|
|
||||||
rimebuf_clear();
|
|
||||||
rimebuf_set_datalen(sizeof(struct adv_msg));
|
|
||||||
hdr = rimebuf_dataptr();
|
|
||||||
hdr->hopcount = tc->hops_from_sink;
|
|
||||||
uibc_send(&tc->uibc_conn, MAX_INTERVAL);
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
adv_packet_received(struct uibc_conn *c, rimeaddr_t *from)
|
adv_packet_received(struct uibc_conn *c, rimeaddr_t *from)
|
||||||
{
|
{
|
||||||
struct tree_conn *tc = (struct tree_conn *)
|
struct tree_conn *tc = (struct tree_conn *)
|
||||||
@ -131,9 +145,9 @@ adv_packet_received(struct uibc_conn *c, rimeaddr_t *from)
|
|||||||
struct adv_msg *msg = rimebuf_dataptr();
|
struct adv_msg *msg = rimebuf_dataptr();
|
||||||
struct neighbor *n;
|
struct neighbor *n;
|
||||||
|
|
||||||
/* printf("%d: neighbor_packet_received from %d with hopcount %d\n",
|
/* PRINTF("%d.%d: adv_packet_received from %d.%d with hopcount %d\n",
|
||||||
node_id, from, hdr->hopcount
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||||
);*/
|
from->u8[0], from->u8[1], msg->hopcount);*/
|
||||||
|
|
||||||
n = neighbor_find(from);
|
n = neighbor_find(from);
|
||||||
|
|
||||||
@ -152,7 +166,7 @@ adv_packet_sent(struct uibc_conn *c)
|
|||||||
{
|
{
|
||||||
struct tree_conn *tc = (struct tree_conn *)
|
struct tree_conn *tc = (struct tree_conn *)
|
||||||
((char *)c - offsetof(struct tree_conn, uibc_conn));
|
((char *)c - offsetof(struct tree_conn, uibc_conn));
|
||||||
send_adv(tc);
|
send_adv(tc, MAX_INTERVAL);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
@ -160,7 +174,7 @@ adv_packet_dropped(struct uibc_conn *c)
|
|||||||
{
|
{
|
||||||
struct tree_conn *tc = (struct tree_conn *)
|
struct tree_conn *tc = (struct tree_conn *)
|
||||||
((char *)c - offsetof(struct tree_conn, uibc_conn));
|
((char *)c - offsetof(struct tree_conn, uibc_conn));
|
||||||
send_adv(tc);
|
send_adv(tc, MAX_INTERVAL);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
@ -174,26 +188,38 @@ node_packet_received(struct ruc_conn *c, rimeaddr_t *from, u8_t seqno)
|
|||||||
if(tc->hops_from_sink == SINK) {
|
if(tc->hops_from_sink == SINK) {
|
||||||
|
|
||||||
rimebuf_hdrreduce(sizeof(struct hdr));
|
rimebuf_hdrreduce(sizeof(struct hdr));
|
||||||
|
|
||||||
|
PRINTF("%d.%d: sink received packet from %d.%d via %d.%d with hopcount %d\n",
|
||||||
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||||
|
hdr->originator.u8[0], hdr->originator.u8[1],
|
||||||
|
from->u8[0], from->u8[1], hdr->hopcount);
|
||||||
|
|
||||||
if(tc->cb->recv != NULL) {
|
if(tc->cb->recv != NULL) {
|
||||||
tc->cb->recv(&hdr->originator, hdr->originator_seqno,
|
tc->cb->recv(&hdr->originator, hdr->originator_seqno,
|
||||||
hdr->hopcount, hdr->retransmissions);
|
hdr->hopcount);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
} else if(hdr->hoplim > 1 && tc->hops_from_sink != HOPCOUNT_MAX) {
|
} else if(hdr->hoplim > 1 && tc->hops_from_sink != HOPCOUNT_MAX) {
|
||||||
hdr->hoplim--;
|
hdr->hoplim--;
|
||||||
/* printf("%d: packet received from %d, forwarding %d, best neighbor %p\n",
|
|
||||||
rimeaddr_node_addr.u16[0], from->u16[0], tc->forwarding, neighbor_best());*/
|
|
||||||
|
PRINTF("%d.%d: packet received from %d.%d via %d.%d with hopcount %d, best neighbor %p, forwarding %d\n",
|
||||||
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
||||||
|
hdr->originator.u8[0], hdr->originator.u8[1],
|
||||||
|
from->u8[0], from->u8[1], hdr->hopcount,
|
||||||
|
neighbor_best(), tc->forwarding);
|
||||||
|
|
||||||
if(!tc->forwarding) {
|
if(!tc->forwarding) {
|
||||||
tc->forwarding = 1;
|
tc->forwarding = 1;
|
||||||
n = neighbor_best();
|
n = neighbor_best();
|
||||||
if(n != NULL) {
|
if(n != NULL) {
|
||||||
ruc_send(c, &n->addr);
|
ruc_send(c, &n->addr, MAX_RETRANSMISSIONS);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* printf("%d: still forwarding another packet, not sending ACK\n",
|
PRINTF("%d.%d: still forwarding another packet, not sending ACK\n",
|
||||||
rimeaddr_node_addr.u16[0]);*/
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,7 +251,7 @@ tree_open(struct tree_conn *tc, u16_t channels,
|
|||||||
rimebuf_reference(&tc.hello, sizeof(tc.hello));
|
rimebuf_reference(&tc.hello, sizeof(tc.hello));
|
||||||
sibc_send_stubborn(&sibc_conn, CLOCK_SECOND * 8);*/
|
sibc_send_stubborn(&sibc_conn, CLOCK_SECOND * 8);*/
|
||||||
tc->cb = cb;
|
tc->cb = cb;
|
||||||
send_adv(tc);
|
send_adv(tc, MAX_INTERVAL);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
@ -240,6 +266,7 @@ tree_set_sink(struct tree_conn *tc, int should_be_sink)
|
|||||||
{
|
{
|
||||||
if(should_be_sink) {
|
if(should_be_sink) {
|
||||||
tc->hops_from_sink = SINK;
|
tc->hops_from_sink = SINK;
|
||||||
|
send_adv(tc, MIN_INTERVAL);
|
||||||
} else {
|
} else {
|
||||||
tc->hops_from_sink = HOPCOUNT_MAX;
|
tc->hops_from_sink = HOPCOUNT_MAX;
|
||||||
}
|
}
|
||||||
@ -258,12 +285,10 @@ tree_send(struct tree_conn *tc)
|
|||||||
rimeaddr_copy(&hdr->originator, &rimeaddr_node_addr);
|
rimeaddr_copy(&hdr->originator, &rimeaddr_node_addr);
|
||||||
hdr->hopcount = tc->hops_from_sink;
|
hdr->hopcount = tc->hops_from_sink;
|
||||||
hdr->hoplim = MAX_HOPLIM;
|
hdr->hoplim = MAX_HOPLIM;
|
||||||
hdr->retransmissions = 0;
|
|
||||||
hdr->datalen = 0;
|
|
||||||
n = neighbor_best();
|
n = neighbor_best();
|
||||||
if(n != NULL) {
|
if(n != NULL) {
|
||||||
/* printf("Sending to best neighbor\n");*/
|
/* printf("Sending to best neighbor\n");*/
|
||||||
ruc_send(&tc->ruc_conn, &n->addr);
|
ruc_send(&tc->ruc_conn, &n->addr, MAX_RETRANSMISSIONS);
|
||||||
} else {
|
} else {
|
||||||
/* printf("Didn't find any neighbor\n");*/
|
/* printf("Didn't find any neighbor\n");*/
|
||||||
}
|
}
|
||||||
@ -276,3 +301,4 @@ tree_depth(struct tree_conn *tc)
|
|||||||
return tc->hops_from_sink;
|
return tc->hops_from_sink;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/** @} */
|
||||||
|
Loading…
Reference in New Issue
Block a user