Exemplo n.º 1
0
def test_graph_directed():
    """
    Insure we keep newly constructed topologies as directed graph
    """
    topo = complete_topology(5)
    assert isinstance(topo.get_graph(), networkx.DiGraph)
    # even if original graph is undirected
    topo = Topology('noname', networkx.star_graph(8))
    assert topo.get_graph().is_directed()
Exemplo n.º 2
0
def complete_topology(n, name=u'complete'):
    """
    Generates a complete graph topology

    :param n: number of nodes in the complete graph
    :param name: name of the topology

    :return: the new topology
    :rtype: :py:class:`~sol.topology.topologynx.Topology`

    """
    assert n >= 0
    G = nx.complete_graph(n).to_directed()
    t = Topology(name, G)
    return t
Exemplo n.º 3
0
def chain_topology(n, name=u'chain'):
    """
    Generates a chain topology.

    :param n: number of nodes in the chain
    :param name: name of the topology

    :return: the new topology
    :rtype: :py:class:`~sol.topology.topologynx.Topology`

    """
    assert n >= 0
    G = nx.path_graph(n).to_directed()
    t = Topology(name, G)
    return t
Exemplo n.º 4
0
def test_write_read(tmpdir):
    """Check that writing topology to disk and restoring it produces the expected result"""
    dirname = u(os.path.abspath(tmpdir.dirname))
    topo = complete_topology(5)
    for l in topo.links():
        topo.set_resource(l, 'myresource', 4)
    topo.write_graph(dirname + os.path.sep + u'testgml.gml')
    topo2 = Topology(topo.name)
    topo2.load_graph(dirname + os.path.sep + u'testgml.gml')
    assert networkx.is_isomorphic(topo.get_graph(), topo2.get_graph())
    assert topo.name == topo2.name

    # Check that resources are preserved
    for n in topo.nodes():
        assert topo.get_resources(n) == topo2.get_resources(n)
    for l in topo.links():
        assert topo.get_resources(n) == topo2.get_resources(n)
Exemplo n.º 5
0
def fat_tree(k):
    """
    Creates a FatTree topology with a given '-arity'.

    .. seealso:: The `<ccr.sigcomm.org/online/files/p63-alfares.pdf>`_

    :param k: specify the k-value that controls the size of the topology
    :returns: the new topology
    :rtype: :py:class:`~sol.topology.topologynx.Topology`

    """
    assert k >= 0
    if k % 2 != 0:
        raise ValueError(ERR_ODD_ARITY)
    graph = nx.empty_graph()
    # Let's do the pods first
    index = 0
    bucket_size = int(k / 2)
    middle = []
    for pod in xrange(k):
        lower = xrange(index, index + bucket_size)
        index += bucket_size
        upper = xrange(index, index + bucket_size)
        index += bucket_size
        # Add upper and lower levels
        graph.add_nodes_from(lower, layer=EDGE_LAYER, functions=SWITCH)
        graph.add_nodes_from(upper, layer=AGG_LAYER, functions=SWITCH)
        # connect the levels
        graph.add_edges_from(itertools.product(lower, upper), capacitymult=1)
        # keep the upper level for later
        middle.extend(upper)
    # Now, create the core
    core = []
    for coreswitch in xrange(int((k**2) / 4)):
        graph.add_node(index, layer=CORE_LAYER, functions=SWITCH)
        core.append(index)
        index += 1
    graph.add_edges_from(itertools.product(core, middle), capacitymult=10)
    graph = graph.to_directed()
    return Topology(u'k{}'.format(k), graph)
Exemplo n.º 6
0
# REST-specific configuration here
__API_VERSION = 1  # the current api version
_json_pretty = False  # whether to pretty print json or not (not == save space)
_gzip = True  # whether to gzip the returned responses

# SET THIS TO THE TOPOLOGY WE ARE TESTING
#_topology = None
_topology = nx.DiGraph()
_topology.add_node(0, services='switch', resources={})
_topology.add_node(1, services='switch', resources={})
_topology.add_node(2, services='switch', resources={})
_topology.add_edge(0, 1, source=0, target=1, resources={'bw': 10000})
_topology.add_edge(1, 0, source=1, target=0, resources={'bw': 10000})
_topology.add_edge(2, 1, source=2, target=1, resources={'bw': 10000})
_topology.add_edge(1, 2, source=1, target=2, resources={'bw': 10000})
_topology = Topology(u'NoName', _topology)

_predicatedict = {
    'null': null_predicate,
    'null_predicate': null_predicate,
}


def assign_to_tc(tcs, paths, name):
    """
    Assign paths to traffic classes based on the ingress & egress nodes.
    To be used only if there is one traffic class (predicate)
    per ingress-egress pair.

    :param tcs: list of traffic classes
    :param paths: dictionary of paths: ..