/* ************************************************** */
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;
}
Example #2
0
int rng_init(void) {
    if ((mem_rng = mem_fs_slice_declare(sizeof(uniform_args_t))) == NULL) {
        return -1;
    }
    rngs = hadas_create(rng_hash, rng_equal);
    create_rng(default_rng_type, default_rng_seed);
    return 0;
}