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)
257 struct collect_neighbor *n, *best;
260 rtmetric = RTMETRIC_MAX;
263 if(neighbors_list ==
NULL) {
268 PRINTF(
"collect_neighbor_best: ");
272 PRINTF(
"%d.%d %d+%d=%d, ",
273 n->addr.u8[0], n->addr.u8[1],
274 n->rtmetric, collect_neighbor_link_estimate(n),
275 collect_neighbor_rtmetric(n));
276 if(collect_neighbor_rtmetric_link_estimate(n) < rtmetric) {
277 rtmetric = collect_neighbor_rtmetric_link_estimate(n);
287 collect_neighbor_list_num(
struct collect_neighbor_list *neighbors_list)
289 if(neighbors_list ==
NULL) {
293 PRINTF(
"collect_neighbor_num %d\n",
list_length(neighbors_list->list));
297 struct collect_neighbor *
298 collect_neighbor_list_get(
struct collect_neighbor_list *neighbors_list,
int num)
301 struct collect_neighbor *n;
303 if(neighbors_list ==
NULL) {
307 PRINTF(
"collect_neighbor_get %d\n", num);
312 PRINTF(
"collect_neighbor_get found %d.%d\n",
313 n->addr.u8[0], n->addr.u8[1]);
322 collect_neighbor_list_purge(
struct collect_neighbor_list *neighbors_list)
324 if(neighbors_list ==
NULL) {
334 collect_neighbor_update_rtmetric(
struct collect_neighbor *n, uint16_t rtmetric)
337 PRINTF(
"%d.%d: collect_neighbor_update %d.%d rtmetric %d\n",
339 n->addr.u8[0], n->addr.u8[1], rtmetric);
340 n->rtmetric = rtmetric;
346 collect_neighbor_tx_fail(
struct collect_neighbor *n, uint16_t num_tx)
357 collect_neighbor_tx(
struct collect_neighbor *n, uint16_t num_tx)
368 collect_neighbor_rx(
struct collect_neighbor *n)
378 collect_neighbor_link_estimate(
struct collect_neighbor *n)
383 if(collect_neighbor_is_congested(n)) {
395 collect_neighbor_rtmetric_link_estimate(
struct collect_neighbor *n)
404 collect_neighbor_rtmetric(
struct collect_neighbor *n)
414 collect_neighbor_set_congested(
struct collect_neighbor *n)
419 timer_set(&n->congested_timer, EXPECTED_CONGESTION_DURATION);
423 collect_neighbor_is_congested(
struct collect_neighbor *n)
uint16_t collect_link_estimate(struct collect_link_estimate *le)
Compute the link estimate metric for a link estimate.
void list_remove(list_t list, void *item)
Remove a specific element from a list.
void collect_link_estimate_update_rx(struct collect_link_estimate *n)
Update a link estimate when a packet has been received.
static uip_ds6_addr_t * addr
Pointer to a router list entry.
#define MEMB(name, structure, num)
Declare a memory block.
void timer_set(struct timer *t, clock_time_t interval)
Set a timer.
void * list_pop(list_t list)
Remove the first object on a list.
void * list_item_next(void *item)
Get the next item following this item.
Header file for the Contiki radio neighborhood management
void ** list_t
The linked list type.
void list_init(list_t list)
Initialize a list.
void memb_init(struct memb *m)
Initialize a memory block that was declared with MEMB().
void * list_head(list_t list)
Get a pointer to the first element of a list.
#define NULL
The null pointer.
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.
void list_add(list_t list, void *item)
Add an item at the end of a list.
#define CLOCK_SECOND
A second, measured in system clock time.
Linked list manipulation routines.
Header file for hop-by-hop reliable data collection
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
Memory block allocation routines.
int linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two Rime addresses.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a Rime address.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
int list_length(list_t list)
Get the length of a list.
#define LIST_STRUCT_INIT(struct_ptr, name)
Initialize a linked list that is part of a structure.
void * memb_alloc(struct memb *m)
Allocate a memory block from a block of memory declared with MEMB().
void collect_link_estimate_update_tx(struct collect_link_estimate *le, uint8_t tx)
Update a link estimate when a packet has been sent.
char memb_free(struct memb *m, void *ptr)
Deallocate a memory block from a memory block previously declared with MEMB().
void collect_link_estimate_new(struct collect_link_estimate *le)
Initialize a new link estimate.
int timer_expired(struct timer *t)
Check if a timer has expired.