예제 #1
0
/*---------------------------------------------------------------------------*/
static void
create_dag_callback(void *ptr)
{
    const uip_ipaddr_t *root, *ipaddr;
    printf("\r\nCtimer timer callback for dag root");
    root = simple_rpl_root();
    ipaddr = simple_rpl_global_address();

    if(root == NULL || uip_ipaddr_cmp(root, ipaddr)) {
        /* The RPL network we are joining is one that we created, so we
           become root. */
        printf("\r\n No root available, we'll make ourself as root ");
        if(to_become_root) {
            simple_rpl_init_dag_immediately();
            to_become_root = 0;
        }
    } else {
        rpl_dag_t *dag;

        dag = rpl_get_any_dag();
#if 1
        printf("\r\nFound a network we did not create, ");
        printf("version %d grounded %d preference %d used %d joined %d rank %d\n",
               dag->version, dag->grounded,
               dag->preference, dag->used,
               dag->joined, dag->rank);
        printf("\r\n Root's nodeid = 0x%2X%2X. ", root->u8[14], root->u8[15]);
#endif /* _DEBUG_ */

        /* We found a RPL network that we did not create so we just join
           it without becoming root. But if the network has an infinite
           rank, we assume the network has broken, and we become the new
           root of the network. */

        if(dag->rank == INFINITE_RANK) {
            if(to_become_root) {
                printf("\r\n The dag rank is infinite, so we'll become the root");
                simple_rpl_init_dag_immediately();
                to_become_root = 0;
            }
        }

        /* Try again after the grace period */
        ctimer_set(&c, RPL_DAG_GRACE_PERIOD, create_dag_callback, NULL);
    }
}
예제 #2
0
/*---------------------------------------------------------------------------*/
static void
create_dag_callback(void *ptr)
{
  const uip_ipaddr_t *root, *ipaddr;

  root = simple_rpl_root();
  ipaddr = simple_rpl_global_address();

  if(root == NULL || uip_ipaddr_cmp(root, ipaddr)) {
    /* The RPL network we are joining is one that we created, so we
       become root. */
    if(to_become_root) {
      simple_rpl_init_dag_immediately();
      to_become_root = 0;
    }
  } else {
    rpl_dag_t *dag;

    dag = rpl_get_any_dag();
#if DEBUG
    printf("Found a network we did not create\n");
    printf("version %d grounded %d preference %d used %d joined %d rank %d\n",
           dag->version, dag->grounded,
           dag->preference, dag->used,
           dag->joined, dag->rank);
#endif /* DEBUG */

    /* We found a RPL network that we did not create so we just join
       it without becoming root. But if the network has an infinite
       rank, we assume the network has broken, and we become the new
       root of the network. */

    if(dag->rank == INFINITE_RANK) {
      if(to_become_root) {
        simple_rpl_init_dag_immediately();
        to_become_root = 0;
      }
    }

    /* Try again after the grace period */
    ctimer_set(&c, RPL_DAG_GRACE_PERIOD, create_dag_callback, NULL);
  }
}