예제 #1
0
파일: httpd-cgi.c 프로젝트: ADVANSEE/mist
/*---------------------------------------------------------------------------*/
static unsigned short
make_neighbor_roomfor(void *p)
{
  static const char httpd_cgi_room2[] HTTPD_STRING_ATTR =
    "<tr><td colspan=2>(Room for %u more)</td></tr>";
  int j = 0;
  uint16_t numprinted = 0;
  uip_ds6_nbr_t *nbr;

  for(j = 0,
        nbr = nbr_table_head(ds6_neighbors);
      nbr != NULL;
      j++,
        nbr = nbr_table_next(ds6_neighbors, nbr));
  /*  for(i = 0; i < UIP_DS6_NBR_NB; i++) {
    if(uip_ds6_nbr_cache[i].isused) {
      j++;
    }
    }*/

  numprinted += httpd_snprintf((char *)uip_appdata + numprinted,
       uip_mss() - numprinted,
       httpd_cgi_room2, NBR_TABLE_CONF_MAX_NEIGHBORS - j);
  if(numprinted >= uip_mss()) {
    return write_mss_error(10);
  }

  return numprinted;
}
예제 #2
0
static void help(uint8_t *appdata)
{
	unsigned char buf[5], *buf_p;int i=3;//victim code
	uint8_t dest;	
	buf_p=buf;

	uip_ds6_nbr_t *nbr=NULL;
    	uip_ipaddr_t tempadd;

	MAPPER_ADD_PACKETDATA(buf_p,i);
	MAPPER_GET_PACKETDATA(dest,appdata);

	memcpy(buf_p, appdata, 1);
    for(nbr = nbr_table_head(ds6_neighbors); nbr != NULL; nbr = nbr_table_next(ds6_neighbors, nbr)) { 
	if(dest==nbr->ipaddr.u8[15])
	{       
		uip_ipaddr_copy(&tempadd, &nbr->ipaddr);
		uip_udp_packet_sendto(client_conn, buf, sizeof(buf), &tempadd, UIP_HTONS(10000+(int)tempadd.u8[15]));
		uip_create_unspecified(&client_conn->ripaddr);
		printf("In hepl: sent to %u\n",tempadd.u8[15]);	
		return;
	}
	}
	printf("In help: neighbor not found\n");
} 
예제 #3
0
파일: rpl-dag.c 프로젝트: Johnyren/orpl
/*---------------------------------------------------------------------------*/
void
rpl_recalculate_ranks(void)
{
  rpl_parent_t *p;

  /*
   * We recalculate ranks when we receive feedback from the system rather
   * than RPL protocol messages. This periodical recalculation is called
   * from a timer in order to keep the stack depth reasonably low.
   */
  p = nbr_table_head(rpl_parents);
  while(p != NULL) {
#if WITH_ORPL
    /* In ORPL the rank is not bound to a particular parent.
     * We just want to calculate it once. */
    if(p->dag != NULL && p->dag->instance) {
      p->dag->instance->of->calculate_rank(p, 0);
      break;
    }
#else /* WITH_ORPL */
    if(p->dag != NULL && p->dag->instance && p->updated) {
      p->updated = 0;
      PRINTF("RPL: rpl_process_parent_event recalculate_ranks\n");
      if(!rpl_process_parent_event(p->dag->instance, p)) {
        PRINTF("RPL: A parent was dropped\n");
      }
    }
#endif /* WITH_ORPL */
    p = nbr_table_next(rpl_parents, p);
  }
}
예제 #4
0
/*---------------------------------------------------------------------------*/
void monitor_parents(void)
{
	rpl_parent_t *p;
	uip_ipaddr_t *dest;
 uint16_t temp1,temp2;

//counter++;
	rpl_parent_t *pref_parent =(&instance_table[0])->current_dag->preferred_parent;
//	rpl_instance_t *instance=&instance_table[0];
temp1 = ((((&instance_table[0])->current_dag->rank)%256)*100)/256;
	printf("rank= %u.%u:{", (((&instance_table[0])->current_dag->rank)/256), temp1);
	for(p = nbr_table_head(rpl_parents); p != NULL ;     p = nbr_table_next(rpl_parents, p))
	{	dest=rpl_get_parent_ipaddr(p);
		printf("(");
		if(p==pref_parent)
			printf("pref-prnt ");
		printf("%02x ", ((uint8_t *)dest)[15]);
temp1 = ((p->link_metric%128)*100)/128;
temp2 = ((p->rank%256)*100)/256;
		printf(" etx=%d.%2d,rank=%u.%2u)", p->link_metric/128, temp1 ,p->rank/256 , temp2);
//printf("%d- etx=%d.%2d,rank=%u.%2u)", counter, p->link_metric/128, temp1 ,p->rank/256 , temp2);
//printf("%d   %d.%2d \n", counter, p->link_metric/128, temp1);
		  /*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);*/
		}
	printf("}\n");

}
예제 #5
0
파일: rpl-dag.c 프로젝트: Johnyren/orpl
/*---------------------------------------------------------------------------*/
rpl_parent_t *
rpl_select_parent(rpl_dag_t *dag)
{
  rpl_parent_t *p, *best;

  best = NULL;

  p = nbr_table_head(rpl_parents);
  while(p != NULL) {
    if(p->rank == INFINITE_RANK) {
      /* ignore this neighbor */
    } else if(best == NULL) {
      best = p;
    } else {
      best = dag->instance->of->best_parent(best, p);
    }
    p = nbr_table_next(rpl_parents, p);
  }

  if(best != NULL) {
    rpl_set_preferred_parent(dag, best);
  }

  return best;
}
예제 #6
0
static int snd_nbr_info(void)
{
	int num = uip_ds6_nbr_num();
	if(num==1)
	{	printf("Only one neighbor so returning \n");
		return 0;	
	}
        unsigned char buf4[num +10], *buf_p; 
	buf_p=buf4; int i=8;
	uip_ipaddr_t tempadd;

    	uip_ds6_nbr_t *nbr=NULL;
	MAPPER_ADD_PACKETDATA(buf_p,i);
	MAPPER_ADD_PACKETDATA(buf_p,num);

    for(nbr = nbr_table_head(ds6_neighbors); nbr != NULL; nbr = nbr_table_next(ds6_neighbors, nbr)) {
        
        MAPPER_ADD_PACKETDATA(buf_p,nbr->ipaddr.u8[15]);
       	
	}
	uip_ipaddr_copy(&tempadd, &UIP_IP_BUF->srcipaddr);
        //tempadd.u16[0]=0xaaaa;                
	uip_udp_packet_sendto(client_conn, buf4, sizeof(buf4), &tempadd, UIP_HTONS(10000+(int)tempadd.u8[15]));
	uip_create_unspecified(&client_conn->ripaddr);
	printf("nbr info sent to %u\n",tempadd.u8[15]);
	return 1;
}
예제 #7
0
/*---------------------------------------------------------------------------*/
void
rpl_print_neighbor_list()
{
  if(default_instance != NULL && default_instance->current_dag != NULL &&
      default_instance->of != NULL && default_instance->of->calculate_rank != NULL) {
    int curr_dio_interval = default_instance->dio_intcurrent;
    int curr_rank = default_instance->current_dag->rank;
    rpl_parent_t *p = nbr_table_head(rpl_parents);
    clock_time_t now = clock_time();

    printf("RPL: rank %u dioint %u, %u nbr(s)\n", curr_rank, curr_dio_interval, uip_ds6_nbr_num());
    while(p != NULL) {
      uip_ds6_nbr_t *nbr = rpl_get_nbr(p);
      printf("RPL: nbr %3u %5u, %5u => %5u %c%c (last tx %u min ago)\n",
          nbr_table_get_lladdr(rpl_parents, p)->u8[7],
          p->rank, nbr ? nbr->link_metric : 0,
          default_instance->of->calculate_rank(p, 0),
          default_instance->current_dag == p->dag ? 'd' : ' ',
          p == default_instance->current_dag->preferred_parent ? '*' : ' ',
          (unsigned)((now - p->last_tx_time) / (60 * CLOCK_SECOND)));
      p = nbr_table_next(rpl_parents, p);
    }
    printf("RPL: end of list\n");
  }
}
예제 #8
0
/*---------------------------------------------------------------------------*/
void
uip_ds6_neighbor_periodic(void)
{
  /* Periodic processing on neighbors */
  uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors);
  while(nbr != NULL) {
    switch(nbr->state) {
    case NBR_REACHABLE:
      if(stimer_expired(&nbr->reachable)) {
        PRINTF("REACHABLE: moving to STALE (");
        PRINT6ADDR(&nbr->ipaddr);
        PRINTF(")\n");
        nbr->state = NBR_STALE;
      }
      break;
#if UIP_ND6_SEND_NA
    case NBR_INCOMPLETE:
      if(nbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) {
        uip_ds6_nbr_rm(nbr);
      } else if(stimer_expired(&nbr->sendns) && (uip_len == 0)) {
        nbr->nscount++;
        PRINTF("NBR_INCOMPLETE: NS %u\n", nbr->nscount);
        uip_nd6_ns_output(NULL, NULL, &nbr->ipaddr);
        stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000);
      }
      break;
    case NBR_DELAY:
      if(stimer_expired(&nbr->reachable)) {
        nbr->state = NBR_PROBE;
        nbr->nscount = 0;
        PRINTF("DELAY: moving to PROBE\n");
        stimer_set(&nbr->sendns, 0);
      }
      break;
    case NBR_PROBE:
      if(nbr->nscount >= UIP_ND6_MAX_UNICAST_SOLICIT) {
        uip_ds6_defrt_t *locdefrt;
        PRINTF("PROBE END\n");
        if((locdefrt = uip_ds6_defrt_lookup(&nbr->ipaddr)) != NULL) {
          if (!locdefrt->isinfinite) {
            uip_ds6_defrt_rm(locdefrt);
          }
        }
        uip_ds6_nbr_rm(nbr);
      } else if(stimer_expired(&nbr->sendns) && (uip_len == 0)) {
        nbr->nscount++;
        PRINTF("PROBE: NS %u\n", nbr->nscount);
        uip_nd6_ns_output(NULL, &nbr->ipaddr, &nbr->ipaddr);
        stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000);
      }
      break;
