示例#1
0
/* ************************************************** */
int setnode(call_t *c, void *params) {
    struct nodedata *nodedata = malloc(sizeof(struct nodedata));
    param_t *param;
    uint64_t min_pausetime, max_pausetime;
    
    /* default values */
    get_node_position(c->node)->x = get_random_x_position();
    get_node_position(c->node)->y = get_random_y_position();
    get_node_position(c->node)->z = get_random_z_position();

    nodedata->pausetime = 2000000000;
    min_pausetime       = 0;
    max_pausetime       = 0;

    /* get parameters */
    das_init_traverse(params);
    while ((param = (param_t *) das_traverse(params)) != NULL) {
        if (!strcmp(param->key, "x")) {
            if (get_param_x_position(param->value, &(get_node_position(c->node)->x))) {
                goto error;
            }
        }
        if (!strcmp(param->key, "y")) {
            if (get_param_y_position(param->value, &(get_node_position(c->node)->y))) {
                goto error;
            }
        }
        if (!strcmp(param->key, "z")) {
            if (get_param_z_position(param->value, &(get_node_position(c->node)->z))) {
                goto error;
            }
        }
        if (!strcmp(param->key, "pausetime")) {
            if (get_param_time(param->value, &(nodedata->pausetime))) {
                goto error;
            }
        }
        if (!strcmp(param->key, "min-pausetime")) {
            if (get_param_time(param->value, &min_pausetime)) {
                goto error;
            }
        }
        if (!strcmp(param->key, "max-pausetime")) {
            if (get_param_time(param->value, &max_pausetime)) {
                goto error;
            }
        }
    }
    
    if (min_pausetime < max_pausetime ) {
        nodedata->pausetime = get_random_time_range(min_pausetime, max_pausetime);
    }
    
    set_node_private_data(c, nodedata);
    return 0;

 error:
    free(nodedata);
    return -1;
}
/* ************************************************** */
int setnode(call_t *c, void *params) {
    struct nodedata *nodedata = malloc(sizeof(struct nodedata));
    param_t *param;

    /* default values */
    nodedata->neighbors = das_create();
    nodedata->overhead = -1;
    nodedata->hello_tx = 0;
    nodedata->hello_rx = 0;
    nodedata->data_tx = 0;
    nodedata->data_rx = 0;
    nodedata->data_noroute = 0;
    nodedata->data_hop = 0;
    nodedata->start = 0;
    nodedata->hop = 32;
    nodedata->period = 1000000000;
    nodedata->timeout = 2500000000ull;
 
    /* get params */
    das_init_traverse(params);
    while ((param = (param_t *) das_traverse(params)) != NULL) {
        if (!strcmp(param->key, "start")) {
            if (get_param_time(param->value, &(nodedata->start))) {
                goto error;
            }
        }
        if (!strcmp(param->key, "period")) {
            if (get_param_time(param->value, &(nodedata->period))) {
                goto error;
            }
        }
        if (!strcmp(param->key, "hop")) {
            if (get_param_integer(param->value, &(nodedata->hop))) {
                goto error;
            }
        }
        if (!strcmp(param->key, "timeout")) {
            if (get_param_time(param->value, &(nodedata->timeout))) {
                goto error;
            }
        }
    }
    
    set_node_private_data(c, nodedata);
    return 0;
    
 error:
    free(nodedata);
    return -1;
}
/* ************************************************** */
int parse_simulation(xmlNodeSetPtr nodeset) {
    xmlAttrPtr attr;
    uint64_t duration;
    
    if (nodeset == NULL) {
        fprintf(stderr, "config: schema must require one '" XML_E_SIMULATION "' (parse_simulation())\n");
        return -1;
    }
    
    /* retrieve @nodes / @duration / @x / @y / @z */
    for (attr = nodeset->nodeTab[0]->properties ; attr ; attr = attr->next) {
        if (! strcmp((char *) attr->name, XML_A_NODES)) {
            /* xsd: 1 <= @nodes <= 65535 */
            nodes.size = strtoll((char *) attr->children->content, NULL, 10);
        } else if (! strcmp((char *) attr->name, XML_A_DURATION)) {
            /* xsd: 0 <= @duration */
            get_param_time((char *) attr->children->content, &duration);
            scheduler_set_end(duration);
        } else if (! strcmp((char *) attr->name, XML_A_X)) {
            /* xsd: 0 <= @x */
            get_topology_area()->x = strtod((char *) attr->children->content, NULL);
        } else if (! strcmp((char *) attr->name, XML_A_Y)) {
            /* xsd: 0 <= @y */
            get_topology_area()->y = strtod((char *) attr->children->content, NULL);
        } else if (! strcmp((char *) attr->name, XML_A_Z)) {
            /* xsd: 0 <= @z */
            get_topology_area()->z = strtod((char *) attr->children->content, NULL);
        }
    }

    print_simulation();
    return 0;
}
示例#4
0
文件: nrj.c 项目: gabrielleLQX/wsnet
/* ************************************************** */
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 setnode(call_t *c, void *params) {
    struct nodedata *nodedata = malloc(sizeof(struct nodedata));
    param_t *param;
    
    /* default values */
    nodedata->Ts = 91;
    nodedata->channel = 0;
    nodedata->power = 0;
    nodedata->modulation = -1;
    nodedata->mindBm = -92;
    nodedata->sleep = 0;

    /* get parameters */
    das_init_traverse(params);
    while ((param = (param_t *) das_traverse(params)) != NULL) {
        if (!strcmp(param->key, "sensibility")) {
            if (get_param_double(param->value, &(nodedata->mindBm))) {
                goto error;
            }
        }
        if (!strcmp(param->key, "T_s")) {
            if (get_param_time(param->value, &(nodedata->Ts))) {
                goto error;
            }
        }
        if (!strcmp(param->key, "channel")) {
            if (get_param_integer(param->value, &(nodedata->channel))) {
                goto error;
            }
        }
        if (!strcmp(param->key, "dBm")) {
            if (get_param_double(param->value, &(nodedata->power))) {
                goto error;
            }
        }
        if (!strcmp(param->key, "modulation")) {
            if (get_param_entity(param->value, &(nodedata->modulation))) {
                goto error;
            }
        }
    }

    set_node_private_data(c, nodedata);
    return 0;

 error:
    free(nodedata);
    return -1;
}
示例#6
0
int setnode(call_t *c, void *params) {
    struct nodedata *nodedata     = malloc(sizeof(struct nodedata));
    param_t *param;

    int i = MAX_METADATA;
    int j = MAX_SOURCE;
    int k = MAX_SINK;
    
    /* default values */
    nodedata->h_start   = 0;
    nodedata->h_period  = 1000000000;	
    nodedata->h_timeout = nodedata->h_period * 2.5;
    nodedata->h_nbr     = -1;
    nodedata->neighbors = das_create();

    while (i--) {
        nodedata->d_source[i] = -1;
        nodedata->d_value[i]  = -1;
        nodedata->d_seq[i]    = -1;
        nodedata->d_hop[i]    = -1;
        nodedata->d_time[i]   = -1;
    }
    while (j--) {
        nodedata->s_seq[j] = -1;        
    }
    while (k--) {
        nodedata->r_seq[k] = -1;        
    }

    /* get parameters */
    das_init_traverse(params);
    while ((param = (param_t *) das_traverse(params)) != NULL) {
        if (!strcmp(param->key, "hello-start")) {
	  if (get_param_time(param->value, &(nodedata->h_start))) {
	        fprintf(stderr,"[XY] Error while reading the hello-start parameter ! (%s)\n",param->value);
                goto error;
	  }
        }
        if (!strcmp(param->key, "hello-period")) {
	  if (get_param_time(param->value, &(nodedata->h_period))) {
	        fprintf(stderr,"[XY] Error while reading the hello-period parameter ! (%s)\n",param->value);
                goto error;
	  }
        }
        if (!strcmp(param->key, "hello-timeout")) {
	  if (get_param_time(param->value, &(nodedata->h_timeout))) {
	        fprintf(stderr,"[XY] Error while reading the hello-timeout parameter ! (%s)\n",param->value);
                goto error;
	  }
        }
        if (!strcmp(param->key, "hello-nbr")) {
	  if (get_param_integer(param->value, &(nodedata->h_nbr))) {
	        fprintf(stderr,"[XY] Error while reading the hello-nbr parameter ! (%s)\n",param->value);
                goto error;
	  }
        }
    }

    set_node_private_data(c, nodedata);
    return 0;

 error:
    free(nodedata);
    return -1;

}