Merge pull request #1215 from joakimeriksson/rpl-child-locking
Move locking of neighbors / children from RPL to uip-ds6-route module
This commit is contained in:
commit
92c1a68b94
5 changed files with 54 additions and 12 deletions
|
@ -367,6 +367,9 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
|
|||
num_routes++;
|
||||
|
||||
PRINTF("uip_ds6_route_add num %d\n", num_routes);
|
||||
|
||||
/* lock this entry so that nexthop is not removed */
|
||||
nbr_table_lock(nbr_routes, routes);
|
||||
}
|
||||
|
||||
uip_ipaddr_copy(&(r->ipaddr), ipaddr);
|
||||
|
@ -423,7 +426,7 @@ uip_ds6_route_rm(uip_ds6_route_t *route)
|
|||
list_remove(route->neighbor_routes->route_list, neighbor_route);
|
||||
if(list_head(route->neighbor_routes->route_list) == NULL) {
|
||||
/* If this was the only route using this neighbor, remove the
|
||||
neibhor from the table */
|
||||
neighbor from the table - this implicitly unlocks nexthop */
|
||||
PRINTF("uip_ds6_route_rm: removing neighbor too\n");
|
||||
nbr_table_remove(nbr_routes, route->neighbor_routes->route_list);
|
||||
}
|
||||
|
|
|
@ -40,6 +40,18 @@
|
|||
#include "lib/list.h"
|
||||
#include "net/nbr-table.h"
|
||||
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
#include "sys/ctimer.h"
|
||||
static void handle_periodic_timer(void *ptr);
|
||||
static struct ctimer periodic_timer;
|
||||
static uint8_t initialized = 0;
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
/* List of link-layer addresses of the neighbors, used as key in the tables */
|
||||
typedef struct nbr_table_key {
|
||||
struct nbr_table_key *next;
|
||||
|
@ -143,6 +155,7 @@ static int
|
|||
nbr_set_bit(uint8_t *bitmap, nbr_table_t *table, nbr_table_item_t *item, int value)
|
||||
{
|
||||
int item_index = index_from_item(table, item);
|
||||
|
||||
if(table != NULL && item_index != -1) {
|
||||
if(value) {
|
||||
bitmap[item_index] |= 1 << table->index;
|
||||
|
@ -229,6 +242,13 @@ nbr_table_allocate(void)
|
|||
int
|
||||
nbr_table_register(nbr_table_t *table, nbr_table_callback *callback)
|
||||
{
|
||||
#if DEBUG
|
||||
if(!initialized) {
|
||||
initialized = 1;
|
||||
/* schedule a debug printout per minute */
|
||||
ctimer_set(&periodic_timer, CLOCK_SECOND * 60, handle_periodic_timer, NULL);
|
||||
}
|
||||
#endif
|
||||
if(num_tables < MAX_NUM_TABLES) {
|
||||
table->index = num_tables++;
|
||||
table->callback = callback;
|
||||
|
@ -331,6 +351,10 @@ nbr_table_remove(nbr_table_t *table, void *item)
|
|||
int
|
||||
nbr_table_lock(nbr_table_t *table, void *item)
|
||||
{
|
||||
#if DEBUG
|
||||
int i = index_from_item(table, item);
|
||||
PRINTF("*** Lock %d\n", i);
|
||||
#endif
|
||||
return nbr_set_bit(locked_map, table, item, 1);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -338,6 +362,10 @@ nbr_table_lock(nbr_table_t *table, void *item)
|
|||
int
|
||||
nbr_table_unlock(nbr_table_t *table, void *item)
|
||||
{
|
||||
#if DEBUG
|
||||
int i = index_from_item(table, item);
|
||||
PRINTF("*** Unlock %d\n", i);
|
||||
#endif
|
||||
return nbr_set_bit(locked_map, table, item, 0);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -348,3 +376,25 @@ nbr_table_get_lladdr(nbr_table_t *table, const void *item)
|
|||
nbr_table_key_t *key = key_from_item(table, item);
|
||||
return key != NULL ? &key->lladdr : NULL;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if DEBUG
|
||||
static void
|
||||
handle_periodic_timer(void *ptr)
|
||||
{
|
||||
int i, j;
|
||||
/* Printout all neighbors and which tables they are used in */
|
||||
PRINTF("NBR TABLE:\n");
|
||||
for(i = 0; i < NBR_TABLE_MAX_NEIGHBORS; i++) {
|
||||
if(used_map[i] > 0) {
|
||||
PRINTF(" %02d %02d",i , key_from_index(i)->lladdr.u8[LINKADDR_SIZE - 1]);
|
||||
for(j = 0; j < num_tables; j++) {
|
||||
PRINTF(" [%d:%d]", (used_map[i] & (1 << j)) != 0,
|
||||
(locked_map[i] & (1 << j)) != 0);
|
||||
}
|
||||
PRINTF("\n");
|
||||
}
|
||||
}
|
||||
ctimer_reset(&periodic_timer);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1408,10 +1408,4 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
|
|||
p->dtsn = dio->dtsn;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rpl_lock_parent(rpl_parent_t *p)
|
||||
{
|
||||
nbr_table_lock(rpl_parents, p);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
|
|
@ -773,8 +773,6 @@ dao_input(void)
|
|||
PRINTF("RPL: Neighbor already in neighbor cache\n");
|
||||
}
|
||||
|
||||
rpl_lock_parent(parent);
|
||||
|
||||
rep = rpl_add_route(dag, &prefix, prefixlen, &dao_sender_addr);
|
||||
if(rep == NULL) {
|
||||
RPL_STAT(rpl_stats.mem_overflows++);
|
||||
|
|
|
@ -303,9 +303,6 @@ uip_ds6_route_t *rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix,
|
|||
int prefix_len, uip_ipaddr_t *next_hop);
|
||||
void rpl_purge_routes(void);
|
||||
|
||||
/* Lock a parent in the neighbor cache. */
|
||||
void rpl_lock_parent(rpl_parent_t *p);
|
||||
|
||||
/* Objective function. */
|
||||
rpl_of_t *rpl_find_of(rpl_ocp_t);
|
||||
|
||||
|
|
Loading…
Reference in a new issue