56 #ifdef COLLECT_NEIGHBOR_CONF_MAX_COLLECT_NEIGHBORS
57 #define MAX_COLLECT_NEIGHBORS COLLECT_NEIGHBOR_CONF_MAX_COLLECT_NEIGHBORS
59 #define MAX_COLLECT_NEIGHBORS 8
62 #define RTMETRIC_MAX COLLECT_MAX_DEPTH
64 MEMB(collect_neighbors_mem,
struct collect_neighbor, MAX_COLLECT_NEIGHBORS);
68 #define PERIODIC_INTERVAL CLOCK_SECOND * 60
70 #define EXPECTED_CONGESTION_DURATION CLOCK_SECOND * 240
71 #define CONGESTION_PENALTY 8 * COLLECT_LINK_ESTIMATE_UNIT
76 #define PRINTF(...) printf(__VA_ARGS__)
85 struct collect_neighbor_list *neighbor_list;
86 struct collect_neighbor *n;
96 if(n->le_age == MAX_LE_AGE) {
100 if(n->age == MAX_AGE) {
106 ctimer_set(&neighbor_list->periodic, PERIODIC_INTERVAL,
107 periodic, neighbor_list);
111 collect_neighbor_init(
void)
113 static uint8_t initialized = 0;
114 if(initialized == 0) {
121 collect_neighbor_list_new(
struct collect_neighbor_list *neighbors_list)
128 struct collect_neighbor *
129 collect_neighbor_list_find(
struct collect_neighbor_list *neighbors_list,
130 const rimeaddr_t *addr)
132 struct collect_neighbor *n;
142 collect_neighbor_list_add(
struct collect_neighbor_list *neighbors_list,
143 const rimeaddr_t *addr, uint16_t nrtmetric)
145 struct collect_neighbor *n;
148 PRINTF(
"collect_neighbor_list_add: attempt to add NULL addr\n");
152 PRINTF(
"collect_neighbor_add: adding %d.%d\n", addr->u8[0], addr->u8[1]);
157 PRINTF(
"collect_neighbor_add: already on list %d.%d\n",
158 addr->u8[0], addr->u8[1]);
166 PRINTF(
"collect_neighbor_add: not on list, allocating %d.%d\n",
167 addr->u8[0], addr->u8[1]);
179 uint16_t worst_rtmetric;
180 struct collect_neighbor *worst_neighbor;
188 worst_neighbor =
NULL;
192 if(n->rtmetric > worst_rtmetric) {
194 worst_rtmetric = n->rtmetric;
200 if(nrtmetric < worst_rtmetric) {
204 PRINTF(
"collect_neighbor_add: not on list, not allocated, recycling %d.%d\n",
205 n->addr.u8[0], n->addr.u8[1]);
212 n->rtmetric = nrtmetric;
221 collect_neighbor_list(
struct collect_neighbor_list *neighbors_list)
223 return neighbors_list->list;
227 collect_neighbor_list_remove(
struct collect_neighbor_list *neighbors_list,
228 const rimeaddr_t *addr)
230 struct collect_neighbor *n = collect_neighbor_list_find(neighbors_list, addr);
238 struct collect_neighbor *
239 collect_neighbor_list_best(
struct collect_neighbor_list *neighbors_list)
242 struct collect_neighbor *n, *best;
245 rtmetric = RTMETRIC_MAX;
250 PRINTF(
"collect_neighbor_best: ");
254 PRINTF(
"%d.%d %d+%d=%d, ",
255 n->addr.u8[0], n->addr.u8[1],
256 n->rtmetric, collect_neighbor_link_estimate(n),
257 collect_neighbor_rtmetric(n));
258 if(collect_neighbor_rtmetric_link_estimate(n) < rtmetric) {
259 rtmetric = collect_neighbor_rtmetric_link_estimate(n);
269 collect_neighbor_list_num(
struct collect_neighbor_list *neighbors_list)
271 PRINTF(
"collect_neighbor_num %d\n",
list_length(neighbors_list->list));
275 struct collect_neighbor *
276 collect_neighbor_list_get(
struct collect_neighbor_list *neighbors_list,
int num)
279 struct collect_neighbor *n;
281 PRINTF(
"collect_neighbor_get %d\n", num);
286 PRINTF(
"collect_neighbor_get found %d.%d\n",
287 n->addr.u8[0], n->addr.u8[1]);
296 collect_neighbor_list_purge(
struct collect_neighbor_list *neighbors_list)
304 collect_neighbor_update_rtmetric(
struct collect_neighbor *n, uint16_t rtmetric)
307 PRINTF(
"%d.%d: collect_neighbor_update %d.%d rtmetric %d\n",
309 n->addr.u8[0], n->addr.u8[1], rtmetric);
310 n->rtmetric = rtmetric;
316 collect_neighbor_tx_fail(
struct collect_neighbor *n, uint16_t num_tx)
324 collect_neighbor_tx(
struct collect_neighbor *n, uint16_t num_tx)
332 collect_neighbor_rx(
struct collect_neighbor *n)
339 collect_neighbor_link_estimate(
struct collect_neighbor *n)
341 if(collect_neighbor_is_congested(n)) {
353 collect_neighbor_rtmetric_link_estimate(
struct collect_neighbor *n)
359 collect_neighbor_rtmetric(
struct collect_neighbor *n)
365 collect_neighbor_set_congested(
struct collect_neighbor *n)
367 timer_set(&n->congested_timer, EXPECTED_CONGESTION_DURATION);
371 collect_neighbor_is_congested(
struct collect_neighbor *n)