int main(int argc, char ** argv) { int ret, i; netloc_topology_t topology; char ** search_uris = NULL; int num_search_uris = 1; int num_all_networks = 0; netloc_network_t **all_networks = NULL; char * filename = NULL; /* * Parse Args */ if( 0 != (ret = parse_args(argc, argv)) ) { printf("Usage: %s [<input directory>] [%s|%s] [%s|%s <export type>] [%s|%s] [%s|%s]\n", argv[0], ARG_FULL, ARG_SHORT_FULL, ARG_EXPORT, ARG_SHORT_EXPORT, ARG_VERBOSE, ARG_SHORT_VERBOSE, ARG_HELP, ARG_SHORT_HELP); printf(" Default <input directory> = current working directory\n"); printf(" Valid Options for %s:\n", ARG_EXPORT ); for(i = 0; i < num_valid_export_types; ++i ) { printf("\t\t%s\n", valid_export_types[i]); } return NETLOC_ERROR; } /* * Find all networks */ search_uris = (char **)malloc(sizeof(char*) * num_search_uris); asprintf(&search_uris[0], "file://%s", indir); ret = netloc_foreach_network((const char * const *)search_uris, 1, NULL, NULL, &num_all_networks, &all_networks); if( verbose ) { printf(" Found %d Networks.\n", num_all_networks); printf("---------------------------------------------------\n"); } for(i = 0; i < num_all_networks; ++i) { /* * Attach to the topology */ ret = netloc_attach(&topology, *all_networks[i]); if( NETLOC_SUCCESS != ret ) { return ret; } /* * Display the topology */ if( 0 == strncmp("screen", export_type, strlen("screen") )) { ret = display_topo_screen(topology, all_networks[i] ); } else if( 0 == strncmp("graphml", export_type, strlen("graphml")) ) { asprintf(&filename, "%s-%s.graphml", netloc_decode_network_type(all_networks[i]->network_type), all_networks[i]->subnet_id); printf("Network: %s\n", netloc_pretty_print_network_t(all_networks[i]) ); printf("\tFilename: %s\n", filename); ret = netloc_topology_export_graphml(topology, filename); } else if( 0 == strncmp("gexf", export_type, strlen("gexf")) ) { asprintf(&filename, "%s-%s.gexf", netloc_decode_network_type(all_networks[i]->network_type), all_networks[i]->subnet_id); printf("Network: %s\n", netloc_pretty_print_network_t(all_networks[i]) ); printf("\tFilename: %s\n", filename); ret = netloc_topology_export_gexf(topology, filename); } if( NETLOC_SUCCESS != ret ) { return ret; } /* * Detach from the topology */ ret = netloc_detach(topology); if( NETLOC_SUCCESS != ret ) { return ret; } } if( NULL != filename ) { free(filename); filename = NULL; } if( NULL != search_uris ) { for(i = 0; i < num_search_uris; ++i ) { free(search_uris[i]); search_uris[i] = NULL; } free(search_uris); search_uris = NULL; } return NETLOC_SUCCESS; }
int main(void) { int ret, exit_status = NETLOC_SUCCESS; netloc_topology_t topology; netloc_network_t *tmp_network = NULL; char *search_uri = NULL; /* * Setup a Network connection */ tmp_network = netloc_dt_network_t_construct(); tmp_network->network_type = NETLOC_NETWORK_TYPE_ETHERNET; tmp_network->subnet_id = strdup("unknown"); search_uri = strdup("file://data/netloc"); ret = netloc_find_network(search_uri, tmp_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, *tmp_network); if( NETLOC_SUCCESS != ret ) { fprintf(stderr, "Error: netloc_attach returned an error (%d)\n", ret); return ret; } printf("Success\n"); /* * Test all_switch_nodes */ printf("Test get_all_switch_nodes: "); fflush(NULL); ret = test_all_switch_nodes(topology); if( NETLOC_SUCCESS != ret ) { exit_status = ret; goto cleanup; } printf("Success\n"); /* * Test all_host_nodes */ printf("Test get_all_host_nodes: "); fflush(NULL); ret = test_all_host_nodes(topology); if( NETLOC_SUCCESS != ret ) { exit_status = ret; goto cleanup; } printf("Success\n"); /* * Test all_nodes */ printf("Test get_all_nodes: "); fflush(NULL); ret = test_all_nodes(topology); if( NETLOC_SUCCESS != ret ) { exit_status = ret; goto cleanup; } printf("Success\n"); /* * Test all_edges */ printf("Test get_all_edges: "); fflush(NULL); ret = test_all_edges(topology); if( NETLOC_SUCCESS != ret ) { exit_status = ret; goto cleanup; } printf("Success\n"); /* * Test get_physical_path */ printf("Test get_physical_path: "); fflush(NULL); ret = test_get_physical_path(topology); if( NETLOC_SUCCESS != ret ) { exit_status = ret; goto cleanup; } printf("Success\n"); /* * Test get_logical_path */ printf("Test get_logical_path: "); fflush(NULL); #if 0 ret = test_get_logical_path(topology); if( NETLOC_SUCCESS != ret ) { exit_status = ret; goto cleanup; } printf("Success\n"); #else printf("Not Implemented\n"); #endif 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; }
int main(void) { int i, num_uris = 1; char **search_uris = NULL; int ret, exit_status = NETLOC_SUCCESS; int num_all_networks = 0; netloc_network_t **all_networks = NULL; netloc_topology_t topology; netloc_dt_lookup_table_t nodes = NULL; netloc_dt_lookup_table_iterator_t hti = NULL; netloc_node_t *node = NULL; /* * Where to search for network topology information. * Information generated from a netloc reader. */ search_uris = (char**)malloc(sizeof(char*) * num_uris ); if( NULL == search_uris ) { return NETLOC_ERROR; } search_uris[0] = strdup("file://data/netloc"); /* * Find all of the networks in the specified serach URI locations */ ret = netloc_foreach_network((const char * const *) search_uris, num_uris, NULL, // Callback function (NULL = include all networks) NULL, // Callback function data &num_all_networks, &all_networks); if( NETLOC_SUCCESS != ret ) { fprintf(stderr, "Error: netloc_foreach_network returned an error (%d)\n", ret); exit_status = ret; goto cleanup; } /* * For each of those networks access the detailed topology */ for(i = 0; i < num_all_networks; ++i ) { // Pretty print the network for debugging purposes printf("\tIncluded Network: %s\n", netloc_pretty_print_network_t(all_networks[i]) ); /* * Attach to the network */ ret = netloc_attach(&topology, *(all_networks[i])); if( NETLOC_SUCCESS != ret ) { fprintf(stderr, "Error: netloc_attach returned an error (%d)\n", ret); return ret; } /* * 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) ) { node = netloc_lookup_table_iterator_next_entry(hti); if( NULL == node ) { break; } 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 */ cleanup: 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; } if( NULL != all_networks ) { for(i = 0; i < num_all_networks; ++i ) { netloc_dt_network_t_destruct(all_networks[i]); all_networks[i] = NULL; } free(all_networks); all_networks = NULL; } if( NULL != search_uris ) { for(i = 0; i < num_uris; ++i) { free(search_uris[i]); search_uris[i] = NULL; } free(search_uris); search_uris = NULL; } return NETLOC_SUCCESS; }
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; }
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; }
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_node_t *node = NULL; int num_edges; netloc_edge_t **edges = NULL; netloc_node_t *src_node = NULL; char * phy_id = NULL; char * tmp_str = NULL; phy_id = strdup("0002:c903:0002:a0eb"); /* * Setup a Network connection */ network = netloc_dt_network_t_construct(); network->network_type = NETLOC_NETWORK_TYPE_INFINIBAND; network->subnet_id = strdup("fe80:0000:0000:0000"); 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; } netloc_dt_network_t_destruct(network); network = NULL; 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; } /* * Get all of the edges */ src_node = netloc_get_node_by_physical_id(topology, phy_id); if( NULL == src_node ) { fprintf(stderr, "Error: Failed to in the node associated with the physical id %s\n", phy_id); return NETLOC_ERROR; } ret = netloc_get_all_edges(topology, src_node, &num_edges, &edges); if( NETLOC_SUCCESS != ret ) { tmp_str = netloc_pretty_print_node_t(node); fprintf(stderr, "Error: get_all_edges_by_id returned %d for node %s\n", ret, tmp_str); free(tmp_str); return ret; } /* * Display the data */ tmp_str = netloc_pretty_print_node_t(src_node); printf("Neighbors of %s\n", tmp_str); free(tmp_str); for(i = 0; i < num_edges; ++i ) { node = netloc_get_node_by_physical_id(topology, edges[i]->dest_node_id); printf("%s ( from port %3s to port %3s, type: %6s) has %3d directed edge(s)\n", node->physical_id, edges[i]->src_port_id, edges[i]->dest_port_id, (NETLOC_NODE_TYPE_SWITCH == node->node_type ? "switch" : "host"), node->num_edges); } /* Cleanup */ 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 != phy_id ) { free(phy_id); phy_id = NULL; } if( NULL != search_uri ) { free(search_uri); search_uri = NULL; } return exit_status; }
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; }