47 #include "net/routing/rpl-classic/rpl-private.h" 48 #include "net/nbr-table.h" 52 #define DEBUG DEBUG_NONE 65 #define MAX_CHILDREN (NBR_TABLE_MAX_NEIGHBORS - 2) 66 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) 68 static int num_parents;
69 static int num_children;
71 static linkaddr_t *worst_rank_nbr;
72 static rpl_rank_t worst_rank;
74 #if DEBUG == DEBUG_FULL 79 static void update_nbr(
void);
80 static struct ctimer periodic_timer;
81 static int timer_init = 0;
83 handle_periodic_timer(
void *ptr)
99 #if DEBUG == DEBUG_FULL 103 &handle_periodic_timer, NULL);
108 worst_rank_nbr = NULL;
113 nbr = nbr_table_head(ds6_neighbors);
115 linkaddr_t *lladdr = nbr_table_get_lladdr(ds6_neighbors, nbr);
123 if(uip_ds6_route_is_nexthop(&nbr->ipaddr) != 0) {
128 parent = rpl_get_parent((uip_lladdr_t *)lladdr);
132 if(parent->dag != NULL && parent->dag->preferred_parent == parent) {
137 }
else if(is_used == 0 && worst_rank < RPL_INFINITE_RANK &&
139 parent->dag != NULL &&
140 parent->dag->instance != NULL &&
141 (rank = parent->dag->instance->of->rank_via_parent(parent)) > worst_rank) {
144 worst_rank_nbr = lladdr;
152 worst_rank_nbr = lladdr;
153 worst_rank = RPL_INFINITE_RANK;
154 }
else if(is_used > 1) {
155 PRINTF(
"NBR-POLICY: *** Neighbor is both child and candidate parent: ");
156 PRINTLLADDR((uip_lladdr_t *)lladdr);
160 nbr = nbr_table_next(ds6_neighbors, nbr);
164 num_free = NBR_TABLE_MAX_NEIGHBORS - num_used;
166 PRINTF(
"NBR-POLICY: Free: %d, Children: %d, Parents: %d Routes: %d\n",
167 num_free, num_children, num_parents, uip_ds6_route_num_routes());
173 find_removable_dis(uip_ipaddr_t *from)
180 PRINTF(
"Num-free > 0 = %d - Other for RPL/ND6 unused NBR entry exists .",
183 if(num_children < MAX_CHILDREN) {
184 return worst_rank_nbr;
190 find_removable_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
196 instance = rpl_get_instance(dio->instance_id);
197 if(instance == NULL || instance->current_dag == NULL) {
198 PRINTF(
"Did not find instance id: %d\n", dio->instance_id);
203 if(dio->rank + instance->min_hoprankinc < worst_rank - instance->min_hoprankinc / 2) {
205 PRINTF(
"Found better neighbor %d < %d - add to cache...\n",
206 dio->rank, worst_rank);
208 return worst_rank_nbr;
211 PRINTF(
"Found worse neighbor with new %d and old %d - NOT add to cache.\n",
212 dio->rank, worst_rank);
219 int max = MAX_CHILDREN;
222 if(instance != NULL) {
224 if(instance->current_dag->rank ==
ROOT_RANK(instance)) {
225 max = NBR_TABLE_MAX_NEIGHBORS;
231 if(num_children >= max) {
232 PRINTF(
"Can not add another child - already at max.\n");
236 return worst_rank_nbr;
240 rpl_nbr_policy_find_removable(nbr_table_reason_t reason,
void * data)
245 case NBR_TABLE_REASON_RPL_DIO:
246 return find_removable_dio(&
UIP_IP_BUF->srcipaddr, data);
247 case NBR_TABLE_REASON_RPL_DAO:
248 return find_removable_dao(&
UIP_IP_BUF->srcipaddr, data);
249 case NBR_TABLE_REASON_RPL_DIS:
250 return find_removable_dis(&
UIP_IP_BUF->srcipaddr);
#define UIP_IP_BUF
Pointer to IP header.
static uip_ds6_nbr_t * nbr
Pointer to llao option in uip_buf.
#define ROOT_RANK
Rank of a root node.
IPv6 Neighbor cache (link-layer/IPv6 address mapping)
A set of debugging macros for the IP stack
#define CLOCK_SECOND
A second, measured in system clock time.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
void ctimer_restart(struct ctimer *c)
Restart a callback timer from the current point in time.
Header file for routing table manipulation.
An entry in the nbr cache.