int bootstrap(call_t *c) { struct nodedata *nodedata = get_node_private_data(c); struct protocoleData *entitydata = get_entity_private_data(c); call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity}; /* get mac header overhead */ nodedata->overhead = GET_HEADER_SIZE(&c0); broadcast_hello(c, NULL); uint64_t at=get_time_now()+time_seconds_to_nanos(2); scheduler_add_callback(at, c, init_lbop, NULL); at=get_time_now()+time_seconds_to_nanos(3); scheduler_add_callback(at, c, broadcast_lmst, NULL); return 0; }
/* ************************************************** */ int event_callback(call_t *c, void *data) { struct _env_data *entitydata = get_entity_private_data(c); struct _collec_event *event = (struct _collec_event *) data; call_t c0; array_t *app_layer = NULL; int type, value; /* Execute the event using an IOCTL */ type = event->event_type; value = event->event_value; c0.node = event->node_id; app_layer = get_application_entities(&c0); c0.entity = app_layer->elts[0]; IOCTL(&c0, type, &value, 0); DBG("Time %"PRId64", IOCTL for node %d, type %d, value %d\n", event->time, event->node_id, type, value); /* Delete the event */ free(event); /* Schedule the next event */ event = (struct _collec_event *) sodas_pop(entitydata->events); if (event == NULL) { DBG("No more events in queue\n"); return 0; } scheduler_add_callback(event->time, c, event_callback, event); return 0; }
/* ************************************************** */ int bootstrap(call_t *c) { struct nodedata *nodedata = get_node_private_data(c); call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity}; /* get mac header overhead */ nodedata->overhead = GET_HEADER_SIZE(&c0); /* hello packet */ if (nodedata->period > 0) { uint64_t start = get_time() + nodedata->start + get_random_double() * nodedata->period; scheduler_add_callback(start, c, advert_callback, NULL); } return 0; }
/* ************************************************** */ int bootstrap(call_t *c) { struct entitydata *entitydata = get_entity_private_data(c); /* log initial active nodes number */ log_activenodes(c); /* log initial energy map */ log_energymap(c); if (entitydata->map_period > 0) { scheduler_add_callback(entitydata->map_period, c, map_callback, NULL); } return 0; }
/* ************************************************** */ int bootstrap(call_t *c) { struct _env_data *entitydata = get_entity_private_data(c); struct _collec_event *event = NULL; /* Get the first event */ event = (struct _collec_event *) sodas_pop(entitydata->events); if (event == NULL) { DBG("ERROR: no events in queue\n"); return 0; } /* Schedule the first event */ scheduler_add_callback(event->time, c, event_callback, event); return 0; }
/* Periodic exchange of hello packets */ int hello_callback(call_t *c, void *args) { struct entitydata *entitydata = get_entity_private_data(c); struct nodedata *nodedata = get_node_private_data(c); entityid_t *down = get_entity_links_down(c); call_t c0 = {down[0], c->node, c->entity}; destination_t destination = {BROADCAST_ADDR, {-1, -1, -1}}; packet_t *packet = packet_create(c, nodedata->overhead + sizeof(struct xy_hello_p), -1); struct xy_hello_p *hello = (struct xy_hello_p *) (packet->data + nodedata->overhead); position_t *pos = get_node_position(c->node); /* set mac header */ if (SET_HEADER(&c0, packet, &destination) == -1) { packet_dealloc(packet); return -1; } /* set header */ hello->type = XY_HELLO_TYPE; hello->src = c->node; hello->position.x = pos->x; hello->position.y = pos->y; hello->position.z = pos->z; TX(&c0, packet); entitydata->TX_hello++; /* check neighbors timeout */ if (nodedata->h_timeout > 0) { das_selective_delete(nodedata->neighbors, neighbor_timeout, (void *) c); } /* schedules hello */ if (nodedata->h_nbr > 0) { nodedata->h_nbr --; } if (nodedata->h_nbr == -1 || nodedata->h_nbr > 0) { scheduler_add_callback(get_time() + nodedata->h_period, c, hello_callback, NULL); } return 0; }
/** * Program new callback event to send measure and send new rp **/ static int worldsens_rx_measure_req(struct _worldsens_c_measure_req *msg) { call_t c = {-1, worldsens_get_wsnet_node_id(msg->node_id), -1}; /* create a copy of the received packet */ struct _worldsens_c_measure_req *msg_cpy = malloc(sizeof(struct _worldsens_c_measure_req)); msg_cpy->type = msg->type; msg_cpy->node_id = msg->node_id; msg_cpy->measure_id = msg->measure_id; msg_cpy->period = msg->period; /* add immediate measure event to scheduler */ scheduler_add_callback(get_time() + msg->period, &c, worldsens_callback_tx_measure, (void *) msg_cpy); /* reply by sending a backtrack or a rp reminder */ worldsens_send_reply(); return 0; }
int bootstrap(call_t *c) { struct nodedata *nodedata = get_node_private_data(c); entityid_t *down = get_entity_links_down(c); call_t c0 = {down[0], c->node, c->entity}; uint64_t schedule = get_time() + nodedata->h_start + get_random_double() * nodedata->h_period; /* get overhead */ if ((get_entity_type(&c0) != MODELTYPE_ROUTING) && (get_entity_type(&c0) != MODELTYPE_MAC)) { nodedata->overhead = 0; } else { nodedata->overhead = GET_HEADER_SIZE(&c0); } /* scheduler first hello */ if (nodedata->h_nbr == -1 || nodedata->h_nbr > 0) { scheduler_add_callback(schedule, c, hello_callback, NULL); } return 0; }
int bootstrap(call_t *c) { struct nodedata *nodedata = get_node_private_data(c); struct protocoleData *entitydata = get_entity_private_data(c); call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity}; /* get mac header overhead */ nodedata->overhead = GET_HEADER_SIZE(&c0); int i; for(i = 0 ; i < get_node_count() ; i++) { nodedata->lastIDs[i] = -1; nodedata->energiesRem[i] = battery_remaining(c) - 2*getCoutFromDistance(getRange(c), entitydata->alpha, entitydata->c); } broadcast_hello(c, NULL); uint64_t at=get_time_now()+time_seconds_to_nanos(2); scheduler_add_callback(at, c, broadcast_hello2, NULL); return 0; }
int advert_callback(call_t *c, void *args) { struct nodedata *nodedata = get_node_private_data(c); call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity}; destination_t destination = {BROADCAST_ADDR, {-1, -1, -1}}; packet_t *packet = packet_create(c, nodedata->overhead + sizeof(struct routing_header), -1); struct routing_header *header = (struct routing_header*) (packet->data + nodedata->overhead); /* set mac header */ if (SET_HEADER(&c0, packet, &destination) == -1) { packet_dealloc(packet); return -1; } /* set routing header */ header->dst = BROADCAST_ADDR; header->dst_pos.x = -1; header->dst_pos.y = -1; header->dst_pos.z = -1; header->src = c->node; header->src_pos.x = get_node_position(c->node)->x; header->src_pos.y = get_node_position(c->node)->y; header->src_pos.z = get_node_position(c->node)->z; header->type = HELLO_PACKET; header->hop = 1; /* send hello */ TX(&c0, packet); nodedata->hello_tx++; /* check neighbors timeout */ das_selective_delete(nodedata->neighbors, neighbor_timeout, (void *) c); /* schedules hello */ scheduler_add_callback(get_time() + nodedata->period, c, advert_callback, NULL); return 0; }
void get_one_hop(call_t *c, double eps) { uint64_t at=c->node*time_seconds_to_nanos(eps); scheduler_add_callback(at, c, init_one_hop, NULL); }
int state_machine(call_t *c, void *args) { struct nodedata *nodedata = get_node_private_data(c); call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity}; uint64_t timeout; uint64_t backoff; packet_t *packet; if (nodedata->clock != get_time()) { return 0; } switch (nodedata->state) { case STATE_IDLE: if (nodedata->txbuf == NULL) { nodedata->txbuf = (packet_t *) das_pop_FIFO(nodedata->packets); if (nodedata->txbuf == NULL) { return 0; } } if (nodedata->MaxCSMABackoffs != 0) { nodedata->state = STATE_BACKOFF; nodedata->BE = nodedata->MinBE; nodedata->NB = 0; backoff = get_random_double() * (pow(2, nodedata->BE) - 1) * aUnitBackoffPeriod; nodedata->clock = get_time() + backoff; scheduler_add_callback(nodedata->clock, c, state_machine, NULL); return 0; } else { nodedata->state = STATE_TX; nodedata->clock = get_time(); scheduler_add_callback(nodedata->clock, c, state_machine, NULL); return 0; } case STATE_BACKOFF: if (check_channel_busy(c)) { if ((++nodedata->BE) > nodedata->MaxBE) { nodedata->BE = nodedata->MaxBE; } if (++nodedata->NB >= nodedata->MaxCSMABackoffs) { packet_dealloc(nodedata->txbuf); nodedata->txbuf = NULL; nodedata->state = STATE_IDLE; nodedata->clock = get_time(); state_machine(c,NULL); return 0; } backoff = get_random_double() * (pow(2, nodedata->BE) - 1) * aUnitBackoffPeriod; nodedata->clock = get_time() + backoff; scheduler_add_callback(nodedata->clock, c, state_machine, NULL); return 0; } nodedata->state = STATE_TX; nodedata->clock = get_time(); state_machine(c,NULL); return 0; case STATE_TX: packet = nodedata->txbuf; nodedata->txbuf = NULL; timeout = packet->size * 8 * radio_get_Tb(&c0) + macMinSIFSPeriod; TX(&c0, packet); nodedata->state = STATE_TXING; nodedata->clock = get_time() + timeout; scheduler_add_callback(nodedata->clock, c, state_machine, NULL); return 0; case STATE_TXING: nodedata->state = STATE_IDLE; nodedata->clock = get_time(); state_machine(c,NULL); return 0; default: break; } return 0; }
/* ************************************************** */ int map_callback(call_t *c, void *args) { struct entitydata *entitydata = get_entity_private_data(c); log_energymap(c); scheduler_add_callback(get_time() + entitydata->map_period, c, map_callback, NULL); return 0; }