52 #include "contiki-conf.h"
54 #ifdef ROUTE_CONF_ENTRIES
55 #define NUM_RT_ENTRIES ROUTE_CONF_ENTRIES
57 #define NUM_RT_ENTRIES 8
60 #ifdef ROUTE_CONF_DECAY_THRESHOLD
61 #define DECAY_THRESHOLD ROUTE_CONF_DECAY_THRESHOLD
63 #define DECAY_THRESHOLD 8
66 #ifdef ROUTE_CONF_DEFAULT_LIFETIME
67 #define DEFAULT_LIFETIME ROUTE_CONF_DEFAULT_LIFETIME
69 #define DEFAULT_LIFETIME 60
76 MEMB(route_mem,
struct route_entry, NUM_RT_ENTRIES);
78 static struct ctimer t;
80 static int max_time = DEFAULT_LIFETIME;
85 #define PRINTF(...) printf(__VA_ARGS__)
95 struct route_entry *e;
99 if(e->time >= max_time) {
100 PRINTF(
"route periodic: removing entry to %d.%d with nexthop %d.%d and cost %d\n",
101 e->dest.u8[0], e->dest.u8[1],
102 e->nexthop.u8[0], e->nexthop.u8[1],
122 route_add(
const rimeaddr_t *dest,
const rimeaddr_t *nexthop,
123 uint8_t cost, uint8_t seqno)
125 struct route_entry *e;
128 e = route_lookup(dest);
137 PRINTF(
"route_add: removing entry to %d.%d with nexthop %d.%d and cost %d\n",
138 e->dest.u8[0], e->dest.u8[1],
139 e->nexthop.u8[0], e->nexthop.u8[1],
154 PRINTF(
"route_add: new entry to %d.%d with nexthop %d.%d and cost %d\n",
155 e->dest.u8[0], e->dest.u8[1],
156 e->nexthop.u8[0], e->nexthop.u8[1],
163 route_lookup(
const rimeaddr_t *dest)
165 struct route_entry *e;
167 struct route_entry *best_entry;
178 if(e->cost < lowest_cost) {
180 lowest_cost = e->cost;
188 route_refresh(
struct route_entry *e)
196 PRINTF(
"route_refresh: time %d last %d decay %d for entry to %d.%d with nexthop %d.%d and cost %d\n",
197 e->time, e->time_last_decay, e->decay,
198 e->dest.u8[0], e->dest.u8[1],
199 e->nexthop.u8[0], e->nexthop.u8[1],
206 route_decay(
struct route_entry *e)
211 PRINTF(
"route_decay: time %d last %d decay %d for entry to %d.%d with nexthop %d.%d and cost %d\n",
212 e->time, e->time_last_decay, e->decay,
213 e->dest.u8[0], e->dest.u8[1],
214 e->nexthop.u8[0], e->nexthop.u8[1],
217 if(e->time != e->time_last_decay) {
219 e->time_last_decay = e->time;
222 if(e->decay >= DECAY_THRESHOLD) {
223 PRINTF(
"route_decay: removing entry to %d.%d with nexthop %d.%d and cost %d\n",
224 e->dest.u8[0], e->dest.u8[1],
225 e->nexthop.u8[0], e->nexthop.u8[1],
233 route_remove(
struct route_entry *e)
240 route_flush_all(
void)
242 struct route_entry *e;
255 route_set_lifetime(
int seconds)
263 struct route_entry *e;
275 struct route_entry *e;