/* ************************************************** */
void tx(call_t *c, packet_t *packet) {
    struct nodedata *nodedata = get_node_private_data(c);
    array_t *down = get_entity_bindings_down(c);
    int i = down->size;
    
    /* radio sleep */
    if (nodedata->sleep) {
        packet_dealloc(packet);
        return;
    }

    /* radio activity */
    cs_init(c);
    nodedata->tx_busy = packet->id;

    /* log tx */
    PRINT_REPLAY("radio-tx0 %"PRId64" %d 50\n", get_time(), c->node);

    /* transmit to antenna */
    while (i--) {
        packet_t *packet_down;
        
        if (i > 0) {
            packet_down = packet_clone(packet);         
        } else {
            packet_down = packet;
        }
        c->from = down->elts[i];
        MEDIA_TX(c, packet_down);
    }

    return;
}
/* ************************************************** */
void tx(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};
    
    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 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);
}
Пример #4
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 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);
}
Пример #6
0
int bootstrap(call_t *c) {
    struct nodedata *nodedata = get_node_private_data(c);
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};
  
    /* get overhead */
    nodedata->overhead = GET_HEADER_SIZE(&c0);

    return 0;
}
/* *********************************************** */
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);
}
int get_header_real_size(call_t *c) {
    struct nodedata *nodedata = get_node_private_data(c);

    if (nodedata->overhead == -1) {
        call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};        
        nodedata->overhead = GET_HEADER_REAL_SIZE(&c0);
    }
    
    return nodedata->overhead + sizeof(struct routing_header);
}
void tx( call_t *c , packet_t * packet )
{
    struct nodedata *nodedata = get_node_private_data(c);
    packet_PROTOCOLE *data = (packet_PROTOCOLE *) (packet->data + nodedata->overhead);
	
	
    //printf("DLBIP - Paquet de type %d envoye depuis %d par %d a %d (at %lf s).\n", data->type, data->src, c->node, data->dst, get_time_now_second());
	
	//retransmettre
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};
    TX(&c0,packet);
}
/* ************************************************** */
int check_channel_busy(call_t *c) {
    struct nodedata *nodedata = get_node_private_data(c);
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};

    if (nodedata->cs && (radio_get_cs(&c0) >= nodedata->EDThreshold)) {
        return 1;
    }
    if (nodedata->cca && (radio_get_noise(&c0) >= nodedata->EDThreshold)) {
        return 1;
    }
    return 0;
}
int get_header_size( call_t * c )
{
    struct nodedata *nodedata = get_node_private_data(c);

    if (nodedata->overhead == -1)
    {
        call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};
        nodedata->overhead = GET_HEADER_SIZE(&c0);
    }

    return nodedata->overhead + sizeof(packet_PROTOCOLE);
}
/* ************************************************** */
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 bootstrap(call_t *c) {
    struct nodedata *nodedata = get_node_private_data(c);
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};
    int nb_neigh = 0;
    nb_neigh=nb_neigh;
    /* Get mac header overhead */
    nodedata->overhead = GET_HEADER_SIZE(&c0);

    /* Find all the node's neighbors (i.e. the one in range) */
    
    nb_neigh = find_neighbors(c);
    PRINT_ROUTING("Node %d has %d neighbors\n", c->node, nb_neigh);
        
    return 0;
}
/* ************************************************** */
int bootstrap(call_t *c) {
    struct nodedata *nodedata = get_node_private_data(c);
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};
    
    /* get mac header overhead */
    nodedata->overhead = GET_HEADER_SIZE(&c0);
        
    /*  hello packet */
    if (nodedata->period > 0) {
        uint64_t start = get_time() + nodedata->start + get_random_double() * nodedata->period;
        scheduler_add_callback(start, c, advert_callback, NULL);
    }

    return 0;
}
/* ************************************************** */
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);
}
int bootstrap(call_t *c) {
    struct nodedata *nodedata = get_node_private_data(c);
    struct protocoleData *entitydata = get_entity_private_data(c);

    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};
    /* get mac header overhead */
    nodedata->overhead = GET_HEADER_SIZE(&c0);

    broadcast_hello(c, NULL);
    uint64_t at=get_time_now()+time_seconds_to_nanos(3);
    scheduler_add_callback(at, c, init_rbop, NULL);



    return 0;
}
Пример #17
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;
}
/* ************************************************** */
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);
}
Пример #19
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);
    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);
}
int bootstrap(call_t *c) {
    struct nodedata *nodedata = get_node_private_data(c);
    struct protocoleData *entitydata = get_entity_private_data(c);
	
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};
	/* get mac header overhead */
    nodedata->overhead = GET_HEADER_SIZE(&c0);
	
	int i;
	for(i = 0 ; i < get_node_count() ; i++)
	{
		nodedata->lastIDs[i] = -1;
		nodedata->energiesRem[i] = battery_remaining(c) - 2*getCoutFromDistance(getRange(c), entitydata->alpha, entitydata->c);
	}
	
	broadcast_hello(c, NULL);
    uint64_t at=get_time_now()+time_seconds_to_nanos(2);
    scheduler_add_callback(at, c, broadcast_hello2, 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 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);
}
Пример #23
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;
}
int state_machine(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};
    uint64_t timeout;
    uint64_t backoff;
    packet_t *packet;	

    if (nodedata->clock != get_time()) {
        return 0;
    }

    switch (nodedata->state) {
		
    case STATE_IDLE:
        if (nodedata->txbuf == NULL) {
            nodedata->txbuf = (packet_t *) das_pop_FIFO(nodedata->packets);
            if (nodedata->txbuf == NULL) {
                return 0;
            }
        }
        
        if (nodedata->MaxCSMABackoffs != 0) {
            nodedata->state = STATE_BACKOFF;
            nodedata->BE = nodedata->MinBE;
            nodedata->NB = 0;
            backoff = get_random_double() * (pow(2, nodedata->BE) - 1) * aUnitBackoffPeriod;
			
            nodedata->clock = get_time() + backoff;  
            scheduler_add_callback(nodedata->clock, c, state_machine, NULL);
            return 0;	
        } else {
            nodedata->state = STATE_TX;
            nodedata->clock = get_time();  
            scheduler_add_callback(nodedata->clock, c, state_machine, NULL);
            return 0;
        }		

    case STATE_BACKOFF:
        if (check_channel_busy(c)) { 
            if ((++nodedata->BE) > nodedata->MaxBE) {
                nodedata->BE = nodedata->MaxBE;
            } 
            if (++nodedata->NB >= nodedata->MaxCSMABackoffs) {
                packet_dealloc(nodedata->txbuf);            
                nodedata->txbuf = NULL;

                nodedata->state = STATE_IDLE;
                nodedata->clock = get_time();
                state_machine(c,NULL);
                return 0;
            }
            backoff = get_random_double() * (pow(2, nodedata->BE) - 1) * aUnitBackoffPeriod;
            nodedata->clock = get_time() + backoff;
            scheduler_add_callback(nodedata->clock, c, state_machine, NULL);
            return 0;
        }
        
        nodedata->state = STATE_TX;
        nodedata->clock = get_time();  
        state_machine(c,NULL);
        return 0;
        
    case STATE_TX:
        packet = nodedata->txbuf;
        nodedata->txbuf = NULL;
        timeout = packet->size * 8 * radio_get_Tb(&c0) + macMinSIFSPeriod;
        TX(&c0, packet); 

        nodedata->state = STATE_TXING;
        nodedata->clock = get_time() + timeout;
        scheduler_add_callback(nodedata->clock, c, state_machine, NULL);
        return 0;

    case STATE_TXING:
        nodedata->state = STATE_IDLE;
        nodedata->clock = get_time();
        state_machine(c,NULL);
        return 0;

    default:
        break;
    }

    return 0;
}
/* ************************************************** */
void tx(call_t *c, packet_t *packet) {
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};
    TX(&c0, packet);
}