コード例 #1
0
static uint32_t worldsens_register_node_infos (ws_id_node wsim_id) {
    ws_id_node wsnet_id = 0;
    ws_node_features_t *ws_node_feat_next = malloc(sizeof(ws_node_features_t));

    /* puts new structure at the end of the pointer chain */
    if(ws_nodes_feat == NULL) {
        ws_nodes_feat = ws_node_feat_next;
    }
    else {
        ws_node_features_t *p_temp = ws_nodes_feat;
	wsnet_id = 1;
	while(p_temp->next != NULL) {
   	    p_temp = p_temp->next;
	    wsnet_id++;
	}
	p_temp->next = ws_node_feat_next;
    }    

    /* fills node infos */
    node_t *node = get_node_by_id(wsnet_id);
    ws_node_feat_next->wsim_node_id = wsim_id;
    ws_node_feat_next->position_backup.x = node->position.x;
    ws_node_feat_next->position_backup.y = node->position.y;
    ws_node_feat_next->position_backup.z = node->position.z;
    ws_node_feat_next->next = NULL;

    return wsnet_id;
}
コード例 #2
0
ファイル: medium.c プロジェクト: gabrielleLQX/wsnet
void medium_rx(packet_t *packet, call_t *c) {
    node_t *node = get_node_by_id(c->node);

    /* check wether the node is able to receive */
    if (node->state != NODE_ACTIVE) {
        packet_dealloc(packet);
        return;
    }

    /* noise & PER */
#if (SNR_STEP != 0)
    packet->PER = 1;
    noise_packet_rx(c, packet);
    packet->PER = 1 - packet->PER;
#ifdef SNR_ERRORS
    modulation_errors(packet);
#endif /*SNR_ERRORS*/
#else /*SNR_STEP == 0*/
    packet->PER = 0;
#endif /*SNR_STEP*/

    /* receive */
    /* edit by Loic Lemaitre */
    if (node->worldsens == NODE_LOCAL) {   /* WORLDSENS MODE? */
        antenna_rx(c, packet);
    }
    else {
        worldsens_nodes_rx(c, packet);
    }
    /* end of edition */

}
コード例 #3
0
/* ************************************************** */
void do_end(void) {
    int i = get_node_count();
    
    /* unsetnode */
    while (i--) {
        int j;
        node_t *node = get_node_by_id(i);
        if ((node->state == NODE_DEAD) || (node->state == NODE_UNDEF)) {
            continue;
        }
        for (j = 0; j < bundles.elts[node->bundle].entity.size; j++) {
            entity_t *entity = get_entity_by_id(bundles.elts[node->bundle].entity.elts[j]);
            call_t c = {entity->id, node->id, -1};
            if ((entity)->unsetnode) {
                (entity)->unsetnode(&c);
            }
        }
    }

    /* unsetnode */
    i = entities.size;
    while (i--) {
        entity_t *entity = get_entity_by_id(i);
        call_t c = {entity->id, -1, -1};
        if ((entity)->destroy) {
            (entity)->destroy(&c);
        }
    }
}
コード例 #4
0
ファイル: medium.c プロジェクト: gabrielleLQX/wsnet
/* ************************************************** */
void medium_cs(packet_t *packet, call_t *c) {
    uint64_t clock = get_time() + packet->duration;
    node_t *node = get_node_by_id(c->node);
    entity_t *entity = get_entity_by_id(c->entity);

    /* check wether the node is able to receive */
    if (node->state != NODE_ACTIVE) {
        packet_dealloc(packet);
        return;
    }

    /*  propagation */
    medium_compute_rxdBm(packet, c);

    /* filter */
    /* edit by Loic Lemaitre */
    if (node->worldsens == NODE_LOCAL) {  /* WORLDSENS MODE? wsim deals with filtering */
        if (packet->rxdBm == MIN_DBM) {
	    packet_dealloc(packet);
	    return;
	}
    }
    /* end of edition */
    
    /* update noise */
#if (SNR_STEP != 0)
    noise_packet_cs(c, packet);
#endif /*SNR_STEP*/
    /* start reception */
    entity->methods->antenna.cs(c, packet);
    /* end reception */
    scheduler_add_rx_end(clock, c, packet);
}
コード例 #5
0
ファイル: medium.c プロジェクト: gabrielleLQX/wsnet
void medium_tx_end(packet_t *packet, call_t *c) {
    node_t *node = get_node_by_id(c->node);
    entity_t *entity = get_entity_by_id(c->entity);
    
    /* check wether the node is still active */
    if (node->state == NODE_ACTIVE) {
        entity->methods->radio.tx_end(c, packet);
    }
    
    packet_dealloc(packet);
    return;
}
コード例 #6
0
/**
 * Deal with data sent by a node
 */
