/** * Forge response to a node connect request */ static void worldsens_rx_connect_req(struct _worldsens_c_connect_req *pkt, struct sockaddr_in *addr) { node_t *node = get_node_by_id(worldsens_register_node_infos(pkt->node_id)); bundle_t *bundle = get_bundle_by_id(node->bundle); entity_t *entity; union _worldsens_pkt pkt0; int offset = 0; int i; int nb_mod = 0; if (node->worldsens != NODE_DISCONNECTED) { //PRINT_WORLDSENS("wsnet:worldsens_rx_connect_req (%"PRId64"): node %d not disconnected!\n", get_time(), node->id); return; } /* forge response*/ pkt0.cnx_rsp_ok.type = WORLDSENS_S_CONNECT_RSP_OK; pkt0.cnx_rsp_ok.seq = ws_seq; pkt0.cnx_rsp_ok.rp_next = ws_nsyncseq; pkt0.cnx_rsp_ok.rp_duration = ws_nsync - ws_csync; pkt0.cnx_rsp_ok.n_antenna_id = bundle->antenna.size; pkt0.cnx_rsp_ok.n_measure_id = measures.size; /* pkt->cnx_rsp_ok.names_and_ids format: */ /*|***************antennas***************|**************modulations*************|***************measures***************|*/ /*|ant id1|ant name1|ant id2|ant name2|..|mod id1|mod name1|mod id2|mod name2|..|mea id1|mea name1|mea id2|mea name2|..|*/ /* *********************************************************************************************************************/ /* forge list of available antennas */ for (i = 0; i < bundle->antenna.size; i++) { entity = get_entity_by_id(bundle->antenna.elts[i]); /* PRINT_WORLDSENS("wsnet: worldsens_rx_connect_req (%"PRId64"): antenna '%s' (id %d) available\n", get_time(), entity->name, entity->id); */ *((uint32_t *) (pkt0.cnx_rsp_ok.names_and_ids + offset)) = entity->id; offset += sizeof(uint32_t); strcpy(pkt0.cnx_rsp_ok.names_and_ids + offset, entity->name); offset += strlen(entity->name) + 1; } /* forge list of available modulations */ das_init_traverse(modulation_entities); while ((entity = (entity_t *) das_traverse(modulation_entities)) != NULL) { /*PRINT_WORLDSENS("wsnet: worldsens_rx_connect_req (%"PRId64"): modulation '%s' (id %d) available\n", get_time(), entity->library.name, entity->id); */ *((uint32_t *) (pkt0.cnx_rsp_ok.names_and_ids + offset)) = entity->id; offset += sizeof(uint32_t); strcpy(pkt0.cnx_rsp_ok.names_and_ids + offset, entity->library.name); offset += strlen(entity->library.name) + 1; nb_mod++; if ((nb_mod == 1) || (strcmp(entity->library.name, "modulation_none") == 0)) { ws_default_mod = entity->id; } } pkt0.cnx_rsp_ok.n_modulation_id = nb_mod; /* forge list of available measure */ for (i = 0; i < measures.size; i++) { measure_t *measure = get_measure_by_id(i); /* PRINT_WORLDSENS("wsnet: worldsens_rx_connect_req (%"PRId64"): measure '%s' (id %d) available\n", get_time(), measure->name, measure->id); */ *((uint32_t *) (pkt0.cnx_rsp_ok.names_and_ids + offset)) = measure->id; offset += sizeof(uint32_t); strcpy(pkt0.cnx_rsp_ok.names_and_ids + offset, measure->name); offset += strlen(measure->name) + 1; } /* give birth to node */ ws_connected++; node->worldsens = NODE_CONNECTED; node_birth(node->id); WSNET_S_DBG_DBG("WSNET2:: <-- CONNECT(%d/%d) (ip: %d)\n", ws_connected, ws_count, pkt->node_id); WSNET_S_DBG_DBG("WSNET2:: --> RP (seq: %"PRId64") (rp seq: %"PRId64", period: %"PRId64", rp:%"PRId64")\n", ws_seq, ws_nsyncseq, ws_nsync - ws_csync, ws_nsync); /* send response */ worldsens_packet_display(&pkt0); worldsens_packet_hton(&pkt0); wsens_srv_send(addr, (char *) &pkt0, sizeof(struct _worldsens_s_connect_rsp_ok)); }
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 */ }