Ejemplo n.º 1
0
int get_node_count(group *g)
{
    int count = 1;
    if(g->negative != NULL) {
        count += get_node_count(g->negative);
        count += get_node_count(g->positive);
    }
    return count;
}
Ejemplo n.º 2
0
/**
 * Prints the graph by printing Node informations and Edge informations while iterating it
 * Testcase:Node:%d,%d\n	with the linkaddr.u8[0] and the depth
 * Testcase:Edge:%d,%d\n	with the linkaddr.u8[0] of the source and the linkaddr.u8[0] of the drain
 */
static void debug_k_hop_timer_event(void *ptr)
{
	printf("Print Graph for Node %d\n", linkaddr_node_addr.u8[0]);
	uint8_t count = 0;

	uint8_t i = 0;
	printf("Saved Nodes:%d\n", get_node_count());
	printf("Saved Edges:%d\n", get_edge_count());

	//print nodes
	p_hop_t *hops = get_hop_counts(&count);
	printf("Count Node hops:%d\n", count);
	//also print root
	printf("Testcase:Node:%d,%d\n", linkaddr_node_addr.u8[0], 0);
	for (i = 0; i < count; i++)
	{
		printf("Testcase:Node:%d,%d\n", hops[i].addr.u8[0], hops[i].hop_count);
	}
	free(hops);

	//print edges
	p_edge_t **edge_array = get_all_edges(&count);
	printf("Count Edge:%d\n", count);
	for (i = 0; i < count; i++)
	{
		printf("Testcase:Edge:%d,%d\n", edge_array[i]->src.u8[0], edge_array[i]->dst.u8[0]);
	}
}
Ejemplo n.º 3
0
int log_energymap(call_t *c) {
    struct entitydata *entitydata = get_entity_private_data(c);
    int i = get_node_count();
    FILE *file = NULL;
    char file_map[100];
    double time = get_time() * 0.000001;
    
    /* create file */
    sprintf(file_map, "%s/%s.%.0lf.data", entitydata->directory, entitydata->map_prefix, time);    
    if ((file = fopen(file_map, "w+")) == NULL) {
        fprintf(stderr, "My monitor: can not open file %s in monitor_event()\n", file_map);
        return -1;
    }
    
    /* log energy map */
    while (i--) {
        call_t c0 = {-1, i, -1};
        position_t *position = get_node_position(c0.node);
        fprintf(file, "%d %lf %lf %lf %lf\n", c0.node, position->x, position->y, position->z, battery_status(&c0));
    }

    /* log virtual nodes for the 4 area corners */
    fprintf(file, "%d %lf %lf %lf %lf\n", -1, 0.0, 0.0, 0.0, 1.0);
    fprintf(file, "%d %lf %lf %lf %lf\n", -1, get_topology_area()->x, 0.0, 0.0, 1.0);
    fprintf(file, "%d %lf %lf %lf %lf\n", -1, 0.0, get_topology_area()->y, 0.0, 1.0);
    fprintf(file, "%d %lf %lf %lf %lf\n", -1, get_topology_area()->x, get_topology_area()->y, 0.0, 1.0);
    
    fclose(file);
    return 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);
        }
    }
}
/* Find all the neighbors (i.e. nodes in range) of the current node */
int find_neighbors(call_t *c) {
    struct nodedata *nodedata = get_node_private_data(c);
    struct neighbor *neighbor = NULL;    
    nodeid_t i;
    double dist = 0;
    int nb_neigh = 0;

    /* Parse all the nodes in the simulation: and find the ones 
     * that are in range of that node
     */
    for(i = 0; i < get_node_count(); i++) {
        /* Do not include myself */
        if (i == c->node) {
            continue;
        }

        dist = distance(get_node_position(c->node), get_node_position(i));
        if (dist <= nodedata->range) {
            /* Add the node in the list of neighbors */
            neighbor = (struct neighbor *) malloc(sizeof(struct neighbor));
            neighbor->id = i;
            neighbor->position.x = get_node_position(i)->x;
            neighbor->position.y = get_node_position(i)->y;
            neighbor->position.z = get_node_position(i)->z;
            neighbor->time = get_time();
            //PRINT_ROUTING("Node %d is added to neighbor list of node %d\n",
            //              neighbor->id, c->node);    
            das_insert(nodedata->neighbors, (void *) neighbor);
            nb_neigh++;
        }
    }

    return nb_neigh;
}
int unsetnode(call_t *c) {
    struct nodedata *nodedata = get_node_private_data(c);
    struct route *route;
    int i = get_node_count();
    while (i--) {
        if ((route = (struct route *) hadas_get(nodedata->routes, (void *) ((unsigned long) i))) != NULL) {
            free(route);
        }
    }
    hadas_destroy(nodedata->routes);    
    free(nodedata);
    return 0;
}
Ejemplo n.º 7
0
//
// Function:	move()
// 
// Purpose:		Moves ALL the nodes for the member func by the delta passed in.
//
// Arguments:
//
//		int x_delta - how many 'x' elements (in the values[] array) to move each node by 
//
// Returns:
//
//		void
//
// Author:	Michael Zarozinski
// Date:	7/99
// 
// Modification History
// Author	Date		Modification
// ------	----		------------
//
//
void MemberFuncBase::move(int x_delta) 
{

	if (x_delta == 0)
		return; // nothing to do!

	// move all the nodes... 

	// we need to be careful about the order we move them in.
	// if they are being move to the right (positive offset) we need to
	// move the last point and work our way to the first point so we don't
	// cross any points if the offset is large.
	// likewize if we're moving to the left (negative offset) move them in
	// order (first to last)

	int start, end, increment;	// values that determine how we loop
 	int node_count = get_node_count();

	if (x_delta < 0)
		{
		// moving to the left
		start = 0;
		end = node_count;
		increment = 1;

		// adjust the delta so we don't "collapse" the term
		
		if (nodes[0].x + x_delta < 0)
			x_delta = -nodes[0].x;

		} // end if offset negative
	else
		{
		// offset is positive
		start = node_count - 1;
		end = -1;
		increment = -1;
		if (nodes[node_count - 1].x + x_delta > FuzzyVariableBase::get_x_array_max_idx())
			x_delta = ( FuzzyVariableBase::get_x_array_max_idx()) - nodes[node_count - 1].x;

		} // end if offset positive

	// now move them all (note the 'y' direction is invariant when moving all nodes at once)

	for (int i = start; i != end; i += increment)
		{
  		move_node(i, nodes[i].x + x_delta, nodes[i].y );

		} // end loop through nodes

} // end MemberFuncBase::move()
Ejemplo n.º 8
0
/* ************************************************** */
int init(call_t *c, void *params) {
    struct entitydata *entitydata = malloc(sizeof(struct entitydata));
    char filenode[100];
    param_t *param;

    /* default values */
    entitydata->callbacks = das_create();
    entitydata->nbr_nodes = get_node_count();
    strcpy(entitydata->map_prefix, "energymap");
    strcpy(entitydata->directory,"./");
    entitydata->map_period = 1000000000;
    
    das_init_traverse(params);
    while ((param = (param_t *) das_traverse(params)) != NULL) {
        int i = 0;
        if (!strcmp(param->key, "directory")) {
            strcpy(entitydata->directory, param->value);
            goto parse_key_ok;
        } 
        if (!strcmp(param->key, "prefix")) {
            strcpy(entitydata->map_prefix, param->value);
            goto parse_key_ok;
        } 
        
        if (!strcmp(param->key, "map-period")) {
            if (get_param_time(param->value, &(entitydata->map_period))) {
                goto error;
            }
        goto parse_key_ok;
        }
        (void) fprintf(stderr,
                       "WARNING: token %s is not recognized\n",
                        param->key);
parse_key_ok:
        i++; 
    }
    
    /* open node activity file */
    sprintf(filenode, "%s/%s.data", entitydata->directory, "activenodes");
    if ((entitydata->filenode = fopen(filenode, "w")) == NULL) {
        fprintf(stderr, "NRJ monitor: can not open file %s !\n", filenode);
        goto error;
    }

    set_entity_private_data(c, entitydata);
    return 0;

 error:
    free(entitydata);
    return -1;
}
/* ************************************************** */
int init(call_t *c, void *params) {
    struct entitydata *entitydata = malloc(sizeof(struct entitydata));
    param_t *param;
    char *filepath = NULL;
    int src, dst;
    double proba;
    FILE *file;
    char str[128];

    /* default values */
    filepath = "propagation.data";

    /* get parameters */
    das_init_traverse(params);
    while ((param = (param_t *) das_traverse(params)) != NULL) {
        if (!strcmp(param->key, "file")) {
            filepath = param->value;
        }
    }

    /* open file */
    if ((file = fopen(filepath, "r")) == NULL) {
        fprintf(stderr, "filestatic: can not open file %s in init()\n", filepath);
        goto error;
    }

    /* extract link success probability */
    entitydata->node_cnt = get_node_count();
    entitydata->success = malloc(sizeof(double) * entitydata->node_cnt *entitydata->node_cnt);
    for (src = 0; src < entitydata->node_cnt; src++) {
        for (dst = 0; dst < entitydata->node_cnt; dst++) {
            
            *(entitydata->success + (src * entitydata->node_cnt) + dst) = MIN_DBM;
        }
    }
    fseek(file, 0L, SEEK_SET);
    while (fgets(str, 128, file) != NULL) {
        sscanf(str, "%d %d %lf\n",  &src, &dst, &proba);
        *(entitydata->success + (src * entitydata->node_cnt) + dst) = proba;
    }

    fclose(file);
    set_entity_private_data(c, entitydata);
    return 0;

 error:
    free(entitydata);
    return -1;
}
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();
      }
}
// initialisation des noeuds a partir du fichier xml
int setnode(call_t *c, void *params) {
    struct nodedata *nodedata = malloc(sizeof(struct nodedata));
    struct protocoleData *entitydata = malloc(sizeof(struct protocoleData));
	
	nodedata->overhead = -1;
    nodedata->oneHopNeighbourhood = 0;
	nodedata->twoHopNeighbourhood = 0;
	nodedata->g2hop = malloc(sizeof(graphe));
	initGraphe(nodedata->g2hop, c->node);
	nodedata->BIP_tree = 0;
	nodedata->nbr_evenement = 0; //STATS
	nodedata->lastIDs = malloc(get_node_count()*sizeof(int));
	nodedata->energiesRem = malloc(get_node_count()*sizeof(double));
	
	
    set_node_private_data(c, nodedata);
	
	
    SHOW_GRAPH("N: %d %lf %f\n",c->node,get_node_position(c->node)->x,get_node_position(c->node)->y);
	
//	printf("Node %d at ( %.1lf ; %.1lf ; %.1lf )\n", c->node,get_node_position(c->node)->x,get_node_position(c->node)->y,get_node_position(c->node)->z);
	
    return 0;
}
Ejemplo n.º 12
0
void MemberFuncBase::save_to_fcl_file(std::ofstream& file_contents)
{
 
	char  val[6];	// temp string to hold the string version of a number
	int precision ;	// how many decimal places to show  

 	// list the points...
	for (int i = 0; i < get_node_count(); i++)
		{
		// convert the index in the values array to an 'x' value
 		RealType fvalue = get_parent()->convert_idx_to_value(get_node_x(i));

		// if there is a decimal point for this, display only 2 decimal places,
		// else don't display any (this just makes the FCL file easier to read)
		if (fmod(fvalue, 1) == 0)
			precision = 0;
		else
			precision = 2;

 		// trim 'x' value to the specified precision
		sprintf( val, "%.*lf", precision, fvalue );
 
 		file_contents << "(" <<  val << ", ";
 
		// convert to 'y' coordinates
		fvalue = static_cast<RealType>(get_node_y(i)) / static_cast<RealType>(FuzzyVariableBase::get_dom_array_max_idx());

		if (fmod(fvalue, 1) == 0)
			precision = 0;
		else
			precision = 2;

		sprintf( val, "%.*lf", precision, fvalue );
		
		file_contents << val << ") ";

		} // end loop through nodes

	// add ending semi-colon
	file_contents << ";";

} // end MemberFuncBase::save_to_file()
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;
}
Ejemplo n.º 14
0
void get_shader_data(world *w, scene_shader_data &data, unsigned int row_pad)
{
    data.row_pad = row_pad;
    data.sphere_count = w->sphere_count;
    data.sphere_data_rows = (data.sphere_count + row_pad - 1) / row_pad;
    data.sphere_geometries = new float[4 * row_pad * data.sphere_data_rows];
    data.sphere_colors = new float[3 * row_pad * data.sphere_data_rows];

    for(int i = 0; i < w->sphere_count; i++) {
        const sphere &s = w->spheres[i];
        data.sphere_geometries[i * 4 + 0] = s.center.x;
        data.sphere_geometries[i * 4 + 1] = s.center.y;
        data.sphere_geometries[i * 4 + 2] = s.center.z;
        data.sphere_geometries[i * 4 + 3] = s.radius;
        data.sphere_colors[i * 3 + 0] = s.color.x;
        data.sphere_colors[i * 3 + 1] = s.color.y;
        data.sphere_colors[i * 3 + 2] = s.color.z;
    }

    data.group_count = get_node_count(w->root);
    data.group_data_rows = (data.group_count + row_pad - 1) / row_pad;
    data.group_directions = new float[3 * row_pad * data.group_data_rows];
    data.group_boxmin = new float[3 * row_pad * data.group_data_rows];
    data.group_boxmax = new float[3 * row_pad * data.group_data_rows];
    data.group_children = new float[2 * row_pad * data.group_data_rows];
    data.group_objects = new float[2 * row_pad * data.group_data_rows];
    data.group_hitmiss = new float[2 * row_pad * data.group_data_rows];

    int used;
    generate_group_indices(w->root, 0, &used, data.group_count, data.row_pad);
    assert(used == data.group_count);
    data.tree_root = w->root->my_index;

    store_group_data(w->root, data);

    create_hitmiss(w->root, data);

    // xxx_dump_group_code(w->root, "g");
}
Ejemplo n.º 15
0
int MemberFuncBase::get_end_x(void) const
{
	return(nodes[get_node_count() - 1].x);
}  
Ejemplo n.º 16
0
int MemberFuncBase::get_center_x(void) const 
{
	return nodes[0].x + ((nodes[get_node_count() - 1].x - nodes[0].x)/2);
}; 
Ejemplo n.º 17
0
long get_item_count(void)
{
	return get_node_count(item_space_root);
}
Ejemplo n.º 18
0
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 */

}
Ejemplo n.º 19
0
//
// Function:	MemberFuncTri()
// 
// Purpose:		Constructor
//
// Arguments:
//
//		FuzzySetBase* _parent - Set this member function is part of
//
// Returns:
//
//		nothing
//
// Author:	Michael Zarozinski
// Date:	8/99
// 
// Modification History
// Author	Date		Modification
// ------	----		------------
//
//
MemberFuncTri::MemberFuncTri(FuzzySetBase* _parent) : MemberFuncBase(_parent), FFLLBase(_parent)
{
	// create the nodes array
	alloc_nodes( get_node_count() );

} // MemberFuncTri::MemberFuncTri()
Ejemplo n.º 20
0
long get_user_count(void)
{
	return get_node_count(user_space_root);
}
Ejemplo n.º 21
0
/* ************************************************** */
int init(call_t *c, void *params) {
    struct _env_data *entitydata = malloc(sizeof(struct _env_data));
    char *filepath = "collection_ctrl.data";
    int line;
    struct _collec_event *event;
    param_t *param;
    char str[128];
    char event_str[30];
    FILE *file;

    /* We use a sorted list for the events (sorted by time) */
    entitydata->events = sodas_create(event_compare);

    /* Get parameters from the configuration file */
    das_init_traverse(params);
    while ((param = (param_t *) das_traverse(params)) != NULL) {
        if (!strcmp(param->key, "file")) {
            filepath = param->value;            
        }
    }

    /* Open the data collection scheme file */
    if ((file = fopen(filepath, "r")) == NULL) {
        DBG("ERROR: cannot open file %s in init()\n", filepath);
        goto error;
    }

    /* Save the events in a data structure */
    /* Structure of the file is:
     * <time> <node id> <event type> <value>
     */
    fseek(file, 0L, SEEK_SET);
    line = 1;
    while (fgets(str, 128, file) != NULL) {
        event = malloc(sizeof(struct _collec_event));
        memset(event_str, 0, sizeof(event_str));

        if (event == NULL) {
            DBG("ERROR: malloc failed\n");
            goto error;
        }

        if (str[0] == '#' || str[0] == '\n') {
            /* Line is a comment or an empty line */
            line++;
            continue;
        }

        if (sscanf(str, "%"PRId64" %d %s %d\n", 
                   &event->time, &event->node_id,
                   event_str, &event->event_value) != 4) {
            DBG("ERROR: cannot read event in file %s, line %d\n", 
                    filepath, line);
            free(event);
            goto error;
        }

        if (!strncmp(event_str, "APP_TIME_DRV", sizeof(event_str))) {
            event->event_type = APP_TIME_DRV;
        } else if (!strncmp(event_str, "APP_EVENT_DRV", sizeof(event_str))) {
            event->event_type = APP_EVENT_DRV;
        } else if (!strncmp(event_str, "APP_QUERY_DRV", sizeof(event_str))) {
            event->event_type = APP_QUERY_DRV;
        } else if (!strncmp(event_str, "APP_PAYLOAD_SIZE", sizeof(event_str))) {
            event->event_type = APP_PAYLOAD_SIZE;
        } else if (!strncmp(event_str, "ENV_EVENT", sizeof(event_str))) {
            event->event_type = ENV_EVENT;
        } else if (!strncmp(event_str, "QUERY_MSG", sizeof(event_str))) {
            event->event_type = QUERY_MSG;
        } else if (!strncmp(event_str, "CHANGE_APP_DST", sizeof(event_str))) {
            event->event_type = CHANGE_APP_DST;
        } else {
            DBG("ERROR: event type %s unknown in file %s, line %d\n", 
                    event_str, filepath, line);
            free(event);
            goto error;
        }
            
        //DBG("EVENT: %"PRId64" %d %d %d\n", 
        //    event->time, event->node_id, 
        //    event->event_type, event->event_value);

        if (event->node_id >= get_node_count()) {
            DBG("ERROR: node id %d (line %d) does not exist, "
                "skipping this event \n", event->node_id, line);
            free(event);
        } else {
            /* Insert the event in the sorted data structure */
            sodas_insert(entitydata->events, &event->time, event);
        }

        line++;
    }

    /* Close the opened file */
    fclose(file);

    set_entity_private_data(c, entitydata);
    return 0;

error:
    free(entitydata);
    return -1;
}