static void worldsens_tx_byte(struct _worldsens_c_byte_tx *pkt){
    uint64_t tx_start = ws_csync + pkt->period;
    uint64_t tx_end   = tx_start + pkt->duration;

    /* create packet */
    packet_t *packet;
    node_t   *node   = get_node_by_id(worldsens_get_wsnet_node_id(pkt->node_id));
    entity_t *entity = get_entity_by_id(pkt->antenna_id);
    call_t c = {entity->id, node->id, -1};

    /* put uint64_t into doubles to retrieve double value after swap */
    double *power_dbm = (double *) &(pkt->power_dbm);
    double *freq      = (double *) &(pkt->freq);  
    
    packet = packet_alloc(&c, 1);

    packet->clock0         =  tx_start;                /* tx start */
    packet->clock1         =  tx_end;                  /* tx end */
    packet->duration       =  pkt->duration;
    packet->node           =  node->id;                /* source */
    packet->antenna        =  pkt->antenna_id;
    packet->worldsens_mod  =  pkt->wsim_mod_id;        /* radio modulation in wsim. Better when it matches with wsnet modulation... */
    packet->channel        =  0;                       /* TODO: handle channel from wsim radio */
    packet->worldsens_freq = *freq;
    packet->txdBm          = *power_dbm;
    packet->Tb             =  pkt->duration / packet->real_size;
    *(packet->data)        =  pkt->data;

    if (pkt->wsnet_mod_id == -1)
        packet->modulation = ws_default_mod;
    else 
        packet->modulation = pkt->wsnet_mod_id;       /* modulation we are using in wsnet for calculation */

    /* log informations*/
    int iii;
    WSNET_S_DBG_DBG ("WSNET2:: <-- TX (%"PRId64") (src ip:%d,size:%d,data",
		     packet->clock0, pkt->node_id, packet->size);
    for(iii=0; iii<packet->size; iii++) {
        WSNET_S_DBG_DBG(":%02x", packet->data[ iii ] & 0xff);
    }
    WSNET_S_DBG_DBG (",duration:%"PRId64",freq:%ghz,wsim modul:%d,tx:%lgdbm)\n",
		     packet->duration, packet->worldsens_freq, packet->worldsens_mod, packet->txdBm);

    /* proceed TX */
    MEDIA_TX(&c, packet);

    /* reply by sending a backtrack or a rp reminder */
    worldsens_send_reply();

    return;
}
コード例 #7
0
static void worldsens_rx_disconnect(struct _worldsens_c_disconnect *pkt) {
    node_t *node = get_node_by_id(worldsens_get_wsnet_node_id(pkt->node_id));

    if (node->worldsens != NODE_CONNECTED) {
        return;
    }
    
    node->worldsens = NODE_DISCONNECTED;
    node_kill(node->id);

    if (ws_connected == 0 && ws_count == get_node_count())
      {
	end_simulation();
      }
}
コード例 #8
0
ファイル: graph.cpp プロジェクト: higginsrty/RoutingApp
Node* Graph::add_node(QString name, int x, int y, int id)
{
    Node *node = get_node_by_name(name);
    if (node != NULL)
        return NULL;
    node = get_node_by_id(id);
    if (node != NULL)
        return NULL;
    node = new Node();
    node->setup_node(name, x, y, panel, engine);
    node->set_id(id);
    QObject::connect(node->get_q_object(),SIGNAL(position_changed_sig(qreal,qreal,QString)),this,SLOT(update_node_position(qreal,qreal,QString)));
    QObject::connect(node->get_q_object(), SIGNAL(press_and_hold_node(QString)), this, SLOT(press_and_hold_node(QString)));
    QObject::connect(node->get_q_object(), SIGNAL(show_routing_table(QString)), this, SLOT(show_routing_table(QString)));
    node_pool.push_back(node);
    update_algorithm(0);
    return node;
}
コード例 #9
0
static int worldsens_restore_nodes_pos(void) {
    ws_node_features_t *p_node_feat = ws_nodes_feat;
    int i;
    node_t *node;

    for(i=0; i<ws_connected; i++) {
        if(p_node_feat == NULL) {
	    return -1;
	}
	node = get_node_by_id(i);
        node->position.x = p_node_feat->position_backup.x;
        node->position.y = p_node_feat->position_backup.y;
        node->position.z = p_node_feat->position_backup.z;
	p_node_feat = p_node_feat->next;
    }

    return 0;
}
コード例 #10
0
ファイル: node_info.c プロジェクト: OpenSIPS/opensips
clusterer_node_t *api_get_next_hop(int cluster_id, int node_id)
{
	clusterer_node_t *ret = NULL;
	node_info_t *dest_node;
	cluster_info_t *cluster;
	int rc;

	lock_start_read(cl_list_lock);

	cluster = get_cluster_by_id(cluster_id);
	if (!cluster) {
		LM_DBG("Cluster id: %d not found!\n", cluster_id);
		return NULL;
	}
	dest_node = get_node_by_id(cluster, node_id);
	if (!dest_node) {
		LM_DBG("Node id: %d no found!\n", node_id);
		return NULL;
	}

	rc = get_next_hop(dest_node);
	if (rc < 0)
		return NULL;
	else if (rc == 0) {
		LM_DBG("No other path to node: %d\n", node_id);
		return NULL;
	}

	lock_get(dest_node->lock);

	if (add_clusterer_node(&ret, dest_node->next_hop) < 0) {
		LM_ERR("Failed to allocate next hop\n");
		return NULL;
	}

	lock_release(dest_node->lock);

	lock_stop_read(cl_list_lock);

	return ret;
}
コード例 #11
0
ファイル: listener.c プロジェクト: swhatelse/URB_Final
void handle_connexion_requests(fd_set active_set) {
    message_id_t msg;

    // First connexion step
    if(FD_ISSET(listening_fd, &active_set)) {
        connexion_accept();
    }

    GList* current;
    for(current = connexions_pending; current != NULL; current = current->next) {
        connexion_t* cnx = (connexion_t*)current->data;
        if(cnx && FD_ISSET(cnx->fd, &active_set)) {
            bool retval = recv_all(cnx->fd, (void*)&msg, sizeof(message_id_t));
            // Client has validated the connexion
            // Remove it from pending connexion and register it using its id.
            if(retval) {
                DEBUG("[%d] Client validation validated [%s:%d][%d]\n", msg.node_id, inet_ntoa(cnx->infos.sin_addr), ntohs(cnx->infos.sin_port), cnx->fd);
                // Register the node in the incomming connexion
                add_node(cnx, msg.node_id);
                connexions_pending = g_list_remove(connexions_pending, cnx);
                // If the sending connexion is not establish, establishes it
                node_t* node = get_node_by_id(msg.node_id);
                if(!node->out_connected) {
                    DEBUG_ERR("Rejoin %d / %d\n", msg.node_id, node->id);
                    connexion(node->outbox);
                    node->out_connected = true;
                }
            }
            else {
                // Disconnection
                if(cnx) {
                    DEBUG("[?] Client validation aborted [%s:%d][%d]\n", inet_ntoa(cnx->infos.sin_addr), ntohs(cnx->infos.sin_port), cnx->fd);
                    FD_CLR(cnx->fd, &reception_fd_set);
                    close(cnx->fd);
                    connexion_pending_remove(current);
                    connexions_pending = g_list_remove(connexions_pending, cnx);
                }
            }
        }
    }
}
コード例 #12
0
ファイル: input.c プロジェクト: LukeShu/Graph-Reply
void process_input(char *input, struct Graph *g){
    int i = 0;
    char name_a[50];
    char name_b[50];
    char type[5];
    sscanf(input, "%s %s %s", type, name_a, name_b);
    if(!strcmp(type,"new")){
        add_new_node(name_a, g);
    }
    else if(!strcmp(type,"link")){
        add_new_link(name_a, name_b, g);
    }
    else if(!strcmp(type,"out")){
        print_outgoing_nodes(name_a, g);
    }
    else if(!strcmp(type,"in")){
        print_incoming_nodes(name_a, g);
    }
    else if(!strcmp(type,"wn")){
        write_data_prompt(name_a, g);
    }
    else if(!strcmp(type,"rn")){
        read_data(name_a, g);
    }
    else if(!strcmp(type, "all")){
        print_graph(g);
    }
    else if(!strcmp(type,"wl")){
        write_link_data_prompt(name_a, name_b, g);
    }
    else if(!strcmp(type,"rl")){
        read_link_data(name_a, name_b, g);
    }
    else if(!strcmp(type, "path")){
        // printf("Hey");
        test_for_path(name_a, name_b, g);
    }
    else if(!strcmp(type, "save")){
        save_to_disk(g, name_a);
    }
    else if(!strcmp(type, "load")){
        read_from_disk(name_a, g);
    }
    else if(!strcmp(type, "getl")){
        get_links(g);
        // all links (node pairs) with X data
    }
    else if(!strcmp(type, "getn")){
        get_nodes(g);
        // all nodes with X data
    }
    else if(!strcmp(type, "add")){
        add_nodes(name_a, name_b, g);
    }
    else if(!strcmp(type, "div")){
        divide_nodes(name_a, name_b, g);
    }
    else if(!strcmp(type, "sub")){
        subtract_nodes(name_a, name_b, g);
    }
    else if(!strcmp(type, "mult")){
        multiply_nodes(name_a, name_b, g);
    }
    else if(!strcmp(type, "cmd")){
        run_command(name_a, g);
    }
    else if(!strcmp(type, "id")){
        long long_val;
        long_val = strtol(name_a, NULL, 10);
        int id = (int) long_val;
        struct Node *node; 
        node = get_node_by_id(id, g);
        if(!strcmp(node->name, "NULL")){
            printf("{ \"error\": \"No node with id %d\" }\n", id);
            free(node->name);
            free(node);
        } else {
            printf("{ \"id: %d, \"name\": \"%s\", \"data\": \"%s\" }\n", id, node->name, node->data);
        }
    }
}
コード例 #13
0
/**
 * Forge response to a node connect request
 */
