本文整理汇总了C++中ROOT_RANK函数的典型用法代码示例。如果您正苦于以下问题:C++ ROOT_RANK函数的具体用法?C++ ROOT_RANK怎么用?C++ ROOT_RANK使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ROOT_RANK函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update_metric_container
static void
update_metric_container(rpl_instance_t *instance)
{
rpl_path_metric_t path_metric;
rpl_dag_t *dag;
#if RPL_DAG_MC == RPL_DAG_MC_ENERGY
uint8_t type;
#endif
instance->mc.flags = RPL_DAG_MC_FLAG_P;
instance->mc.aggr = RPL_DAG_MC_AGGR_ADDITIVE;
instance->mc.prec = 0;
dag = instance->current_dag;
if (!dag->joined) {
/* We should probably do something here */
return;
}
if(dag->rank == ROOT_RANK(instance)) {
path_metric = 0;
} else {
path_metric = calculate_path_metric(dag->preferred_parent);
}
#if RPL_DAG_MC == RPL_DAG_MC_ETX
instance->mc.type = RPL_DAG_MC_ETX;
instance->mc.length = sizeof(instance->mc.obj.etx);
instance->mc.obj.etx = path_metric;
PRINTF("RPL: My path ETX to the root is %u.%u\n",
instance->mc.obj.etx / RPL_DAG_MC_ETX_DIVISOR,
(instance->mc.obj.etx % RPL_DAG_MC_ETX_DIVISOR * 100) / RPL_DAG_MC_ETX_DIVISOR);
#elif RPL_DAG_MC == RPL_DAG_MC_ENERGY
instance->mc.type = RPL_DAG_MC_ENERGY;
instance->mc.length = sizeof(instance->mc.obj.energy);
if(dag->rank == ROOT_RANK(instance)) {
type = RPL_DAG_MC_ENERGY_TYPE_MAINS;
} else {
type = RPL_DAG_MC_ENERGY_TYPE_BATTERY;
}
instance->mc.obj.energy.flags = type << RPL_DAG_MC_ENERGY_TYPE;
instance->mc.obj.energy.energy_est = path_metric;
#else
#error "Unsupported RPL_DAG_MC configured. See rpl.h."
#endif /* RPL_DAG_MC */
}
示例2: update_metric_container
static void
update_metric_container(rpl_instance_t *instance)
{
rpl_path_metric_t path_metric;
rpl_dag_t *dag;
#if RPL_DAG_MC == RPL_DAG_MC_ENERGY
uint8_t type;
#endif
instance->mc.type = RPL_DAG_MC;
instance->mc.flags = RPL_DAG_MC_FLAG_P;
instance->mc.aggr = RPL_DAG_MC_AGGR_ADDITIVE;
instance->mc.prec = 0;
dag = instance->current_dag;
if (!dag->joined) {
PRINTF("RPL: Cannot update the metric container when not joined\n");
return;
}
if(dag->rank == ROOT_RANK(instance)) {
path_metric = 0;
} else {
path_metric = calculate_path_metric(dag->preferred_parent);
}
#if RPL_DAG_MC == RPL_DAG_MC_ETX
instance->mc.length = sizeof(instance->mc.obj.etx);
instance->mc.obj.etx = path_metric;
PRINTF("RPL: My path ETX to the root is %u.%u\n",
instance->mc.obj.etx / RPL_DAG_MC_ETX_DIVISOR,
(instance->mc.obj.etx % RPL_DAG_MC_ETX_DIVISOR * 100) /
RPL_DAG_MC_ETX_DIVISOR);
#elif RPL_DAG_MC == RPL_DAG_MC_ENERGY
instance->mc.length = sizeof(instance->mc.obj.energy);
if(dag->rank == ROOT_RANK(instance)) {
type = RPL_DAG_MC_ENERGY_TYPE_MAINS;
} else {
type = RPL_DAG_MC_ENERGY_TYPE_BATTERY;
}
instance->mc.obj.energy.flags = type << RPL_DAG_MC_ENERGY_TYPE;
instance->mc.obj.energy.energy_est = path_metric;
#elif RPL_DAG_MC == RPL_DAG_MC_TOTALENERGY
instance->mc.length = sizeof(instance->mc.obj.total_energy);
instance->mc.obj.total_energy = path_metric;
// printf("total_energy path_metric:%u\n", path_metric);
#endif /* RPL_DAG_MC == RPL_DAG_MC_ETX */
}
示例3: update_metric_container
static void
update_metric_container(rpl_dag_t *dag)
{
rpl_path_metric_t path_metric;
#if RPL_DAG_MC == RPL_DAG_MC_ENERGY
uint8_t type;
#endif
dag->mc.flags = RPL_DAG_MC_FLAG_P;
dag->mc.aggr = RPL_DAG_MC_AGGR_ADDITIVE;
dag->mc.prec = 0;
if(dag->rank == ROOT_RANK(dag)) {
path_metric = 0;
} else {
path_metric = calculate_path_metric(dag->preferred_parent);
}
#if RPL_DAG_MC == RPL_DAG_MC_ETX
dag->mc.type = RPL_DAG_MC_ETX;
dag->mc.length = sizeof(dag->mc.obj.etx);
dag->mc.obj.etx = path_metric;
PRINTF("RPL: My path ETX to the root is %u.%u\n",
dag->mc.obj.etx / RPL_DAG_MC_ETX_DIVISOR,
(dag->mc.obj.etx % RPL_DAG_MC_ETX_DIVISOR * 100) / RPL_DAG_MC_ETX_DIVISOR);
#elif RPL_DAG_MC == RPL_DAG_MC_ENERGY
dag->mc.type = RPL_DAG_MC_ENERGY;
dag->mc.length = sizeof(dag->mc.obj.energy);
if(dag->rank == ROOT_RANK(dag)) {
type = RPL_DAG_MC_ENERGY_TYPE_MAINS;
} else {
type = RPL_DAG_MC_ENERGY_TYPE_BATTERY;
}
dag->mc.obj.energy.flags = type << RPL_DAG_MC_ENERGY_TYPE;
dag->mc.obj.energy.energy_est = path_metric;
#else
#error "Unsupported RPL_DAG_MC configured. See rpl.h."
#endif /* RPL_DAG_MC */
}
示例4: update_metric_container
/*---------------------------------------------------------------------------*/
#if !RPL_WITH_MC
static void
update_metric_container(rpl_instance_t *instance)
{
instance->mc.type = RPL_DAG_MC_NONE;
}
#else /* RPL_WITH_MC */
static void
update_metric_container(rpl_instance_t *instance)
{
rpl_dag_t *dag;
uint16_t path_cost;
uint8_t type;
dag = instance->current_dag;
if(dag == NULL || !dag->joined) {
PRINTF("RPL: Cannot update the metric container when not joined\n");
return;
}
if(dag->rank == ROOT_RANK(instance)) {
/* Configure MC at root only, other nodes are auto-configured when joining */
instance->mc.type = RPL_DAG_MC;
instance->mc.flags = 0;
instance->mc.aggr = RPL_DAG_MC_AGGR_ADDITIVE;
instance->mc.prec = 0;
path_cost = dag->rank;
} else {
path_cost = parent_path_cost(dag->preferred_parent);
}
/* Handle the different MC types */
switch(instance->mc.type) {
case RPL_DAG_MC_NONE:
break;
case RPL_DAG_MC_ETX:
instance->mc.length = sizeof(instance->mc.obj.etx);
instance->mc.obj.etx = path_cost;
break;
case RPL_DAG_MC_ENERGY:
instance->mc.length = sizeof(instance->mc.obj.energy);
if(dag->rank == ROOT_RANK(instance)) {
type = RPL_DAG_MC_ENERGY_TYPE_MAINS;
} else {
type = RPL_DAG_MC_ENERGY_TYPE_BATTERY;
}
instance->mc.obj.energy.flags = type << RPL_DAG_MC_ENERGY_TYPE;
/* Energy_est is only one byte, use the least significant byte of the path metric. */
instance->mc.obj.energy.energy_est = path_cost >> 8;
break;
default:
PRINTF("RPL: MRHOF, non-supported MC %u\n", instance->mc.type);
break;
}
}
示例5: calculate_path_metric
static rpl_path_metric_t
calculate_path_metric(rpl_parent_t *p)
{
if(p == NULL || (p->mc.obj.etx == 0 && p->rank > ROOT_RANK(p->dag))) {
return MAX_PATH_COST * RPL_DAG_MC_ETX_DIVISOR;
}
return p->mc.obj.etx + NI_ETX_TO_RPL_ETX(p->link_metric);
}
示例6: new_dio_interval
/*---------------------------------------------------------------------------*/
static void
new_dio_interval(rpl_instance_t *instance, int isReset)
{
uint32_t time;
clock_time_t ticks;
/* TODO: too small timer intervals for many cases */
time = 1UL << instance->dio_intcurrent;
/* Convert from milliseconds to CLOCK_TICKS. */
ticks = (time * CLOCK_SECOND) / 1000;
instance->dio_next_delay = ticks;
/* random number between I/2 and I */
ticks = ticks / 2 + (ticks / 2 * (uint32_t)random_rand()) / RANDOM_RAND_MAX;
/* opt trickle*/
/*
if (isReset == 1) {
ticks * (uint32_t)random_rand() / RANDOM_RAND_MAX;
}
else {
ticks = ticks / 2 + (ticks / 2 * (uint32_t)random_rand()) / RANDOM_RAND_MAX;
}
*/
/*
* The intervals must be equally long among the nodes for Trickle to
* operate efficiently. Therefore we need to calculate the delay between
* the randomized time and the start time of the next interval.
*/
instance->dio_next_delay -= ticks;
instance->dio_send = 1;
#if RPL_CONF_STATS
/* keep some stats */
instance->dio_totint++;
instance->dio_totrecv += instance->dio_counter;
ANNOTATE("#A rank=%u.%u(%u),stats=%d %d %d %d,color=%s\n",
DAG_RANK(instance->current_dag->rank, instance),
(10 * (instance->current_dag->rank % instance->min_hoprankinc)) / instance->min_hoprankinc,
instance->current_dag->version,
instance->dio_totint, instance->dio_totsend,
instance->dio_totrecv,instance->dio_intcurrent,
instance->current_dag->rank == ROOT_RANK(instance) ? "BLUE" : "ORANGE");
#endif /* RPL_CONF_STATS */
/* reset the redundancy counter */
instance->dio_counter = 0;
/* schedule the timer */
PRINTF("RPL: Scheduling DIO timer %lu ticks in future (Interval)\n", ticks);
ctimer_set(&instance->dio_timer, ticks, &handle_dio_timer, instance);
}
示例7: calculate_path_metric
static rpl_path_metric_t
calculate_path_metric(rpl_parent_t *p)
{
if(p == NULL || (p->mc.obj.etx == 0 && p->rank > ROOT_RANK(p->dag->instance))) {
return MAX_PATH_COST * RPL_DAG_MC_ETX_DIVISOR;
} else {
long etx = p->link_metric;
etx = (etx * RPL_DAG_MC_ETX_DIVISOR) / NEIGHBOR_INFO_ETX_DIVISOR;
return p->mc.obj.etx + (uint16_t) etx;
}
}
示例8: rpl_set_root
rpl_dag_t *
rpl_set_root(uip_ipaddr_t *dag_id)
{
rpl_dag_t *dag;
int version;
version = -1;
dag = rpl_get_dag(RPL_DEFAULT_INSTANCE);
if(dag != NULL) {
PRINTF("RPL: Dropping a joined DAG when setting this node as root");
version = dag->version;
rpl_free_dag(dag);
}
dag = rpl_alloc_dag(RPL_DEFAULT_INSTANCE);
if(dag == NULL) {
PRINTF("RPL: Failed to allocate a DAG\n");
return NULL;
}
dag->joined = 1;
dag->version = version + 1;
dag->grounded = RPL_GROUNDED;
dag->mop = RPL_MOP_DEFAULT;
dag->of = &RPL_OF;
dag->preferred_parent = NULL;
dag->dtsn_out = 1; /* Trigger DAOs from the beginning. */
memcpy(&dag->dag_id, dag_id, sizeof(dag->dag_id));
dag->dio_intdoubl = DEFAULT_DIO_INTERVAL_DOUBLINGS;
dag->dio_intmin = DEFAULT_DIO_INTERVAL_MIN;
dag->dio_redundancy = DEFAULT_DIO_REDUNDANCY;
dag->max_rankinc = DEFAULT_MAX_RANKINC;
dag->min_hoprankinc = DEFAULT_MIN_HOPRANKINC;
dag->default_lifetime = RPL_DEFAULT_LIFETIME;
dag->lifetime_unit = RPL_DEFAULT_LIFETIME_UNIT;
dag->rank = ROOT_RANK(dag);
dag->of->update_metric_container(dag);
PRINTF("RPL: Node set to be a DAG root with DAG ID ");
PRINT6ADDR(&dag->dag_id);
PRINTF("\n");
ANNOTATE("#A root=%u\n",dag->dag_id.u8[sizeof(dag->dag_id) - 1]);
rpl_reset_dio_timer(dag, 1);
return dag;
}
示例9: rpl_repair_dag
int
rpl_repair_dag(rpl_dag_t *dag)
{
if(dag->rank == ROOT_RANK(dag)) {
dag->version++;
dag->dtsn_out = 1;
rpl_reset_dio_timer(dag, 1);
return 1;
}
return 0;
}
示例10: rpl_opp_routing_reset
void
rpl_opp_routing_reset(void)
{
rpl_dag_t *dag;
dag = rpl_get_any_dag();
if(uip_ds6_is_my_addr(&dag->dag_id)) {
we_are_root = 1;
current_rank = ROOT_RANK(dag->instance);
} else {
current_rank = INFINITE_RANK;
}
}
示例11: rpl_purge_routes
/*---------------------------------------------------------------------------*/
void
rpl_purge_routes(void)
{
uip_ds6_route_t *r;
uip_ipaddr_t prefix;
rpl_dag_t *dag;
rpl_instance_t *instance; //changed
/* First pass, decrement lifetime */
r = uip_ds6_route_head();
while(r != NULL) {
if(r->state.lifetime >= 1) {
/*
* If a route is at lifetime == 1, set it to 0, scheduling it for
* immediate removal below. This achieves the same as the original code,
* which would delete lifetime <= 1
*/
r->state.lifetime--;
}
r = uip_ds6_route_next(r);
}
/* Second pass, remove dead routes */
r = uip_ds6_route_head();
while(r != NULL) {
/*Pre-change handle second_instance*/
if(r->state.lifetime < 1) {
/* Routes with lifetime == 1 have only just been decremented from 2 to 1,
* thus we want to keep them. Hence < and not <= */
uip_ipaddr_copy(&prefix, &r->ipaddr);
uip_ds6_route_rm(r);
r = uip_ds6_route_head();
PRINTF("No more routes to ");
PRINT6ADDR(&prefix);
/*Changed*/
instance = rpl_get_instance(r->state.instance_id);
dag = instance->current_dag;
//dag1 = second_instance->current_dag;
/* Propagate this information with a No-Path DAO to preferred parent if we are not a RPL Root */
if(dag->rank != ROOT_RANK(instance)) {
PRINTF(" -> generate No-Path DAO\n");
dao_output_target(dag->preferred_parent, &prefix, RPL_ZERO_LIFETIME);
/* Don't schedule more than 1 No-Path DAO, let next iteration handle that */
return;
}
PRINTF("\n");
} else {
r = uip_ds6_route_next(r);
}
}
}
示例12: rpl_opp_routing_init
void
rpl_opp_routing_init(void)
{
nbr_table_register(forwarder_set, NULL);
memb_init(&forwarder_set_memb);
rpl_dag_t *dag;
dag = rpl_get_any_dag();
if(uip_ds6_is_my_addr(&dag->dag_id)) {
we_are_root = 1;
current_rank = ROOT_RANK(dag->instance);
} else {
process_start(&rpl_forwarder_set_update_process, NULL);
}
}
示例13: rpl_repair_root
/*---------------------------------------------------------------------------*/
int
rpl_repair_root(uint8_t instance_id)
{
rpl_instance_t *instance;
instance = rpl_get_instance(instance_id);
if(instance == NULL ||
instance->current_dag->rank != ROOT_RANK(instance)) {
return 0;
}
RPL_LOLLIPOP_INCREMENT(instance->current_dag->version);
RPL_LOLLIPOP_INCREMENT(instance->dtsn_out);
rpl_reset_dio_timer(instance);
return 1;
}
示例14: update_metric_container
static void
update_metric_container(rpl_dag_t *dag)
{
dag->mc.type = RPL_DAG_MC_ETX;
dag->mc.flags = RPL_DAG_MC_FLAG_P;
dag->mc.aggr = RPL_DAG_MC_AGGR_ADDITIVE;
dag->mc.prec = 0;
dag->mc.length = sizeof(dag->mc.etx.etx);
if(dag->rank == ROOT_RANK(dag)) {
dag->mc.etx.etx = 0;
} else {
dag->mc.etx.etx = calculate_etx(dag->preferred_parent);
}
PRINTF("RPL: My path ETX to the root is %u.%u\n",
dag->mc.etx.etx / RPL_DAG_MC_ETX_DIVISOR,
(dag->mc.etx.etx % RPL_DAG_MC_ETX_DIVISOR * 100) / RPL_DAG_MC_ETX_DIVISOR);
}
示例15: rpl_repair_root
/*---------------------------------------------------------------------------*/
int
rpl_repair_root(uint8_t instance_id)
{
rpl_instance_t *instance;
instance = rpl_get_instance(instance_id);
if(instance == NULL ||
instance->current_dag->rank != ROOT_RANK(instance)) {
PRINTF("RPL: rpl_repair_root triggered but not root\n");
return 0;
}
RPL_LOLLIPOP_INCREMENT(instance->current_dag->version);
RPL_LOLLIPOP_INCREMENT(instance->dtsn_out);
PRINTF("RPL: rpl_repair_root initiating global repair with version %d\n", instance->current_dag->version);
rpl_reset_dio_timer(instance);
return 1;
}