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 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; }
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 void display_edge(netloc_edge_t *edge, char * prefix) { printf("%s%s\n", prefix, netloc_pretty_print_edge_t(edge)); }