Exemplo n.º 1
0
void netloc_dc_pretty_print(netloc_data_collection_handle_t *handle)
{
    int p;
    struct netloc_dt_lookup_table_iterator *hti = NULL;
    const char * key = NULL;
    netloc_edge_t **path = NULL;
    int path_len;
    struct netloc_dt_lookup_table_iterator *htin = NULL;
    netloc_node_t *cur_node = NULL;

    htin = netloc_dt_lookup_table_iterator_t_construct(handle->node_list);
    while( !netloc_lookup_table_iterator_at_end(htin) ) {
        cur_node = (netloc_node_t*)netloc_lookup_table_iterator_next_entry(htin);
        if( NULL == cur_node ) {
            break;
        }
        display_node(cur_node, strdup(""));

        printf("Physical Paths\n");
        printf("--------------\n");
        // Display all of the paths from this node to other nodes (if any)
        hti = netloc_dt_lookup_table_iterator_t_construct(cur_node->physical_paths);
        while( !netloc_lookup_table_iterator_at_end(hti) ) {
            key = netloc_lookup_table_iterator_next_key(hti);
            if( NULL == key ) {
                break;
            }
            path = (netloc_edge_t**)netloc_lookup_table_access(cur_node->physical_paths, key);
            path_len = 0;
            for(p = 0; NULL != path[p]; ++p) {
                ++path_len;
            }
            display_path(cur_node->physical_id,
                         key, path_len, path, strdup("\t"));
        }

        printf("Logical Paths\n");
        printf("--------------\n");
        // Display all of the paths from this node to other nodes (if any)
        hti = netloc_dt_lookup_table_iterator_t_construct(cur_node->logical_paths);
        while( !netloc_lookup_table_iterator_at_end(hti) ) {
            key = netloc_lookup_table_iterator_next_key(hti);
            if( NULL == key ) {
                break;
            }
            path = (netloc_edge_t**)netloc_lookup_table_access(cur_node->logical_paths, key);
            path_len = 0;
            for(p = 0; NULL != path[p]; ++p) {
                ++path_len;
            }
            display_path(cur_node->physical_id,
                         key, path_len, path, strdup("\t"));
        }
    }
    netloc_dt_lookup_table_iterator_t_destruct(htin);
}
Exemplo n.º 2
0
json_t* netloc_dt_lookup_table_t_json_encode(struct netloc_dt_lookup_table *table,
                                             json_t* (*func)(const char * key, void *value))
{
    json_t *json_lt = NULL;
    struct netloc_dt_lookup_table_iterator *hti = NULL;
    const char * key = NULL;
    void * value = NULL;

    json_lt = json_object();

    hti = netloc_dt_lookup_table_iterator_t_construct(table);
    while( !netloc_lookup_table_iterator_at_end(hti) ) {
        key = netloc_lookup_table_iterator_next_key(hti);
        if( NULL == key ) {
            break;
        }

        value = netloc_lookup_table_access(table, key);

        json_object_set_new(json_lt, key, func(key, value));
    }

    netloc_dt_lookup_table_iterator_t_destruct(hti);

    return json_lt;
}
Exemplo n.º 3
0
int test_all_edges(netloc_topology_t topology)
{
    int ret;
    netloc_dt_lookup_table_t nodes = NULL;
    netloc_dt_lookup_table_iterator_t hti = NULL;
    const char * key = NULL;
    netloc_node_t *node = NULL;
    int num_edges;
    netloc_edge_t **edges = NULL;

    ret = netloc_get_all_nodes(topology, &nodes);
    if( NETLOC_SUCCESS != ret ) {
        fprintf(stderr, "Error: get_all_nodes returned %d\n", ret);
        return ret;
    }

    /*
     * For each node, get the edges from it
     */
    hti = netloc_dt_lookup_table_iterator_t_construct( nodes );
    while( !netloc_lookup_table_iterator_at_end(hti) ) {
        key = netloc_lookup_table_iterator_next_key(hti);
        if( NULL == key ) {
            break;
        }

        node = (netloc_node_t*)netloc_lookup_table_access(nodes, key);

        /*
         * Get all of the edges
         */
        ret = netloc_get_all_edges(topology, node, &num_edges, &edges);
        if( NETLOC_SUCCESS != ret ) {
            fprintf(stderr, "Error: get_all_edges_by_id returned %d for node %s\n", ret, netloc_pretty_print_node_t(node));
            return ret;
        }

        /*
         * Verify the edges
         */
#if DEBUG == 1
        printf("Found: %d edges for host %s\n", num_edges, netloc_pretty_print_node_t(node));
        for(i = 0; i < num_edges; ++i ) {
            printf("\tEdge: %s\n", netloc_pretty_print_edge_t(edges[i]));
        }
#endif
    }

    /* Cleanup */
    netloc_dt_lookup_table_iterator_t_destruct(hti);
    netloc_lookup_table_destroy(nodes);
    free(nodes);

    return NETLOC_SUCCESS;
}
Exemplo n.º 4
0
int test_all_host_nodes(netloc_topology_t topology)
{
    int ret;
    netloc_dt_lookup_table_t hosts = NULL;
    netloc_dt_lookup_table_iterator_t hti = NULL;
    const char * key = NULL;
    netloc_node_t *node = NULL;

    ret = netloc_get_all_host_nodes(topology, &hosts);
    if( NETLOC_SUCCESS != ret ) {
        fprintf(stderr, "Error: get_all_host_nodes returned %d\n", ret);
        return ret;
    }

    /* Verify the data */
    hti = netloc_dt_lookup_table_iterator_t_construct( hosts );
    while( !netloc_lookup_table_iterator_at_end(hti) ) {
        key = netloc_lookup_table_iterator_next_key(hti);
        if( NULL == key ) {
            break;
        }

        node = (netloc_node_t*)netloc_lookup_table_access(hosts, key);
        if( NETLOC_NODE_TYPE_HOST != node->node_type ) {
            fprintf(stderr, "Error: Returned unexpected node: %s\n", netloc_pretty_print_node_t(node));
            return NETLOC_ERROR;
        }
#if DEBUG == 1
        printf("Found: %s\n", netloc_pretty_print_node_t(node));
#endif
    }

    /* Cleanup */
    netloc_dt_lookup_table_iterator_t_destruct(hti);
    netloc_lookup_table_destroy(hosts);
    free(hosts);

    return NETLOC_SUCCESS;
}
Exemplo n.º 5
0
int test_get_logical_path(netloc_topology_t topology)
{
    int ret;
    netloc_dt_lookup_table_t nodes = NULL;
    netloc_dt_lookup_table_iterator_t hti_src = NULL;
    netloc_dt_lookup_table_iterator_t hti_dest = NULL;
    const char * src_key = NULL;
    const char * dest_key = NULL;
    netloc_node_t *src_node = NULL;
    netloc_node_t *dest_node = NULL;
    int num_edges;
    netloc_edge_t **edges = NULL;

    ret = netloc_get_all_host_nodes(topology, &nodes);
    if( NETLOC_SUCCESS != ret ) {
        fprintf(stderr, "Error: get_all_host_nodes returned %d\n", ret);
        return ret;
    }

    /*
     * For each node, get the physical path for the node
     */
    hti_src = netloc_dt_lookup_table_iterator_t_construct( nodes );
    while( !netloc_lookup_table_iterator_at_end(hti_src) ) {
        src_key = netloc_lookup_table_iterator_next_key(hti_src);
        if( NULL == src_key ) {
            break;
        }

        src_node = (netloc_node_t*)netloc_lookup_table_access(nodes, src_key);

        /*
         * From this source to all destinations
         */
        hti_dest = netloc_dt_lookup_table_iterator_t_construct( nodes );
        while( !netloc_lookup_table_iterator_at_end(hti_dest) ) {
            dest_key = netloc_lookup_table_iterator_next_key(hti_dest);
            if( NULL == dest_key ) {
                break;
            }

            /*
             * Skip self reference
             */
            dest_node = (netloc_node_t*)netloc_lookup_table_access(nodes, dest_key);
            if( NETLOC_CMP_SAME == netloc_dt_node_t_compare(src_node, dest_node) ) {
                continue;
            }

            /*
             * Get the logical path, if any
             */
            ret = netloc_get_path(topology, src_node, dest_node, &num_edges, &edges, true);
            if( NETLOC_ERROR_NOT_FOUND == ret ) {
                fprintf(stderr, "Warning: No path information between these two nodes\n\tSrc  node %s\n\tDest node %s\n",
                        netloc_pretty_print_node_t(src_node),
                        netloc_pretty_print_node_t(dest_node));
                continue;
            }
            else if( NETLOC_SUCCESS != ret ) {
                fprintf(stderr, "Error: get_logical_path returned %d\nError: Src  node %s\nError: Dest node %s\n",
                        ret,
                        netloc_pretty_print_node_t(src_node),
                        netloc_pretty_print_node_t(dest_node));
                return ret;
            }

            /*
             * Verify the edges
             */
#if DEBUG == 1
            printf("Path Between: %d edges\n", num_edges);
            printf("\tSrc : %s\n", netloc_pretty_print_node_t(src_node));
            printf("\tDest: %s\n", netloc_pretty_print_node_t(dest_node));
            for(i = 0; i < num_edges; ++i ) {
                printf("\t\tEdge: %s\n", netloc_pretty_print_edge_t(edges[i]));
            }
#endif
        }
        netloc_dt_lookup_table_iterator_t_destruct(hti_dest);
    }

    /* Cleanup */
    netloc_dt_lookup_table_iterator_t_destruct(hti_src);
    netloc_lookup_table_destroy(nodes);
    free(nodes);

    return NETLOC_SUCCESS;
}
Exemplo n.º 6
0
static int display_topo_screen(netloc_topology_t topology, netloc_network_t *network) {
    int ret, exit_status = NETLOC_SUCCESS;
    int i;
    netloc_dt_lookup_table_t hosts_nodes = NULL;
    netloc_dt_lookup_table_t switches_nodes = NULL;
    netloc_dt_lookup_table_iterator_t hti = NULL;
    const char * key = NULL;
    netloc_node_t *node = NULL;
    int num_edges;
    netloc_edge_t **edges = NULL;

    printf("Network: %s\n", netloc_pretty_print_network_t(network) );
    printf("  Type    : %s\n", netloc_decode_network_type_readable(network->network_type) );
    printf("  Subnet  : %s\n", network->subnet_id);

    /*
     * Get hosts and switches
     */
    ret = netloc_get_all_host_nodes(topology, &hosts_nodes);
    if( NETLOC_SUCCESS != ret ) {
        exit_status = ret;
        goto cleanup;
    }
    printf("  Hosts   :   %d\n", netloc_lookup_table_size(hosts_nodes));;

	ret = netloc_get_all_switch_nodes(topology, &switches_nodes);
    if( NETLOC_SUCCESS != ret ) {
        exit_status = ret;
        goto cleanup;
    }
    printf("  Switches:   %d\n", netloc_lookup_table_size(switches_nodes) );
    printf("---------------------------------------------------\n");

    if( full_output ) {
        /*
         * Print out a list of hosts and their connections
         */
        printf("\n");
        printf("Information by Host\n");
        printf("---------------------\n");

        hti = netloc_dt_lookup_table_iterator_t_construct( hosts_nodes );
        while( !netloc_lookup_table_iterator_at_end(hti) ) {
            key = netloc_lookup_table_iterator_next_key(hti);
            if( NULL == key ) {
                break;
            }

            node = (netloc_node_t*)netloc_lookup_table_access(hosts_nodes, key);

            ret = netloc_get_all_edges(topology, node, &num_edges, &edges);
            if( NETLOC_SUCCESS != ret ) {
                exit_status = ret;
                goto cleanup;
            }

            for(i = 0; i < num_edges; ++i ) {
                display_netloc_edge_screen(edges[i]);
            }
        }


        /*
         * Print out a list of switches and their connections
         */
        printf("\n");
        printf("Information by Switch\n");
        printf("---------------------\n");

        hti = netloc_dt_lookup_table_iterator_t_construct( switches_nodes );
        while( !netloc_lookup_table_iterator_at_end(hti) ) {
            key = netloc_lookup_table_iterator_next_key(hti);
            if( NULL == key ) {
                break;
            }

            node = (netloc_node_t*)netloc_lookup_table_access(switches_nodes, key);

            ret = netloc_get_all_edges(topology, node, &num_edges, &edges);
            if( NETLOC_SUCCESS != ret ) {
                exit_status = ret;
                goto cleanup;
            }

            for(i = 0; i < num_edges; ++i ) {
                display_netloc_edge_screen(edges[i]);
            }
        }

        printf("------------------------------------------------------------------------------\n");
    }

    printf("\n");

 cleanup:

    return exit_status;
}
Exemplo n.º 7
0
int main(void) {
    char **search_uris = NULL;
    int num_uris = 1, ret;
    netloc_network_t *tmp_network = NULL;

    netloc_topology_t topology;

    netloc_dt_lookup_table_t nodes = NULL;
    netloc_dt_lookup_table_iterator_t hti = NULL;
    const char * key = NULL;
    netloc_node_t *node = NULL;


    // Specify where to search for network data
    search_uris = (char**)malloc(sizeof(char*) * num_uris );
    search_uris[0] = strdup("file://data/netloc");

    // Find a specific InfiniBand network
    tmp_network = netloc_dt_network_t_construct();
    tmp_network->network_type = NETLOC_NETWORK_TYPE_INFINIBAND;
    tmp_network->subnet_id    = strdup("fe80:0000:0000:0000");

    // Search for the specific network
    ret = netloc_find_network(search_uris[0], tmp_network);
    if( NETLOC_SUCCESS != ret ) {
        fprintf(stderr, "Error: network not found!\n");
        netloc_dt_network_t_destruct(tmp_network);
        return NETLOC_ERROR;
    }

    printf("\tFound Network: %s\n", netloc_pretty_print_network_t(tmp_network));

    // Attach to the network
    ret = netloc_attach(&topology, *tmp_network);
    if( NETLOC_SUCCESS != ret ) {
        fprintf(stderr, "Error: netloc_attach returned an error (%d)\n", ret);
        return ret;
    }

    // Query the network topology

    // Access all of the nodes in the topology
    ret = netloc_get_all_nodes(topology, &nodes);
    if( NETLOC_SUCCESS != ret ) {
        fprintf(stderr, "Error: get_all_nodes returned %d\n", ret);
        return ret;
    }

    // Display all of the nodes found
    hti = netloc_dt_lookup_table_iterator_t_construct( nodes );
    while( !netloc_lookup_table_iterator_at_end(hti) ) {
        // Access the data by key (could also access by entry in the example)
        key = netloc_lookup_table_iterator_next_key(hti);
        if( NULL == key ) {
            break;
        }

        node = (netloc_node_t*)netloc_lookup_table_access(nodes, key);
        if( NETLOC_NODE_TYPE_INVALID == node->node_type ) {
            fprintf(stderr, "Error: Returned unexpected node: %s\n", netloc_pretty_print_node_t(node));
            return NETLOC_ERROR;
        }

        printf("Found: %s\n", netloc_pretty_print_node_t(node));
    }

    /* Cleanup the lookup table objects */
    if( NULL != hti ) {
        netloc_dt_lookup_table_iterator_t_destruct(hti);
        hti = NULL;
    }
    if( NULL != nodes ) {
        netloc_lookup_table_destroy(nodes);
        free(nodes);
        nodes = NULL;
    }

    // Detach from the network
    ret = netloc_detach(topology);
    if( NETLOC_SUCCESS != ret ) {
        fprintf(stderr, "Error: netloc_detach returned an error (%d)\n", ret);
        return ret;
    }

    /*
     * Cleanup
     */
    netloc_dt_network_t_destruct(tmp_network);
    tmp_network = NULL;

    return NETLOC_SUCCESS;
}
Exemplo n.º 8
0
int main(void) {
    int ret, exit_status = NETLOC_SUCCESS;

    int i;
    netloc_topology_t topology;
    netloc_network_t *network = NULL;
    char *search_uri = NULL;

    netloc_dt_lookup_table_t *nodes = NULL;
    netloc_dt_lookup_table_iterator_t *hti = NULL;
    const char * key = NULL;
    netloc_node_t *node = NULL;

    int num_edges;
    netloc_edge_t **edges = NULL;


    /*
     * Setup a Network connection
     */
    network = netloc_dt_network_t_construct();
    network->network_type = NETLOC_NETWORK_TYPE_ETHERNET;
    network->subnet_id    = strdup("unknown");
    search_uri = strdup("file://data/");

    ret = netloc_find_network(search_uri, network);
    if( NETLOC_SUCCESS != ret ) {
        fprintf(stderr, "Error: netloc_find_network returned an error (%d)\n", ret);
        return ret;
    }

    /*
     * Attach to the topology context
     */
    printf("Test attach: ");
    fflush(NULL);
    ret = netloc_attach(&topology, *network);
    if( NETLOC_SUCCESS != ret ) {
        fprintf(stderr, "Error: netloc_attach returned an error (%d)\n", ret);
        return ret;
    }
    printf("Success\n");


    /*
     * Get all the verticies
     */
    ret = netloc_get_all_nodes(topology, &nodes);
    if( NETLOC_SUCCESS != ret ) {
        fprintf(stderr, "Error: get_all_nodes returned %d\n", ret);
        exit_status = ret;
        goto cleanup;
    }

    /*
     * Display the data
     */
    hti = netloc_dt_lookup_table_iterator_t_construct( nodes );
    while( !netloc_lookup_table_iterator_at_end(hti) ) {
        key = netloc_lookup_table_iterator_next_key(hti);
        if( NULL == key ) {
            break;
        }

        node = (netloc_node_t*)netloc_lookup_table_access(nodes, key);
        if( NETLOC_NODE_TYPE_INVALID == node->node_type ) {
            fprintf(stderr, "Error: Returned unexpected node: %s\n", netloc_pretty_print_node_t(node));
            return NETLOC_ERROR;
        }

        /*
         * Get all of the edges
         */
        ret = netloc_get_all_edges(topology, node, &num_edges, &edges);
        if( NETLOC_SUCCESS != ret ) {
            fprintf(stderr, "Error: get_all_edges_by_id returned %d for node %s\n", ret, netloc_pretty_print_node_t(node));
            return ret;
        }

        /*
         * Verify the edges
         */
        printf("Found: %d edges for host %s\n", num_edges, netloc_pretty_print_node_t(node));
        for(i = 0; i < num_edges; ++i ) {
            printf("\tEdge: %s\n", netloc_pretty_print_edge_t(edges[i]));
        }
    }

    /* Cleanup */
    netloc_dt_lookup_table_iterator_t_destruct(hti);
    netloc_lookup_table_destroy(nodes);
    free(nodes);

 cleanup:
    /*
     * Cleanup
     */
    ret = netloc_detach(topology);
    if( NETLOC_SUCCESS != ret ) {
        fprintf(stderr, "Error: netloc_detach returned an error (%d)\n", ret);
        return ret;
    }

    if( NULL != search_uri ) {
        free(search_uri);
        search_uri = NULL;
    }

    return exit_status;
}
Exemplo n.º 9
0
int main(int argc, char *argv[])
{
  netloc_map_t map;
  netloc_topology_t *ntopos;
  netloc_map_server_t *servers;
  char *datadir, *path;
  unsigned nr_ntopos, nr_servers, i, j;
  int verbose = 0;
  int err;

  argc--;
  argv++;
  if (argc >= 1) {
    if (!strcmp(argv[0], "--verbose")) {
      verbose = 1;
      argc--;
      argv++;
    }
  }

  if (argc < 1) {
    fprintf(stderr, "Missing data directory argument\n");
    return -1;
  }
  datadir = argv[0];
  argv++;
  argc--;

  err = netloc_map_create(&map);
  if (err) {
    fprintf(stderr, "Failed to create the map\n");
    return -1;
  }

  asprintf(&path, "%s/hwloc", datadir);
  err = netloc_map_load_hwloc_data(map, path);
  if (err) {
    fprintf(stderr, "Failed to load hwloc data from %s\n", path);
    return -1;
  }
  free(path);

  asprintf(&path, "file://%s/netloc", datadir);
  err = netloc_map_load_netloc_data(map, path);
  if (err) {
    fprintf(stderr, "Failed to load netloc data from %s\n", path);
    return -1;
  }
  free(path);

  err = netloc_map_build(map, NETLOC_MAP_BUILD_FLAG_COMPRESS_HWLOC);
  if (err) {
    fprintf(stderr, "Failed to build map data\n");
    return -1;
  }

  if (verbose)
    netloc_map_dump(map);

  err = netloc_map_get_subnets(map, &nr_ntopos, &ntopos);
  if (err) {
    fprintf(stderr, "Failed to get the number of subnets\n");
    return -1;
  }

  for(i=0; i<nr_ntopos; i++) {
    netloc_topology_t ntopo = ntopos[i];
    netloc_network_t *net = netloc_access_network_ref(ntopo);
    const char *type = netloc_decode_network_type(net->network_type);

    printf("Subnet type %s id %s\n",
	   type, net->subnet_id);

    netloc_dt_lookup_table_t *nodes;
    err = netloc_get_all_host_nodes(ntopo, &nodes);
    if (err)
      continue;

    netloc_dt_lookup_table_iterator_t *iter = netloc_dt_lookup_table_iterator_t_construct(nodes);
    while( !netloc_lookup_table_iterator_at_end(iter) ) {
      const char *key;
      netloc_node_t *nnode;
      netloc_map_port_t port;
      netloc_map_server_t server;
      hwloc_topology_t htopo;
      hwloc_obj_t hobj;
      const char *servername;

      key = netloc_lookup_table_iterator_next_key(iter);
      if (NULL == key)
	break;
      
      nnode = (netloc_node_t*) netloc_lookup_table_access(nodes, key);
      if (NETLOC_NODE_TYPE_INVALID == nnode->node_type)
	continue;

      err = netloc_map_netloc2port(map, ntopo, nnode, NULL, &port);
      if (err < 0)
	continue;

      err = netloc_map_port2hwloc(port, &htopo, &hobj);
      if (err < 0)
	continue;

      err = netloc_map_port2server(port, &server);
      if (err < 0)
	continue;

      err = netloc_map_server2name(server, &servername);
      if (err < 0)
	continue;

      printf(" node %s connected through object %s address %s\n", servername, hobj->name, nnode->physical_id);

      netloc_map_put_hwloc(map, htopo);
    }

    netloc_dt_lookup_table_iterator_t_destruct(iter);
    netloc_lookup_table_destroy(nodes);
    free(nodes);
  }

  err = netloc_map_get_nbservers(map);
  if (err < 0) {
    fprintf(stderr, "Failed to get the number of servers\n");
    return -1;
  }
  nr_servers = err;

  servers = malloc(nr_servers * sizeof(*servers));
  if (!servers) {
    fprintf(stderr, "Failed to allocate servers array\n");
    return -1;
  }

  err = netloc_map_get_servers(map, 0, nr_servers, servers);
  if (err < 0) {
    fprintf(stderr, "Failed to get servers\n");
    return -1;
  }
  assert((unsigned) err == nr_servers);

  for(i=0; i<nr_servers; i++) {
    const char *servername = "unknown";
    netloc_map_port_t *ports;
    unsigned ports_nr;

    err = netloc_map_server2name(servers[i], &servername);
    assert(!err);
    printf("Server %s\n", servername);

    err = netloc_map_get_server_ports(servers[i], &ports_nr, &ports);
    assert(!err);

    if (!ports)
      continue;

    for(j=0; j<ports_nr; j++) {
      netloc_topology_t ntopo;
      netloc_network_t *net;
      netloc_node_t *nnode;
      netloc_edge_t *nedge;
      hwloc_topology_t htopo;
      hwloc_obj_t hobj;

      err = netloc_map_port2netloc(ports[j], &ntopo, &nnode, &nedge);
      assert(!err);
      net = netloc_access_network_ref(ntopo);

      err = netloc_map_port2hwloc(ports[j], &htopo, &hobj);
      assert(!err);

      const char *type = netloc_decode_network_type(net->network_type);
      printf(" port %s of device %s (id %s)\n"
	     "  on subnet type %s id %s\n"
	     "   towards node %s port %s\n",
	     nedge ? nedge->src_port_id : "<unknown>",
	     hobj->name,
	     nnode ? nnode->physical_id : "<none>",
	     type, 
	     net->subnet_id,
	     nedge ? nedge->dest_node_id : "<none>",
	     nedge ? nedge->dest_port_id : "<unknown>");

      netloc_map_put_hwloc(map, htopo);
    }
  }

  free(servers);
  free(ntopos);
  netloc_map_destroy(map);

  return 0;
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
0
static int check_dat_files() {
    int ret, exit_status = NETLOC_SUCCESS;
    char * spec = NULL;
    char * hosts_filename = NULL;
    char * switches_filename = NULL;

    char *search_uri = NULL;
    netloc_topology_t topology;

    netloc_dt_lookup_table_t nodes = NULL;
    netloc_dt_lookup_table_iterator_t hti = NULL;
    const char * key = NULL;
    netloc_node_t *node = NULL;

    int num_bad = 0;
    netloc_network_t *network = NULL;

    int total_num_edges = 0;

    printf("Status: Validating the output...\n");

    network = netloc_dt_network_t_construct();
    network->network_type = NETLOC_NETWORK_TYPE_ETHERNET;
    network->subnet_id    = strdup(subnet);
    asprintf(&search_uri, "file://%s/", outdir);

    if( NETLOC_SUCCESS != (ret = netloc_find_network(search_uri, network)) ) {
        fprintf(stderr, "Error: Cannot find the network data. (%d)\n", ret);
        exit_status = ret;
        goto cleanup;
    }

    /*
     * Attach to Netloc
     */
    if( NETLOC_SUCCESS != (ret = netloc_attach(&topology, *network)) ) {
        fprintf(stderr, "Error: Cannot attach the topology\n");
        exit_status = ret;
        goto cleanup;
    }


    /*
     * Check the 'hosts'
     */
    ret = netloc_get_all_host_nodes(topology, &nodes);
    if( NETLOC_SUCCESS != ret ) {
        fprintf(stderr, "Error: Cannot access the list of hosts!\n");
        exit_status = ret;
        goto cleanup;
    }

    printf("\tNumber of hosts   : %4d\n", netloc_lookup_table_size(nodes) );

    hti = netloc_dt_lookup_table_iterator_t_construct( nodes );
    while( !netloc_lookup_table_iterator_at_end(hti) ) {
        key = netloc_lookup_table_iterator_next_key(hti);
        if( NULL == key ) {
            break;
        }

        node = (netloc_node_t*)netloc_lookup_table_access(nodes, key);

        if( NETLOC_NODE_TYPE_INVALID == node->node_type ) {
            printf("Host Node: %s is invalid\n", netloc_pretty_print_node_t(node) );
            num_bad++;
        }
        else {
            total_num_edges += node->num_edges;
        }
    }

    netloc_dt_lookup_table_iterator_t_destruct(hti);
    netloc_lookup_table_destroy(nodes);
    free(nodes);

    /*
     * Check 'switches'
     */
    ret = netloc_get_all_switch_nodes(topology, &nodes);
    if( NETLOC_SUCCESS != ret ) {
        fprintf(stderr, "Error: Cannot access the list of switches!\n");
        exit_status = ret;
        goto cleanup;
    }

    printf("\tNumber of switches: %4d\n", netloc_lookup_table_size(nodes) );

    hti = netloc_dt_lookup_table_iterator_t_construct( nodes );
    while( !netloc_lookup_table_iterator_at_end(hti) ) {
        key = netloc_lookup_table_iterator_next_key(hti);
        if( NULL == key ) {
            break;
        }

        node = (netloc_node_t*)netloc_lookup_table_access(nodes, key);

        if( NETLOC_NODE_TYPE_INVALID == node->node_type ) {
            printf("Switch Node: %s is invalid\n", netloc_pretty_print_node_t(node) );
            num_bad++;
        }
        else {
            total_num_edges += node->num_edges;
        }
    }

    netloc_dt_lookup_table_iterator_t_destruct(hti);
    netloc_lookup_table_destroy(nodes);
    free(nodes);

    if( num_bad > 0 ) {
        fprintf(stderr, "Error: Found %2d malformed nodes in the .dat files\n", num_bad);
        exit_status = NETLOC_ERROR;
    }

    printf("\tNumber of edges   : %4d\n", total_num_edges );

    /*
     * Cleanup
     */
    if( NETLOC_SUCCESS != (ret = netloc_detach(topology)) ) {
        fprintf(stderr, "Error: Failed to detach the topology\n");
        exit_status = ret;
        goto cleanup;
    }

 cleanup:
    netloc_dt_network_t_destruct(network);
    free(search_uri);
    free(spec);
    free(hosts_filename);
    free(switches_filename);
    return exit_status;
}