// ENVOI DE PACKET HELLO int init_one_hop(call_t *c, void *args) { struct nodedata *nodedata = get_node_private_data(c); //recuperer le support de communication DOWN entityid_t *down = get_entity_links_down(c); call_t c0 = {down[0], c->node}; //destination de paquet destination_t destination = {BROADCAST_ADDR, {-1, -1, -1}}; //creation de paquet et initialisation de son data packet_t *packet = packet_alloc(c, nodedata->overhead[0] + sizeof(struct packet_hello)); struct packet_hello *hello = (struct packet_hello *) (packet->data + nodedata->overhead[0]); //initilailser les données hello->type=HELLO; hello->source=c->node; if (SET_HEADER(&c0, packet, &destination) == -1) { packet_dealloc(packet); return -1; } DEBUG; /*printf("Node %d (%lf %lf %lf) broadcast a packet hello, at %lf\n", c->node, //id de Noeud get_node_position(c->node)->x,get_node_position(c->node)->y,get_node_position(c->node)->z, //la postion x, y,z de Noeud get_time_now_second());//*/ //l'instant d'envoi. //L'envoi TX(&c0,packet); //tous c'est bien passé return 1; }
/* ************************************************** */ double get_noise(call_t *c) { struct nodedata *nodedata = get_node_private_data(c); entityid_t *down = get_entity_links_down(c); c->from = down[0]; return MEDIA_GET_NOISE(c, nodedata->channel); }
//RECEPTION et REPONDRE AU PACKET HELLO int rx_one_hop(call_t *c, packet_t *packet) { struct nodedata *nodedata = get_node_private_data(c); //RECEPTION DE PACKET HELLO struct packet_hello *hello = (struct packet_hello *) (packet->data + nodedata->overhead[0]); DEBUG; /*printf("NOde %d a recu un HELLO de %d (%lf %lf %lf) at %lf\n",c->node, hello->source, get_node_position(hello->source)->x,get_node_position(hello->source)->y,get_node_position(hello->source)->z, get_time_now_second());//*/ //l'ajoute de voisin if(!list_recherche(nodedata->N1,hello->source)) list_insert(&nodedata->N1,hello->source); //REPONSE DE PAKET HELLO //recuperer le support de communication MAC entityid_t *down = get_entity_links_down(c); call_t c0 = {down[0], c->node}; //destination de paquet destination_t destination = {hello->source, {get_node_position(hello->source)->x,get_node_position(hello->source)->y,get_node_position(hello->source)->z}}; //creation de paquet et initialisation de son data packet_t *rpacket = packet_alloc(c, nodedata->overhead[0] + sizeof(struct packet_hello)); struct packet_hello *rhello = (struct packet_hello *) (rpacket->data + nodedata->overhead[0]); //initilailser les données rhello->type = REP_HELLO; rhello->source = c->node; if (SET_HEADER(&c0, rpacket, &destination) == -1) { packet_dealloc(rpacket); return -1; } DEBUG; /*printf("Node %d (%lf %lf %lf) repond a %d packet hello, at %lf\n", c->node, //id de Noeud de noeud encours get_node_position(c->node)->x,get_node_position(c->node)->y,get_node_position(c->node)->z, //la postion x, y,z de Noeud hello->source, //id de noued de destination get_time_now_second()); //*/ //l'instant d'envoi. //L'envoi TX(&c0,rpacket); //liberer le packet packet_dealloc(packet); //tous c'est bien passé return 1; }
void tx( call_t *c , packet_t * packet ) { struct nodedata *nodedata = get_node_private_data(c); struct protocoleData *entitydata = get_entity_private_data(c); if(entitydata->debug) DBG("LBOP BROADCAST - ON %d WITH RANGE %.2lf At %lf \n",c->node,get_range_Tr(c), get_time_now_second()); entityid_t *down = get_entity_links_down(c); call_t c0 = {down[0], c->node}; TX(&c0,packet); }
/* 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; }
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; }
/* ************************************************** */ void rx_source_adv(call_t *c, packet_t *packet) { struct nodedata *nodedata = get_node_private_data(c); struct entitydata *entitydata = get_entity_private_data(c); struct source_adv_p *source = (struct source_adv_p *) (packet->data + nodedata->overhead); struct sensor_adv_p *sensor; packet_t *packet0; destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}}; entityid_t *down = get_entity_links_down(c); call_t c0 = {down[0], c->node, c->entity}; /* check adv sequence */ if (source->s_seq <= nodedata->s_seq[source->source]) { /* old request */ packet_dealloc(packet); return; } nodedata->s_seq[source->source] = source->s_seq; /* reply */ packet0 = packet_create(c, nodedata->overhead + sizeof(struct sensor_adv_p), -1); sensor = (struct sensor_adv_p *) (packet0->data + nodedata->overhead); if (SET_HEADER(&c0, packet0, &dst) == -1) { packet_dealloc(packet); packet_dealloc(packet0); return; } sensor->type = SENSOR_ADV_TYPE; sensor->sensor = c->node; sensor->source = source->source; sensor->s_seq = source->s_seq; TX(&c0, packet0); entitydata->TX_sensor_adv++; packet_dealloc(packet); return; }
/* received a request from a sensor */ void rx_xy_request(call_t *c, packet_t *packet) { struct nodedata *nodedata = get_node_private_data(c); struct entitydata *entitydata = get_entity_private_data(c); struct xy_request_p *request = (struct xy_request_p *) (packet->data + nodedata->overhead); position_t rdv_position; struct xy_neighbor *n_hop; entityid_t *down = get_entity_links_down(c); call_t c0 = {down[0], c->node, c->entity}; /* are we the next hop */ if (request->n_hop != c->node) { packet_dealloc(packet); return; } /* do we have the requested data (or some more recent data) ? */ if (request->d_seq <= nodedata->d_seq[request->metadata]) { packet_t *packet0; destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}}; n_hop = xy_next_hop(c, &(request->position)); if (n_hop == NULL) { struct sensor_data_p *data; packet0 = packet_create(c, nodedata->overhead + sizeof(struct sensor_data_p), -1); data = (struct sensor_data_p *) (packet0->data + nodedata->overhead); if (SET_HEADER(&c0, packet0, &dst) == -1) { packet_dealloc(packet); packet_dealloc(packet0); return; } data->type = SENSOR_DATA_TYPE; data->metadata = request->metadata; data->sink = request->sink; data->r_seq = request->r_seq; data->source = nodedata->d_source[request->metadata]; data->d_seq = nodedata->d_seq[request->metadata]; data->d_value = nodedata->d_value[request->metadata]; data->delay = nodedata->d_time[request->metadata]; data->hop = nodedata->d_hop[request->metadata]; #ifdef LOG_APPLICATION_REQUEST printf("[XY] Node %d (%lf,%lf) : broadcasting DATA REPLY (%d,%d,%d) to sink %d (%lf,%lf)\n", c->node, (get_node_position(c->node))->x, (get_node_position(c->node))->y, nodedata->d_source[request->metadata], request->metadata, nodedata->d_seq[request->metadata], request->sink, (get_node_position(request->sink))->x, (get_node_position(request->sink))->y); #endif TX(&c0, packet0); entitydata->TX_sensor_data++; packet_dealloc(packet); return; } else { struct xy_response_p *response; /* reply */ packet0 = packet_create(c, nodedata->overhead + sizeof(struct xy_response_p), -1); response = (struct xy_response_p *) (packet0->data + nodedata->overhead); if (SET_HEADER(&c0, packet0, &dst) == -1) { packet_dealloc(packet); packet_dealloc(packet0); return; } response->type = XY_RESPONSE_TYPE; response->n_hop = n_hop->id; response->metadata = request->metadata; response->sink = request->sink; response->r_seq = request->r_seq; response->source = nodedata->d_source[request->metadata]; response->d_seq = nodedata->d_seq[request->metadata]; response->d_value = nodedata->d_value[request->metadata]; response->time = nodedata->d_time[request->metadata]; response->hop = nodedata->d_hop[request->metadata]; response->position.x = request->position.x; response->position.y = request->position.y; response->position.z = request->position.z; TX(&c0, packet0); entitydata->TX_response++; packet_dealloc(packet); return; } } /* forwards the query towards the specified direction */ else { switch(request->direction){ case DIRECTION_EAST: rdv_position.x = (get_topology_area())->x; rdv_position.y = (get_node_position(c->node))->y; rdv_position.z = 0.0; break; case DIRECTION_WEST: rdv_position.x = 0.0; rdv_position.y = (get_node_position(c->node))->y; rdv_position.z = 0.0; break; default: #ifdef LOG_APPLICATION_REQUEST_ROUTING printf("[XY] Node %d (%lf,%lf) received a DATA with incorrect forwarding direction (%c) !\n",c->node,(get_node_position(c->node))->x,(get_node_position(c->node))->y,request->direction); #endif packet_dealloc(packet); return; } /* get next hop */ n_hop = xy_next_hop(c, &rdv_position); if (n_hop != NULL) { #ifdef LOG_APPLICATION_REQUEST_ROUTING printf("[XY] node %d (%lf,%lf) : forwarding request towards direction %c via node %d \n", c->node,(get_node_position(c->node))->x,(get_node_position(c->node))->y,request->direction,n_hop->id); #endif destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}}; /* forward data */ if (SET_HEADER(&c0, packet, &dst) == -1) { packet_dealloc(packet); return; } request->n_hop = n_hop->id; TX(&c0, packet); entitydata->TX_query++; } else { #ifdef LOG_APPLICATION_REQUEST_ROUTING printf("[XY] node %d (%lf,%lf) : no path towards %c direction\n", c->node,(get_node_position(c->node))->x,(get_node_position(c->node))->y,request->direction); #endif } } return; }
/* Received a request from a sink */ void rx_sink_adv(call_t *c, packet_t *packet) { struct nodedata *nodedata = get_node_private_data(c); struct entitydata *entitydata = get_entity_private_data(c); struct sink_adv_p *sink = (struct sink_adv_p *) (packet->data + nodedata->overhead); entityid_t *down = get_entity_links_down(c); call_t c0 = {down[0], c->node, c->entity}; /* starts home node election */ if (sink->home == -1) { packet_t *packet0; struct home_adv_p *adv; destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}}; /* check request sequence */ if (sink->r_seq <= nodedata->r_seq[sink->sink]) { /* old request */ packet_dealloc(packet); return; } nodedata->r_seq[sink->sink] = sink->r_seq; packet0 = packet_create(c, nodedata->overhead + sizeof(struct home_adv_p), -1); adv = (struct home_adv_p *) (packet0->data + nodedata->overhead); if (SET_HEADER(&c0, packet0, &dst) == -1) { packet_dealloc(packet); packet_dealloc(packet0); return; } adv->type = HOME_ADV_TYPE; adv->sensor = c->node; adv->sink = sink->sink; adv->r_seq = sink->r_seq; TX(&c0, packet0); entitydata->TX_home_adv++; packet_dealloc(packet); return; } else if (sink->home == c->node) { /* do we have the requested data (or some more recent data) ? */ if (sink->d_seq <= nodedata->d_seq[sink->metadata]) { packet_t *packet0; struct sensor_data_p *data; destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}}; packet0 = packet_create(c, nodedata->overhead + sizeof(struct sensor_data_p), -1); data = (struct sensor_data_p *) (packet0->data + nodedata->overhead); if (SET_HEADER(&c0, packet0, &dst) == -1) { packet_dealloc(packet); packet_dealloc(packet0); return; } data->type = SENSOR_DATA_TYPE; data->metadata = sink->metadata; data->sink = sink->sink; data->r_seq = sink->r_seq; data->source = nodedata->d_source[sink->metadata]; data->d_seq = nodedata->d_seq[sink->metadata]; data->d_value = nodedata->d_value[sink->metadata]; data->delay = (get_time()-nodedata->d_time[sink->metadata])*0.000001; data->hop = nodedata->d_hop[sink->metadata]; #ifdef LOG_APPLICATION_REQUEST printf("[XY] Home-Node %d (%lf,%lf) : broadcasting DATA REPLY (%d,%d,%d) to sink %d (%lf,%lf)\n", c->node, (get_node_position(c->node))->x, (get_node_position(c->node))->y, nodedata->d_source[sink->metadata], sink->metadata, nodedata->d_seq[sink->metadata], sink->sink,(get_node_position(sink->sink))->x, (get_node_position(sink->sink))->y); #endif TX(&c0, packet0); entitydata->TX_sensor_data++; packet_dealloc(packet); return; } else { position_t rdv_position; struct xy_neighbor *n_hop = NULL; destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}}; /* forwards the query to EAST direction */ rdv_position.x = (get_topology_area())->x; rdv_position.y = (get_node_position(c->node))->y; rdv_position.z = -1; n_hop = xy_next_hop(c, &rdv_position); if (n_hop != NULL) { packet_t *packet0 = packet_create(c, nodedata->overhead + sizeof(struct xy_request_p), -1); struct xy_request_p *request = (struct xy_request_p *) (packet0->data + nodedata->overhead); position_t *pos = get_node_position(c->node); /* create request */ if (SET_HEADER(&c0, packet0, &dst) == -1) { packet_dealloc(packet); packet_dealloc(packet0); return; } request->type = XY_REQUEST_TYPE; request->n_hop = n_hop->id; request->sink = sink->sink; request->r_seq = sink->r_seq; request->metadata = sink->metadata; request->d_seq = sink->d_seq; request->position.x = pos->x; request->position.y = pos->y; request->position.z = pos->z; request->direction = DIRECTION_EAST; #ifdef LOG_APPLICATION_REQUEST_ROUTING printf("[XY] Node %d (%lf,%lf) : forwarding REQUEST(sink=%d,%d,%d) to EAST direction via node %d (%lf,%lf)\n", c->node, get_node_position(c->node)->x, get_node_position(c->node)->y, sink->sink, sink->metadata, sink->r_seq, n_hop->id, get_node_position(n_hop->id)->x, get_node_position(n_hop->id)->y); #endif TX(&c0, packet0); entitydata->TX_query++; } else { #ifdef LOG_APPLICATION_REQUEST printf("[XY] Node %d : no path towards EAST direction\n", c->node); #endif } /* forwards the query to WEST direction */ rdv_position.x = 0.0; rdv_position.y = (get_node_position(c->node))->y; rdv_position.z = -1; n_hop = xy_next_hop(c, &rdv_position); if (n_hop != NULL) { packet_t *packet0 = packet_create(c, nodedata->overhead + sizeof(struct xy_request_p), -1); struct xy_request_p *request = (struct xy_request_p *) (packet0->data + nodedata->overhead); position_t *pos = get_node_position(c->node); /* create request */ if (SET_HEADER(&c0, packet0, &dst) == -1) { packet_dealloc(packet); packet_dealloc(packet0); return; } request->type = XY_REQUEST_TYPE; request->n_hop = n_hop->id; request->sink = sink->sink; request->r_seq = sink->r_seq; request->metadata = sink->metadata; request->d_seq = sink->d_seq; request->position.x = pos->x; request->position.y = pos->y; request->position.z = pos->z; request->direction = DIRECTION_WEST; #ifdef LOG_APPLICATION_REQUEST_ROUTING printf("[XY] Node %d (%lf,%lf) : forwarding REQUEST(sink=%d,%d,%d) to WEST direction via node %d (%lf,%lf)\n", c->node, get_node_position(c->node)->x, get_node_position(c->node)->y, sink->sink, sink->metadata, sink->r_seq, n_hop->id, get_node_position(n_hop->id)->x, get_node_position(n_hop->id)->y); #endif TX(&c0, packet0); entitydata->TX_query++; } else { #ifdef LOG_APPLICATION_REQUEST printf("[XY] Node %d : no path towards WEST direction\n", c->node); #endif } packet_dealloc(packet); return; } } else { packet_dealloc(packet); return; } }
/* Received a DATA report from a sensor */ void rx_xy_data(call_t *c, packet_t *packet) { struct nodedata *nodedata = get_node_private_data(c); struct entitydata *entitydata = get_entity_private_data(c); struct xy_data_p *data = (struct xy_data_p *) (packet->data + nodedata->overhead); position_t rdv_position; struct xy_neighbor *n_hop; /* stores the received data */ if (data->d_seq > nodedata->d_seq[data->metadata]) { nodedata->d_seq[data->metadata] = data->d_seq; nodedata->d_source[data->metadata] = data->source; nodedata->d_value[data->metadata] = data->d_value; nodedata->d_hop[data->metadata] = data->hop; nodedata->d_time[data->metadata] = data->time; } /* check sensor */ if (data->n_hop != c->node) { /* not for us */ packet_dealloc(packet); return; } #ifdef LOG_APPLICATION_DISSEMINATION_ROUTING printf("[XY] Node %d (%lf,%lf) received a DATA from sensor %d => replication towards %c direction\n",c->node,(get_node_position(c->node))->x,(get_node_position(c->node))->y,data->source,data->direction); #endif /* replicates the DATA towards the choosed direction */ switch(data->direction){ case DIRECTION_NORTH: rdv_position.x = (get_node_position(c->node))->x; rdv_position.y = 0.0; rdv_position.z = 0.0; break; case DIRECTION_SOUTH: rdv_position.x = (get_node_position(c->node))->x; rdv_position.y = (get_topology_area())->y; rdv_position.z = 0.0; break; default: #ifdef LOG_APPLICATION_DISSEMINATION_ROUTING printf("[XY] Node %d (%lf,%lf) received a DATA from source %d with incorrect forwarding direction (%d) !\n",c->node,(get_node_position(c->node))->x,(get_node_position(c->node))->y,data->source,data->direction); #endif packet_dealloc(packet); return; } /* get next hop */ n_hop = xy_next_hop(c, &rdv_position); if (n_hop != NULL) { #ifdef LOG_APPLICATION_DISSEMINATION_ROUTING printf("[XY] node %d (%lf,%lf) : forwardind data towards direction %c via node %d \n", c->node,(get_node_position(c->node))->x,(get_node_position(c->node))->y,data->direction,n_hop->id); #endif destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}}; entityid_t *down = get_entity_links_down(c); call_t c0 = {down[0], c->node, c->entity}; /* forward data */ if (SET_HEADER(&c0, packet, &dst) == -1) { packet_dealloc(packet); return; } data->n_hop = n_hop->id; data->hop++; TX(&c0, packet); entitydata->TX_data++; } else { #ifdef LOG_APPLICATION_DISSEMINATION_ROUTING printf("[XY] node %d (%lf,%lf) : no path towards %c direction\n", c->node,(get_node_position(c->node))->x,(get_node_position(c->node))->y,data->direction); #endif } return; }
/* received a DATA report from a source node => forwarding towards the rendez-vous area */ void rx_source_data(call_t *c, packet_t *packet) { struct nodedata *nodedata = get_node_private_data(c); struct entitydata *entitydata = get_entity_private_data(c); struct source_data_p *data = (struct source_data_p *) (packet->data + nodedata->overhead); position_t rdv_position; struct xy_neighbor *n_hop; /* stores the received data */ if (data->d_seq > nodedata->d_seq[data->metadata]) { nodedata->d_seq[data->metadata] = data->d_seq; nodedata->d_source[data->metadata] = data->source; nodedata->d_value[data->metadata] = data->d_value; nodedata->d_hop[data->metadata] = 1; nodedata->d_time[data->metadata] = get_time(); } /* check sensor */ if (data->sensor != c->node) { /* not for us */ packet_dealloc(packet); return; } #ifdef LOG_APPLICATION_DISSEMINATION printf("[XY] Node %d (%lf,%lf) received a new DATA from source %d => replication towards north and south directions\n",c->node,(get_node_position(c->node))->x,(get_node_position(c->node))->y,data->source); #endif /* replicates data towards north direction */ rdv_position.x = (get_node_position(c->node))->x; rdv_position.y = 0.0; rdv_position.z = 0.0; /* get next hop */ n_hop = xy_next_hop(c, &rdv_position); if (n_hop != NULL) { destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}}; packet_t *packet0 = packet_create(c, nodedata->overhead + sizeof(struct xy_data_p), -1); struct xy_data_p *disseminate = (struct xy_data_p *) (packet0->data + nodedata->overhead); entityid_t *down = get_entity_links_down(c); call_t c0 = {down[0], c->node, c->entity}; /* forward data */ if (SET_HEADER(&c0, packet0, &dst) == -1) { packet_dealloc(packet0); packet_dealloc(packet); return; } disseminate->type = XY_DATA_TYPE; disseminate->n_hop = n_hop->id; disseminate->source = data->source; disseminate->metadata = data->metadata; disseminate->d_seq = data->d_seq; disseminate->d_value = data->d_value; disseminate->hop = 2; disseminate->time = get_time(); disseminate->direction = DIRECTION_NORTH; TX(&c0, packet0); entitydata->TX_data++; } else { #ifdef LOG_APPLICATION_DISSEMINATION_ROUTING printf("[XY] node %d (%lf,%lf) : no path towards NORTH direction\n", c->node,(get_node_position(c->node))->x,(get_node_position(c->node))->y); #endif } /* replicates data towards south direction */ rdv_position.x = (get_node_position(c->node))->x; rdv_position.y = (get_topology_area())->y; rdv_position.z = 0.0; /* get next hop */ n_hop = xy_next_hop(c, &rdv_position); if (n_hop != NULL) { destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}}; packet_t *packet0 = packet_create(c, nodedata->overhead + sizeof(struct xy_data_p), -1); struct xy_data_p *disseminate = (struct xy_data_p *) (packet0->data + nodedata->overhead); entityid_t *down = get_entity_links_down(c); call_t c0 = {down[0], c->node, c->entity}; /* forward data */ if (SET_HEADER(&c0, packet0, &dst) == -1) { packet_dealloc(packet0); packet_dealloc(packet); return; } disseminate->type = XY_DATA_TYPE; disseminate->n_hop = n_hop->id; disseminate->source = data->source; disseminate->metadata = data->metadata; disseminate->d_seq = data->d_seq; disseminate->d_value = data->d_value; disseminate->hop = 2; disseminate->time = get_time(); disseminate->direction = DIRECTION_SOUTH; TX(&c0, packet0); entitydata->TX_data++; } else { #ifdef LOG_APPLICATION_DISSEMINATION_ROUTING printf("[XY] node %d (%lf,%lf) : no path towards SOUTH direction\n", c->node,(get_node_position(c->node))->x,(get_node_position(c->node))->y); #endif } packet_dealloc(packet); return; }
void rx_xy_response(call_t *c, packet_t *packet) { struct nodedata *nodedata = get_node_private_data(c); struct entitydata *entitydata = get_entity_private_data(c); struct xy_response_p *response = (struct xy_response_p *) (packet->data + nodedata->overhead); struct xy_neighbor *n_hop; entityid_t *down = get_entity_links_down(c); call_t c0 = {down[0], c->node, c->entity}; /* are we the next hop */ if (response->n_hop != c->node) { packet_dealloc(packet); return; } /* get next hop */ n_hop = xy_next_hop(c, &(response->position)); /* if I am the home node */ if (n_hop == NULL) { #ifdef LOG_APPLICATION_RESPONSE printf("[HOME] node %d : broadcasting received DATA to (sink=%d,%d,%d)\n", c->node, response->sink, response->metadata, response->r_seq); #endif packet_t *packet0; struct sensor_data_p *data; destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}}; /* reply */ packet0 = packet_create(c, nodedata->overhead + sizeof(struct sensor_data_p), -1); data = (struct sensor_data_p *) (packet0->data + nodedata->overhead); if (SET_HEADER(&c0, packet0, &dst) == -1) { packet_dealloc(packet); packet_dealloc(packet0); return; } data->type = SENSOR_DATA_TYPE; data->metadata = response->metadata; data->sink = response->sink; data->r_seq = response->r_seq; data->source = response->source; data->d_seq = response->d_seq; data->d_value = response->d_value; data->delay = (get_time()-response->time)*0.000001; data->hop = response->hop; TX(&c0, packet0); entitydata->TX_sensor_data++; packet_dealloc(packet); return; } else { #ifdef LOG_APPLICATION_RESPONSE_ROUTING printf("Node %d : forwarding REPLAY to (sink=%d,%d,%d) via node %d \n", c->node, response->sink, response->metadata, response->r_seq, n_hop->id); #endif /* forward packet */ #ifdef USE_BROADCAST_COMMUNICATIONS destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}}; #else destination_t dst = {n_hop->id, {-1, -1, -1}}; #endif /* forward data */ if (SET_HEADER(&c0, packet, &dst) == -1) { packet_dealloc(packet); return; } response->n_hop = n_hop->id; response->hop++; TX(&c0, packet); entitydata->TX_response++; } return; }
int set_header( call_t *c , packet_t * packet , destination_t * dst ) { struct nodedata *nodedata = get_node_private_data(c); double cout; //recuperer le support de communication DOWN entityid_t *down = get_entity_links_down(c); call_t cdown = {down[0], c->node, c->entity}; // initialisation des donnees de routage du paquet packet_PROTOCOLE *header = (packet_PROTOCOLE *) (packet->data + nodedata->overhead); header->type = APP; header->src = c->node; header->dst = dst->id; header->pred = c->node; header->askedToRedirect = 0; header->needsToBeCovered = 0; header->id = last_id++; if(dst->id == BROADCAST_ADDR) { /*printf("Graphe de 2-voisinage de %d :\n", c->node); afficherGraphe(nodedata->g2hop);*/ graphe* g = copieGraphe(nodedata->g2hop); int i; voisin* trans; for(i = 0 ; i < g->nbSommets ; i++) { trans = g->listeVoisins[i]; while(trans != 0) { trans->cout /= nodedata->energiesRem[getLabelFromNum(g, i)]; trans = trans->vSuiv; } } if(nodedata->BIP_tree != 0) { arbre_detruire(&nodedata->BIP_tree); } nodedata->BIP_tree = computeBIPtree(c, g, 0, 0, 0); //afficherGraphe(nodedata->g2hop); //arbre_affiche(nodedata->BIP_tree); cout = setRangeToFarestNeighbour(c, nodedata->g2hop, nodedata->BIP_tree); setRelayNodes(c, nodedata->g2hop, nodedata->BIP_tree, &header->askedToRedirect, &header->needsToBeCovered, c->node); deleteGraphe(g); free(g); call_t c0 = {-1,c->node,-1}; header->energyRem = battery_remaining(&c0) - cout; nodedata->energiesRem[c->node] = header->energyRem; } else { // TODO } if (SET_HEADER(&cdown, packet, dst) == -1) { packet_dealloc(packet); return -1; } return 0; }