/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_sender_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t global_ipaddr;

  PROCESS_BEGIN();


  random_rand();
  rpl_log_start();
  if(node_id ==0) {
    NETSTACK_RDC.off(0);
    uint16_t mymac = linkaddr_node_addr.u8[7] << 8 | linkaddr_node_addr.u8[6];
    printf("Node id unset, my mac is 0x%04x\n", mymac);
    PROCESS_EXIT();
  }

  cc2420_set_txpower(RF_POWER);
  cc2420_set_cca_threshold(RSSI_THR);
  printf("App: %u starting\n", node_id);

  deployment_init(&global_ipaddr);
  //rpl_setup(node_id == ROOT_ID, node_id);
  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  if(node_id == ROOT_ID) {
    uip_ipaddr_t my_ipaddr;
    set_ipaddr_from_id(&my_ipaddr, node_id);
    //NETSTACK_RDC.off(1);
  }
  else {
    etimer_set(&periodic_timer,1 * 30 * CLOCK_SECOND);

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    etimer_set(&periodic_timer, SEND_INTERVAL);


    while(1) {

      etimer_set(&send_timer, random_rand() % (SEND_INTERVAL));

      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));
      int rank = default_instance != NULL ? default_instance->current_dag->rank : 0xffff;
     if(rank != 0xffff){
      app_send_to(ROOT_ID);
      }
      else{
        printf("App: not in DODAG\n");
      }

      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
      etimer_reset(&periodic_timer);

    }
  }

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void app_send_to(uint16_t id) {
  static unsigned int cpt;
  struct app_data data;
  uip_ipaddr_t dest_ipaddr;

  data.magic = ORPL_LOG_MAGIC;
  data.seqno = ((uint32_t)node_id << 16) + cpt;
  data.src = node_id;
  data.dest = id;
  data.hop = 0;
  data.fpcount = 0;
#if WITH_LB && WITH_DIO_TARGET
  extern uint16_t last_periodic_value;
  data.dc_metric=last_periodic_value+1;//+1 to account with the packet we send
#endif
  //node_ip6addr(&dest_ipaddr, id);
  set_ipaddr_from_id(&dest_ipaddr, id);

  LOG_FROM_APPDATAPTR(&data,"App: sending");//ORPL_LOG(&data);
  simple_udp_sendto(&unicast_connection, &data, sizeof(data), &dest_ipaddr);


//  printf("to ");
//  LOG_IPADDR(&dest_ipaddr);
//  printf("\n");
  cpt++;
}
Beispiel #3
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_sender_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t global_ipaddr;

  PROCESS_BEGIN();

  if(node_id == 0) {
    NETSTACK_RDC.off(0);
    printf("Node id unset, my mac is ");
    uip_debug_lladdr_print(&rimeaddr_node_addr);
    printf("\n");
    PROCESS_EXIT();
  }

  cc2420_set_txpower(RF_POWER);
  cc2420_set_cca_threshold(RSSI_THR);
  orpl_log_start();

  printf("App: %u starting\n", node_id);

  deployment_init(&global_ipaddr);
#if WITH_ORPL
  orpl_init(node_id == ROOT_ID, 0);
#endif /* WITH_ORPL */
  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  if(node_id == ROOT_ID) {
    NETSTACK_RDC.off(1);
    etimer_set(&periodic_timer, 2 * 60 * CLOCK_SECOND);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    etimer_set(&periodic_timer, SEND_INTERVAL);
    while(1) {
      etimer_set(&send_timer, random_rand() % (SEND_INTERVAL));
      PROCESS_WAIT_UNTIL(etimer_expired(&send_timer));

      if(check_reachable_count()) {
        uip_ipaddr_t dest_ipaddr;
        static uint16_t target_id;
        static uint16_t i;
        do {
          target_id = get_node_id_from_index((random_rand()>>8)%get_n_nodes());
          set_ipaddr_from_id(&dest_ipaddr, target_id);
        } while (target_id == ROOT_ID || !orpl_routing_set_contains(&dest_ipaddr));
        app_send_to(target_id);
      }

      PROCESS_WAIT_UNTIL(etimer_expired(&periodic_timer));
      etimer_reset(&periodic_timer);
    }
  }
Beispiel #4
0
/*---------------------------------------------------------------------------*/
int check_reachable_count() {
  int i;
  int count = 0;

  for(i=0; i<get_n_nodes(); i++) {
    uip_ipaddr_t dest_ipaddr;
    uint8_t id = get_node_id_from_index(i);
    if(id == ROOT_ID) {
      continue;
    }
    set_ipaddr_from_id(&dest_ipaddr, id);
    if(orpl_routing_set_contains(&dest_ipaddr)) {
      count++;
    }
  }

  if(count != get_n_nodes()-1) {
    printf("App: nodes reachable: %u/%u\n", count, get_n_nodes()-1 /* exclude sink */);
  }
  return count >= ((get_n_nodes()-1) * (TARGET_REACHABLE_RATIO)) / 100;
}
Beispiel #5
0
/*---------------------------------------------------------------------------*/
void app_send_to(uint16_t id) {

  static unsigned int cnt;
  struct app_data data;
  uip_ipaddr_t dest_ipaddr;

  data.magic = ORPL_LOG_MAGIC;
  data.seqno = ((uint32_t)node_id << 16) + cnt;
  data.src = node_id;
  data.dest = id;
  data.hop = 0;
  data.fpcount = 0;

  ORPL_LOG_FROM_APPDATAPTR(&data, "App: sending");

#if WITH_ORPL
  orpl_set_curr_seqno(data.seqno);
#endif /* WITH_ORPL */
  set_ipaddr_from_id(&dest_ipaddr, id);

  simple_udp_sendto(&unicast_connection, &data, sizeof(data), &dest_ipaddr);

  cnt++;
}