/* ************************************************** */
int set_header(call_t *c, packet_t *packet, destination_t *dst) {
    struct nodedata *nodedata = get_node_private_data(c);
    struct neighbor *n_hop = get_nexthop(c, dst->id);
    destination_t destination;
    struct routing_header *header = (struct routing_header *) 
                                            (packet->data + nodedata->overhead);
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};

    /* No route available */
    if (dst->id != BROADCAST_ADDR && n_hop == NULL) {
        return -1;
    } 

    /* Set routing header */
    header->dst = dst->id;
    header->src = c->node;
    header->hop = nodedata->hop;

    /* Set MAC header */
    if (dst->id == BROADCAST_ADDR) {
        destination.id = BROADCAST_ADDR;
    } else {
        destination.id = n_hop->id;        
    }
    destination.position.x = -1;
    destination.position.y = -1;
    destination.position.z = -1;

    return SET_HEADER(&c0, packet, &destination);
}
示例#2
0
JS_ArenaAllocate(JSArenaPool *pool, size_t nb)
{
    JSArena **ap, *a, *b;
    jsuword extra, hdrsz, gross;
    void *p;

    /*
     * Search pool from current forward till we find or make enough space.
     *
     * NB: subtract nb from a->limit in the loop condition, instead of adding
     * nb to a->avail, to avoid overflowing a 32-bit address space (possible
     * when running a 32-bit program on a 64-bit system where the kernel maps
     * the heap up against the top of the 32-bit address space).
     *
     * Thanks to Juergen Kreileder <*****@*****.**>, who brought this up in
     * https://bugzilla.mozilla.org/show_bug.cgi?id=279273.
     */
    JS_ASSERT((nb & pool->mask) == 0);
    for (a = pool->current; nb > a->limit || a->avail > a->limit - nb;
         pool->current = a) {
        ap = &a->next;
        if (!*ap) {
            /* Not enough space in pool, so we must malloc. */
            extra = (nb > pool->arenasize) ? HEADER_SIZE(pool) : 0;
            hdrsz = sizeof *a + extra + pool->mask;
            gross = hdrsz + JS_MAX(nb, pool->arenasize);
            if (gross < nb)
                return NULL;
            if (pool->quotap) {
                if (gross > *pool->quotap)
                    return NULL;
                b = (JSArena *) js_malloc(gross);
                if (!b)
                    return NULL;
                *pool->quotap -= gross;
            } else {
                b = (JSArena *) js_malloc(gross);
                if (!b)
                    return NULL;
            }

            b->next = NULL;
            b->limit = (jsuword)b + gross;
            JS_COUNT_ARENA(pool,++);
            COUNT(pool, nmallocs);

            /* If oversized, store ap in the header, just before a->base. */
            *ap = a = b;
            JS_ASSERT(gross <= JS_UPTRDIFF(a->limit, a));
            if (extra) {
                a->base = a->avail =
                    ((jsuword)a + hdrsz) & ~HEADER_BASE_MASK(pool);
                SET_HEADER(pool, a, ap);
            } else {
                a->base = a->avail = JS_ARENA_ALIGN(pool, a + 1);
            }
            continue;
        }
        a = *ap;                                /* move to next arena */
    }
示例#3
0
// 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;
}
/* ************************************************** */
int set_header(call_t *c, packet_t *packet, destination_t *dst) {
    struct nodedata *nodedata = get_node_private_data(c);
    struct neighbor *n_hop = get_nexthop(c, &(dst->position));
    destination_t destination;
    struct routing_header *header = (struct routing_header *) (packet->data + nodedata->overhead);
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};

    /* if no route, return -1 */
    if (dst->id != BROADCAST_ADDR && n_hop == NULL) {
        nodedata->data_noroute++;
        return -1;
    }
    else if (dst->id == BROADCAST_ADDR) {
      n_hop->id = BROADCAST_ADDR;
    }

    /* set routing header */
    header->dst = dst->id;
    header->dst_pos.x = dst->position.x;
    header->dst_pos.y = dst->position.y;
    header->dst_pos.z = dst->position.z;
    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 = DATA_PACKET;
    header->hop = nodedata->hop;

    /* Set mac header */
    destination.id = n_hop->id;
    destination.position.x = -1;
    destination.position.y = -1;
    destination.position.z = -1;
    return SET_HEADER(&c0, packet, &destination);
}
示例#5
0
void rx_source_adv(call_t *c, packet_t *packet) {
    struct nodedata *nodedata = get_node_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}};
    call_t c0 = {get_entity_bindings_down(c)->elts[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);
    packet_dealloc(packet);

    return;
}
/* *********************************************** */
int set_header( call_t *c , packet_t * packet , destination_t * dst )
{
    struct nodedata *nodedata = get_node_private_data(c);
    struct protocoleData *entitydata =get_entity_private_data(c);

    packet_PROTOCOLE *data = (packet_PROTOCOLE *) (packet->data + nodedata->overhead);
    //augmenter le nbr d'evenement
    nodedata->nbr_evenement++;

    if(entitydata->debug)
        DBG("RBOP - %d SET HEADER  \n",c->node);

    //Fixé le rayon
    if(nodedata->range<0)
    {

        listeNodes *tmp=nodedata->oneHopNeighbourhood;
        position_t pos1 = *get_node_position(c->node);
        double distMax = 0;
        while(tmp)
        {
            if(list_recherche(nodedata->RNG,tmp->values.node))
            {
                position_t pos2= {tmp->values.x,tmp->values.y,tmp->values.z};
                double dist=distance(&pos1,&pos2);
                if(distMax<dist)    distMax=dist;
            }
            tmp=tmp->suiv;
        }
        set_range_Tr(c,distMax);
        nodedata->range=get_range_Tr(c);
        if(entitydata->debug)
            DBG("RBOP  - %d FIXE RANGE TO %.2lf  \n",c->node,get_range_Tr(c));
    }



    //remplissage de data
    data->type=RBOP;
    data->src=c->node;
    data->src_pos=*get_node_position(c->node);
    data->seq=nodedata->nbr_evenement;
    data->redirected_by=c->node;

    data->destinations=Nullptr(list);
    list_copy(&data->destinations,nodedata->RNG);

    list_PACKET_insert_tout(&nodedata->paquets,data->src,data->seq,data->redirected_by);



    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};

    destination_t destination = {BROADCAST_ADDR, {-1, -1, -1}};

    return SET_HEADER(&c0, packet, &destination);
}
示例#7
0
//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 forward(call_t *c, packet_t *packet) {  
    struct nodedata *nodedata = get_node_private_data(c);
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};
    struct routing_header *header = (struct routing_header *) (packet->data + nodedata->overhead);
    struct neighbor *n_hop = get_nexthop(c, &(header->dst_pos));
    destination_t destination;    

    /* delivers packet to application layer */
    if (n_hop == NULL) {
        array_t *up = get_entity_bindings_up(c);
        int i = up->size;
        
        while (i--) {
            call_t c_up = {up->elts[i], c->node, c->entity};
            packet_t *packet_up;
            
            if (i > 0) {
                packet_up = packet_clone(packet);         
            } else {
                packet_up = packet;
            }
            
            RX(&c_up, packet_up);
        }

        return;
    }
    
    /* update hop count */
    header->hop--;
    if (header->hop == 0) {
        nodedata->data_hop++;
        packet_dealloc(packet);
        return;
    }
    

    /* set mac header */
    destination.id = n_hop->id;
    destination.position.x = -1;
    destination.position.y = -1;
    destination.position.z = -1;
    if (SET_HEADER(&c0, packet, &destination) == -1) {
        packet_dealloc(packet);
        return;
    }
    
    /* forwarding packet */
    nodedata->data_tx++;
    TX(&c0, packet);
}
/* ************************************************** */
int set_header(call_t *c, packet_t *packet, destination_t *dst) {
    struct nodedata *nodedata = get_node_private_data(c);
    struct route *route = hadas_get(nodedata->routes, (void *) ((unsigned long) (dst->id)));
    struct routing_header *header = (struct routing_header *) (packet->data + nodedata->overhead);
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};
    destination_t n_hop;

    if (route == NULL) {
        return -1;
    }
    header->dst = dst->id;
    header->src = c->node;
    
    n_hop.id = route->n_hop;
    return SET_HEADER(&c0, packet, &n_hop);
}
示例#10
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;
}
/* ************************************************** */
void forward(call_t *c, packet_t *packet) {
    struct nodedata *nodedata = get_node_private_data(c);
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};
    struct routing_header *header = (struct routing_header *) (packet->data + nodedata->overhead);
    struct route *route = hadas_get(nodedata->routes, (void *) ((unsigned long) (header->dst)));
    destination_t destination;

    if (route == NULL) {
        packet_dealloc(packet);
        return;
    }

    destination.id = route->n_hop;
    if (SET_HEADER(&c0, packet, (void *) &destination) == -1) {
        packet_dealloc(packet);
        return;
    }
    TX(&c0, packet);
}
void forward(call_t* c, packet_t *packet)
{
	struct nodedata *nodedata = get_node_private_data(c);
    struct protocoleData *entitydata = get_entity_private_data(c);
	array_t *down = get_entity_bindings_down(c);
	packet_PROTOCOLE *data = (packet_PROTOCOLE *) (packet->data + nodedata->overhead);
	
	//printf("%d doit relayer depuis %d\n", c->node, data->pred);
	
	// construire le bip tree pour relayer a partir des infos du paquet
	int indice = listeNodes_get_index(data->askedToRedirect, c->node);
	graphe* g = purgeGraphe(c, listeNodes_get(data->needsToBeCovered, indice), data->src, data->pred);
	arbre* bipTree = computeBIPtree(c, g, data->askedToRedirect, data->needsToBeCovered, 0);
	
	if(entitydata->debug)
	{
		printf("%d relai depuis %d :\n", c->node, data->pred);
		arbre_affiche(bipTree);
	}
	
	// relayer le paquet
	destination_t dst = {-1,{-1,-1,-1}};
	double cout = setRangeToFarestNeighbour(c, g, bipTree);
	
	
	//listeNodes_detruire(&data->askedToRedirect);
	data->askedToRedirect = 0;
	//listeNodes_detruire(&data->needsToBeCovered);
	data->needsToBeCovered = 0;
	data->pred = c->node;
	
	//call_t c0 = {-1,c->node,-1};
	//data->energyRem = battery_remaining(&c0) - cout;
	//nodedata->energiesRem[c->node] = data->energyRem;
	
	setRelayNodes(c, g, bipTree, &data->askedToRedirect, &data->needsToBeCovered, c->node);
	call_t c_down = {down->elts[0], c->node, c->entity};
	SET_HEADER(&c_down, packet, &dst);
	tx(c, packet);
	arbre_detruire(&bipTree);
	deleteGraphe(g);
	free(g);
}
示例#13
0
void rx_source_data(call_t *c, packet_t *packet) {
    struct nodedata *nodedata = get_node_private_data(c);
    struct source_data_p *data = (struct source_data_p *) (packet->data + nodedata->overhead);
    struct gossip_data_p *gossip;
    packet_t *packet0;
    destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}};
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};

    /* check sensor */
    if (data->sensor != c->node) {
        /* not for us */
        packet_dealloc(packet);
        return;
    }

    /* check data sequence */
    if (data->d_seq <= nodedata->d_seq[data->metadata]) {
        /* old data */
        packet_dealloc(packet);
        return;
    }
    nodedata->d_seq[data->metadata] = data->d_seq;
    nodedata->d_source[data->metadata] = data->source;
    nodedata->d_value[data->metadata] = data->d_value;
    
    /* start gossip */
    packet0 = packet_create(c, nodedata->overhead + sizeof(struct gossip_data_p), -1);
    gossip = (struct gossip_data_p *) (packet0->data + nodedata->overhead);
    if (SET_HEADER(&c0, packet0, &dst) == -1) {
        packet_dealloc(packet);
        packet_dealloc(packet0);
        return;
    }
    gossip->type = GOSSIP_DATA_TYPE;
    gossip->source = data->source;
    gossip->metadata = data->metadata;
    gossip->d_seq = data->d_seq;
    gossip->d_value = data->d_value;
    TX(&c0, packet0);
    packet_dealloc(packet);

    return;
}
示例#14
0
void rx_sink_adv(call_t *c, packet_t *packet) {
    struct nodedata *nodedata = get_node_private_data(c);
    struct sink_adv_p *sink = (struct sink_adv_p *) (packet->data + nodedata->overhead);
    struct sensor_data_p *data;
    packet_t *packet0;
    destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}};
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};

    /* 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;
    
    /* check wether we have the data */
    if (sink->d_seq > nodedata->d_seq[sink->metadata]) {
        /* our data is not up to date */
        packet_dealloc(packet);
        return;
    }

    /* 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 = 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];
    TX(&c0, packet0);
    packet_dealloc(packet);

    return;
}
/* ************************************************** */
void forward(call_t *c, packet_t *packet) {  
    struct nodedata *nodedata = get_node_private_data(c);
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};
    struct routing_header *header = (struct routing_header *) 
        (packet->data + nodedata->overhead);
    struct neighbor *n_hop = get_nexthop(c, header->dst);
    destination_t destination;    

    /* No route available */    
    if (n_hop == NULL) {
        packet_dealloc(packet);        
        return;
    }
    
    /* Update hop count */
    header->hop--;

    /* Hop count reached */
    if (header->hop == 0) {
        packet_dealloc(packet);
        return;
    }

    /* Set MAC header */
    destination.id = n_hop->id;
    destination.position.x = -1;
    destination.position.y = -1;
    destination.position.z = -1;
    if (SET_HEADER(&c0, packet, &destination) == -1) {
        packet_dealloc(packet);
        return;
    }
    
    /* Forwarding packet */
    PRINT_ROUTING("forward: Node %d forwards a packet "
                  "(from %d to %d, hop limit %d)\n",
                   c->node, header->src, header->dst, 
                   header->hop);
    TX(&c0, packet);
}
示例#16
0
void rx_gossip_data(call_t *c, packet_t *packet) {
    struct nodedata *nodedata = get_node_private_data(c);
    struct gossip_data_p *data = (struct gossip_data_p *) (packet->data + nodedata->overhead);
    destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}};
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};

    /* check data sequence */
    if (data->d_seq <= nodedata->d_seq[data->metadata]) {
        /* old data */
        packet_dealloc(packet);
        return;
    }
    nodedata->d_seq[data->metadata] = data->d_seq;
    nodedata->d_source[data->metadata] = data->source;
    nodedata->d_value[data->metadata] = data->d_value;
    
    /* forward gossip */
    if (SET_HEADER(&c0, packet, &dst) == -1) {
        packet_dealloc(packet);
        return;
    }
    TX(&c0, packet);    
}
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;
}
示例#18
0
/* 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;
}
示例#19
0
/* 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;
}
示例#20
0
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;
}
示例#21
0
/* 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;
    }
}
示例#22
0
文件: jsarena.c 项目: Kitiara/UOX3
JS_ArenaAllocate(JSArenaPool *pool, size_t nb)
{
    JSArena **ap, **bp, *a, *b;
    jsuword extra, hdrsz, gross, sz;
    void *p;

    /*
     * Search pool from current forward till we find or make enough space.
     *
     * NB: subtract nb from a->limit in the loop condition, instead of adding
     * nb to a->avail, to avoid overflowing a 32-bit address space (possible
     * when running a 32-bit program on a 64-bit system where the kernel maps
     * the heap up against the top of the 32-bit address space).
     *
     * Thanks to Juergen Kreileder <*****@*****.**>, who brought this up in
     * https://bugzilla.mozilla.org/show_bug.cgi?id=279273.
     */
    JS_ASSERT((nb & pool->mask) == 0);
    for (a = pool->current; nb > a->limit || a->avail > a->limit - nb;
         pool->current = a) {
        ap = &a->next;
        if (!*ap) {
            /* Not enough space in pool -- try to reclaim a free arena. */
            extra = (nb > pool->arenasize) ? HEADER_SIZE(pool) : 0;
            hdrsz = sizeof *a + extra + pool->mask;
            gross = hdrsz + JS_MAX(nb, pool->arenasize);
            if (gross < nb)
                return NULL;

            bp = &arena_freelist;
            JS_ACQUIRE_LOCK(arena_freelist_lock);
            while ((b = *bp) != NULL) {
                /*
                 * Insist on exact arenasize match to avoid leaving alloc'able
                 * space after an oversized allocation as it grows.
                 */
                sz = JS_UPTRDIFF(b->limit, b);
                if (sz == gross) {
                    *bp = b->next;
                    JS_RELEASE_LOCK(arena_freelist_lock);
                    b->next = NULL;
                    COUNT(pool, nreclaims);
                    goto claim;
                }
                bp = &b->next;
            }

            /* Nothing big enough on the freelist, so we must malloc. */
            JS_RELEASE_LOCK(arena_freelist_lock);
            b = (JSArena *) malloc(gross);
            if (!b)
                return NULL;
            b->next = NULL;
            b->limit = (jsuword)b + gross;
            JS_COUNT_ARENA(pool,++);
            COUNT(pool, nmallocs);

        claim:
            /* If oversized, store ap in the header, just before a->base. */
            *ap = a = b;
            JS_ASSERT(gross <= JS_UPTRDIFF(a->limit, a));
            if (extra) {
                a->base = a->avail =
                    ((jsuword)a + hdrsz) & ~HEADER_BASE_MASK(pool);
                SET_HEADER(pool, a, ap);
            } else {
                a->base = a->avail = JS_ARENA_ALIGN(pool, a + 1);
            }
            continue;
        }
        a = *ap;                                /* move to next arena */
    }
示例#23
0
/* 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;
}
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;
}