Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(1)  |  Call(1)  |  Derive(0)  |  Import(0)
Loads a network from the zoo into AutoNetkit.
If the file is interconnect.gml, it will treat the "type" of each node as
the source filename of a network to load. This can be used to construct
graphs of Multiple ASes.

        def load_zoo(network, net_file):
    #TODO: remove the network part - make return just a graphs
#TODO: make a seperate function that merges a new network, allocating ASNs as appropriate 
    Loads a network from the zoo into AutoNetkit.
    If the file is interconnect.gml, it will treat the "type" of each node as
    the source filename of a network to load. This can be used to construct
    graphs of Multiple ASes.

    #TODO: combine with current graph as final step, see if netx
    # will auto renumber nodes if necessary, to allow multiple ASes to be
    # loaded and combined

    #TODO: allow support for loading interconnect file
    #TODO: allow support for loading multiple zoo files, inc node
    #renumbering if necessary
    #TODO: set speeds based on linkspeed edge attribute from zoo, with
    # default speed if none set
    input_graph = load_graph(net_file)
    if not input_graph:
        # Nothing to process

    # See if normal zoo graph of interconnect graph
    interconnect_graph = None
    # Graphs in the network to process
    if ('label' in input_graph.graph and
        input_graph.graph['label'] == 'interconnect'):
        network_graphs = []
        # Map filenames (used in interconnect graph) to
        # network names (used in ank), so can connect the networks
        network_graph_names = {}
        interconnect_graph = input_graph
        networks_to_load = [data['type'] for n, data in
        # Remove duplicates
        networks_to_load = list(set(networks_to_load))
        # Get location of zoo networks from config
        #TODO: document this config setting
        #zoo_dir = settings.get('Zoo', 'zoo_dir')
        # Assume files in same directory as interconnect file
        zoo_dir = os.path.split(net_file)[0]
        # Now look for the files in the zoo dir
        for net_load_file in networks_to_load:
            full_path = "{0}/{1}".format(zoo_dir, net_load_file)
            if os.path.exists(full_path):
                # load the network
                graph = load_graph(full_path)
                # Get the name of the network, to use when interconnecting
                network_graph_names[net_load_file] = graph.graph['Network']
                LOG.warn("Unable to find {0} in {1}".format(net_load_file,
        for graph in network_graphs:
            #TODO: dont load external graphs for interconnect
            graph = graph_to_ank(network, graph, include_ext_nodes = False)
            network.graph = nx.disjoint_union(network.graph, graph)
        # TODO: clean this up
        if ('Network' in input_graph.graph 
            and input_graph.graph['Network'] == "European NRENs"):
            # For Infocom Paper
            # Use graph directly
            network.graph = input_graph.to_directed()
            # Store the AS names
            as_names = dict( set( (int(data['asn']), data['Network']) for
                                 node, data in

            # And allocate AS graph
            # ANK uses directed graphs
            # convert as appropriate
            network.graph = graph_to_ank(network, input_graph)

    def ank_node_from_inter(data):
        #TODO: generalise the last section
        # Network specified as a file, get the network name for this node
        filename = data['type']
        if filename in network_graph_names:
            network_name = network_graph_names[filename]
            # and convert to asn
            asn = None
            #TODO: look for cleaner way to search dict items
            for curr_asn, curr_asn_name in network.as_names.items():
                if curr_asn_name == network_name:
                    asn = int(curr_asn)
                    if not asn:
                        LOG.warn("Unable to find ASN for network "
                label = data['label']
                # Now find the node that has this asn and label
                for node, data in network.graph.nodes(data=True):
                    if data['label'] == label and data['asn'] == asn:
                        return node
                # Probably didn't load the network correctly
                # TODO: throw error

    if interconnect_graph:
        # Connect the networks together
        add_edge_list = []
        for src, dst in interconnect_graph.edges():
            # Need to find the src and dst nodes in the ank network
            src_ank = ank_node_from_inter(interconnect_graph.node[src])
            dst_ank = ank_node_from_inter(interconnect_graph.node[dst])
            if src_ank != None and dst_ank != None:
                # And connect these two nodes in the main graph
                #TODO: apply any appropriate BGP policy from interconnect_graph
                add_edge_list.append((src_ank, dst_ank))
                add_edge_list.append((dst_ank, src_ank))
    #TODO: make this only apply to graph nodes for newly added graph not
    #globally to whole network

    for node, data in network.graph.nodes(data=True):
        if 'label' not in data:
            input_graph.node[node]['label'] = node
        if 'device_type' not in data:
            default_device_type = 'router'
            input_graph.node[node]['device_type'] = default_device_type 
            LOG.debug("Setting device_type for %s to %s" % ( 
                input_graph.node[node]['label'], default_device_type) )

src/a/n/ank_le-HEAD/AutoNetkit/internet.py   ank_le(Download)
        elif ext == ".gml":
            # GML file from Topology Zoo
            ank.load_zoo(self.network, filename)
        elif ext == ".graphml":
            self.network.graph = ank.load_graphml(filename)