Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;
}