47 #include "net/rpl/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) {
132 if(parent->dag !=
NULL && parent->dag->preferred_parent == parent) {
137 }
else if(is_used == 0 && worst_rank < 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 = INFINITE_RANK;
154 }
else if(is_used > 1) {
155 PRINTF(
"NBR-POLICY: *** Neighbor is both child and candidate parent: ");
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)
192 rpl_instance_t *instance;
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",
208 return worst_rank_nbr;
211 PRINTF(
"Found worse neighbor with new %d and old %d - NOT add to cache.\n",
217 find_removable_dao(uip_ipaddr_t *from, rpl_instance_t *instance)
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);
Header file for routing table manipulation.
An entry in the nbr cache.
#define UIP_IP_BUF
Pointer to IP header.
IPv6 Neighbor cache (link-layer/IPv6 address mapping)
#define NULL
The null pointer.
static uip_ds6_nbr_t * nbr
Pointer to llao option in uip_buf.
void ctimer_restart(struct ctimer *c)
Restart a callback timer from the current point in time.
#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.
A set of debugging macros for the IP stack