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; }
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; }
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; }
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; }