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;
127 e = route_lookup(dest);
136 PRINTF(
"route_add: removing entry to %d.%d with nexthop %d.%d and cost %d\n",
137 e->dest.u8[0], e->dest.u8[1],
138 e->nexthop.u8[0], e->nexthop.u8[1],
153 PRINTF(
"route_add: new entry to %d.%d with nexthop %d.%d and cost %d\n",
154 e->dest.u8[0], e->dest.u8[1],
155 e->nexthop.u8[0], e->nexthop.u8[1],
162 route_lookup(
const linkaddr_t *dest)
164 struct route_entry *e;
166 struct route_entry *best_entry;
177 if(e->cost < lowest_cost) {
179 lowest_cost = e->cost;
187 route_refresh(
struct route_entry *e)
195 PRINTF(
"route_refresh: time %d last %d decay %d for entry to %d.%d with nexthop %d.%d and cost %d\n",
196 e->time, e->time_last_decay, e->decay,
197 e->dest.u8[0], e->dest.u8[1],
198 e->nexthop.u8[0], e->nexthop.u8[1],
205 route_decay(
struct route_entry *e)
210 PRINTF(
"route_decay: time %d last %d decay %d for entry to %d.%d with nexthop %d.%d and cost %d\n",
211 e->time, e->time_last_decay, e->decay,
212 e->dest.u8[0], e->dest.u8[1],
213 e->nexthop.u8[0], e->nexthop.u8[1],
216 if(e->time != e->time_last_decay) {
218 e->time_last_decay = e->time;
221 if(e->decay >= DECAY_THRESHOLD) {
222 PRINTF(
"route_decay: removing entry to %d.%d with nexthop %d.%d and cost %d\n",
223 e->dest.u8[0], e->dest.u8[1],
224 e->nexthop.u8[0], e->nexthop.u8[1],
232 route_remove(
struct route_entry *e)
239 route_flush_all(
void)
241 struct route_entry *e;
254 route_set_lifetime(
int seconds)
262 struct route_entry *e;
274 struct route_entry *e;
void * list_pop(list_t list)
Remove the first object on a list.
Linked list manipulation routines.
void memb_init(struct memb *m)
Initialize a memory block that was declared with MEMB().
void list_push(list_t list, void *item)
Add an item to the start of the list.
void * list_item_next(void *item)
Get the next item following this item.
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.
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.
#define MEMB(name, structure, num)
Declare a memory block.
#define LIST(name)
Declare a linked list.
Header file for the callback timer
void * list_chop(list_t list)
Remove the last object on the list.
int linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two Rime addresses.
Memory block allocation routines.
Header file for the Rime route table
#define CLOCK_SECOND
A second, measured in system clock time.