41 #include "net/neighbor-attr.h"
43 #define DEBUG DEBUG_NONE
49 #define ETX_NOACK_PENALTY ETX_LIMIT
51 NEIGHBOR_ATTRIBUTE(link_metric_t, etx,
NULL);
53 static neighbor_info_subscriber_t subscriber_callback;
56 update_metric(
const rimeaddr_t *dest,
int packet_metric)
58 link_metric_t *metricp;
59 link_metric_t recorded_metric, new_metric;
61 metricp = (link_metric_t *)neighbor_attr_get_data(&etx, dest);
62 packet_metric = NEIGHBOR_INFO_ETX2FIX(packet_metric);
63 if(metricp ==
NULL || *metricp == 0) {
64 recorded_metric = NEIGHBOR_INFO_ETX2FIX(ETX_LIMIT);
65 new_metric = packet_metric;
67 recorded_metric = *metricp;
69 new_metric = ((uint16_t)recorded_metric * ETX_ALPHA +
70 (uint16_t)packet_metric * (ETX_SCALE - ETX_ALPHA)) / ETX_SCALE;
73 PRINTF(
"neighbor-info: ETX changed from %d to %d (packet ETX = %d) %d\n",
74 NEIGHBOR_INFO_FIX2ETX(recorded_metric),
75 NEIGHBOR_INFO_FIX2ETX(new_metric),
76 NEIGHBOR_INFO_FIX2ETX(packet_metric),
79 if(neighbor_attr_has_neighbor(dest)) {
80 neighbor_attr_set_data(&etx, dest, &new_metric);
81 if(new_metric != recorded_metric && subscriber_callback !=
NULL) {
82 subscriber_callback(dest, 1, new_metric);
88 add_neighbor(
const rimeaddr_t *addr)
90 switch(neighbor_attr_add_neighbor(addr)) {
92 PRINTF(
"neighbor-info: failed to add a node.\n");
95 PRINTF(
"neighbor-info: The neighbor is already known\n");
105 const rimeaddr_t *dest;
106 link_metric_t packet_metric;
108 dest = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
113 PRINTF(
"neighbor-info: packet sent to %d.%d, status=%d, numtx=%d\n",
114 dest->u8[
sizeof(*dest) - 2], dest->u8[
sizeof(*dest) - 1],
119 packet_metric = numtx;
123 packet_metric = numtx;
126 packet_metric = ETX_NOACK_PENALTY;
134 update_metric(dest, packet_metric);
140 const rimeaddr_t *src;
142 src = packetbuf_addr(PACKETBUF_ADDR_SENDER);
147 PRINTF(
"neighbor-info: packet received from %d.%d\n",
148 src->u8[
sizeof(*src) - 2], src->u8[
sizeof(*src) - 1]);
156 if(subscriber_callback ==
NULL) {
157 neighbor_attr_register(&etx);
158 subscriber_callback = s;
168 link_metric_t *metricp;
170 metricp = (link_metric_t *)neighbor_attr_get_data(&etx, addr);
171 return metricp ==
NULL ? ETX_LIMIT : *metricp;