added timestamp to neighbor info

This commit is contained in:
Joakim Eriksson 2012-01-10 16:04:56 +01:00
parent 237100f6fa
commit d24ecf8d59
3 changed files with 25 additions and 14 deletions

View file

@ -77,16 +77,18 @@ struct neighbor_attr {
#define NEIGHBOR_ATTRIBUTE(type, name, default_value_ptr) \
static type _##name##_mem[NEIGHBOR_ATTR_MAX_NEIGHBORS]; \
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
* this way you can say <tt>extern struct neighbor_attr name</tt> in header to declare
* a global neighbor attribute
*/
#define NEIGHBOR_ATTRIBUTE_NONSTATIC(type, name, default_value_ptr) \
static type _##name##_mem[MAX_NEIGHBORS]; \
#define NEIGHBOR_ATTRIBUTE_GLOBAL(type, name, default_value_ptr) \
static type _##name##_mem[NEIGHBOR_ATTR_MAX_NEIGHBORS]; \
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
@ -103,20 +105,20 @@ struct neighbor_addr *neighbor_attr_list_neighbors(void);
* \brief Check if a neighbor is already added to the neighbor table
* \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
* \retval -1 if unsuccessful, 0 if the neighbor was already
* 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
* \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
@ -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
* 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
@ -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.
* 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);
/**

View file

@ -50,7 +50,8 @@
#define ETX_ALPHA 90
#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;
/*---------------------------------------------------------------------------*/
@ -59,8 +60,9 @@ update_metric(const rimeaddr_t *dest, int packet_metric)
{
link_metric_t *metricp;
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);
if(metricp == NULL || *metricp == 0) {
recorded_metric = NEIGHBOR_INFO_ETX2FIX(ETX_LIMIT);
@ -79,7 +81,9 @@ update_metric(const rimeaddr_t *dest, int packet_metric)
dest->u8[7]);
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) {
subscriber_callback(dest, 1, new_metric);
}
@ -168,7 +172,8 @@ int
neighbor_info_subscribe(neighbor_info_subscriber_t s)
{
if(subscriber_callback == NULL) {
neighbor_attr_register(&etx);
neighbor_attr_register(&attr_etx);
neighbor_attr_register(&attr_timestamp);
subscriber_callback = s;
return 1;
}
@ -181,7 +186,7 @@ neighbor_info_get_metric(const rimeaddr_t *addr)
{
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;
}
/*---------------------------------------------------------------------------*/

View file

@ -40,6 +40,7 @@
#ifndef NEIGHBOR_INFO_H
#define NEIGHBOR_INFO_H
#include "net/neighbor-attr.h"
#include "net/rime.h"
/* 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 uint8_t link_metric_t;
NEIGHBOR_ATTRIBUTE_DECLARE(attr_etx);
NEIGHBOR_ATTRIBUTE_DECLARE(attr_timestamp);
/**
* Notify the neighbor information module about the status of
* a packet transmission.