51 #include "contiki-conf.h"
53 #ifdef ROUTE_CONF_ENTRIES
54 #define NUM_RT_ENTRIES ROUTE_CONF_ENTRIES
56 #define NUM_RT_ENTRIES 8
59 #ifdef ROUTE_CONF_DECAY_THRESHOLD
60 #define DECAY_THRESHOLD ROUTE_CONF_DECAY_THRESHOLD
62 #define DECAY_THRESHOLD 8
65 #ifdef ROUTE_CONF_DEFAULT_LIFETIME
66 #define DEFAULT_LIFETIME ROUTE_CONF_DEFAULT_LIFETIME
68 #define DEFAULT_LIFETIME 60
75 MEMB(route_mem,
struct route_entry, NUM_RT_ENTRIES);
77 static struct ctimer t;
79 static int max_time = DEFAULT_LIFETIME;
84 #define PRINTF(...) printf(__VA_ARGS__)
94 struct route_entry *e;
98 if(e->time >= max_time) {
99 PRINTF(
"route periodic: removing entry to %d.%d with nexthop %d.%d and cost %d\n",
100 e->dest.u8[0], e->dest.u8[1],
101 e->nexthop.u8[0], e->nexthop.u8[1],
121 route_add(
const linkaddr_t *dest,
const linkaddr_t *nexthop,
122 uint8_t cost, uint8_t seqno)
124 struct route_entry *e, *oldest =
NULL;
127 e = route_lookup(dest);
136 if(oldest ==
NULL || e->time >= oldest->time) {
142 PRINTF(
"route_add: removing entry to %d.%d with nexthop %d.%d and cost %d\n",
143 e->dest.u8[0], e->dest.u8[1],
144 e->nexthop.u8[0], e->nexthop.u8[1],
159 PRINTF(
"route_add: new entry to %d.%d with nexthop %d.%d and cost %d\n",
160 e->dest.u8[0], e->dest.u8[1],
161 e->nexthop.u8[0], e->nexthop.u8[1],
168 route_lookup(
const linkaddr_t *dest)
170 struct route_entry *e;
172 struct route_entry *best_entry;
183 if(e->cost < lowest_cost) {
185 lowest_cost = e->cost;
193 route_refresh(
struct route_entry *e)
201 PRINTF(
"route_refresh: time %d last %d decay %d for entry to %d.%d with nexthop %d.%d and cost %d\n",
202 e->time, e->time_last_decay, e->decay,
203 e->dest.u8[0], e->dest.u8[1],
204 e->nexthop.u8[0], e->nexthop.u8[1],
211 route_decay(
struct route_entry *e)
216 PRINTF(
"route_decay: time %d last %d decay %d for entry to %d.%d with nexthop %d.%d and cost %d\n",
217 e->time, e->time_last_decay, e->decay,
218 e->dest.u8[0], e->dest.u8[1],
219 e->nexthop.u8[0], e->nexthop.u8[1],
222 if(e->time != e->time_last_decay) {
224 e->time_last_decay = e->time;
227 if(e->decay >= DECAY_THRESHOLD) {
228 PRINTF(
"route_decay: removing entry to %d.%d with nexthop %d.%d and cost %d\n",
229 e->dest.u8[0], e->dest.u8[1],
230 e->nexthop.u8[0], e->nexthop.u8[1],
238 route_remove(
struct route_entry *e)
245 route_flush_all(
void)
247 struct route_entry *e;
260 route_set_lifetime(
int seconds)
268 struct route_entry *e;
280 struct route_entry *e;
void list_remove(list_t list, void *item)
Remove a specific element from a list.
#define LIST(name)
Declare a linked list.
#define MEMB(name, structure, num)
Declare a memory block.
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.
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.
Header file for the callback timer
#define NULL
The null pointer.
Header file for the Rime route table
#define CLOCK_SECOND
A second, measured in system clock time.
Linked list manipulation routines.
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.
void * memb_alloc(struct memb *m)
Allocate a memory block from a block of memory declared with MEMB().
char memb_free(struct memb *m, void *ptr)
Deallocate a memory block from a memory block previously declared with MEMB().
void list_push(list_t list, void *item)
Add an item to the start of the list.