void listC_to_list(list **l,listC *c)
{
    while(c)
    {
        if(!list_recherche(*l,c->node1)) list_insert(l,c->node1);
        if(!list_recherche(*l,c->node2)) list_insert(l,c->node2);
        c=c->suiv;
    }
}
/***********************TRENSFORMER**************************/
void list2_to_list(list **l,list2 *l2)
{
    while(l2)
    {
        if(!list_recherche(*l,l2->node)) list_insert(l,l2->node);
        int i=0;
        for(i=0;i<list_taille(l2->peres);i++)
        {
            int node= list_get(l2->peres,i);
            if(!list_recherche(*l,node)) list_insert(l,node);
        }

        l2=l2->suiv;
    }
}
/* ************************************************** */
void rx(call_t *c, packet_t *packet) {
    struct nodedata *nodedata = get_node_private_data(c);

    packet_PROTOCOLE *data = (packet_PROTOCOLE *) (packet->data + nodedata->overhead);


    /*******************************HELLO 1 voisinage***************************/
    switch(data->type)
    {
    case HELLO:
    {
        rx_hello(c,packet);
        break;
    }
    case RBOP:
    {
        if(list_recherche(data->destinations,c->node))
        {
            SHOW_GRAPH("G: %d %d\n",data->redirected_by,c->node);
            if(list_PACKET_recherche_tout(nodedata->paquets,data->src,data->seq)==0)
                PROTOCOLE_reception(c,packet);
        }

        break;
    }
    default:
        printf("J'ai recu un packet de type %d NON reconnu\n", data->type);
        break;
    }
}
/* ************************************************** */
void rx(call_t *c, packet_t *packet) {


    if(!is_node_alive(c->node))
        return;


    struct nodedata *nodedata = get_node_private_data(c);

    struct packet_general *packetType= (struct packet_general *)(packet->data + nodedata->overhead);


    /*******************************HELLO 1 voisinage***************************/
        switch(packetType->type)
	{	
        case HELLO:
        {
                rx_hello(c,packet);
                break;
        }

        case LMST:
        {
            packet_lmst *lmstPacket = (packet_lmst *) (packet->data + nodedata->overhead);
            if(list_recherche(lmstPacket->MST,c->node))
                rx_lmst(c,packet);
            break;
        }//*/

        case LBOP:
        {
            packet_PROTOCOLE *data = (packet_PROTOCOLE *) (packet->data + nodedata->overhead);
            if(list_recherche(data->destinations,c->node))
                    {
                       SHOW_GRAPH("G: %d %d\n",data->redirected_by,c->node);
                        if(list_PACKET_recherche_tout(nodedata->paquets,data->src,data->seq)==0)
                             PROTOCOLE_reception(c,packet);
                    }

            break;
        }
        default:
                printf("J'ai recu un packet de type %d NON reconnu\n", packetType->type);
                break;
	}
}
/* *********************************************** */
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);
}
Beispiel #6
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;

}
Beispiel #7
0
//RECEPTION DE LA REPONSE DE PAKET HELLO
void rx_one_hop_reponse(call_t *c, packet_t *packet) {
    struct nodedata *nodedata = get_node_private_data(c);

    struct packet_hello *data = (struct packet_hello *) (packet->data + nodedata->overhead[0]);


    DEBUG;
    /*printf("je suis le noeud %d j'ai recu la REPONSE de %d \n",c->node,
            data->source);//*/

    //l'ajoute de voisin
    if(!list_recherche(nodedata->N1,data->source))
        list_insert(&nodedata->N1,data->source);

    //tous c'est bien passé
    return;
}