55 #ifdef COLLECT_NEIGHBOR_CONF_MAX_COLLECT_NEIGHBORS
56 #define MAX_COLLECT_NEIGHBORS COLLECT_NEIGHBOR_CONF_MAX_COLLECT_NEIGHBORS
58 #define MAX_COLLECT_NEIGHBORS 8
61 #define RTMETRIC_MAX COLLECT_MAX_DEPTH
63 MEMB(collect_neighbors_mem,
struct collect_neighbor, MAX_COLLECT_NEIGHBORS);
67 #define PERIODIC_INTERVAL CLOCK_SECOND * 60
69 #define EXPECTED_CONGESTION_DURATION CLOCK_SECOND * 240
70 #define CONGESTION_PENALTY 8 * COLLECT_LINK_ESTIMATE_UNIT
75 #define PRINTF(...) printf(__VA_ARGS__)
84 struct collect_neighbor_list *neighbor_list;
85 struct collect_neighbor *n;
95 if(n->le_age == MAX_LE_AGE) {
99 if(n->age == MAX_AGE) {
105 ctimer_set(&neighbor_list->periodic, PERIODIC_INTERVAL,
106 periodic, neighbor_list);
110 collect_neighbor_init(
void)
112 static uint8_t initialized = 0;
113 if(initialized == 0) {
120 collect_neighbor_list_new(
struct collect_neighbor_list *neighbors_list)
127 struct collect_neighbor *
128 collect_neighbor_list_find(
struct collect_neighbor_list *neighbors_list,
129 const linkaddr_t *addr)
131 struct collect_neighbor *n;
132 if(neighbors_list ==
NULL) {
144 collect_neighbor_list_add(
struct collect_neighbor_list *neighbors_list,
145 const linkaddr_t *addr, uint16_t nrtmetric)
147 struct collect_neighbor *n;
150 PRINTF(
"collect_neighbor_list_add: attempt to add NULL addr\n");
154 if(neighbors_list ==
NULL) {
158 PRINTF(
"collect_neighbor_add: adding %d.%d\n", addr->u8[0], addr->u8[1]);
163 PRINTF(
"collect_neighbor_add: already on list %d.%d\n",
164 addr->u8[0], addr->u8[1]);
172 PRINTF(
"collect_neighbor_add: not on list, allocating %d.%d\n",
173 addr->u8[0], addr->u8[1]);
185 uint16_t worst_rtmetric;
186 struct collect_neighbor *worst_neighbor;
194 worst_neighbor =
NULL;
198 if(n->rtmetric > worst_rtmetric) {
200 worst_rtmetric = n->rtmetric;
206 if(nrtmetric < worst_rtmetric) {
210 PRINTF(
"collect_neighbor_add: not on list, not allocated, recycling %d.%d\n",
211 n->addr.u8[0], n->addr.u8[1]);
218 n->rtmetric = nrtmetric;
227 collect_neighbor_list(
struct collect_neighbor_list *neighbors_list)
229 if(neighbors_list ==
NULL) {
233 return neighbors_list->list;
237 collect_neighbor_list_remove(
struct collect_neighbor_list *neighbors_list,
238 const linkaddr_t *addr)
240 struct collect_neighbor *n;
242 if(neighbors_list ==
NULL) {
246 n = collect_neighbor_list_find(neighbors_list, addr);
254 struct collect_neighbor *
255 collect_neighbor_list_best(
struct collect_neighbor_list *neighbors_list)
258 struct collect_neighbor *n, *best;
261 rtmetric = RTMETRIC_MAX;
265 if(neighbors_list ==
NULL) {
270 PRINTF(
"collect_neighbor_best: ");
274 PRINTF(
"%d.%d %d+%d=%d, ",
275 n->addr.u8[0], n->addr.u8[1],
276 n->rtmetric, collect_neighbor_link_estimate(n),
277 collect_neighbor_rtmetric(n));
278 if(collect_neighbor_rtmetric_link_estimate(n) < rtmetric) {
279 rtmetric = collect_neighbor_rtmetric_link_estimate(n);
289 collect_neighbor_list_num(
struct collect_neighbor_list *neighbors_list)
291 if(neighbors_list ==
NULL) {
295 PRINTF(
"collect_neighbor_num %d\n",
list_length(neighbors_list->list));
299 struct collect_neighbor *
300 collect_neighbor_list_get(
struct collect_neighbor_list *neighbors_list,
int num)
303 struct collect_neighbor *n;
305 if(neighbors_list ==
NULL) {
309 PRINTF(
"collect_neighbor_get %d\n", num);
314 PRINTF(
"collect_neighbor_get found %d.%d\n",
315 n->addr.u8[0], n->addr.u8[1]);
324 collect_neighbor_list_purge(
struct collect_neighbor_list *neighbors_list)
326 if(neighbors_list ==
NULL) {
336 collect_neighbor_update_rtmetric(
struct collect_neighbor *n, uint16_t rtmetric)
339 PRINTF(
"%d.%d: collect_neighbor_update %d.%d rtmetric %d\n",
341 n->addr.u8[0], n->addr.u8[1], rtmetric);
342 n->rtmetric = rtmetric;
348 collect_neighbor_tx_fail(
struct collect_neighbor *n, uint16_t num_tx)
359 collect_neighbor_tx(
struct collect_neighbor *n, uint16_t num_tx)
370 collect_neighbor_rx(
struct collect_neighbor *n)
380 collect_neighbor_link_estimate(
struct collect_neighbor *n)
385 if(collect_neighbor_is_congested(n)) {
397 collect_neighbor_rtmetric_link_estimate(
struct collect_neighbor *n)
406 collect_neighbor_rtmetric(
struct collect_neighbor *n)
416 collect_neighbor_set_congested(
struct collect_neighbor *n)
421 timer_set(&n->congested_timer, EXPECTED_CONGESTION_DURATION);
425 collect_neighbor_is_congested(
struct collect_neighbor *n)
void * list_pop(list_t list)
Remove the first object on a list.
Linked list manipulation routines.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
void collect_link_estimate_update_tx(struct collect_link_estimate *le, uint8_t tx)
Update a link estimate when a packet has been sent.
void memb_init(struct memb *m)
Initialize a memory block that was declared with MEMB().
void ** list_t
The linked list type.
Header file for hop-by-hop reliable data collection
void * list_item_next(void *item)
Get the next item following this item.
void timer_set(struct timer *t, clock_time_t interval)
Set a timer.
char memb_free(struct memb *m, void *ptr)
Deallocate a memory block from a memory block previously declared with MEMB().
void * memb_alloc(struct memb *m)
Allocate a memory block from a block of memory declared with MEMB().
#define NULL
The null pointer.
void list_remove(list_t list, void *item)
Remove a specific element from a list.
int list_length(list_t list)
Get the length of a list.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a Rime address.
void list_init(list_t list)
Initialize a list.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
void * list_head(list_t list)
Get a pointer to the first element of a list.
void collect_link_estimate_new(struct collect_link_estimate *le)
Initialize a new link estimate.
#define MEMB(name, structure, num)
Declare a memory block.
void collect_link_estimate_update_rx(struct collect_link_estimate *n)
Update a link estimate when a packet has been received.
void list_add(list_t list, void *item)
Add an item at the end of a list.
#define LIST_STRUCT_INIT(struct_ptr, name)
Initialize a linked list that is part of a structure.
Header file for the Contiki radio neighborhood management
uint16_t collect_link_estimate(struct collect_link_estimate *le)
Compute the link estimate metric for a link estimate.
int linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two Rime addresses.
void collect_link_estimate_update_tx_fail(struct collect_link_estimate *le, uint8_t tx)
Update a link estimate when a packet has failed to be sent.
Memory block allocation routines.
int timer_expired(struct timer *t)
Check if a timer has expired.
#define CLOCK_SECOND
A second, measured in system clock time.