/* ************************************************** */ int setnode(call_t *c, void *params) { struct entitydata *entitydata = get_entity_private_data(c); struct nodedata *nodedata = malloc(sizeof(struct nodedata)); char str[128]; int id, dst, n_hop; /* extract routing table from file */ nodedata->routes = hadas_create(route_hash, route_equal); /* extract routing table from file */ fseek(entitydata->file, 0L, SEEK_SET); while (fgets(str, 128, entitydata->file) != NULL) { if (sscanf(str, "%d %d %d\n", &id, &dst, &n_hop) != 3) { fprintf(stderr, "filestatic: unable to read route in setnode()\n"); goto error; } if (id == c->node) { struct route *route = (struct route *) malloc(sizeof(struct route)); route->dst = dst; route->n_hop = n_hop; hadas_insert(nodedata->routes, (void *) ((unsigned long) (route->dst)), (void *) route); } } nodedata->overhead = -1; set_node_private_data(c, nodedata); return 0; error: free(entitydata); return -1; }
void *create_rng(int rng_type, unsigned long int seed) { gsl_rng *r = NULL; rng_t *rng = malloc(sizeof (rng_t)); switch (rng_type) { case MT19937: r = gsl_rng_alloc(gsl_rng_mt19937); break; case RANLXS0: r = gsl_rng_alloc(gsl_rng_ranlxs0); break; case RANLXS1: r = gsl_rng_alloc(gsl_rng_ranlxs1); break; case RANLXS2: r = gsl_rng_alloc(gsl_rng_ranlxs2); break; case RANLXD1: r = gsl_rng_alloc(gsl_rng_ranlxd1); break; case RANLXD2: r = gsl_rng_alloc(gsl_rng_ranlxd2); break; case RANLUX: r = gsl_rng_alloc(gsl_rng_ranlux); break; case RANLUX389: r = gsl_rng_alloc(gsl_rng_ranlux389); break; default: /* should not happen */ break; } rng->r = r; if (seed) { rng->seed = seed; gsl_rng_set(r, seed); } else { struct timeval tv; gettimeofday(&tv, NULL); gsl_rng_set(r, tv.tv_usec + tv.tv_sec); rng->seed = tv.tv_usec + tv.tv_sec; } hadas_insert(rngs, hash_index, (void *) rng); /* edit by Fabrice Theoleyre <*****@*****.**> */ hash_index = (char*) hash_index + 1; return ((char*)hash_index - 1); /* end of edition */ }