Exemplo n.º 1
0
struct netloc_dt_lookup_table* netloc_dt_lookup_table_t_json_decode(json_t *json_lt,
                                                               void * (*func)(const char *key, json_t* json_obj))
{
    struct netloc_dt_lookup_table *table = NULL;
    const char * key = NULL;
    json_t     * value = NULL;

    table = calloc(1, sizeof(*table));
    netloc_lookup_table_init(table, json_object_size(json_lt), 0);

    json_object_foreach(json_lt, key, value) {
        netloc_lookup_table_append(table, key, func(key, value));
    }
Exemplo n.º 2
0
int netloc_dc_append_path(netloc_data_collection_handle_t *handle,
                          const char * src_node_id,
                          const char * dest_node_id,
                          int num_edges, netloc_edge_t **edges,
                          bool is_logical)
{
    int i;
    netloc_node_t *node = NULL;
    int *edge_ids = NULL;
    unsigned long key_int;

    /*
     * Find the source Node
     */
    SUPPORT_CONVERT_ADDR_TO_INT(src_node_id, handle->network->network_type, key_int);
    node = netloc_lookup_table_access_with_int( handle->node_list, src_node_id, key_int );

    if( NULL == node ) {
        fprintf(stderr, "Error: node not found in the list (id = %s)\n", src_node_id);
        return NETLOC_ERROR;
    }

    /*
     * Copy the edge id's
     * Note: The 'path' storage is not a set of edge pointers, but edge ids.
     * It is assumed that the user will push paths into the data collection, but
     * not have to retrieve that path from the dc_handle.
     */
    edge_ids = (int*)malloc(sizeof(int)* (num_edges+1));
    if( NULL == edge_ids ) {
        return NETLOC_ERROR;
    }

    for(i = 0; i < num_edges; ++i) {
        if( NULL == edges[i] ) {
            edge_ids[i] = NETLOC_EDGE_UID_INVALID;
        } else {
            edge_ids[i] = edges[i]->edge_uid;
        }
    }
    // Null terminated array
    edge_ids[num_edges] = NETLOC_EDGE_UID_NULL;


    /*
     * Add the entry to the hash
     */
    if( is_logical ) {
        if( NULL == node->logical_paths ) {
	    node->logical_paths = calloc(1, sizeof(*node->logical_paths));
            netloc_lookup_table_init(node->logical_paths, 1, 0);
            node->num_log_paths = 0;
        }
        node->num_log_paths += 1;
        netloc_lookup_table_append( node->logical_paths, dest_node_id, edge_ids);
    } else {
        if( NULL == node->physical_paths ) {
	    node->physical_paths = calloc(1, sizeof(*node->physical_paths));
            netloc_lookup_table_init(node->physical_paths, 1, 0);
            node->num_log_paths = 0;
        }
        node->num_log_paths += 1;
        netloc_lookup_table_append( node->physical_paths, dest_node_id, edge_ids);
    }


    return NETLOC_SUCCESS;
}
Exemplo n.º 3
0
int netloc_dc_append_edge_to_node(netloc_data_collection_handle_t *handle, netloc_node_t *node, netloc_edge_t *edge)
{
    char *key = NULL;
    netloc_edge_t *found_edge = NULL;
    netloc_node_t *found_node = NULL;
    unsigned long key_int;
    bool is_cached = false;

    /*
     * Setup the table for the first edge
     */
    if( NULL == handle->edges ) {
        handle->edges = calloc(1, sizeof(*handle->edges));
        netloc_lookup_table_init(handle->edges, 1, 0);
    }

    /*
     * Setup the table for the first node
     */
    if(NULL == handle->node_list) {
        handle->node_list = calloc(1, sizeof(*handle->node_list));
        netloc_lookup_table_init(handle->node_list, 1, 0);
    }

    /*
     * Check to see if we have seen this edge before
     */
    asprintf(&key, "%d", edge->edge_uid);
    found_edge = (netloc_edge_t*)netloc_lookup_table_access(handle->edges, key);
    free(key);
    key = NULL;
    // JJH: Should we be checking the contents of the edge, not just the key?

    /*
     * If not add it to the edges lookup table
     */
    if( NULL == found_edge ) {
        found_edge = netloc_dt_edge_t_dup(edge);

        asprintf(&key, "%d", found_edge->edge_uid);
        netloc_lookup_table_append(handle->edges, key, found_edge);
        free(key);
        key = NULL;
    }

    /*
     * Update the edge links
     * if the node endpoint is not in the list, then add a stub
     */
    if( NULL == edge->src_node_id ) {
        return NETLOC_ERROR_NOT_FOUND;
    }
    SUPPORT_CONVERT_ADDR_TO_INT(edge->src_node_id, handle->network->network_type, key_int);
    asprintf(&key, "%s", edge->src_node_id);
    found_node = netloc_lookup_table_access_with_int(handle->node_list, key, key_int);

    if( NULL == found_node ) {
        found_node = netloc_dt_node_t_construct();

        found_node->physical_id = strdup(edge->src_node_id);
        found_node->physical_id_int = key_int;
        found_node->node_type = NETLOC_NODE_TYPE_INVALID;

        netloc_lookup_table_append_with_int(handle->node_list, key, key_int, found_node);
    } else {
        is_cached = true;
    }
    found_edge->src_node = found_node;
    free(key);
    key = NULL;

    if( NULL == edge->dest_node_id ) {
        return NETLOC_ERROR_NOT_FOUND;
    }
    asprintf(&key, "%s", edge->dest_node_id);
    SUPPORT_CONVERT_ADDR_TO_INT(edge->dest_node_id, handle->network->network_type, key_int);
    found_node = netloc_lookup_table_access_with_int(handle->node_list, key, key_int);

    if( NULL == found_node ) {
        found_node = netloc_dt_node_t_construct();

        found_node->physical_id = strdup(edge->dest_node_id);
        found_node->physical_id_int = key_int;
        found_node->node_type = NETLOC_NODE_TYPE_INVALID;

        netloc_lookup_table_append_with_int(handle->node_list, key, key_int, found_node);
    }
    found_edge->dest_node = found_node;
    free(key);
    key = NULL;

    /*
     * Add the edge index to the node passed to us
     */
    node->num_edge_ids++;
    node->edge_ids = (int*)realloc(node->edge_ids, sizeof(int) * node->num_edge_ids);
    node->edge_ids[node->num_edge_ids -1] = found_edge->edge_uid;

    node->num_edges++;
    node->edges = (netloc_edge_t**)realloc(node->edges, sizeof(netloc_edge_t*) * node->num_edges);
    node->edges[node->num_edges -1] = found_edge;

    /*
     * Update the cached version of this node
     */
    if( is_cached ) {
        json_object_del(handle->node_data_acc, node->physical_id);
        json_object_set_new(handle->node_data_acc, node->physical_id, netloc_dt_node_t_json_encode(node));
    }

    return NETLOC_SUCCESS;
}