47 #include "net/routing/rpl-classic/rpl-private.h" 48 #include "net/nbr-table.h" 54 #define LOG_MODULE "RPL" 55 #define LOG_LEVEL LOG_LEVEL_RPL 67 #define MAX_CHILDREN (NBR_TABLE_MAX_NEIGHBORS - 2) 69 static int num_parents;
70 static int num_children;
72 static const linkaddr_t *worst_rank_nbr;
73 static rpl_rank_t worst_rank;
80 static void update_nbr(
void);
81 static struct ctimer periodic_timer;
82 static int timer_init = 0;
84 handle_periodic_timer(
void *ptr)
104 &handle_periodic_timer, NULL);
109 worst_rank_nbr = NULL;
124 if(uip_ds6_route_is_nexthop(&nbr->ipaddr) != 0) {
129 parent = rpl_get_parent((
const uip_lladdr_t *)lladdr);
133 if(parent->dag != NULL && parent->dag->preferred_parent == parent) {
138 }
else if(is_used == 0 && worst_rank < RPL_INFINITE_RANK &&
140 parent->dag != NULL &&
141 parent->dag->instance != NULL &&
142 (rank = parent->dag->instance->of->rank_via_parent(parent)) > worst_rank) {
145 worst_rank_nbr = lladdr;
153 worst_rank_nbr = lladdr;
154 worst_rank = RPL_INFINITE_RANK;
155 }
else if(is_used > 1) {
156 LOG_DBG(
"nbr-policy: *** neighbor is both child and candidate parent: ");
157 LOG_DBG_LLADDR(lladdr);
165 num_free = NBR_TABLE_MAX_NEIGHBORS - num_used;
167 LOG_DBG(
"nbr-policy: free: %d, children: %d, parents: %d routes: %d\n",
168 num_free, num_children, num_parents, uip_ds6_route_num_routes());
174 find_removable_dis(uip_ipaddr_t *from)
181 LOG_DBG(
"nbr-policy: num-free > 0 = %d - Other for RPL/ND6 unused NBR entry exists.\n",
184 if(num_children < MAX_CHILDREN) {
185 return worst_rank_nbr;
191 find_removable_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
197 instance = rpl_get_instance(dio->instance_id);
198 if(instance == NULL || instance->current_dag == NULL) {
199 LOG_WARN(
"nbr-policy: did not find instance id: %d\n", dio->instance_id);
204 if(dio->rank + instance->min_hoprankinc < worst_rank - instance->min_hoprankinc / 2) {
206 LOG_DBG(
"nbr-policy: DIO rank %u, worst_rank %u -- add to cache\n",
207 dio->rank, worst_rank);
209 return worst_rank_nbr;
212 LOG_DBG(
"nbr-policy: DIO rank %u, worst_rank %u -- do not add to cache\n",
213 dio->rank, worst_rank);
220 int max = MAX_CHILDREN;
223 if(instance != NULL) {
225 if(instance->current_dag->rank ==
ROOT_RANK(instance)) {
226 max = NBR_TABLE_MAX_NEIGHBORS;
232 if(num_children >= max) {
233 LOG_ERR(
"nbr-policy: can not add another child - already at max.\n");
237 return worst_rank_nbr;
241 rpl_nbr_policy_find_removable(nbr_table_reason_t reason,
void * data)
246 case NBR_TABLE_REASON_RPL_DIO:
247 return find_removable_dio(&
UIP_IP_BUF->srcipaddr, data);
248 case NBR_TABLE_REASON_RPL_DAO:
249 return find_removable_dao(&
UIP_IP_BUF->srcipaddr, data);
250 case NBR_TABLE_REASON_RPL_DIS:
251 return find_removable_dis(&
UIP_IP_BUF->srcipaddr);
#define UIP_IP_BUF
Direct access to IPv6 header.
static uip_ds6_nbr_t * nbr
Pointer to llao option in uip_buf.
#define ROOT_RANK
Rank of a root node.
uip_ds6_nbr_t * uip_ds6_nbr_head(void)
Get the first neighbor cache in nbr_table.
IPv6 Neighbor cache (link-layer/IPv6 address mapping)
#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.
uip_ds6_nbr_t * uip_ds6_nbr_next(uip_ds6_nbr_t *nbr)
Get the next neighbor cache of a specified one.
const uip_lladdr_t * uip_ds6_nbr_get_ll(const uip_ds6_nbr_t *nbr)
Get the link-layer address associated with a specified nbr cache.
Header file for the logging system
The default nbr_table entry (when UIP_DS6_NBR_MULTI_IPV6_ADDRS is disabled), that implements nbr cach...