/* ************************************************** */
void rx(call_t *c, packet_t *packet) {
    struct nodedata *nodedata = get_node_private_data(c);
    array_t *up = get_entity_bindings_up(c);
    int i = up->size;
    struct routing_header *header = (struct routing_header *) 
        (packet->data + nodedata->overhead);

    /* Forward packet if node is not the recipient */
	if ((header->dst != BROADCAST_ADDR) && (header->dst != c->node) ) {
        forward(c, packet);
        return;
    }
        
    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;
}
/* ************************************************** */
void rx(call_t *c, packet_t *packet) {
    struct nodedata *nodedata = get_node_private_data(c);
    struct _802_15_4_header *header = (struct _802_15_4_header *) packet->data;
    array_t *up = get_entity_bindings_up(c);
    int i = up->size;

    /* cf p171 ref 802.15.4-2006: discard packet while in backoff */
    if (nodedata->state != STATE_IDLE) {
        packet_dealloc(packet);
        return;
        
    }

    if ((header->dst != c->node) && (header->dst != BROADCAST_ADDR)) {
        packet_dealloc(packet);
        return;
    }
    
    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;
}
/* ************************************************** */
void rx(call_t *c, packet_t *packet) {
    struct nodedata *nodedata = get_node_private_data(c);
    array_t *up = get_entity_bindings_up(c);
    int i = up->size;

    /* radio sleep */
    if (nodedata->sleep) {
        packet_dealloc(packet);
        return;
    }

    /* half-duplex */
    if (nodedata->tx_busy != -1) {
        packet_dealloc(packet);
        return;
    }
    
    /* handle carrier sense */
    if (nodedata->rx_busy == packet->id) {
        nodedata->rx_busy = -1;
        nodedata->rxdBm   = MIN_DBM;
        /* log rx */
        PRINT_REPLAY("radio-rx1 %"PRId64" %d\n", get_time(), c->node);
        /* consume energy */
        battery_consume_rx(c, packet->duration);
    } else {
        packet_dealloc(packet);
        return;
    }

    /* check wether the reception has killed us */
    if (!is_node_alive(c->node)) {
        packet_dealloc(packet);
        return;
    }

    /* drop packet depending on the FER */
    if (get_random_double() < packet->PER) {
        packet_dealloc(packet);
        return;
    }    

    /* forward to upper layers */
    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;
}
Beispiel #4
0
/* ************************************************** */
void cs(call_t *c, packet_t *packet) {
    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};
        radio_cs(&c_up, 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_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);
}
Beispiel #6
0
void rx(call_t *c, packet_t *packet) {
    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;
}
/* ************************************************** */
void rx(call_t *c, packet_t *packet) {
    struct nodedata *nodedata = get_node_private_data(c);
    array_t *up = get_entity_bindings_up(c);
    int i = up->size;
    struct routing_header *header = (struct routing_header *) (packet->data + nodedata->overhead);

    switch(header->type) {
    case HELLO_PACKET:         
        nodedata->hello_rx++;
        add_neighbor(c, header);
        packet_dealloc(packet);
        break;

    case DATA_PACKET : 
        nodedata->data_rx++;

	if ((header->dst != BROADCAST_ADDR) && (header->dst != c->node) ) {
            forward(c, packet);
            return;
        }
        
        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);
        }
        break;

    default : 
        break;       
    }

    return;
}
/* ************************************************** */
void rx(call_t *c, packet_t *packet) {
	if(!is_node_alive(c->node))
		return;
    struct nodedata *nodedata = get_node_private_data(c);
    struct protocoleData *entitydata = get_entity_private_data(c);
	
	array_t *up = get_entity_bindings_up(c);
	
    packet_PROTOCOLE *data = (packet_PROTOCOLE *) (packet->data + nodedata->overhead);
	
	switch(data->type)
	{	
		case HELLO:
		{
			//printf("BIP - Paquet de type HELLO recu par %d depuis %d\n", c->node, data->src);
			rx_hello(c,packet);
			break;
		}
		case HELLO2:
		{
			//printf("BIP - Paquet de type HELLO2 recu par %d depuis %d\n", c->node, data->src);
			rx_two_hop(c,packet);
			break;
		}
		case APP:
		{
			//printf("DLBIP - Paquet de type APP recu par %d depuis %d ; source : %d et destine a %d\n", c->node, data->pred, data->src, data->dst);
			nodedata->energiesRem[data->pred] = data->energyRem;
			if(nodedata->lastIDs[data->src] == data->id || data->src == c->node)
			{
				break;
			}
			else
			{
				nodedata->lastIDs[data->src] = data->id;
			}
			if(data->dst == BROADCAST_ADDR)
			{
				SHOW_GRAPH("G: %d %d\n",data->pred,c->node);
				double cout;
				listeNodes* trans = data->askedToRedirect;
				listeNodes* trans2 = data->needsToBeCovered;
				while(trans != 0)
				{
					position_t p1, p2;
					p1.x = trans->values.x;
					p1.y = trans->values.y;
					p1.z = trans->values.z;
					p2.x = trans2->values.x;
					p2.y = trans2->values.y;
					p2.z = trans2->values.z;
					cout = getCoutFromDistance(distance(&p1, &p2), entitydata->alpha, entitydata->c);
					//printf("cout estime de (%d,%d)\n", );
					nodedata->energiesRem[trans->values.node] -= cout;
					
					trans = trans->suiv;
					trans2 = trans2->suiv;
				}
				
				//SHOW_GRAPH("G: %d %d\n",data->pred,c->node);
				
				// faire remonter le paquet a la couche application
				call_t c_up = {up->elts[0], c->node, c->entity};
				RX(&c_up, packet_clone(packet));
				
				if(listeNodes_recherche(data->askedToRedirect, c->node)) // si le paquet contient des instructions pour ce noeud
				{
					forward(c, packet);
				}
			}
			else
			{
				printf("Message non broadcaste pas traite ... TODO\n");
			}
			
			//packet_dealloc(packet);
			break;
		}
		default:
			printf("%d a recu un packet de type %d NON reconnu\n", c->node, data->type);
			break;
	}
	
	/*printf("estimation de l'energie restante depuis %d :\n", c->node);
	int i;
	for(i = 0 ; i < get_node_count() ; i++)
	{
		printf("\t%d : %.1lf\n", i, nodedata->energiesRem[i]);
	}*/
}