Added automatic timeouts

This commit is contained in:
adamdunkels 2007-03-22 17:34:43 +00:00
parent 2ef8c91bbc
commit 5af2430f95
4 changed files with 47 additions and 12 deletions

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: neighbor.c,v 1.3 2007/03/15 19:43:07 adamdunkels Exp $ * $Id: neighbor.c,v 1.4 2007/03/22 17:34:43 adamdunkels Exp $
*/ */
/** /**
@ -42,15 +42,20 @@
#include "contiki.h" #include "contiki.h"
#include "net/rime/neighbor.h" #include "net/rime/neighbor.h"
#include "net/rime/ctimer.h"
#define MAX_NEIGHBORS 5 #define MAX_NEIGHBORS 5
#define HOPCOUNT_MAX 32 #define HOPCOUNT_MAX 32
static struct neighbor neighbors[MAX_NEIGHBORS]; static struct neighbor neighbors[MAX_NEIGHBORS];
static struct ctimer t;
static int max_time = 20;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void static void
neighbor_periodic(int max_time) periodic(void *ptr)
{ {
int i; int i;
@ -65,6 +70,8 @@ neighbor_periodic(int max_time)
} }
} }
} }
printf("neighbor periodic\n");
ctimer_set(&t, CLOCK_SECOND, periodic, NULL);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
@ -75,6 +82,8 @@ neighbor_init(void)
for(i = 0; i < MAX_NEIGHBORS; ++i) { for(i = 0; i < MAX_NEIGHBORS; ++i) {
rimeaddr_copy(&neighbors[i].addr, &rimeaddr_null); rimeaddr_copy(&neighbors[i].addr, &rimeaddr_null);
} }
ctimer_set(&t, periodic, CLOCK_SECOND, NULL);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
struct neighbor * struct neighbor *
@ -153,7 +162,7 @@ neighbor_remove(rimeaddr_t *addr)
for(i = 0; i < MAX_NEIGHBORS; ++i) { for(i = 0; i < MAX_NEIGHBORS; ++i) {
if(rimeaddr_cmp(&neighbors[i].addr, addr)) { if(rimeaddr_cmp(&neighbors[i].addr, addr)) {
printf("%d: removing %d @ %d\n", rimeaddr_node_addr.u16, addr->u16, i); printf("%d: removing %d @ %d\n", rimeaddr_node_addr.u16[0], addr->u16[0], i);
rimeaddr_copy(&neighbors[i].addr, &rimeaddr_null); rimeaddr_copy(&neighbors[i].addr, &rimeaddr_null);
neighbors[i].hopcount = HOPCOUNT_MAX; neighbors[i].hopcount = HOPCOUNT_MAX;
return; return;

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: neighbor.h,v 1.2 2007/03/15 19:43:07 adamdunkels Exp $ * $Id: neighbor.h,v 1.3 2007/03/22 17:34:43 adamdunkels Exp $
*/ */
/** /**
@ -51,7 +51,7 @@ struct neighbor {
}; };
void neighbor_init(void); void neighbor_init(void);
void neighbor_periodic(int max_time); /*void neighbor_periodic(int max_time);*/
void neighbor_add(rimeaddr_t *addr, u8_t hopcount, u16_t signal); void neighbor_add(rimeaddr_t *addr, u8_t hopcount, u16_t signal);
void neighbor_update(struct neighbor *n, u8_t hopcount, u16_t signal); void neighbor_update(struct neighbor *n, u8_t hopcount, u16_t signal);

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: route.c,v 1.1 2007/03/15 19:52:51 adamdunkels Exp $ * $Id: route.c,v 1.2 2007/03/22 17:34:43 adamdunkels Exp $
*/ */
/** /**
@ -49,17 +49,41 @@
LIST(route_table); LIST(route_table);
MEMB(route_mem, struct route_entry, NUM_RT_ENTRIES); MEMB(route_mem, struct route_entry, NUM_RT_ENTRIES);
static struct ctimer t;
#define MAX_TIME 10
/*---------------------------------------------------------------------------*/
static void
periodic(void *ptr)
{
struct route_entry *e;
for(e = list_head(route_table); e != NULL; e = e->next) {
e->time++;
if(e->time >= MAX_TIME) {
printf("Route to %d.%d bropped\n",
e->dest.u8[0], e->dest.u8[1]);
list_remove(route_table, e);
memb_free(&route_mem, e);
}
}
ctimer_set(&t, CLOCK_SECOND * 2, periodic, NULL);
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
route_init(void) route_init(void)
{ {
list_init(route_table); list_init(route_table);
memb_init(&route_mem); memb_init(&route_mem);
ctimer_set(&t, CLOCK_SECOND * 2, periodic, NULL);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
route_add(rimeaddr_t *dest, rimeaddr_t *nexthop, route_add(rimeaddr_t *dest, rimeaddr_t *nexthop,
u16_t hop_count, u16_t seqno) u8_t hop_count, u8_t seqno)
{ {
struct route_entry *e; struct route_entry *e;
@ -79,6 +103,7 @@ route_add(rimeaddr_t *dest, rimeaddr_t *nexthop,
rimeaddr_copy(&e->nexthop, nexthop); rimeaddr_copy(&e->nexthop, nexthop);
e->hop_count = hop_count; e->hop_count = hop_count;
e->seqno = seqno; e->seqno = seqno;
e->time = 0;
/* New entry goes first. */ /* New entry goes first. */
list_push(route_table, e); list_push(route_table, e);

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: route.h,v 1.1 2007/03/15 19:52:51 adamdunkels Exp $ * $Id: route.h,v 1.2 2007/03/22 17:34:43 adamdunkels Exp $
*/ */
/** /**
@ -48,12 +48,13 @@ struct route_entry {
struct route_entry *next; struct route_entry *next;
rimeaddr_t dest; rimeaddr_t dest;
rimeaddr_t nexthop; rimeaddr_t nexthop;
u16_t seqno; u8_t seqno;
u16_t hop_count; u8_t hop_count;
u8_t time;
}; };
int route_add(rimeaddr_t *dest, rimeaddr_t *nexthop, int route_add(rimeaddr_t *dest, rimeaddr_t *nexthop,
u16_t hop_count, u16_t seqno); u8_t hop_count, u8_t seqno);
struct route_entry *route_lookup(rimeaddr_t *dest); struct route_entry *route_lookup(rimeaddr_t *dest);
void route_remove(struct route_entry *e); void route_remove(struct route_entry *e);
void route_flush_all(void); void route_flush_all(void);