/* ************************************************** */ void clean_params() { if (dflt_params) { dflt_param_t *dflt_param; while ((dflt_param = (dflt_param_t *) das_pop(dflt_params)) != NULL) { param_t *param; while ((param = (param_t *) das_pop(dflt_param->params)) != NULL) { free(param); } das_destroy(dflt_param->params); free(dflt_param); } das_destroy(dflt_params); } }
int unsetnode(call_t *c) { struct nodedata *nodedata = get_node_private_data(c); struct neighbor *neighbor; while ((neighbor = (struct neighbor *) das_pop(nodedata->neighbors)) != NULL) { free(neighbor); } das_destroy(nodedata->neighbors); free(nodedata); return 0; }
int unsetnode(call_t *c) { struct nodedata *nodedata = get_node_private_data(c); packet_t *packet; while ((packet = (packet_t *) das_pop(nodedata->packets)) != NULL) { packet_dealloc(packet); } das_destroy(nodedata->packets); if (nodedata->txbuf) { packet_dealloc(nodedata->txbuf); } free(nodedata); return 0; }
int destroy(call_t *c) { struct entitydata *entitydata = get_entity_private_data(c); struct monitor_callback *callback; long time = (long) (get_time() * 0.000001); fprintf(entitydata->filenode, "%ld %d\n", time, entitydata->nbr_nodes); while ((callback = (struct monitor_callback *) das_pop(entitydata->callbacks)) != NULL) { free(callback); } das_destroy(entitydata->callbacks); if (entitydata->filenode) { fclose(entitydata->filenode); } free(entitydata); return 0; }
/* Get the best next hop for a specific destination */ struct neighbor* get_nexthop(call_t *c, nodeid_t dst) { struct nodedata *nodedata = get_node_private_data(c); struct neighbor *neighbor = NULL, *n_hop = NULL; double dist = distance(get_node_position(c->node), get_node_position(dst)); double d = dist; if (nodedata->curr_dst != dst || (nodedata->curr_nexthop != NULL && !is_node_alive(nodedata->curr_nexthop->id))) { /* If the destination is different from the last one, * or if the current next hop is dead, reinit the * random counters (to force the selection of a * new next_hop) */ nodedata->random_counter = nodedata->random_nexthop; } if (nodedata->random_nexthop == 0) { /* We keep the current next hop if * - next hop is not randomized * - the next hop is is still alive * - the destination is the same */ if (nodedata->curr_nexthop != NULL && nodedata->curr_dst == dst && is_node_alive(nodedata->curr_nexthop->id)) { return nodedata->curr_nexthop; } /* Parse neighbors */ das_init_traverse(nodedata->neighbors); while ((neighbor = (struct neighbor *) das_traverse(nodedata->neighbors)) != NULL) { /* Choose next hop (the one the nearest from the final dst) * and verify if it is still alive */ if ((d = distance(&(neighbor->position), get_node_position(dst))) < dist && is_node_alive(neighbor->id)) { dist = d; n_hop = neighbor; } } } else if (nodedata->random_counter == nodedata->random_nexthop) { void *next_hops = das_create(); int nh = 0; double nexthop_dst = 0; /* Random geographic routing : we choose randomly among * the neighbors that are nearer from the destination * than the current node. */ das_init_traverse(nodedata->neighbors); while ((neighbor = (struct neighbor *) das_traverse(nodedata->neighbors)) != NULL) { /* If the neighbor happens to be the final destination, * then we just choose it as the next hop */ if (neighbor->id == dst) { n_hop = neighbor; goto out; } /* Store the neighbors that are nearer from the destination * and that are still alive */ nexthop_dst = distance(&(neighbor->position), get_node_position(dst)); if (nexthop_dst < dist && is_node_alive(neighbor->id)) { das_insert(next_hops, (void *) neighbor); } } /* Choose next hop randomly among the list */ nh = das_getsize(next_hops); if (nh > 0) { int rnd = get_random_integer_range(1, nh); while (rnd--) { neighbor = das_pop(next_hops); } n_hop = neighbor; } das_destroy(next_hops); } else /* nodedata->random_counter != nodedata->random_nexthop */ { /* Keep the current next hop */ n_hop = nodedata->curr_nexthop; } out: nodedata->random_counter--; if (nodedata->random_counter <= 0) { nodedata->random_counter = nodedata->random_nexthop; } /* Save the current next hop and destination */ nodedata->curr_nexthop = n_hop; nodedata->curr_dst = dst; return n_hop; }
void MEDIA_TX(call_t *c, packet_t *packet) { int i = get_node_count(); node_t *node = get_node_by_id(c->node); uint64_t clock; /* check wether node is active */ if (node->state != NODE_ACTIVE) { packet_dealloc(packet); return; } /* edit by Loic Lemaitre */ if (node->worldsens == NODE_LOCAL) { /* WORLDSENS MODE? -> radio part is simulated in wsim */ /* fill packet info */ packet->node = c->node; packet->antenna = c->from; packet->txdBm = radio_get_power(c); packet->channel = radio_get_channel(c); packet->modulation = radio_get_modulation(c); packet->Tb = radio_get_Tb(c); //packet->duration = packet->size * packet->Tb * 8; /* edit by Quentin Lampin <*****@*****.**> */ packet->duration = packet->real_size * packet->Tb; /* end of edition */ packet->clock0 = get_time(); packet->clock1 = packet->clock0 + packet->duration; /* scheduler tx_end event */ scheduler_add_tx_end(packet->clock1, c, packet); } /* end of edition */ /* scheduler rx_begin event */ #ifdef N_DAS_O if (propagation_range) { void *rx_nodes; node_t *rx_node; rx_nodes = spadas_rangesearch(location, NULL, &(node->position), propagation_range); while ((rx_node = (node_t *) das_pop(rx_nodes)) != NULL) { double derive = distance(&(node->position), &(rx_node->position)) / 0.3; bundle_t *bundle = get_bundle_by_id(rx_node->bundle); int i; if (rx_node->state == NODE_DEAD) { continue; } for (i = 0; i < bundle->antenna.size; i++) { entity_t *entity = get_entity_by_id(bundle->antenna.elts[i]); call_t c0 = {entity->id, rx_node->id, -1}; packet_t *packet_rx = packet_rxclone(packet); clock = packet->clock0 + ((uint64_t) derive); packet_rx->clock0 = clock; packet_rx->clock1 = clock + packet->duration; scheduler_add_rx_begin(clock, &c0, packet_rx); } } das_destroy(rx_nodes); } else { while (i--) { node_t *rx_node = get_node_by_id(i); double derive = distance(&(node->position), &(rx_node->position)) / 0.3; bundle_t *bundle = get_bundle_by_id(rx_node->bundle); int i; if (rx_node->state == NODE_DEAD) { continue; } for (i = 0; i < bundle->antenna.size; i++) { entity_t *entity = get_entity_by_id(bundle->antenna.elts[i]); call_t c0 = {entity->id, rx_node->id, -1}; packet_t *packet_rx = packet_rxclone(packet); clock = packet->clock0 + ((uint64_t) derive); packet_rx->clock0 = clock; packet_rx->clock1 = clock + packet->duration; scheduler_add_rx_begin(clock, &c0, packet_rx); } } } #else /* N_DAS_O */ while (i--) { node_t *rx_node = get_node_by_id(i); double dist = distance(&(node->position), &(rx_node->position)); double derive = dist / 0.3; bundle_t *bundle = get_bundle_by_id(rx_node->bundle); int i; if (rx_node->state == NODE_DEAD) { continue; } if ((propagation_range) && (dist > propagation_range)) { continue; } for (i = 0; i < bundle->antenna.size; i++) { entity_t *entity = get_entity_by_id(bundle->antenna.elts[i]); call_t c0 = {entity->id, rx_node->id, -1}; packet_t *packet_rx = packet_rxclone(packet); clock = packet->clock0 + ((uint64_t) derive); packet_rx->clock0 = clock; packet_rx->clock1 = clock + packet->duration; scheduler_add_rx_begin(clock, &c0, packet_rx); } } #endif /* N_DAS_O */ }