/* Set to 1 to enable RPL statistics */ #ifndef RPL_CONF_STATS #define RPL_CONF_STATS 0 #endif /* RPL_CONF_STATS */
这里禁用了RPL配置统计信息。我们需要将它设置为1。
RPL_DAG_MC
1 2 3 4 5 6 7 8 9 10 11 12
/* * Select routing metric supported at runtime. This must be a valid * DAG Metric Container Object Type (see below). Currently, we only * support RPL_DAG_MC_ETX and RPL_DAG_MC_ENERGY. * When MRHOF (RFC6719) is used with ETX, no metric container must * be used; instead the rank carries ETX directly. */ #ifdef RPL_CONF_DAG_MC #define RPL_DAG_MC RPL_CONF_DAG_MC #else #define RPL_DAG_MC RPL_DAG_MC_NONE #endif /* RPL_CONF_DAG_MC */
/* * The objective function used by RPL is configurable through the * RPL_CONF_OF parameter. This should be defined to be the name of an * rpl_of object linked into the system image, e.g., rpl_of0. */ #ifdef RPL_CONF_OF #define RPL_OF RPL_CONF_OF #else /* ETX is the default objective function. */ #define RPL_OF rpl_mrhof #endif /* RPL_CONF_OF */
/* * This value decides if this node must stay as a leaf or not * as allowed by draft-ietf-roll-rpl-19#section-8.5 */ #ifdef RPL_CONF_LEAF_ONLY #define RPL_LEAF_ONLY RPL_CONF_LEAF_ONLY #else #define RPL_LEAF_ONLY 0 #endif
/* * RPL Default route lifetime * The RPL route lifetime is used for the downward routes and for the default * route. In a high density network with DIO suppression activated it may happen * that a node will never send a DIO once the DIO interval becomes high as it * has heard DIO from many neighbors already. As the default route to the * preferred parent has a lifetime reset by receiving DIO from the parent, it * means that the default route can be destroyed after a while. Setting the * default route with infinite lifetime secures the upstream route. */ #ifdef RPL_CONF_DEFAULT_ROUTE_INFINITE_LIFETIME #define RPL_DEFAULT_ROUTE_INFINITE_LIFETIME RPL_CONF_DEFAULT_ROUTE_INFINITE_LIFETIME #else #define RPL_DEFAULT_ROUTE_INFINITE_LIFETIME 0 #endif /* RPL_CONF_DEFAULT_ROUTE_INFINITE_LIFETIME */
/* * The DIO interval (n) represents 2^n ms. * * According to the specification, the default value is 3 which * means 8 milliseconds. That is far too low when using duty cycling * with wake-up intervals that are typically hundreds of milliseconds. * ContikiRPL thus sets the default to 2^12 ms = 4.096 s. */ #ifdef RPL_CONF_DIO_INTERVAL_MIN #define RPL_DIO_INTERVAL_MIN RPL_CONF_DIO_INTERVAL_MIN #else #define RPL_DIO_INTERVAL_MIN 12 #endif
DIO以2^n ms的时间间隔对外发送。 根据说明,默认的值为3(即2^3=8 ms)。当使用任务循环时,这个值太低了唤醒间隔通常为数百毫秒。 ContikiRPL因此设置默认值为2^12 ms = 4.096 s.
RPL_INIT_LINK_METRIC
1 2 3 4 5 6 7 8
/* * Initial metric attributed to a link when the ETX is unknown */ #ifndef RPL_CONF_INIT_LINK_METRIC #define RPL_INIT_LINK_METRIC 2 #else #define RPL_INIT_LINK_METRIC RPL_CONF_INIT_LINK_METRIC #endif
r1 = DAG_RANK(p1->rank, p1->dag->instance) * RPL_MIN_HOPRANKINC + nbr1->link_metric; r2 = DAG_RANK(p2->rank, p1->dag->instance) * RPL_MIN_HOPRANKINC + nbr2->link_metric; /* Compare two parents by looking both and their rank and at the ETX for that parent. We choose the parent that has the most favourable combination. */
nbr = rpl_get_nbr(p); if(nbr == NULL) { /* No neighbor for this parent - something bad has occurred */ return; }
recorded_etx = nbr->link_metric;
/* Do not penalize the ETX when collisions or transmission errors occur. */ if(status == MAC_TX_OK || status == MAC_TX_NOACK) { if(status == MAC_TX_NOACK) { packet_etx = MAX_LINK_METRIC * RPL_DAG_MC_ETX_DIVISOR; }
if(p->flags & RPL_PARENT_FLAG_LINK_METRIC_VALID) { /* We already have a valid link metric, use weighted moving average to update it */ new_etx = ((uint32_t)recorded_etx * ETX_ALPHA + (uint32_t)packet_etx * (ETX_SCALE - ETX_ALPHA)) / ETX_SCALE; } else { /* We don't have a valid link metric, set it to the current packet's ETX */ new_etx = packet_etx; /* Set link metric as valid */ p->flags |= RPL_PARENT_FLAG_LINK_METRIC_VALID; }
PRINTF("RPL: ETX changed from %u to %u (packet ETX = %u)\n", (unsigned)(recorded_etx / RPL_DAG_MC_ETX_DIVISOR), (unsigned)(new_etx / RPL_DAG_MC_ETX_DIVISOR), (unsigned)(packet_etx / RPL_DAG_MC_ETX_DIVISOR)); /* update the link metric for this nbr */ nbr->link_metric = new_etx; } }
if(INFINITE_RANK - base_rank < rank_increase) { /* Reached the maximum rank. */ new_rank = INFINITE_RANK; } else { /* Calculate the rank based on the new rank information from DIO or stored otherwise. */ new_rank = base_rank + rank_increase; }
return new_rank; }
这类似于前面介绍的calculate_rank()函数,但有一点不同。 在这个函数中,如果parent = NULL,rank_increase是一个等于RPL_INIT_LINK_METRIC的增量。否则它等于link_metric。 new_rank = the increment + base rank