Exemple #1
0
def smallworld(n, rewire=0.3, seed=35):
    """Return a watts-strogatz small world graph.

    Mimics the layout of smallworld_topo.SmallWorldTopology.
    """
    graph = nx.connected_watts_strogatz_graph(n, min(4, n/3), rewire, seed=seed)
    return from_graph(graph)
Exemple #2
0
def waxman(n, alpha=0.8, beta=0.1):
    """Return a waxman random graph with n nodes.

    alpha increases edge probability, beta increases long edge probability.
    """
    import waxman_topo
    return from_graph(waxman_topo.waxman_graph(n, alpha, beta))
Exemple #3
0
def linear_hosts(*linear_nodes):
    """Returns topo, [(slice, policy)]"""
    topo = nxtopo.from_graph(nx.path_graph(4))
    nodes = [set(ns) for ns in linear_nodes]
    for n in topo.nodes():
        h1 = 100 + n*10 + 1
        h2 = 100 + n*10 + 2
        topo.add_host(h1)
        topo.add_host(h2)
        topo.add_link(n, h1)
        topo.add_link(n, h2)
        for ns in nodes:
            if n in ns:
                ns.update([h1, h2])
    topo.finalize()

    edge_policies = []
    for ns in linear_nodes:
        predicates = {}
        for n in ns:
            h1 = 100 + n*10 + 1
            h2 = 100 + n*10 + 2
            h1_port = topo.node[h1]['port'][0]
            h2_port = topo.node[h2]['port'][0]
            predicates[h1_port] = nc.Top()
            predicates[h2_port] = nc.Top()
        edge_policies.append(predicates)

    topos = [topo.subgraph(ns) for ns in nodes]
    slices = [slicing.ident_map_slice(t, pol)
              for t, pol in zip(topos, edge_policies)]
    combined = zip(slices, [policy_gen.flood_observe(t) for t in topos])
    return (topo, combined)
Exemple #4
0
def linear_all_ports(*linear_nodes):
    """Linear graph on four nodes with reflexive forwarding."""
    topo = nxtopo.from_graph(nx.path_graph(4))
    topo.finalize()

    topos = [topo.subgraph(nodes) for nodes in linear_nodes]
    policies = [policy_gen.flood_observe(t, all_ports=True) for t in topos]
    return topo, policies
Exemple #5
0
def linear(*linear_nodes):
    """Linear graph on four nodes, slices from input."""
    topo = nxtopo.from_graph(nx.path_graph(4))
    topo.finalize()

    topos = [topo.subgraph(nodes) for nodes in linear_nodes]
    policies = [policy_gen.flood_observe(t) for t in topos]
    return topo, policies
Exemple #6
0
def k4():
    """K4 complete graph."""
    topo = nxtopo.from_graph(nx.complete_graph(4))
    topo.finalize()

    topos = [topo.subgraph(nodes) for nodes in k4_nodes]
    edge_policies = [{} for t in topos]
    slices = [slicing.ident_map_slice(t, pol)
              for t, pol in zip(topos, edge_policies)]
    combined = zip(slices, [policy_gen.flood_observe(t) for t in topos])
    return (topo, combined)