Merge branch 'master' of ssh://contiki.git.sourceforge.net/gitroot/contiki/contiki

This commit is contained in:
Nicolas Tsiftes 2012-01-10 16:38:48 +01:00
commit 057398a6d1
4 changed files with 26 additions and 15 deletions

View file

@ -77,16 +77,18 @@ struct neighbor_attr {
#define NEIGHBOR_ATTRIBUTE(type, name, default_value_ptr) \ #define NEIGHBOR_ATTRIBUTE(type, name, default_value_ptr) \
static type _##name##_mem[NEIGHBOR_ATTR_MAX_NEIGHBORS]; \ static type _##name##_mem[NEIGHBOR_ATTR_MAX_NEIGHBORS]; \
static struct neighbor_attr name = \ static struct neighbor_attr name = \
{NULL, sizeof(type), default_value_ptr, (void*)_##name##_mem} ; \ {NULL, sizeof(type), default_value_ptr, (void *)_##name##_mem}
/** Same as NEIGHBOR_ATTRIBUTE, only the attr is not declared static /** Same as NEIGHBOR_ATTRIBUTE, only the attr is not declared static
* this way you can say <tt>extern struct neighbor_attr name</tt> in header to declare * this way you can say <tt>extern struct neighbor_attr name</tt> in header to declare
* a global neighbor attribute * a global neighbor attribute
*/ */
#define NEIGHBOR_ATTRIBUTE_NONSTATIC(type, name, default_value_ptr) \ #define NEIGHBOR_ATTRIBUTE_GLOBAL(type, name, default_value_ptr) \
static type _##name##_mem[MAX_NEIGHBORS]; \ static type _##name##_mem[NEIGHBOR_ATTR_MAX_NEIGHBORS]; \
struct neighbor_attr name = \ struct neighbor_attr name = \
{NULL, sizeof(type), default_value_ptr, (void*)_##name##_mem} ; \ {NULL, sizeof(type), default_value_ptr, (void *)_##name##_mem}
#define NEIGHBOR_ATTRIBUTE_DECLARE(name) extern struct neighbor_attr name
/** /**
* \brief register a neighbor attribute * \brief register a neighbor attribute
@ -103,20 +105,20 @@ struct neighbor_addr *neighbor_attr_list_neighbors(void);
* \brief Check if a neighbor is already added to the neighbor table * \brief Check if a neighbor is already added to the neighbor table
* \retval non-zero if present, zero if not * \retval non-zero if present, zero if not
*/ */
int neighbor_attr_has_neighbor(const rimeaddr_t * addr); int neighbor_attr_has_neighbor(const rimeaddr_t *addr);
/** /**
* \brief Add a neighbor entry to neighbor table * \brief Add a neighbor entry to neighbor table
* \retval -1 if unsuccessful, 0 if the neighbor was already * \retval -1 if unsuccessful, 0 if the neighbor was already
* in the table, and 1 if successful * in the table, and 1 if successful
*/ */
int neighbor_attr_add_neighbor(const rimeaddr_t * addr); int neighbor_attr_add_neighbor(const rimeaddr_t *addr);
/** /**
* \brief Remove a neighbor entry to neighbor table * \brief Remove a neighbor entry to neighbor table
* \retval -1 if unsuccessful, 0 if the neighbor was removed * \retval -1 if unsuccessful, 0 if the neighbor was removed
*/ */
int neighbor_attr_remove_neighbor(const rimeaddr_t * addr); int neighbor_attr_remove_neighbor(const rimeaddr_t *addr);
/** /**
* \brief Get pointer to neighbor table data specified by id * \brief Get pointer to neighbor table data specified by id
@ -129,7 +131,7 @@ int neighbor_attr_remove_neighbor(const rimeaddr_t * addr);
* This pointer should not be saved, as it may point to data from another * This pointer should not be saved, as it may point to data from another
* neighbor in the future if neighbors get removed/added over time. * neighbor in the future if neighbors get removed/added over time.
*/ */
void *neighbor_attr_get_data(struct neighbor_attr *, const rimeaddr_t * addr); void *neighbor_attr_get_data(struct neighbor_attr *, const rimeaddr_t *addr);
/** /**
* \brief Copy data to neighbor table * \brief Copy data to neighbor table
@ -139,7 +141,7 @@ void *neighbor_attr_get_data(struct neighbor_attr *, const rimeaddr_t * addr);
* neighbor and attribute type, and resets timeout for that neighbor. * neighbor and attribute type, and resets timeout for that neighbor.
* If neighbor was not found, this will add a new neighbor to the table. * If neighbor was not found, this will add a new neighbor to the table.
*/ */
int neighbor_attr_set_data(struct neighbor_attr *, const rimeaddr_t * addr, int neighbor_attr_set_data(struct neighbor_attr *, const rimeaddr_t *addr,
void *data); void *data);
/** /**

View file

@ -50,7 +50,8 @@
#define ETX_ALPHA 90 #define ETX_ALPHA 90
#define ETX_NOACK_PENALTY ETX_LIMIT #define ETX_NOACK_PENALTY ETX_LIMIT
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
NEIGHBOR_ATTRIBUTE(link_metric_t, etx, NULL); NEIGHBOR_ATTRIBUTE_GLOBAL(link_metric_t, attr_etx, NULL);
NEIGHBOR_ATTRIBUTE_GLOBAL(unsigned long, attr_timestamp, NULL);
static neighbor_info_subscriber_t subscriber_callback; static neighbor_info_subscriber_t subscriber_callback;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -59,8 +60,9 @@ update_metric(const rimeaddr_t *dest, int packet_metric)
{ {
link_metric_t *metricp; link_metric_t *metricp;
link_metric_t recorded_metric, new_metric; link_metric_t recorded_metric, new_metric;
unsigned long time;
metricp = (link_metric_t *)neighbor_attr_get_data(&etx, dest); metricp = (link_metric_t *)neighbor_attr_get_data(&attr_etx, dest);
packet_metric = NEIGHBOR_INFO_ETX2FIX(packet_metric); packet_metric = NEIGHBOR_INFO_ETX2FIX(packet_metric);
if(metricp == NULL || *metricp == 0) { if(metricp == NULL || *metricp == 0) {
recorded_metric = NEIGHBOR_INFO_ETX2FIX(ETX_LIMIT); recorded_metric = NEIGHBOR_INFO_ETX2FIX(ETX_LIMIT);
@ -79,7 +81,9 @@ update_metric(const rimeaddr_t *dest, int packet_metric)
dest->u8[7]); dest->u8[7]);
if(neighbor_attr_has_neighbor(dest)) { if(neighbor_attr_has_neighbor(dest)) {
neighbor_attr_set_data(&etx, dest, &new_metric); time = clock_seconds();
neighbor_attr_set_data(&attr_etx, dest, &new_metric);
neighbor_attr_set_data(&attr_timestamp, dest, &time);
if(new_metric != recorded_metric && subscriber_callback != NULL) { if(new_metric != recorded_metric && subscriber_callback != NULL) {
subscriber_callback(dest, 1, new_metric); subscriber_callback(dest, 1, new_metric);
} }
@ -168,7 +172,8 @@ int
neighbor_info_subscribe(neighbor_info_subscriber_t s) neighbor_info_subscribe(neighbor_info_subscriber_t s)
{ {
if(subscriber_callback == NULL) { if(subscriber_callback == NULL) {
neighbor_attr_register(&etx); neighbor_attr_register(&attr_etx);
neighbor_attr_register(&attr_timestamp);
subscriber_callback = s; subscriber_callback = s;
return 1; return 1;
} }
@ -181,7 +186,7 @@ neighbor_info_get_metric(const rimeaddr_t *addr)
{ {
link_metric_t *metricp; link_metric_t *metricp;
metricp = (link_metric_t *)neighbor_attr_get_data(&etx, addr); metricp = (link_metric_t *)neighbor_attr_get_data(&attr_etx, addr);
return metricp == NULL ? ETX_LIMIT : *metricp; return metricp == NULL ? ETX_LIMIT : *metricp;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View file

@ -40,6 +40,7 @@
#ifndef NEIGHBOR_INFO_H #ifndef NEIGHBOR_INFO_H
#define NEIGHBOR_INFO_H #define NEIGHBOR_INFO_H
#include "net/neighbor-attr.h"
#include "net/rime.h" #include "net/rime.h"
/* ETX_DIVISOR is the value that a fix-point representation of the ETX /* ETX_DIVISOR is the value that a fix-point representation of the ETX
@ -54,6 +55,9 @@
typedef void (*neighbor_info_subscriber_t)(const rimeaddr_t *, int known, int etx); typedef void (*neighbor_info_subscriber_t)(const rimeaddr_t *, int known, int etx);
typedef uint8_t link_metric_t; typedef uint8_t link_metric_t;
NEIGHBOR_ATTRIBUTE_DECLARE(attr_etx);
NEIGHBOR_ATTRIBUTE_DECLARE(attr_timestamp);
/** /**
* Notify the neighbor information module about the status of * Notify the neighbor information module about the status of
* a packet transmission. * a packet transmission.

2
core/net/rpl/rpl-ext-header.c Executable file → Normal file
View file

@ -168,7 +168,7 @@ rpl_update_header_empty(void)
break; break;
default: default:
PRINTF("RPL: No hop-by-hop option found, creating it\n"); PRINTF("RPL: No hop-by-hop option found, creating it\n");
if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_LINK_MTU) { if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_BUFSIZE) {
PRINTF("RPL: Packet too long: impossible to add hop-by-hop option\n"); PRINTF("RPL: Packet too long: impossible to add hop-by-hop option\n");
uip_ext_len = last_uip_ext_len; uip_ext_len = last_uip_ext_len;
return; return;