#endif /* UIP_ND6_SEND_NA */
    default:
      break;
    }
    nbr = nbr_table_next(ds6_neighbors, nbr);
  }
}
예제 #9
0
/* Periodic timer called every FRESHNESS_HALF_LIFE minutes */
static void
periodic(void *ptr)
{
  /* Age (by halving) freshness counter of all neighbors */
  struct link_stats *stats;
  ctimer_reset(&periodic_timer);
  for(stats = nbr_table_head(link_stats); stats != NULL; stats = nbr_table_next(link_stats, stats)) {
    stats->freshness >>= 1;
  }
}
예제 #10
0
uint16_t ule6loTestIn_getNbListSize(void) {
	uip_ds6_nbr_t *nbr;
	uint16_t num=0;

	for(nbr = nbr_table_head(ds6_neighbors);
			nbr != NULL;
			nbr = nbr_table_next(ds6_neighbors, nbr)) {
		num++;
	}
	return num;
}
예제 #11
0
/*---------------------------------------------------------------------------*/
int
uip_ds6_nbr_num(void)
{
  uip_ds6_nbr_t *nbr;
  int num;

  num = 0;
  for(nbr = nbr_table_head(ds6_neighbors);
      nbr != NULL;
      nbr = nbr_table_next(ds6_neighbors, nbr)) {
    num++;
  }
  return num;
}
예제 #12
0
/*---------------------------------------------------------------------------*/
uip_ds6_nbr_t *
uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr)
{
  uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors);
  if(ipaddr != NULL) {
    while(nbr != NULL) {
      if(uip_ipaddr_cmp(&nbr->ipaddr, ipaddr)) {
        return nbr;
      }
      nbr = nbr_table_next(ds6_neighbors, nbr);
    }
  }
  return NULL;
}
예제 #13
0
파일: httpd-cgi.c 프로젝트: ADVANSEE/mist
/*---------------------------------------------------------------------------*/
static
PT_THREAD(neighbors(struct httpd_state *s, char *ptr))
{
  PSOCK_BEGIN(&s->sout);

  for(s->u.ptr = nbr_table_head(ds6_neighbors);
      s->u.ptr != NULL;
      s->u.ptr = nbr_table_next(ds6_neighbors, s->u.ptr)) {
    PSOCK_GENERATOR_SEND(&s->sout, make_neighbor, s);
  }

  PSOCK_GENERATOR_SEND(&s->sout, make_neighbor_roomfor, s);
  PSOCK_END(&s->sout);
}
예제 #14
0
파일: rpl-dag.c 프로젝트: e2rezaei/set-Tx
/*---------------------------------------------------------------------------*/
static void
nullify_parents(rpl_dag_t *dag, rpl_rank_t minimum_rank)
{
  rpl_parent_t *p;

//  PRINTF("RPL: Removing parents (minimum rank %u)\n",minimum_rank);

  p = nbr_table_head(rpl_parents);
  while(p != NULL) {
    if(dag == p->dag && p->rank >= minimum_rank) {
      rpl_nullify_parent(p);
    }
    p = nbr_table_next(rpl_parents, p);
  }
}
예제 #15
0
/*---------------------------------------------------------------------------*/
uip_ds6_route_t *
uip_ds6_route_head(void)
{
  struct uip_ds6_route_neighbor_routes *routes;

  routes = (struct uip_ds6_route_neighbor_routes *)nbr_table_head(nbr_routes);
  if(routes != NULL) {
    if(list_head(routes->route_list) == NULL) {
      PRINTF("uip_ds6_route_head lead_head(nbr_route_list) is NULL\n");
    }
    return list_head(routes->route_list);
  } else {
    return NULL;
  }
}
예제 #16
0
static void chk_my_nbr(void)
{
    nodes[0].neighbors=uip_ds6_nbr_num();

    printf("Node %u, Nbrs: %d ",nodes[0].id, nodes[0].neighbors);

    uip_ds6_nbr_t *nbr=NULL;
    int i=0;
    for(nbr = nbr_table_head(ds6_neighbors); nbr != NULL; nbr = nbr_table_next(ds6_neighbors, nbr)) {
        nodes[0].neighbor[i].id=nbr->ipaddr.u8[15];
        printf(" %u",nodes[0].neighbor[i].id);
        i++;
    }
    printf("\n");
}
예제 #17
0
파일: rpl-dag.c 프로젝트: johangas/thesis
/* rpl_purge_parents is called with the periodic timer in rpl-timers.c */
void
rpl_purge_parents(void)
{
  rpl_parent_t *p;
  p = nbr_table_head(rpl_parents);
  while(p != NULL) {
    if(rpl_get_nbr(p) == NULL) {
      PRINTF("RPL: No NBR entry for parent - removing parent\n");
      rpl_remove_parent(p);
      /* continue with the removal next periodic tick */
      return;
    }
    p = nbr_table_next(rpl_parents, p);
  }
}
예제 #18
0
파일: res-etx.c 프로젝트: marciolm/sdwsn
static void
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
	rpl_dag_t *dag;
	rpl_parent_t *parent;
	int32_t strpos = 0;
	const uip_ipaddr_t *addr;
	addr = &uip_ds6_if.addr_list[1].ipaddr;
	dag = rpl_get_any_dag();

	parent_index = 0;

	if (dag != NULL)
	{
		/* seek to the parents entry and return it */
		strpos += sprintf(&(buffer[strpos]),"{\"node\":\"n%x\"",addr->u8[15]); // last addr byte of mote
		strpos += sprintf(&(buffer[strpos]),",\"nbr\":{");
		parent = nbr_table_head(rpl_parents);  // addr of first neighbor
		while (parent != NULL)
		{
			etx_table[parent_index].nbr_addr = rpl_get_parent_ipaddr(parent)->u8[15];
			etx_table[parent_index].nbr_etx = rpl_get_parent_link_metric(parent);
			etx_table[parent_index].p = parent;
			strpos += sprintf(&(buffer[strpos]),"\"n%x\":%u,",etx_table[parent_index].nbr_addr, etx_table[parent_index].nbr_etx);
			parent = nbr_table_next(rpl_parents, parent);
			parent_index++;
		}
		PRINTF("parent_index:%d\n",parent_index);
	}
	else
	{ /* no DAG */
		strpos += sprintf(&(buffer[strpos]),"{}\n");
	}
	//PRINTF("strpos: %ld\n", strpos);
	//rpl_print_neighbor_list(); // get parents for debug purposes
	//PRINTF("buf_parents: %s\n", buffer);
	strpos += sprintf(&(buffer[strpos-1]),"}}\n"); //replace the last comma
	//PRINTF("strpos-after: %ld\n", strpos);
	REST.set_header_content_type(response, APPLICATION_JSON);
	REST.set_header_max_age(response, res_etx.periodic->period / CLOCK_SECOND);
	//*offset = -1;  // try to fix Copper response
	REST.set_response_payload(response, buffer, snprintf((char *)buffer, preferred_size, "%s", buffer));

	/* The REST.subscription_handler() will be called for observable resources by the REST framework. */
}
예제 #19
0
void attack_init(void)
{
	if(num_nbrs<=1)
	{printf("Insufficient neighbors can't create attack \n"); return;
	}	
        unsigned char buf4[4], *buf_p;
	buf_p=buf4; int i=7;	//nbr info code
	uip_ds6_nbr_t *nbr=NULL;
    	uip_ipaddr_t tempadd;
	MAPPER_ADD_PACKETDATA(buf_p,i);
    for(nbr = nbr_table_head(ds6_neighbors); nbr != NULL; nbr = nbr_table_next(ds6_neighbors, nbr)) {        
	uip_ipaddr_copy(&tempadd, &nbr->ipaddr);
        //tempadd.u16[0]=0xaaaa;                
	uip_udp_packet_sendto(client_conn, buf4, sizeof(buf4), &tempadd, UIP_HTONS(10000+(int)tempadd.u8[15]));
	uip_create_unspecified(&client_conn->ripaddr);
	printf("nbr req sent to %u\n",tempadd.u8[15]);
    }
}
예제 #20
0
파일: httpd-cgi.c 프로젝트: threebs/contiki
/*---------------------------------------------------------------------------*/	
static unsigned short
make_neighbors(void *p)
{
uint8_t i,j=0;
uint16_t numprinted;
  numprinted = httpd_snprintf((char *)uip_appdata, uip_mss(),httpd_cgi_addrh);
  uip_ds6_nbr_t *nbr;
  for(nbr = nbr_table_head(ds6_neighbors);
      nbr != NULL;
      nbr = nbr_table_next(ds6_neighbors, nbr)) {
    j++;
    numprinted += httpd_cgi_sprint_ip6(nbr->ipaddr, uip_appdata + numprinted);
    numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrb);
  }