static void worldsens_rx_connect_req(struct _worldsens_c_connect_req *pkt, struct sockaddr_in *addr) {

    node_t   *node   = get_node_by_id(worldsens_register_node_infos(pkt->node_id));
    bundle_t *bundle = get_bundle_by_id(node->bundle);
    entity_t *entity;
    union _worldsens_pkt pkt0;
    int offset = 0;
    int i;
    int nb_mod = 0;

    if (node->worldsens != NODE_DISCONNECTED) {
        //PRINT_WORLDSENS("wsnet:worldsens_rx_connect_req (%"PRId64"): node %d not disconnected!\n", get_time(), node->id);
        return;
    }
    
    /* forge response*/
    pkt0.cnx_rsp_ok.type = WORLDSENS_S_CONNECT_RSP_OK;
    pkt0.cnx_rsp_ok.seq = ws_seq;
    pkt0.cnx_rsp_ok.rp_next = ws_nsyncseq;
    pkt0.cnx_rsp_ok.rp_duration = ws_nsync - ws_csync;
    pkt0.cnx_rsp_ok.n_antenna_id = bundle->antenna.size;
    pkt0.cnx_rsp_ok.n_measure_id = measures.size;

   /* pkt->cnx_rsp_ok.names_and_ids format: */

/*|***************antennas***************|**************modulations*************|***************measures***************|*/
/*|ant id1|ant name1|ant id2|ant name2|..|mod id1|mod name1|mod id2|mod name2|..|mea id1|mea name1|mea id2|mea name2|..|*/
/*  *********************************************************************************************************************/

    /* forge list of available antennas */
    for (i = 0; i < bundle->antenna.size; i++) {
        entity = get_entity_by_id(bundle->antenna.elts[i]);
	/* PRINT_WORLDSENS("wsnet: worldsens_rx_connect_req (%"PRId64"): antenna '%s' 
	   (id %d) available\n", get_time(), entity->name, entity->id); */
        *((uint32_t *) (pkt0.cnx_rsp_ok.names_and_ids + offset)) = entity->id;
        offset += sizeof(uint32_t);
        strcpy(pkt0.cnx_rsp_ok.names_and_ids + offset, entity->name);
        offset += strlen(entity->name) + 1;
    }

    /* forge list of available modulations */
    das_init_traverse(modulation_entities);
    while ((entity = (entity_t *) das_traverse(modulation_entities)) != NULL) {
        /*PRINT_WORLDSENS("wsnet: worldsens_rx_connect_req (%"PRId64"): modulation '%s' 
	  (id %d) available\n", get_time(), entity->library.name, entity->id); */
        *((uint32_t *) (pkt0.cnx_rsp_ok.names_and_ids + offset)) = entity->id;
        offset += sizeof(uint32_t);
        strcpy(pkt0.cnx_rsp_ok.names_and_ids + offset, entity->library.name);
        offset += strlen(entity->library.name) + 1;
	nb_mod++;
	if ((nb_mod == 1) || (strcmp(entity->library.name, "modulation_none") == 0)) {
	    ws_default_mod = entity->id;
	}
    }
    pkt0.cnx_rsp_ok.n_modulation_id = nb_mod;

    /* forge list of available measure */
    for (i = 0; i < measures.size; i++) {
        measure_t *measure = get_measure_by_id(i);
	/* PRINT_WORLDSENS("wsnet: worldsens_rx_connect_req (%"PRId64"): measure '%s' 
	   (id %d) available\n", get_time(), measure->name, measure->id); */
        *((uint32_t *) (pkt0.cnx_rsp_ok.names_and_ids + offset)) = measure->id;
        offset += sizeof(uint32_t);
        strcpy(pkt0.cnx_rsp_ok.names_and_ids + offset, measure->name);
        offset += strlen(measure->name) + 1;
    }
    
    /* give birth to node */
    ws_connected++;
    node->worldsens = NODE_CONNECTED;
    node_birth(node->id);

    WSNET_S_DBG_DBG("WSNET2:: <-- CONNECT(%d/%d) (ip: %d)\n", ws_connected, ws_count, pkt->node_id);
    WSNET_S_DBG_DBG("WSNET2:: --> RP (seq: %"PRId64") (rp seq: %"PRId64", period: %"PRId64", rp:%"PRId64")\n", ws_seq, ws_nsyncseq, ws_nsync - ws_csync, ws_nsync);

    /* send response */
    worldsens_packet_display(&pkt0);
    worldsens_packet_hton(&pkt0);
    wsens_srv_send(addr, (char *) &pkt0, sizeof(struct _worldsens_s_connect_rsp_ok));    
}
コード例 #14
0
ファイル: medium.c プロジェクト: gabrielleLQX/wsnet
void MEDIA_TX(call_t *c, packet_t *packet) {
    int i = get_node_count();
    node_t *node = get_node_by_id(c->node);
    uint64_t clock;
    
    /* check wether node is active */
    if (node->state != NODE_ACTIVE) {
        packet_dealloc(packet);
        return;
    }

    /* edit by Loic Lemaitre */
    if (node->worldsens == NODE_LOCAL) {  /* WORLDSENS MODE? -> radio part is simulated in wsim */
        /* fill packet info */
        packet->node = c->node;
	packet->antenna = c->from;
	packet->txdBm = radio_get_power(c);
	packet->channel = radio_get_channel(c);
	packet->modulation = radio_get_modulation(c);
	packet->Tb = radio_get_Tb(c);
	//packet->duration = packet->size * packet->Tb * 8;
	/* edit by Quentin Lampin <*****@*****.**> */
	packet->duration = packet->real_size * packet->Tb;
	/* end of edition */
	packet->clock0 = get_time();
	packet->clock1 = packet->clock0 + packet->duration;

	/* scheduler tx_end event */
	scheduler_add_tx_end(packet->clock1, c, packet);
    }
    /* end of edition */
    
    /* scheduler rx_begin event */
#ifdef N_DAS_O
    if (propagation_range) {
        void *rx_nodes;
        node_t *rx_node;

        rx_nodes = spadas_rangesearch(location, NULL, &(node->position), propagation_range);
        while ((rx_node = (node_t *) das_pop(rx_nodes)) != NULL) {
            double derive = distance(&(node->position), &(rx_node->position)) / 0.3; 
            bundle_t *bundle = get_bundle_by_id(rx_node->bundle);
            int i;
    
            if (rx_node->state == NODE_DEAD) {
                continue;
            }

            for (i = 0; i < bundle->antenna.size; i++) {
                entity_t *entity = get_entity_by_id(bundle->antenna.elts[i]);
                call_t c0 = {entity->id, rx_node->id, -1}; 
                packet_t *packet_rx = packet_rxclone(packet);
                
                clock = packet->clock0 + ((uint64_t) derive);
                packet_rx->clock0 = clock;
                packet_rx->clock1 = clock + packet->duration;
                scheduler_add_rx_begin(clock, &c0, packet_rx);
            }
        }
        das_destroy(rx_nodes);
    } else {
        while (i--) {
            node_t *rx_node = get_node_by_id(i);
            double derive = distance(&(node->position), &(rx_node->position)) / 0.3; 
            bundle_t *bundle = get_bundle_by_id(rx_node->bundle);
            int i;
            
            if (rx_node->state == NODE_DEAD) {
                continue;
            }
            
            for (i = 0; i < bundle->antenna.size; i++) {
                entity_t *entity = get_entity_by_id(bundle->antenna.elts[i]);
                call_t c0 = {entity->id, rx_node->id, -1}; 
                packet_t *packet_rx = packet_rxclone(packet);

                clock = packet->clock0 + ((uint64_t) derive);
                packet_rx->clock0 = clock;
                packet_rx->clock1 = clock + packet->duration;
                scheduler_add_rx_begin(clock, &c0, packet_rx);
            }
        }
    }   
#else /* N_DAS_O */
    while (i--) {
        node_t *rx_node = get_node_by_id(i);
        double dist = distance(&(node->position), &(rx_node->position));
        double derive = dist / 0.3; 
        bundle_t *bundle = get_bundle_by_id(rx_node->bundle);
        int i;

        if (rx_node->state == NODE_DEAD) {
            continue;
        }
        
        if ((propagation_range) && (dist > propagation_range)) {
            continue;
        }
        
        for (i = 0; i < bundle->antenna.size; i++) {
            entity_t *entity = get_entity_by_id(bundle->antenna.elts[i]);
            call_t c0 = {entity->id, rx_node->id, -1}; 
            packet_t *packet_rx = packet_rxclone(packet);
            
            clock = packet->clock0 + ((uint64_t) derive);
            packet_rx->clock0 = clock;
            packet_rx->clock1 = clock + packet->duration;
            scheduler_add_rx_begin(clock, &c0, packet_rx);
        }
    }
#endif /* N_DAS_O */

}