本文整理汇总了C++中rpl_add_parent函数的典型用法代码示例。如果您正苦于以下问题:C++ rpl_add_parent函数的具体用法?C++ rpl_add_parent怎么用?C++ rpl_add_parent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rpl_add_parent函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: global_repair
static void
global_repair(uip_ipaddr_t *from, rpl_dag_t *dag, rpl_dio_t *dio)
{
rpl_parent_t *p;
remove_parents(dag, 0);
dag->version = dio->version;
dag->dtsn_out = 1;
dag->of->reset(dag);
if((p = rpl_add_parent(dag, dio, from)) == NULL) {
PRINTF("RPL: Failed to add a parent during the global repair\n");
dag->rank = INFINITE_RANK;
} else {
rpl_set_default_route(dag, from);
dag->rank = dag->of->calculate_rank(NULL, dio->rank);
dag->min_rank = dag->rank;
rpl_reset_dio_timer(dag, 1);
if(should_send_dao(dag, dio, p)) {
rpl_schedule_dao(dag);
}
}
PRINTF("RPL: Participating in a global repair (version=%u, rank=%hu)\n",
dag->version, dag->rank);
RPL_STAT(rpl_stats.global_repairs++);
}
示例2: global_repair
/*---------------------------------------------------------------------------*/
static void
global_repair(uip_ipaddr_t *from, rpl_dag_t *dag, rpl_dio_t *dio)
{
rpl_parent_t *p;
remove_parents(dag, 0);
dag->version = dio->version;
dag->instance->of->reset(dag);
dag->min_rank = INFINITE_RANK;
RPL_LOLLIPOP_INCREMENT(dag->instance->dtsn_out);
p = rpl_add_parent(dag, dio, from);
if(p == NULL) {
PRINTF("RPL: Failed to add a parent during the global repair\n");
dag->rank = INFINITE_RANK;
} else {
dag->rank = dag->instance->of->calculate_rank(p, 0);
dag->min_rank = dag->rank;
PRINTF("RPL: rpl_process_parent_event global repair\n");
rpl_process_parent_event(dag->instance, p);
}
PRINTF("RPL: Participating in a global repair (version=%u, rank=%hu)\n",
dag->version, dag->rank);
RPL_STAT(rpl_stats.global_repairs++);
}
示例3: rpl_process_dio
/*---------------------------------------------------------------------------*/
void
rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
{
rpl_instance_t *instance;
rpl_dag_t *dag, *previous_dag;
rpl_parent_t *p;
if(dio->mop != RPL_MOP_DEFAULT) {
PRINTF("RPL: Ignoring a DIO with an unsupported MOP: %d\n", dio->mop);
return;
}
dag = get_dag(dio->instance_id, &dio->dag_id);
instance = rpl_get_instance(dio->instance_id);
if(dag != NULL && instance != NULL) {
if(lollipop_greater_than(dio->version, dag->version)) {
if(dag->rank == ROOT_RANK(instance)) {
PRINTF("RPL: Root received inconsistent DIO version number\n");
dag->version = dio->version;
RPL_LOLLIPOP_INCREMENT(dag->version);
rpl_reset_dio_timer(instance);
} else {
PRINTF("RPL: Global Repair\n");
if(dio->prefix_info.length != 0) {
if(dio->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) {
PRINTF("RPL : Prefix announced in DIO\n");
rpl_set_prefix(dag, &dio->prefix_info.prefix, dio->prefix_info.length);
}
}
global_repair(from, dag, dio);
}
return;
}
if(lollipop_greater_than(dag->version, dio->version)) {
/* The DIO sender is on an older version of the DAG. */
PRINTF("RPL: old version received => inconsistency detected\n");
if(dag->joined) {
rpl_reset_dio_timer(instance);
return;
}
}
}
if(instance == NULL) {
PRINTF("RPL: New instance detected: Joining...\n");
rpl_join_instance(from, dio);
return;
}
if(dag == NULL) {
PRINTF("RPL: Adding new DAG to known instance.\n");
rpl_add_dag(from, dio);
return;
}
if(dio->rank < ROOT_RANK(instance)) {
PRINTF("RPL: Ignoring DIO with too low rank: %u\n",
(unsigned)dio->rank);
return;
} else if(dio->rank == INFINITE_RANK && dag->joined) {
rpl_reset_dio_timer(instance);
}
/* Prefix Information Option treated to add new prefix */
if(dio->prefix_info.length != 0) {
if(dio->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) {
PRINTF("RPL : Prefix announced in DIO\n");
rpl_set_prefix(dag, &dio->prefix_info.prefix, dio->prefix_info.length);
}
}
if(dag->rank == ROOT_RANK(instance)) {
if(dio->rank != INFINITE_RANK) {
instance->dio_counter++;
}
#if !WITH_ORPL
return; /* With ORPL we want to have neighbors in the "rpl_parents"
table as we need their rank and ackcount for routing set. */
#endif
}
/*
* At this point, we know that this DIO pertains to a DAG that
* we are already part of. We consider the sender of the DIO to be
* a candidate parent, and let rpl_process_parent_event decide
* whether to keep it in the set.
*/
p = rpl_find_parent(dag, from);
if(p == NULL) {
previous_dag = find_parent_dag(instance, from);
if(previous_dag == NULL) {
/* Add the DIO sender as a candidate parent. */
p = rpl_add_parent(dag, dio, from);
if(p == NULL) {
PRINTF("RPL: Failed to add a new parent (");
//.........这里部分代码省略.........
示例4: rpl_process_dio
/*---------------------------------------------------------------------------*/
void
rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
{
rpl_instance_t *instance;
rpl_dag_t *dag, *previous_dag;
rpl_parent_t *p;
anycast_update_neighbor_edc(packetbuf_addr(PACKETBUF_ADDR_SENDER), dio->rank);
if(dio->mop != RPL_MOP_DEFAULT) {
PRINTF("RPL: Ignoring a DIO with an unsupported MOP: %d\n", dio->mop);
return;
}
dag = get_dag(dio->instance_id, &dio->dag_id);
instance = rpl_get_instance(dio->instance_id);
if(dag != NULL && instance != NULL) {
if(lollipop_greater_than(dio->version, dag->version)) {
if(dag->rank == ROOT_RANK(instance)) {
PRINTF("RPL: Root received inconsistent DIO version number\n");
dag->version = dio->version;
RPL_LOLLIPOP_INCREMENT(dag->version);
rpl_reset_dio_timer(instance);
} else {
global_repair(from, dag, dio);
}
return;
}
if(lollipop_greater_than(dag->version, dio->version)) {
/* The DIO sender is on an older version of the DAG. */
PRINTF("RPL: old version received => inconsistency detected\n");
if(dag->joined) {
rpl_reset_dio_timer(instance);
return;
}
}
}
if(dio->rank == INFINITE_RANK) {
PRINTF("RPL: Ignoring DIO from node with infinite rank: ");
PRINT6ADDR(from);
PRINTF("\n");
return;
}
if(instance == NULL) {
PRINTF("RPL: New instance detected: Joining...\n");
rpl_join_instance(from, dio);
return;
}
if(dag == NULL) {
PRINTF("RPL: Adding new DAG to known instance.\n");
rpl_add_dag(from, dio);
return;
}
if(dio->rank < ROOT_RANK(instance)) {
PRINTF("RPL: Ignoring DIO with too low rank: %u\n",
(unsigned)dio->rank);
return;
} else if(dio->rank == INFINITE_RANK && dag->joined) {
rpl_reset_dio_timer(instance);
}
if(dag->rank == ROOT_RANK(instance)) {
if(dio->rank != INFINITE_RANK) {
instance->dio_counter++;
}
return;
}
/*
* At this point, we know that this DIO pertains to a DAG that
* we are already part of. We consider the sender of the DIO to be
* a candidate parent, and let rpl_process_parent_event decide
* whether to keep it in the set.
*/
p = rpl_find_parent(dag, from);
if(p == NULL) {
previous_dag = find_parent_dag(instance, from);
if(previous_dag == NULL) {
if(RPL_PARENT_COUNT(dag) == RPL_MAX_PARENTS_PER_DAG) {
/* Make room for a new parent. */
remove_worst_parent(dag, dio->rank);
}
/* Add the DIO sender as a candidate parent. */
p = rpl_add_parent(dag, dio, from);
if(p == NULL) {
PRINTF("RPL: Failed to add a new parent (");
PRINT6ADDR(from);
PRINTF(")\n");
return;
}
PRINTF("RPL: New candidate parent with rank %u: ", (unsigned)p->rank);
//.........这里部分代码省略.........
示例5: rpl_process_dio
void
rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
{
rpl_dag_t *dag;
rpl_parent_t *p;
if(dio->mop != RPL_MOP_DEFAULT) {
PRINTF("RPL: Ignoring a DIO with an unsupported MOP: %d\n", dio->mop);
return;
}
// LVD 24/03/2011
instanceID = dio->instance_id;
dag = rpl_get_dag(dio->instance_id);
if(dag == NULL) {
/* Join the first possible DAG of this RPL instance. */
if(dio->rank != INFINITE_RANK) {
join_dag(from, dio);
} else {
PRINTF("RPL: Ignoring DIO from node with infinite rank: ");
PRINT6ADDR(from);
PRINTF("\n");
}
return;
}
if(memcmp(&dag->dag_id, &dio->dag_id, sizeof(dag->dag_id))) {
PRINTF("RPL: Ignoring DIO for another DAG within our instance\n");
return;
}
if(dio->version > dag->version) {
if(dag->rank == ROOT_RANK(dag)) {
PRINTF("RPL: Root received inconsistent DIO version number\n");
dag->version = dio->version + 1;
rpl_reset_dio_timer(dag, 1);
} else {
global_repair(from, dag, dio);
}
return;
} else if(dio->version < dag->version) {
/* Inconsistency detected - someone is still on old version */
PRINTF("RPL: old version received => inconsistency detected\n");
rpl_reset_dio_timer(dag, 1);
return;
}
if(dio->rank == INFINITE_RANK) {
rpl_reset_dio_timer(dag, 1);
} else if(dio->rank < ROOT_RANK(dag)) {
PRINTF("RPL: Ignoring DIO with too low rank: %u\n",
(unsigned)dio->rank);
return;
}
if(dag->rank == ROOT_RANK(dag)) {
if(dio->rank != INFINITE_RANK) {
dag->dio_counter++;
}
return;
}
/*
* At this point, we know that this DIO pertains to a DAG that
* we are already part of. We consider the sender of the DIO to be
* a candidate parent, and let rpl_process_parent_event decide
* whether to keep it in the set.
*/
p = rpl_find_parent(dag, from);
if(p == NULL) {
if(RPL_PARENT_COUNT(dag) == RPL_MAX_PARENTS) {
/* Make room for a new parent. */
remove_worst_parent(dag, dio->rank);
}
/* Add the DIO sender as a candidate parent. */
p = rpl_add_parent(dag, dio, from);
if(p == NULL) {
PRINTF("RPL: Failed to add a new parent (");
PRINT6ADDR(from);
PRINTF(")\n");
return;
}
PRINTF("RPL: New candidate parent with rank %u: ", (unsigned)p->rank);
PRINT6ADDR(from);
PRINTF("\n");
} else if(DAG_RANK(p->rank, dag) == DAG_RANK(dio->rank, dag)) {
PRINTF("RPL: Received consistent DIO\n");
dag->dio_counter++;
}
/* We have allocated a candidate parent; process the DIO further. */
memcpy(&p->mc, &dio->mc, sizeof(p->mc));
p->rank = dio->rank;
if(rpl_process_parent_event(dag, p) == 0) {
/* The candidate parent no longer exists. */
//.........这里部分代码省略.........
示例6: join_dag
static void
join_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
{
rpl_dag_t *dag;
rpl_parent_t *p;
rpl_of_t *of;
dag = rpl_alloc_dag(dio->instance_id);
if(dag == NULL) {
PRINTF("RPL: Failed to allocate a DAG object!\n");
return;
}
p = rpl_add_parent(dag, dio, from);
PRINTF("RPL: Adding ");
PRINT6ADDR(from);
PRINTF(" as a parent: ");
if(p == NULL) {
PRINTF("failed\n");
return;
}
PRINTF("succeeded\n");
/* Determine the objective function by using the
objective code point of the DIO. */
of = rpl_find_of(dio->ocp);
if(of == NULL) {
PRINTF("RPL: DIO for DAG instance %u does not specify a supported OF\n",
dio->instance_id);
return;
}
/* Autoconfigure an address if this node does not already have an address
with this prefix. */
if((dio->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS)) {
uip_ipaddr_t ipaddr;
/* assume that the prefix ends with zeros! */
memcpy(&ipaddr, &dio->prefix_info.prefix, 16);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
if(uip_ds6_addr_lookup(&ipaddr) == NULL) {
PRINTF("RPL: adding global IP address ");
PRINT6ADDR(&ipaddr);
PRINTF("\n");
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
}
}
dag->joined = 1;
dag->used = 1;
dag->of = of;
dag->grounded = dio->grounded;
dag->mop = dio->mop;
dag->preference = dio->preference;
dag->instance_id = dio->instance_id;
dag->max_rankinc = dio->dag_max_rankinc;
dag->min_hoprankinc = dio->dag_min_hoprankinc;
dag->version = dio->version;
dag->preferred_parent = p;
dag->of->update_metric_container(dag);
dag->dio_intdoubl = dio->dag_intdoubl;
dag->dio_intmin = dio->dag_intmin;
dag->dio_redundancy = dio->dag_redund;
memcpy(&dag->dag_id, &dio->dag_id, sizeof(dio->dag_id));
/* copy prefix information into the dag */
memcpy(&dag->prefix_info, &dio->prefix_info, sizeof(rpl_prefix_t));
dag->rank = dag->of->calculate_rank(p, dio->rank);
dag->min_rank = dag->rank; /* So far this is the lowest rank we know of. */
PRINTF("RPL: Joined DAG with instance ID %u, rank %hu, DAG ID ",
dio->instance_id, dag->rank);
PRINT6ADDR(&dag->dag_id);
PRINTF("\n");
ANNOTATE("#A join=%u\n",dag->dag_id.u8[sizeof(dag->dag_id) - 1]);
dag->default_lifetime = dio->default_lifetime;
dag->lifetime_unit = dio->lifetime_unit;
rpl_reset_dio_timer(dag, 1);
rpl_set_default_route(dag, from);
if(should_send_dao(dag, dio, p)) {
rpl_schedule_dao(dag);
} else {
PRINTF("RPL: The DIO does not meet the prerequisites for sending a DAO\n");
}
}
示例7: rpl_join_instance
/*---------------------------------------------------------------------------*/
void
rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio)
{
rpl_instance_t *instance;
rpl_dag_t *dag;
rpl_parent_t *p;
rpl_of_t *of;
int tx;//elnaz
dag = rpl_alloc_dag(dio->instance_id, &dio->dag_id);
if(dag == NULL) {
// PRINTF("RPL: Failed to allocate a DAG object!\n");
return;
}
instance = dag->instance;
p = rpl_add_parent(dag, dio, from);
// PRINTF("RPL: Adding ");
// PRINT6ADDR(from);
// PRINTF(" as a parent: ");
if(p == NULL) {
// PRINTF("failed\n");
instance->used = 0;
return;
}
p->dtsn = dio->dtsn;
// PRINTF("succeeded\n");
/* Determine the objective function by using the
objective code point of the DIO. */
of = rpl_find_of(dio->ocp);
if(of == NULL) {
// PRINTF("RPL: DIO for DAG instance %u does not specify a supported OF\n",dio->instance_id);
rpl_remove_parent(p);
instance->used = 0;
return;
}
/* Autoconfigure an address if this node does not already have an address
with this prefix. */
if(dio->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) {
check_prefix(NULL, &dio->prefix_info);
}
//-----------------elnaz
tx =cc2420_get_txpower();
printf("Power=%d \n",tx);
switch(tx) {
case 3:
dag->Tx = 0.003;
break;
case 7:
dag->Tx = 0.03;
break;
case 11:
dag->Tx = 0.1;
break;
case 15:
dag->Tx = 0.2;
break;
case 19:
dag->Tx = 0.3;
break;
case 23:
dag->Tx = 0.5;
break;
case 27:
dag->Tx = 0.8;
break;
case 31:
dag->Tx = 1;
}
/*
float mv = (bateria * 2.500 * 2) / 4096;
printf("Battery: (%ld.%03d mV)\n", (long) mv, (unsigned) ((mv - floor(mv)) * 1000));
*/
//printf("Test tx=%ld ",(long) (dag->Tx*1000));
//----------------------elnaz
dag->joined = 1;
dag->preference = dio->preference;
dag->grounded = dio->grounded;
dag->version = dio->version;
instance->of = of;
instance->mop = dio->mop;
instance->current_dag = dag;
//.........这里部分代码省略.........
示例8: rpl_process_dio
//.........这里部分代码省略.........
PRINTF("RPL: Ignoring DIO with too low rank: %u\n", (unsigned)dio->rank);
return;
} else if(dio->rank == INFINITE_RANK && dag->joined) {
rpl_reset_dio_timer(instance);
}
/* Prefix Information Option treated to add new prefix */
if(dio->prefix_info.length != 0) {
if(dio->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) {
PRINTF("RPL : Prefix announced in DIO\n");
rpl_set_prefix(dag, &dio->prefix_info.prefix, dio->prefix_info.length);
}
}
if(dag->rank == ROOT_RANK(instance)) {
if(dio->rank != INFINITE_RANK) {
instance->dio_counter++;
}
return;
}
/*
* At this point, we know that this DIO pertains to a DAG that
* we are already part of. We consider the sender of the DIO to be
* a candidate parent, and let rpl_process_parent_event decide
* whether to keep it in the set.
*/
p = rpl_find_parent(dag, from);
if(p == NULL) {
previous_dag = find_parent_dag(instance, from);
if(previous_dag == NULL) {
/* Add the DIO sender as a candidate parent. */
p = rpl_add_parent(dag, dio, from);
if(p == NULL) {
PRINTF("RPL: Failed to add a new parent (");
PRINT6ADDR(from);
PRINTF(")\n");
return;
}
PRINTF("RPL: New candidate parent with rank %u: ", (unsigned)p->rank);
PRINT6ADDR(from);
PRINTF("\n");
} else {
p = rpl_find_parent(previous_dag, from);
if(p != NULL) {
rpl_move_parent(previous_dag, dag, p);
}
}
} else {
if(p->rank == dio->rank) {
PRINTF("RPL: Received consistent DIO\n");
if(dag->joined) {
instance->dio_counter++;
}
} else {
p->rank = dio->rank;
}
}
PRINTF("RPL: preferred DAG ");
PRINT6ADDR(&instance->current_dag->dag_id);
PRINTF(", rank %u, min_rank %u, ",
instance->current_dag->rank, instance->current_dag->min_rank);
PRINTF("parent rank %u, parent etx %u, link metric %u, instance etx %u\n",
p->rank, -1 /*p->mc.obj.etx */, p->link_metric,