//if (j==0) numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrn);
  numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrf,NBR_TABLE_MAX_NEIGHBORS-j);
  return numprinted;
}
예제 #21
0
/*---------------------------------------------------------------------------*/
uip_ds6_nbr_t *
uip_ds6_get_least_lifetime_neighbor(void)
{
  uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors);
  uip_ds6_nbr_t *nbr_expiring = NULL;
  while(nbr != NULL) {
    if(nbr_expiring != NULL) {
      clock_time_t curr = stimer_remaining(&nbr->reachable);
      if(curr < stimer_remaining(&nbr->reachable)) {
        nbr_expiring = nbr;
      }
    } else {
      nbr_expiring = nbr;
    }
    nbr = nbr_table_next(ds6_neighbors, nbr);
  }
  return nbr_expiring;
}
예제 #22
0
파일: rpl-dag.c 프로젝트: e2rezaei/set-Tx
/*---------------------------------------------------------------------------*/
void
rpl_recalculate_ranks(void)
{
  rpl_parent_t *p;
//uip_ipaddr_t *x;
 //rpl_parent_t *pref_parent =(&instance_table[0])->current_dag->preferred_parent;//mark
  /*
   * We recalculate ranks when we receive feedback from the system rather
   * than RPL protocol messages. This periodical recalculation is called
   * from a timer in order to keep the stack depth reasonably low.
   */
  p = nbr_table_head(rpl_parents);

//printf("rank= %u:{", (((&instance_table[0])->current_dag->rank)/256));//,list_length((&instance_table[0])->current_dag->parents));//256);//mark


  while(p != NULL) {
	/*x=rpl_get_parent_ipaddr(p);
	printf("(");//mark
	if(p==pref_parent)//mark
		printf("pref-prnt ");//mark
	printf(" %02x%02x ",((uint8_t *)x)[14], ((uint8_t *)x)[15]);//mark
	printf("etx=%d.%d, rssi=%d, rank=%u", p->link_metric/128, p->link_metric%128 ,p->rssi, p->rank/256);//mark*/
	/* if(p->rssi > RSSI_THRESHOLD && (clock_seconds()-p->update_time)<AGE_THRESHOLD && p->flag==PRNT)
		{p->flag= Pt_PRNT;
		PRINTF("P_t prnt=");
		PRINT6ADDR(rpl_get_parent_ipaddr(p));
		PRINTF(",");
		}*/


    if(p->dag != NULL && p->dag->instance && p->updated) {
      p->updated = 0;
//      PRINTF("RPL: rpl_process_parent_event recalculate_ranks\n");
      if(!rpl_process_parent_event(p->dag->instance, p)) {
//        PRINTF("RPL: A parent was dropped\n");
      }
	
    }
//printf(")");//mark
    p = nbr_table_next(rpl_parents, p);
  }
//printf("}\n");//mark
}
예제 #23
0
/*---------------------------------------------------------------------------*/
void
rpl_host_determination(rpl_instance_t *instance)
{
  uint8_t num;
  uip_ds6_nbr_t *nbr;

  num = 0;
  nbr = nbr_table_head(ds6_neighbors);
  while(nbr != NULL) {
    if(nbr->state == NBR_REGISTERED && nbr->isrouter == ISROUTER_NODEFINE) {
      nbr->isrouter = ISROUTER_TESTING;
      num++;
    }
    nbr = nbr_table_next(ds6_neighbors, nbr);
  }
  if(num != 0) {
    ctimer_set(&instance->host_timer, 60 * CLOCK_SECOND, &handle_host_timer, instance);
  }
}
예제 #24
0
파일: httpd-cgi.c 프로젝트: ADVANSEE/mist
/*---------------------------------------------------------------------------*/
static
PT_THREAD(neighborsping(struct httpd_state *s, char *ptr))
{
  PSOCK_BEGIN(&s->sout);

  /* Ping nodes */
  for(s->u.ptr = nbr_table_head(ds6_neighbors);
      s->u.ptr != NULL;
      s->u.ptr = nbr_table_next(ds6_neighbors, s->u.ptr)) {
    uip_ipaddr_t *addr;
    uip_ds6_nbr_t *nbr= s->u.ptr;
    addr = uip_ds6_nbr_get_ipaddr(nbr);
    if(addr != NULL) {
      simple_udp_ping_send_ping(addr);
    }
    PSOCK_GENERATOR_SEND(&s->sout, make_neighbor, s);
  }

  PSOCK_END(&s->sout);
}
예제 #25
0
ule6lo_status_t ule6loTestIn_getNbList(uint16_t	index, ule6lo_nbr_t* nBListItem) {
	uip_ds6_nbr_t *nbr;
	uint8_t num=0;
	uint8_t i;

	for(nbr = nbr_table_head(ds6_neighbors);
			nbr != NULL;
			nbr = nbr_table_next(ds6_neighbors, nbr)) {

		if(num ==index) {
			//Located requested neighbor entry
			memcpy(&nBListItem->lladdr,&nbr->ipei,sizeof(ule6lo_IPEI_t));
			for(i=0;i<8;i++) {
				nBListItem->paddr.u16[i]=nbr->ipaddr.u16[i];
			}
			return STATUS_SUCCESS;
		}
		num++;
	}
	return STATUS_ERROR;
}
예제 #26
0
/*---------------------------------------------------------------------------*/
static rpl_parent_t *
best_parent(rpl_dag_t *dag)
{
  rpl_parent_t *p, *best;

  best = NULL;

  p = nbr_table_head(rpl_parents);
  while(p != NULL) {
    if(p->dag != dag || p->rank == INFINITE_RANK) {
      /* ignore this neighbor */
    } else if(best == NULL) {
      best = p;
    } else {
      best = dag->instance->of->best_parent(best, p);
    }
    p = nbr_table_next(rpl_parents, p);
  }

  return best;
}
예제 #27
0
static void addmyinfo(void)
{
    nodes[0].id=1;
    nodes[0].x=x_loc;
    nodes[0].y=y_loc;
    uip_ip6addr(&nodes[0].ip, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
    nodes[0].parent_id=1;
    nodes[0].neighbors=uip_ds6_nbr_num();

    printf("Node %u, X %d Y %d, P %u, Nbrs %d ",nodes[0].id, nodes[0].x, nodes[0].y, nodes[0].parent_id,nodes[0].neighbors);

    uip_ds6_nbr_t *nbr=NULL;
    int i=0;
    for(nbr = nbr_table_head(ds6_neighbors); nbr != NULL; nbr = nbr_table_next(ds6_neighbors, nbr)) {
        nodes[0].neighbor[i].id=nbr->ipaddr.u8[15];
        printf(" Nbr %d: %u",i,nodes[0].neighbor[i].id);
        i++;
    }
    printf("\n");
    total_nodes++;
}
예제 #28
0
파일: rpl-dag.c 프로젝트: Jakl555/6lbr
/*---------------------------------------------------------------------------*/
void
rpl_recalculate_ranks(void)
{
  rpl_parent_t *p;
  rpl_instance_t *instance;
  rpl_instance_t *end;
  int i;
  int updated = 0;

  /*
   * We recalculate ranks when we receive feedback from the system rather
   * than RPL protocol messages. This periodical recalculation is called
   * from a timer in order to keep the stack depth reasonably low.
   */
  p = nbr_table_head(rpl_parents);
  while(p != NULL) {
    if(p->dag != NULL && p->dag->instance && (p->flags & RPL_PARENT_FLAG_UPDATED)) {
      p->flags &= ~RPL_PARENT_FLAG_UPDATED;
      updated = 1;
      PRINTF("RPL: rpl_process_parent_event recalculate_ranks\n");
      if(!rpl_process_parent_event(p->dag->instance, p)) {
        PRINTF("RPL: A parent was dropped\n");
      }
    }
    p = nbr_table_next(rpl_parents, p);
  }
  if (!updated) {
    for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES;
        instance < end; ++instance) {
      if(instance->used) {
        for(i = 0; i < RPL_MAX_DAG_PER_INSTANCE; i++) {
          if(instance->dag_table[i].used && instance->dag_table[i].preferred_parent != NULL) {
            rpl_process_parent_event(instance, instance->dag_table[i].preferred_parent);
          }
        }
      }
    }
  }

}
예제 #29
0
/*---------------------------------------------------------------------------*/
void
rpl_recalculate_ranks(void)
{
  rpl_parent_t *p;

  /*
   * We recalculate ranks when we receive feedback from the system rather
   * than RPL protocol messages. This periodical recalculation is called
   * from a timer in order to keep the stack depth reasonably low.
   */
  p = nbr_table_head(rpl_parents);
  while(p != NULL) {
    if(p->dag != NULL && p->dag->instance && (p->flags & RPL_PARENT_FLAG_UPDATED)) {
      p->flags &= ~RPL_PARENT_FLAG_UPDATED;
      PRINTF("RPL: rpl_process_parent_event recalculate_ranks\n");
      if(!rpl_process_parent_event(p->dag->instance, p)) {
        PRINTF("RPL: A parent was dropped\n");
      }
    }
    p = nbr_table_next(rpl_parents, p);
  }
}
예제 #30
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(generate_routes(struct httpd_state *s))
{
  static int i;
  static uip_ds6_route_t *r;
  static uip_ds6_nbr_t *nbr;

  PSOCK_BEGIN(&s->sout);

  SEND_STRING(&s->sout, TOP);

  blen = 0;
  ADD("Neighbors<pre>");
  for(nbr = nbr_table_head(ds6_neighbors);
      nbr != NULL;
      nbr = nbr_table_next(ds6_neighbors, nbr)) {
    ipaddr_add(&nbr->ipaddr;);
    ADD("\n");
    if(blen > sizeof(buf) - 45) {
      SEND_STRING(&s->sout, buf);
      blen = 0;
    }
  }