Esempio n. 1
0
int test_all_switch_nodes(netloc_topology_t topology)
{
    int ret;
    netloc_dt_lookup_table_t switches = NULL;
    netloc_dt_lookup_table_iterator_t hti = NULL;
    const char * key = NULL;
    netloc_node_t *node = NULL;

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

    /* Verify the data */
    hti = netloc_dt_lookup_table_iterator_t_construct( switches );
    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, key);
        if( NETLOC_NODE_TYPE_SWITCH != 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(switches);
    free(switches);

    return NETLOC_SUCCESS;
}
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;
}
Esempio n. 3
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;
}