2007-03-31 20:33:04 +02:00
|
|
|
/**
|
|
|
|
* \addtogroup rimetree
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2007-03-15 21:04:30 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This file is part of the Contiki operating system.
|
|
|
|
*
|
2007-11-13 21:39:29 +01:00
|
|
|
* $Id: tree.c,v 1.13 2007/11/13 20:39:29 adamdunkels Exp $
|
2007-03-15 21:04:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
2007-03-31 20:33:04 +02:00
|
|
|
* Tree-based hop-by-hop reliable data collection
|
2007-03-15 21:04:30 +01:00
|
|
|
* \author
|
|
|
|
* Adam Dunkels <adam@sics.se>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "contiki.h"
|
|
|
|
|
|
|
|
#include "net/rime.h"
|
|
|
|
#include "net/rime/neighbor.h"
|
2007-03-25 14:06:39 +02:00
|
|
|
#include "net/rime/nf.h"
|
2007-03-22 00:22:42 +01:00
|
|
|
#include "net/rime/tree.h"
|
2007-03-15 21:04:30 +01:00
|
|
|
|
|
|
|
#include "dev/radio-sensor.h"
|
|
|
|
|
|
|
|
#if NETSIM
|
|
|
|
#include "ether.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2007-03-22 19:54:22 +01:00
|
|
|
#include <stddef.h>
|
2007-03-15 21:04:30 +01:00
|
|
|
|
2007-11-13 21:39:29 +01:00
|
|
|
/*
|
2007-03-22 19:54:22 +01:00
|
|
|
struct adv_msg {
|
2007-11-13 21:39:29 +01:00
|
|
|
u8_t rtmetric;
|
2007-03-22 19:54:22 +01:00
|
|
|
u8_t pad;
|
|
|
|
};
|
2007-11-13 21:39:29 +01:00
|
|
|
*/
|
2007-03-15 21:04:30 +01:00
|
|
|
|
|
|
|
struct hdr {
|
|
|
|
rimeaddr_t originator;
|
|
|
|
u8_t originator_seqno;
|
2007-11-13 21:39:29 +01:00
|
|
|
u8_t rtmetric;
|
2007-03-15 21:04:30 +01:00
|
|
|
u8_t hoplim;
|
2007-05-22 22:57:44 +02:00
|
|
|
u8_t rexmits;
|
2007-03-15 21:04:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#define SINK 0
|
2007-11-13 21:39:29 +01:00
|
|
|
#define RTMETRIC_MAX TREE_MAX_DEPTH
|
2007-03-15 21:04:30 +01:00
|
|
|
|
|
|
|
#define MAX_HOPLIM 10
|
|
|
|
|
2007-03-31 20:33:04 +02:00
|
|
|
#define MAX_INTERVAL CLOCK_SECOND * 10
|
|
|
|
#define MIN_INTERVAL CLOCK_SECOND * 2
|
|
|
|
|
|
|
|
#define DEBUG 0
|
|
|
|
#if DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
#define PRINTF(...) printf(__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define PRINTF(...)
|
|
|
|
#endif
|
2007-03-15 21:04:30 +01:00
|
|
|
|
2007-03-31 20:33:04 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2007-11-13 21:39:29 +01:00
|
|
|
update_rtmetric(struct tree_conn *tc)
|
2007-03-15 21:04:30 +01:00
|
|
|
{
|
|
|
|
struct neighbor *n;
|
2007-11-13 21:39:29 +01:00
|
|
|
|
|
|
|
/* We should only update the rtmetric if we are not the sink. */
|
|
|
|
if(tc->local_rtmetric != SINK) {
|
|
|
|
|
|
|
|
/* Find the neighbor with the lowest rtmetric. */
|
2007-03-15 21:04:30 +01:00
|
|
|
n = neighbor_best();
|
2007-11-13 21:39:29 +01:00
|
|
|
|
|
|
|
/* If n is NULL, we have no best neighbor. */
|
2007-03-15 21:04:30 +01:00
|
|
|
if(n == NULL) {
|
2007-11-13 21:39:29 +01:00
|
|
|
|
|
|
|
/* If we have don't have any neighbors, we set our rtmetric to
|
|
|
|
the maximum value to indicate that we do not have a route. */
|
|
|
|
|
|
|
|
if(tc->local_rtmetric != RTMETRIC_MAX) {
|
|
|
|
PRINTF("%d.%d: didn't find a best neighbor, setting rtmetric to max\n",
|
2007-05-15 10:09:21 +02:00
|
|
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
|
|
|
}
|
2007-11-13 21:39:29 +01:00
|
|
|
tc->local_rtmetric = RTMETRIC_MAX;
|
2007-03-15 21:04:30 +01:00
|
|
|
} else {
|
2007-11-13 21:39:29 +01:00
|
|
|
|
|
|
|
/* We set our rtmetric to the rtmetric of our best neighbor plus
|
|
|
|
the expected transmissions to reach that neighbor. */
|
|
|
|
if(n->rtmetric + neighbor_etx(n) != tc->local_rtmetric) {
|
|
|
|
tc->local_rtmetric = n->rtmetric + neighbor_etx(n);
|
|
|
|
nbh_start(&tc->nbh_conn, tc->local_rtmetric);
|
|
|
|
/* send_adv(tc, MIN_INTERVAL);*/
|
|
|
|
PRINTF("%d.%d: new rtmetric %d\n",
|
2007-05-15 10:09:21 +02:00
|
|
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
2007-11-13 21:39:29 +01:00
|
|
|
tc->local_rtmetric);
|
2007-03-15 21:04:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-13 21:39:29 +01:00
|
|
|
/* DEBUG_PRINTF("%d: new rtmetric %d\n", node_id, rtmetric);*/
|
2007-03-15 21:04:30 +01:00
|
|
|
#if NETSIM
|
|
|
|
{
|
|
|
|
char buf[8];
|
2007-11-13 21:39:29 +01:00
|
|
|
if(tc->local_rtmetric == RTMETRIC_MAX) {
|
2007-03-15 21:04:30 +01:00
|
|
|
strcpy(buf, " ");
|
|
|
|
} else {
|
2007-11-13 21:39:29 +01:00
|
|
|
snprintf(buf, sizeof(buf), "%d", tc->local_rtmetric);
|
2007-03-15 21:04:30 +01:00
|
|
|
}
|
|
|
|
ether_set_text(buf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2007-11-13 21:39:29 +01:00
|
|
|
#if 0
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
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->rtmetric = tc->local_rtmetric;
|
|
|
|
ipolite_send(&tc->ipolite_conn, interval, rimebuf_totlen());
|
|
|
|
}
|
2007-03-15 21:04:30 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2007-05-15 10:09:21 +02:00
|
|
|
adv_packet_received(struct ipolite_conn *c, rimeaddr_t *from)
|
2007-03-22 19:54:22 +01:00
|
|
|
{
|
|
|
|
struct tree_conn *tc = (struct tree_conn *)
|
2007-05-15 10:09:21 +02:00
|
|
|
((char *)c - offsetof(struct tree_conn, ipolite_conn));
|
2007-03-22 19:54:22 +01:00
|
|
|
struct adv_msg *msg = rimebuf_dataptr();
|
2007-03-15 21:04:30 +01:00
|
|
|
struct neighbor *n;
|
|
|
|
|
2007-11-13 21:39:29 +01:00
|
|
|
/* PRINTF("%d.%d: adv_packet_received from %d.%d with rtmetric %d\n",
|
2007-03-31 20:33:04 +02:00
|
|
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
2007-11-13 21:39:29 +01:00
|
|
|
from->u8[0], from->u8[1], msg->rtmetric);*/
|
2007-03-31 20:33:04 +02:00
|
|
|
|
2007-03-15 21:04:30 +01:00
|
|
|
n = neighbor_find(from);
|
|
|
|
|
|
|
|
if(n == NULL) {
|
2007-11-13 21:39:29 +01:00
|
|
|
neighbor_add(from, msg->rtmetric, radio_sensor.value(1));
|
2007-03-15 21:04:30 +01:00
|
|
|
} else {
|
2007-11-13 21:39:29 +01:00
|
|
|
neighbor_update(n, msg->rtmetric, radio_sensor.value(1));
|
2007-05-15 10:09:21 +02:00
|
|
|
PRINTF("%d.%d: updating neighbor %d.%d, radio sensor %d, hops %d\n",
|
|
|
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
|
|
|
n->addr.u8[0], n->addr.u8[1],
|
2007-11-13 21:39:29 +01:00
|
|
|
radio_sensor.value(1), msg->rtmetric);
|
2007-03-15 21:04:30 +01:00
|
|
|
}
|
|
|
|
|
2007-11-13 21:39:29 +01:00
|
|
|
update_rtmetric(tc);
|
2007-03-15 21:04:30 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-22 19:54:22 +01:00
|
|
|
static void
|
2007-05-15 10:09:21 +02:00
|
|
|
adv_packet_sent(struct ipolite_conn *c)
|
2007-03-22 19:54:22 +01:00
|
|
|
{
|
|
|
|
struct tree_conn *tc = (struct tree_conn *)
|
2007-05-15 10:09:21 +02:00
|
|
|
((char *)c - offsetof(struct tree_conn, ipolite_conn));
|
|
|
|
/* send_adv(tc, MAX_INTERVAL);*/
|
2007-03-22 19:54:22 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2007-05-15 10:09:21 +02:00
|
|
|
adv_packet_dropped(struct ipolite_conn *c)
|
2007-03-22 19:54:22 +01:00
|
|
|
{
|
|
|
|
struct tree_conn *tc = (struct tree_conn *)
|
2007-05-15 10:09:21 +02:00
|
|
|
((char *)c - offsetof(struct tree_conn, ipolite_conn));
|
|
|
|
/* send_adv(tc, MAX_INTERVAL);*/
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
send_timer(void *ptr)
|
|
|
|
{
|
|
|
|
struct tree_conn *tc = ptr;
|
|
|
|
|
|
|
|
send_adv(tc, MAX_INTERVAL / 2);
|
|
|
|
ctimer_set(&tc->t, MAX_INTERVAL, send_timer, tc);
|
2007-03-22 19:54:22 +01:00
|
|
|
}
|
2007-11-13 21:39:29 +01:00
|
|
|
#endif /* 0 */
|
2007-03-22 19:54:22 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-15 21:04:30 +01:00
|
|
|
static int
|
|
|
|
node_packet_received(struct ruc_conn *c, rimeaddr_t *from, u8_t seqno)
|
|
|
|
{
|
2007-03-22 19:54:22 +01:00
|
|
|
struct tree_conn *tc = (struct tree_conn *)
|
|
|
|
((char *)c - offsetof(struct tree_conn, ruc_conn));
|
2007-03-15 21:04:30 +01:00
|
|
|
struct hdr *hdr = rimebuf_dataptr();
|
|
|
|
struct neighbor *n;
|
|
|
|
|
2007-11-13 21:39:29 +01:00
|
|
|
if(tc->local_rtmetric == SINK) {
|
2007-03-22 19:54:22 +01:00
|
|
|
|
2007-03-25 23:44:06 +02:00
|
|
|
rimebuf_hdrreduce(sizeof(struct hdr));
|
2007-03-31 20:33:04 +02:00
|
|
|
|
2007-11-13 21:39:29 +01:00
|
|
|
PRINTF("%d.%d: sink received packet from %d.%d via %d.%d with rtmetric %d\n",
|
2007-03-31 20:33:04 +02:00
|
|
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
|
|
|
hdr->originator.u8[0], hdr->originator.u8[1],
|
2007-11-13 21:39:29 +01:00
|
|
|
from->u8[0], from->u8[1], hdr->rtmetric);
|
2007-03-31 20:33:04 +02:00
|
|
|
|
2007-03-22 19:54:22 +01:00
|
|
|
if(tc->cb->recv != NULL) {
|
|
|
|
tc->cb->recv(&hdr->originator, hdr->originator_seqno,
|
2007-11-13 21:39:29 +01:00
|
|
|
hdr->rtmetric);
|
2007-03-15 21:04:30 +01:00
|
|
|
}
|
|
|
|
return 1;
|
2007-11-13 21:39:29 +01:00
|
|
|
} else if(hdr->hoplim > 1 && tc->local_rtmetric != RTMETRIC_MAX) {
|
2007-03-22 00:22:42 +01:00
|
|
|
hdr->hoplim--;
|
2007-03-31 20:33:04 +02:00
|
|
|
|
|
|
|
|
2007-11-13 21:39:29 +01:00
|
|
|
PRINTF("%d.%d: packet received from %d.%d via %d.%d with rtmetric %d, best neighbor %p, forwarding %d\n",
|
2007-03-31 20:33:04 +02:00
|
|
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
|
|
|
|
hdr->originator.u8[0], hdr->originator.u8[1],
|
2007-11-13 21:39:29 +01:00
|
|
|
from->u8[0], from->u8[1], hdr->rtmetric,
|
2007-03-31 20:33:04 +02:00
|
|
|
neighbor_best(), tc->forwarding);
|
|
|
|
|
2007-03-22 19:54:22 +01:00
|
|
|
if(!tc->forwarding) {
|
|
|
|
tc->forwarding = 1;
|
2007-03-15 21:04:30 +01:00
|
|
|
n = neighbor_best();
|
|
|
|
if(n != NULL) {
|
2007-05-22 22:57:44 +02:00
|
|
|
ruc_send(c, &n->addr, hdr->rexmits);
|
2007-03-15 21:04:30 +01:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
|
2007-03-31 20:33:04 +02:00
|
|
|
PRINTF("%d.%d: still forwarding another packet, not sending ACK\n",
|
|
|
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
2007-03-15 21:04:30 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2007-11-13 21:39:29 +01:00
|
|
|
node_packet_sent(struct ruc_conn *c, rimeaddr_t *to, u8_t retransmissions)
|
2007-03-15 21:04:30 +01:00
|
|
|
{
|
2007-03-22 19:54:22 +01:00
|
|
|
struct tree_conn *tc = (struct tree_conn *)
|
|
|
|
((char *)c - offsetof(struct tree_conn, ruc_conn));
|
|
|
|
|
|
|
|
tc->forwarding = 0;
|
2007-11-13 21:39:29 +01:00
|
|
|
neighbor_update_etx(neighbor_find(to), retransmissions);
|
2007-03-15 21:04:30 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-05-15 10:09:21 +02:00
|
|
|
static void
|
2007-11-13 21:39:29 +01:00
|
|
|
node_packet_timedout(struct ruc_conn *c, rimeaddr_t *to, u8_t retransmissions)
|
2007-05-15 10:09:21 +02:00
|
|
|
{
|
|
|
|
struct tree_conn *tc = (struct tree_conn *)
|
|
|
|
((char *)c - offsetof(struct tree_conn, ruc_conn));
|
|
|
|
|
|
|
|
tc->forwarding = 0;
|
2007-11-13 21:39:29 +01:00
|
|
|
neighbor_timedout_etx(neighbor_find(to), retransmissions);
|
2007-05-15 10:09:21 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-11-13 21:39:29 +01:00
|
|
|
static void
|
|
|
|
adv_received(struct nbh_conn *c, rimeaddr_t *from, uint16_t rtmetric)
|
|
|
|
{
|
|
|
|
struct tree_conn *tc = (struct tree_conn *)
|
|
|
|
((char *)c - offsetof(struct tree_conn, nbh_conn));
|
|
|
|
struct neighbor *n;
|
|
|
|
|
|
|
|
n = neighbor_find(from);
|
|
|
|
|
|
|
|
if(n == NULL) {
|
|
|
|
if(rtmetric < tc->local_rtmetric) {
|
|
|
|
neighbor_add(from, rtmetric, 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
neighbor_update(n, rtmetric, 1);
|
|
|
|
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, rtmetric);
|
|
|
|
}
|
|
|
|
|
|
|
|
update_rtmetric(tc);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/*static const struct ipolite_callbacks ipolite_callbacks =
|
|
|
|
{adv_packet_received, adv_packet_sent, adv_packet_dropped};*/
|
2007-03-15 21:04:30 +01:00
|
|
|
static const struct ruc_callbacks ruc_callbacks = {node_packet_received,
|
2007-05-15 10:09:21 +02:00
|
|
|
node_packet_sent,
|
|
|
|
node_packet_timedout};
|
2007-11-13 21:39:29 +01:00
|
|
|
static const struct nbh_callbacks nbh_callbacks = { adv_received,
|
|
|
|
NULL};
|
2007-03-15 21:04:30 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2007-03-22 19:54:22 +01:00
|
|
|
tree_open(struct tree_conn *tc, u16_t channels,
|
|
|
|
const struct tree_callbacks *cb)
|
2007-03-15 21:04:30 +01:00
|
|
|
{
|
2007-11-13 21:39:29 +01:00
|
|
|
/* ipolite_open(&tc->ipolite_conn, channels, &ipolite_callbacks);*/
|
|
|
|
nbh_open(&tc->nbh_conn, channels, &nbh_callbacks);
|
2007-03-22 19:54:22 +01:00
|
|
|
ruc_open(&tc->ruc_conn, channels + 1, &ruc_callbacks);
|
2007-11-13 21:39:29 +01:00
|
|
|
tc->local_rtmetric = RTMETRIC_MAX;
|
2007-03-22 19:54:22 +01:00
|
|
|
tc->cb = cb;
|
2007-11-13 21:39:29 +01:00
|
|
|
/* send_adv(tc, MAX_INTERVAL);
|
|
|
|
ctimer_set(&tc->t, MAX_INTERVAL, send_timer, tc);*/
|
2007-03-15 21:04:30 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-19 23:10:16 +01:00
|
|
|
void
|
2007-03-22 19:54:22 +01:00
|
|
|
tree_close(struct tree_conn *tc)
|
2007-03-19 23:10:16 +01:00
|
|
|
{
|
2007-11-13 21:39:29 +01:00
|
|
|
/* ipolite_close(&tc->ipolite_conn);*/
|
|
|
|
nbh_close(&tc->nbh_conn);
|
2007-03-22 19:54:22 +01:00
|
|
|
ruc_close(&tc->ruc_conn);
|
2007-03-19 23:10:16 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-15 21:04:30 +01:00
|
|
|
void
|
2007-03-22 19:54:22 +01:00
|
|
|
tree_set_sink(struct tree_conn *tc, int should_be_sink)
|
2007-03-15 21:04:30 +01:00
|
|
|
{
|
|
|
|
if(should_be_sink) {
|
2007-11-13 21:39:29 +01:00
|
|
|
tc->local_rtmetric = SINK;
|
|
|
|
/* send_adv(tc, MIN_INTERVAL);*/
|
|
|
|
nbh_start(&tc->nbh_conn, tc->local_rtmetric);
|
2007-03-15 21:04:30 +01:00
|
|
|
} else {
|
2007-11-13 21:39:29 +01:00
|
|
|
tc->local_rtmetric = RTMETRIC_MAX;
|
2007-03-15 21:04:30 +01:00
|
|
|
}
|
2007-11-13 21:39:29 +01:00
|
|
|
update_rtmetric(tc);
|
2007-03-15 21:04:30 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2007-05-22 22:57:44 +02:00
|
|
|
tree_send(struct tree_conn *tc, int rexmits)
|
2007-03-15 21:04:30 +01:00
|
|
|
{
|
|
|
|
struct neighbor *n;
|
|
|
|
struct hdr *hdr;
|
|
|
|
|
2007-05-15 10:09:21 +02:00
|
|
|
|
2007-03-23 11:46:35 +01:00
|
|
|
if(rimebuf_hdralloc(sizeof(struct hdr))) {
|
2007-03-15 21:04:30 +01:00
|
|
|
hdr = rimebuf_hdrptr();
|
2007-03-22 19:54:22 +01:00
|
|
|
hdr->originator_seqno = tc->seqno++;
|
2007-03-15 21:04:30 +01:00
|
|
|
rimeaddr_copy(&hdr->originator, &rimeaddr_node_addr);
|
2007-11-13 21:39:29 +01:00
|
|
|
hdr->rtmetric = tc->local_rtmetric;
|
2007-03-15 21:04:30 +01:00
|
|
|
hdr->hoplim = MAX_HOPLIM;
|
2007-05-22 22:57:44 +02:00
|
|
|
hdr->rexmits = rexmits;
|
2007-11-13 21:39:29 +01:00
|
|
|
if(tc->local_rtmetric == 0) {
|
2007-05-22 22:57:44 +02:00
|
|
|
if(tc->cb->recv != NULL) {
|
|
|
|
tc->cb->recv(&hdr->originator, hdr->originator_seqno,
|
2007-11-13 21:39:29 +01:00
|
|
|
hdr->rtmetric);
|
|
|
|
}
|
2007-03-15 21:04:30 +01:00
|
|
|
} else {
|
2007-05-22 22:57:44 +02:00
|
|
|
n = neighbor_best();
|
|
|
|
if(n != NULL) {
|
|
|
|
/* printf("Sending to best neighbor\n");*/
|
|
|
|
ruc_send(&tc->ruc_conn, &n->addr, rexmits);
|
|
|
|
} else {
|
|
|
|
/* printf("Didn't find any neighbor\n");*/
|
|
|
|
PRINTF("%d.%d: did not find any neighbor to send to\n",
|
|
|
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
|
|
|
}
|
2007-03-15 21:04:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
int
|
2007-03-22 19:54:22 +01:00
|
|
|
tree_depth(struct tree_conn *tc)
|
2007-03-15 21:04:30 +01:00
|
|
|
{
|
2007-11-13 21:39:29 +01:00
|
|
|
return tc->local_rtmetric;
|
2007-03-15 21:04:30 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-31 20:33:04 +02:00
|
|
|
/** @} */
|