Ejemplo n.º 1
0
 def test_line_connectivity(n):
     G = fnss.line_topology(n)
     self.assertEqual(n, G.number_of_nodes())
     self.assertEqual(n - 1, G.number_of_edges())
     for i in range(n):
         if i <= n - 2: self.assertTrue(G.has_edge(i, i + 1))
         if i >= 1:   self.assertTrue(G.has_edge(i, i - 1))
Ejemplo n.º 2
0
 def test_extract_cluster_level_topology(self):
     t = algorithms.IcnTopology(fnss.line_topology(6))
     t.graph['icr_candidates'] = set(t.nodes())
     clusters = [set([0, 1]), set([2, 3]), set([4, 5])]
     algorithms.deploy_clusters(t, clusters)
     ct = algorithms.extract_cluster_level_topology(t)
     self.assertEqual(len(clusters), len(ct))
def topology_path(n, delay=1, **kwargs):
    """Return a path topology with a receiver on node `0` and a source at node
    'n-1'
    
    Parameters
    ----------
    n : int (>=3)
        The number of nodes
    delay : float
        The link delay in milliseconds
        
    Returns
    -------
    topology : IcnTopology
        The topology object
    """
    topology = fnss.line_topology(n)
    receivers = [0]    
    routers = range(1, n-1)
    sources = [n-1]
    topology.graph['icr_candidates'] = set(routers)
    for v in sources:
        fnss.add_stack(topology, v, 'source')
    for v in receivers:
        fnss.add_stack(topology, v, 'receiver')
    for v in routers:
        fnss.add_stack(topology, v, 'router')
    # set weights and delays on all links
    fnss.set_weights_constant(topology, 1.0)
    fnss.set_delays_constant(topology, delay, 'ms')
    # label links as internal or external
    for u, v in topology.edges_iter():
        topology.edge[u][v]['type'] = 'internal'
    return IcnTopology(topology)
Ejemplo n.º 4
0
def large_line_topology():
    topology = fnss.line_topology(11)
    fnss.add_stack(topology, 0, 'receiver')
    for i in range(1, 10):
        fnss.add_stack(topology, i, 'router')
    topology.graph['icr_candidates'] = [2, 3, 4, 5]
    return topology
Ejemplo n.º 5
0
 def test_extract_cluster_level_topology(self):
     t = algorithms.IcnTopology(fnss.line_topology(6))
     t.graph['icr_candidates'] = set(t.nodes())
     clusters = [set([0, 1]), set([2, 3]), set([4, 5])]
     algorithms.deploy_clusters(t, clusters)
     ct = algorithms.extract_cluster_level_topology(t)
     self.assertEqual(len(clusters), len(ct))
Ejemplo n.º 6
0
 def test_line_connectivity(n):
     G = fnss.line_topology(n)
     self.assertEquals(n, G.number_of_nodes())
     self.assertEquals(n - 1, G.number_of_edges())
     for i in range(n):
         if i <= n - 2: self.assertTrue(G.has_edge(i, i + 1))
         if i >= 1:   self.assertTrue(G.has_edge(i, i - 1))
Ejemplo n.º 7
0
def topology_path(n, delay=1, **kwargs):
    """Return a path topology with a receiver on node `0` and a source at node
    'n-1'

    Parameters
    ----------
    n : int (>=3)
        The number of nodes
    delay : float
        The link delay in milliseconds

    Returns
    -------
    topology : IcnTopology
        The topology object
    """
    topology = fnss.line_topology(n)
    receivers = [0]
    routers = range(1, n - 1)
    sources = [n - 1]
    topology.graph['icr_candidates'] = set(routers)
    for v in sources:
        fnss.add_stack(topology, v, 'source')
    for v in receivers:
        fnss.add_stack(topology, v, 'receiver')
    for v in routers:
        fnss.add_stack(topology, v, 'router')
    # set weights and delays on all links
    fnss.set_weights_constant(topology, 1.0)
    fnss.set_delays_constant(topology, delay, 'ms')
    # label links as internal or external
    for u, v in topology.edges_iter():
        topology.edge[u][v]['type'] = 'internal'
    return IcnTopology(topology)
Ejemplo n.º 8
0
 def test_extract_cluster_level_topology(self):
     t = algorithms.IcnTopology(fnss.line_topology(6))
     t.graph['icr_candidates'] = set(t.nodes())
     clusters = [{0, 1}, {2, 3}, {4, 5}]
     algorithms.deploy_clusters(t, clusters)
     ct = algorithms.extract_cluster_level_topology(t)
     assert len(clusters) == len(ct)
Ejemplo n.º 9
0
 def test_algorithms(self):
     t = algorithms.IcnTopology(fnss.line_topology(6))
     t.graph['icr_candidates'] = set(t.nodes())
     fnss.set_delays_constant(t, 1, 'ms')
     fnss.set_delays_constant(t, 3, 'ms', [(1, 2), (3, 4)])
     clusters = algorithms.compute_clusters(t, 3)
     expected_clusters = [set([0, 1]), set([2, 3]), set([4, 5])]
     self.assertEqual(expected_clusters, clusters)
Ejemplo n.º 10
0
 def setUp(self):
     self.topo = fnss.line_topology(6)
     fnss.add_stack(self.topo, 0, 'receiver')
     self.topo.graph['icr_candidates'] = []
     for i in range(1, 5):
         self.topo.graph['icr_candidates'].append(i)
         fnss.add_stack(self.topo, i, 'router')
     fnss.add_stack(self.topo, 5, 'source')
Ejemplo n.º 11
0
 def test_buffers_size_constant_unit_mismatch(self):
     # If I try to set buffer sizes to some interfaces using a unit and some
     # other interfaces already have buffer sizes assigned using a different
     # unit, then raise an error and ask to use the unit previously used
     topo = fnss.line_topology(3)
     fnss.set_buffer_sizes_constant(topo, 10, 'packets', [(0, 1)])
     self.assertRaises(ValueError, fnss.set_buffer_sizes_constant, topo,
                       200, 'bytes', [(1, 2)])
Ejemplo n.º 12
0
 def setUp(self):
     self.topo = fnss.line_topology(6)
     fnss.add_stack(self.topo, 0, 'receiver')
     self.topo.graph['icr_candidates'] = []
     for i in range(1, 5):
         self.topo.graph['icr_candidates'].append(i)
         fnss.add_stack(self.topo, i, 'router')
     fnss.add_stack(self.topo, 5, 'source')
Ejemplo n.º 13
0
 def setup_method(self):
     self.topo = fnss.line_topology(6)
     fnss.add_stack(self.topo, 0, "receiver")
     self.topo.graph["icr_candidates"] = []
     for i in range(1, 5):
         self.topo.graph["icr_candidates"].append(i)
         fnss.add_stack(self.topo, i, "router")
     fnss.add_stack(self.topo, 5, "source")
Ejemplo n.º 14
0
 def test_buffers_size_constant_unit_mismatch(self):
     # If I try to set buffer sizes to some interfaces using a unit and some
     # other interfaces already have buffer sizes assigned using a different
     # unit, then raise an error and ask to use the unit previously used
     topo = fnss.line_topology(3)
     fnss.set_buffer_sizes_constant(topo, 10, 'packets', [(0, 1)])
     self.assertRaises(ValueError, fnss.set_buffer_sizes_constant,
                       topo, 200, 'bytes', [(1, 2)])
Ejemplo n.º 15
0
 def test_extract_cluster_level_topology_1_cluster(self):
     t = algorithms.IcnTopology(fnss.line_topology(3))
     t.graph['icr_candidates'] = set(t.nodes())
     clusters = [t.graph['icr_candidates']]
     algorithms.deploy_clusters(t, clusters)
     ct = algorithms.extract_cluster_level_topology(t)
     self.assertEqual(1, len(clusters))
     self.assertEqual(1, ct.number_of_nodes())
Ejemplo n.º 16
0
 def test_extract_cluster_level_topology_1_cluster(self):
     t = algorithms.IcnTopology(fnss.line_topology(3))
     t.graph['icr_candidates'] = set(t.nodes())
     clusters = [t.graph['icr_candidates']]
     algorithms.deploy_clusters(t, clusters)
     ct = algorithms.extract_cluster_level_topology(t)
     assert 1 == len(clusters)
     assert 1 == ct.number_of_nodes()
Ejemplo n.º 17
0
 def test_algorithms(self):
     t = algorithms.IcnTopology(fnss.line_topology(6))
     t.graph['icr_candidates'] = set(t.nodes())
     fnss.set_delays_constant(t, 1, 'ms')
     fnss.set_delays_constant(t, 3, 'ms', [(1, 2), (3, 4)])
     clusters = algorithms.compute_clusters(t, 3)
     expected_clusters = [{0, 1}, {2, 3}, {4, 5}]
     assert expected_clusters == clusters
Ejemplo n.º 18
0
 def test_algorithms(self):
     t = algorithms.IcnTopology(fnss.line_topology(6))
     t.graph['icr_candidates'] = set(t.nodes())
     fnss.set_delays_constant(t, 1, 'ms')
     fnss.set_delays_constant(t, 3, 'ms', [(1, 2), (3, 4)])
     clusters = algorithms.compute_clusters(t, 3)
     expected_clusters = [set([0, 1]), set([2, 3]), set([4, 5])]
     self.assertEqual(expected_clusters, clusters)
Ejemplo n.º 19
0
 def test_validate_traffic_matrix_diff_units(self):
     topo = fnss.line_topology(2)
     fnss.set_capacities_constant(topo, 1, capacity_unit='Gbps')
     valid_tm = fnss.TrafficMatrix(volume_unit='Mbps')
     valid_tm.add_flow(0, 1, 999)
     self.assertTrue(fnss.validate_traffic_matrix(topo, valid_tm, validate_load=True))
     invalid_tm = fnss.TrafficMatrix(volume_unit='Mbps')
     invalid_tm.add_flow(0, 1, 1001)
     self.assertFalse(fnss.validate_traffic_matrix(topo, invalid_tm, validate_load=True))
Ejemplo n.º 20
0
 def test_validate_traffic_matrix_diff_units(self):
     topo = fnss.line_topology(2)
     fnss.set_capacities_constant(topo, 1, capacity_unit='Gbps')
     valid_tm = fnss.TrafficMatrix(volume_unit='Mbps')
     valid_tm.add_flow(0, 1, 999)
     self.assertTrue(fnss.validate_traffic_matrix(topo, valid_tm, validate_load=True))
     invalid_tm = fnss.TrafficMatrix(volume_unit='Mbps')
     invalid_tm.add_flow(0, 1, 1001)
     self.assertFalse(fnss.validate_traffic_matrix(topo, invalid_tm, validate_load=True))
Ejemplo n.º 21
0
 def test_deploy_clusters(self):
     t = algorithms.IcnTopology(fnss.line_topology(6))
     t.graph['icr_candidates'] = set(t.nodes())
     clusters = [set([0, 1]), set([2, 3]), set([4, 5])]
     cluster_map = {0: 0, 1: 0, 2: 1, 3: 1, 4: 2, 5: 2}
     algorithms.deploy_clusters(t, clusters)
     self.assertEqual(clusters, t.graph['clusters'])
     for v, data in t.nodes(data=True):
         self.assertEqual(cluster_map[v], data['cluster'])
Ejemplo n.º 22
0
 def test_deploy_clusters(self):
     t = algorithms.IcnTopology(fnss.line_topology(6))
     t.graph['icr_candidates'] = set(t.nodes())
     clusters = [set([0, 1]), set([2, 3]), set([4, 5])]
     cluster_map = {0: 0, 1: 0, 2: 1, 3: 1, 4: 2, 5: 2}
     algorithms.deploy_clusters(t, clusters)
     self.assertEqual(clusters, t.graph['clusters'])
     for v, data in t.nodes(data=True):
         self.assertEqual(cluster_map[v], data['cluster'])
Ejemplo n.º 23
0
 def test_deploy_clusters(self):
     t = algorithms.IcnTopology(fnss.line_topology(6))
     t.graph['icr_candidates'] = set(t.nodes())
     clusters = [{0, 1}, {2, 3}, {4, 5}]
     cluster_map = {0: 0, 1: 0, 2: 1, 3: 1, 4: 2, 5: 2}
     algorithms.deploy_clusters(t, clusters)
     assert clusters == t.graph['clusters']
     for v, data in t.nodes(data=True):
         assert cluster_map[v] == data['cluster']
Ejemplo n.º 24
0
def test_uniform_content_placement():
    t = fnss.line_topology(4)
    fnss.add_stack(t, 0, "router")
    fnss.add_stack(t, 1, "source")
    fnss.add_stack(t, 2, "source")
    fnss.add_stack(t, 3, "receiver")
    contentplacement.uniform_content_placement(t, range(10))
    c1 = t.node[1]["stack"][1].get("contents", set())
    c2 = t.node[2]["stack"][1].get("contents", set())
    assert len(c1) + len(c2) == 10
Ejemplo n.º 25
0
def test_uniform_content_placement():
    t = fnss.line_topology(4)
    fnss.add_stack(t, 0, 'router')
    fnss.add_stack(t, 1, 'source')
    fnss.add_stack(t, 2, 'source')
    fnss.add_stack(t, 3, 'receiver')
    contentplacement.uniform_content_placement(t, range(10))
    c1 = t.node[1]['stack'][1].get('contents', set())
    c2 = t.node[2]['stack'][1].get('contents', set())
    assert len(c1) + len(c2) == 10
Ejemplo n.º 26
0
 def setup_method(self):
     #
     # 0 -- 1 -- 2 -- 3 -- 4 -- 5
     #
     self.topo = fnss.line_topology(6)
     fnss.add_stack(self.topo, 0, 'receiver')
     fnss.add_stack(self.topo, 5, 'source')
     self.topo.graph['icr_candidates'] = {1, 2, 3, 4}
     for i in self.topo.graph['icr_candidates']:
         fnss.add_stack(self.topo, i, 'router')
 def test_uniform(self):
     t = fnss.line_topology(4)
     fnss.add_stack(t, 0, "router")
     fnss.add_stack(t, 1, "source")
     fnss.add_stack(t, 2, "source")
     fnss.add_stack(t, 3, "receiver")
     contentplacement.weighted_content_placement(t, range(10), {1: 0.7, 2: 0.3})
     c1 = t.node[1]["stack"][1]["contents"] if "contents" in t.node[1]["stack"][1] else set()
     c2 = t.node[2]["stack"][1]["contents"] if "contents" in t.node[2]["stack"][1] else set()
     self.assertEqual(len(c1) + len(c2), 10)
 def test_uniform(self):
     t = fnss.line_topology(4)
     fnss.add_stack(t, 0, "router")
     fnss.add_stack(t, 1, "source")
     fnss.add_stack(t, 2, "source")
     fnss.add_stack(t, 3, "receiver")
     contentplacement.uniform_content_placement(t, range(10))
     c1 = t.node[1]["stack"][1]["contents"]
     c2 = t.node[2]["stack"][1]["contents"]
     self.assertEqual(len(c1) + len(c2), 10)
Ejemplo n.º 29
0
 def test_uniform(self):
     t = fnss.line_topology(4)
     fnss.add_stack(t, 0, 'router')
     fnss.add_stack(t, 1, 'source')
     fnss.add_stack(t, 2, 'source')
     fnss.add_stack(t, 3, 'receiver')
     contentplacement.weighted_content_placement(t, range(10), {1: 0.7, 2: 0.3})
     c1 = t.node[1]['stack'][1]['contents'] if 'contents' in t.node[1]['stack'][1] else set()
     c2 = t.node[2]['stack'][1]['contents'] if 'contents' in t.node[2]['stack'][1] else set()
     self.assertEqual(len(c1) + len(c2), 10)
Ejemplo n.º 30
0
 def test_uniform(self):
     t = fnss.line_topology(4)
     fnss.add_stack(t, 0, 'router')
     fnss.add_stack(t, 1, 'source')
     fnss.add_stack(t, 2, 'source')
     fnss.add_stack(t, 3, 'receiver')
     contentplacement.uniform_content_placement(t, range(10))
     c1 = t.node[1]['stack'][1]['contents']
     c2 = t.node[2]['stack'][1]['contents']
     self.assertEqual(len(c1) + len(c2), 10)
Ejemplo n.º 31
0
 def setup_method(self):
     #
     # 0 -- 1 -- 2 -- 3 -- 4 -- 5
     #
     self.topo = fnss.line_topology(6)
     fnss.add_stack(self.topo, 0, "receiver")
     fnss.add_stack(self.topo, 5, "source")
     self.topo.graph["icr_candidates"] = {1, 2, 3, 4}
     for i in self.topo.graph["icr_candidates"]:
         fnss.add_stack(self.topo, i, "router")
Ejemplo n.º 32
0
 def test_uniform(self):
     t = fnss.line_topology(4)
     fnss.add_stack(t, 0, 'router')
     fnss.add_stack(t, 1, 'source')
     fnss.add_stack(t, 2, 'source')
     fnss.add_stack(t, 3, 'receiver')
     contentplacement.uniform_content_placement(t, range(10))
     c1 = t.node[1]['stack'][1].get('contents', set())
     c2 = t.node[2]['stack'][1].get('contents', set())
     self.assertEqual(len(c1) + len(c2), 10)
Ejemplo n.º 33
0
def test_weighted_content_placement():
    t = fnss.line_topology(4)
    fnss.add_stack(t, 0, 'router')
    fnss.add_stack(t, 1, 'source')
    fnss.add_stack(t, 2, 'source')
    fnss.add_stack(t, 3, 'receiver')
    contentplacement.weighted_content_placement(t, range(10), {1: 0.7, 2: 0.3})
    c1 = t.node[1]['stack'][1]['contents'] if 'contents' in t.node[1]['stack'][1] else set()
    c2 = t.node[2]['stack'][1]['contents'] if 'contents' in t.node[2]['stack'][1] else set()
    assert len(c1) + len(c2) == 10
Ejemplo n.º 34
0
def small_line_topology():
    topology = fnss.line_topology(7)
    fnss.add_stack(topology, 0, 'receiver')
    fnss.add_stack(topology, 1, 'router')
    fnss.add_stack(topology, 2, 'router')
    fnss.add_stack(topology, 3, 'router')
    fnss.add_stack(topology, 4, 'router')
    fnss.add_stack(topology, 5, 'router')
    fnss.add_stack(topology, 6, 'source')
    topology.graph['icr_candidates'] = [2, 3]
    return topology
Ejemplo n.º 35
0
def test_weighted_content_placement():
    t = fnss.line_topology(4)
    fnss.add_stack(t, 0, "router")
    fnss.add_stack(t, 1, "source")
    fnss.add_stack(t, 2, "source")
    fnss.add_stack(t, 3, "receiver")
    contentplacement.weighted_content_placement(t, range(10), {1: 0.7, 2: 0.3})
    c1 = (t.node[1]["stack"][1]["contents"]
          if "contents" in t.node[1]["stack"][1] else set())
    c2 = (t.node[2]["stack"][1]["contents"]
          if "contents" in t.node[2]["stack"][1] else set())
    assert len(c1) + len(c2) == 10
Ejemplo n.º 36
0
 def test_buffers_size_link_bandwidth_default_size(self):
     topo = fnss.line_topology(4)
     fnss.set_capacities_constant(topo, 8, 'Mbps', [(0, 1)])
     fnss.set_capacities_constant(topo, 16, 'Mbps', [(1, 2)])
     fnss.set_buffer_sizes_link_bandwidth(topo, buffer_unit='bytes', default_size=10)
     self.assertEquals(topo.graph['buffer_unit'], 'bytes')
     self.assertEquals(topo.adj[0][1]['buffer'], 1000000)
     self.assertEquals(topo.adj[1][2]['buffer'], 2000000)
     self.assertEquals(topo.adj[2][3]['buffer'], 10)
     fnss.clear_buffer_sizes(topo)
     self.assertTrue('capacity' not in topo.adj[2][3])
     self.assertRaises(ValueError, fnss.set_buffer_sizes_link_bandwidth, topo)
Ejemplo n.º 37
0
 def setup_method(self):
     #
     # 0 -- 1 -- 2 -- 3 -- 4
     #           |
     #           5
     self.topo = fnss.line_topology(5)
     fnss.add_stack(self.topo, 0, 'receiver')
     fnss.add_stack(self.topo, 4, 'source')
     self.topo.add_edge(2, 5)
     self.topo.graph['icr_candidates'] = {1, 2, 3, 5}
     for i in self.topo.graph['icr_candidates']:
         fnss.add_stack(self.topo, i, 'router')
Ejemplo n.º 38
0
 def setup_method(self):
     #
     # 0 -- 1 -- 2 -- 3 -- 4
     #           |
     #           5
     self.topo = fnss.line_topology(5)
     fnss.add_stack(self.topo, 0, "receiver")
     fnss.add_stack(self.topo, 4, "source")
     self.topo.add_edge(2, 5)
     self.topo.graph["icr_candidates"] = {1, 2, 3, 5}
     for i in self.topo.graph["icr_candidates"]:
         fnss.add_stack(self.topo, i, "router")
Ejemplo n.º 39
0
def topology_path(network_cache=0.05, n_contents=100000, n=3, seed=None):
    """
    Return a scenario based on path topology
    
    Parameters
    ----------
    network_cache : float
        Size of network cache (sum of all caches) normalized by size of content
        population
    n_contents : int
        Size of content population
    seed : int, optional
        The seed used for random number generation
        
    Returns
    -------
    topology : fnss.Topology
        The topology object
    """
    # 240 nodes in the main component
    topology = fnss.line_topology(n)
    receivers = [0]
    caches = range(1, n - 1)
    sources = [n - 1]
    # randomly allocate contents to sources
    content_placement = uniform_content_placement(topology,
                                                  range(1, n_contents + 1),
                                                  sources,
                                                  seed=seed)
    for v in sources:
        fnss.add_stack(topology, v, 'source',
                       {'contents': content_placement[v]})
    for v in receivers:
        fnss.add_stack(topology, v, 'receiver', {})
    # set weights and delays on all links
    fnss.set_weights_constant(topology, 1.0)
    fnss.set_delays_constant(topology, INTERNAL_LINK_DELAY, 'ms')
    # label links as internal or external
    for u, v in topology.edges_iter():
        if u in sources or v in sources:
            topology.edge[u][v]['type'] = 'external'
            fnss.set_delays_constant(topology, EXTERNAL_LINK_DELAY, 'ms',
                                     [(u, v)])
        else:
            topology.edge[u][v]['type'] = 'internal'
    cache_placement = uniform_cache_placement(topology,
                                              network_cache * n_contents,
                                              caches)
    for node, size in cache_placement.iteritems():
        fnss.add_stack(topology, node, 'cache', {'size': size})
    return topology
Ejemplo n.º 40
0
 def setUp(self):
     topo = cacheplacement.IcnTopology(fnss.line_topology(7))
     receivers = [0]
     sources = [6]
     icr_candidates = [1, 2, 3, 4, 5]
     topo.graph['icr_candidates'] = set(icr_candidates)
     for router in icr_candidates:
         fnss.add_stack(topo, router, 'router')
     for src in sources:
         fnss.add_stack(topo, src, 'source')
     for rcv in receivers:
         fnss.add_stack(topo, rcv, 'receiver')
     fnss.set_delays_constant(topo, 2, 'ms')
     fnss.set_delays_constant(topo, 20, 'ms', [(2, 3)])
     self.topo = topo
Ejemplo n.º 41
0
 def test_uniform(self):
     t = fnss.line_topology(4)
     fnss.add_stack(t, 0, 'router')
     fnss.add_stack(t, 1, 'source')
     fnss.add_stack(t, 2, 'source')
     fnss.add_stack(t, 3, 'receiver')
     contentplacement.weighted_content_placement(t, list(range(10)), {
         1: 0.7,
         2: 0.3
     })
     c1 = t.node[1]['stack'][1]['contents'] if 'contents' in t.node[1][
         'stack'][1] else set()
     c2 = t.node[2]['stack'][1]['contents'] if 'contents' in t.node[2][
         'stack'][1] else set()
     self.assertEqual(len(c1) + len(c2), 10)
Ejemplo n.º 42
0
 def setUp(self):
     topo = cacheplacement.IcnTopology(fnss.line_topology(7))
     receivers = [0]
     sources = [6]
     icr_candidates = [1, 2, 3, 4, 5]
     topo.graph['icr_candidates'] = set(icr_candidates)
     for router in icr_candidates:
         fnss.add_stack(topo, router, 'router')
     for src in sources:
         fnss.add_stack(topo, src, 'source')
     for rcv in receivers:
         fnss.add_stack(topo, rcv, 'receiver')
     fnss.set_delays_constant(topo, 2, 'ms')
     fnss.set_delays_constant(topo, 20, 'ms', [(2, 3)])
     self.topo = topo
Ejemplo n.º 43
0
 def setup_method(self):
     topo = cacheplacement.IcnTopology(fnss.line_topology(7))
     receivers = [0]
     sources = [6]
     icr_candidates = [1, 2, 3, 4, 5]
     topo.graph["icr_candidates"] = set(icr_candidates)
     for router in icr_candidates:
         fnss.add_stack(topo, router, "router")
     for src in sources:
         fnss.add_stack(topo, src, "source")
     for rcv in receivers:
         fnss.add_stack(topo, rcv, "receiver")
     fnss.set_delays_constant(topo, 2, "ms")
     fnss.set_delays_constant(topo, 20, "ms", [(2, 3)])
     self.topo = topo
Ejemplo n.º 44
0
def topology_tandem(n=3,nc=0.01, **kwargs):

    
    T = 'TANDEM' # name of the topology
    
    topology = fnss.line_topology(n)
    topology = list(nx.connected_component_subgraphs(topology))[0]

            
    receivers = [0]
    routers = [1, 2]
    #sources = [2]
    
    source_attachment = routers[1];
    source = source_attachment + 1000
    topology.add_edge(source_attachment, source)

    sources = [source]

    topology.graph['icr_candidates'] = set(routers)
    
    fnss.add_stack(topology, source, 'source')

    #for v in sources:
    #    fnss.add_stack(topology, v, 'source')
    for v in receivers:
        fnss.add_stack(topology, v, 'receiver')
    for v in routers:
        fnss.add_stack(topology, v, 'router')
    
    fnss.set_weights_constant(topology, 1.0)
    fnss.set_delays_constant(topology, INTERNAL_LINK_DELAY, 'ms')
    for u, v in topology.edges_iter():
        if u in sources or v in sources:
            topology.edge[u][v]['type'] = 'external'
            # this prevents sources to be used to route traffic
            fnss.set_weights_constant(topology, 1000.0, [(u, v)])
            fnss.set_delays_constant(topology, EXTERNAL_LINK_DELAY, 'ms', [(u, v)])
        else:
            topology.edge[u][v]['type'] = 'internal'

    C = str(nc)
    fnss.write_topology(topology, path.join(TOPOLOGY_RESOURCES_DIR, topo_prefix + 'T=%s@C=%s' % (T, C)  + '.xml'))

    return IcnTopology(topology)
Ejemplo n.º 45
0
def topology_path(network_cache=0.05, n_contents=100000, n=3, seed=None):
    """
    Return a scenario based on path topology
    
    Parameters
    ----------
    network_cache : float
        Size of network cache (sum of all caches) normalized by size of content
        population
    n_contents : int
        Size of content population
    seed : int, optional
        The seed used for random number generation
        
    Returns
    -------
    topology : fnss.Topology
        The topology object
    """
    # 240 nodes in the main component
    topology = fnss.line_topology(n)
    receivers = [0]    
    caches = range(1, n-1)
    sources = [n-1]
    # randomly allocate contents to sources
    content_placement = uniform_content_placement(topology, range(1, n_contents+1), sources, seed=seed)
    for v in sources:
        fnss.add_stack(topology, v, 'source', {'contents': content_placement[v]})
    for v in receivers:
        fnss.add_stack(topology, v, 'receiver', {})
    # set weights and delays on all links
    fnss.set_weights_constant(topology, 1.0)
    fnss.set_delays_constant(topology, INTERNAL_LINK_DELAY, 'ms')
    # label links as internal or external
    for u, v in topology.edges_iter():
        if u in sources or v in sources:
            topology.edge[u][v]['type'] = 'external'
            fnss.set_delays_constant(topology, EXTERNAL_LINK_DELAY, 'ms', [(u, v)])
        else:
            topology.edge[u][v]['type'] = 'internal'
    cache_placement = uniform_cache_placement(topology, network_cache*n_contents, caches)
    for node, size in cache_placement.iteritems():
        fnss.add_stack(topology, node, 'cache', {'size': size})
    return topology
def on_path_topology():
    """Return topology for testing on-path caching strategies
    """ 
    # Topology sketch
    #
    # 0 ---- 1 ---- 2 ---- 3 ---- 4
    #               |
    #               |
    #               5
    #
    topology = fnss.line_topology(5)
    topology.add_edge(2, 5)
    source = 4
    receivers = (0, 5) 
    caches = (1, 2, 3)
    contents = caches
    fnss.add_stack(topology, source, 'source', {'contents': contents})
    for v in caches:
        fnss.add_stack(topology, v, 'router', {'cache_size': 1})
    for v in receivers:
        fnss.add_stack(topology, v, 'receiver', {})
    return topology
Ejemplo n.º 47
0
 def on_path_topology(cls):
     """Return topology for testing on-path caching strategies
     """
     # Topology sketch
     #
     # 0 ---- 1 ---- 2 ---- 3 ---- 4
     #               |
     #               |
     #               5
     #
     topology = IcnTopology(fnss.line_topology(5))
     topology.add_edge(2, 5)
     source = 4
     receivers = (0, 5)
     caches = (1, 2, 3)
     contents = caches
     fnss.add_stack(topology, source, 'source', {'contents': contents})
     for v in caches:
         fnss.add_stack(topology, v, 'router', {'cache_size': 1})
     for v in receivers:
         fnss.add_stack(topology, v, 'receiver', {})
     return topology
Ejemplo n.º 48
0
def topology_path(n=3, **kwargs):
    """Return a scenario based on path topology
    
    Parameters
    ----------
    seed : int, optional
        The seed used for random number generation
        
    Returns
    -------
    topology : fnss.Topology
        The topology object
    """
    # 240 nodes in the main component
    topology = fnss.line_topology(n)
    receivers = [0]    
    routers = range(1, n-1)
    sources = [n-1]
    topology.graph['icr_candidates'] = set(routers)
    for v in sources:
        fnss.add_stack(topology, v, 'source')
    for v in receivers:
        fnss.add_stack(topology, v, 'receiver')
    for v in routers:
        fnss.add_stack(topology, v, 'router')
    # set weights and delays on all links
    fnss.set_weights_constant(topology, 1.0)
    fnss.set_delays_constant(topology, INTERNAL_LINK_DELAY, 'ms')
    # label links as internal or external
    for u, v in topology.edges_iter():
        if u in sources or v in sources:
            topology.edge[u][v]['type'] = 'external'
            fnss.set_delays_constant(topology, EXTERNAL_LINK_DELAY, 'ms', [(u, v)])
        else:
            topology.edge[u][v]['type'] = 'internal'
    return IcnTopology(topology)
Ejemplo n.º 49
0
"""
Export topology to ns-2
=======================

This example shows how to generate a topology (a line in this case) and export
it to the ns-2 simulator
"""
import fnss

# create a line topology with 10 nodes
topology = fnss.line_topology(10)

# assign capacity of 10 Mbps to each link
fnss.set_capacities_constant(topology, 10, 'Mbps')

# assign delay of 2 ms to each link
fnss.set_delays_constant(topology, 2, 'ms')

# set buffers in each node (use packets, bytes not supported by ns-2)
fnss.set_buffer_sizes_bw_delay_prod(topology, 'packets', 1500)

# Add FTP application to first and last node of the line
tcp_stack_props = {'class': 'Agent/TCP', 'class_': 2, 'fid_': 1}
fnss.add_stack(topology, 0, 'tcp', tcp_stack_props)
fnss.add_stack(topology, 9, 'tcp', tcp_stack_props)

ftp_app_props = {'class': 'Application/FTP', 'type': 'FTP'}
fnss.add_application(topology, 0, 'ftp', ftp_app_props)
fnss.add_application(topology, 9, 'ftp', ftp_app_props)

# export topology to a Tcl script for ns-2
Ejemplo n.º 50
0
def topology_path(n,
                  delay=EXTERNAL_LINK_DELAY / 1000,
                  n_classes=10,
                  min_delay=INTERNAL_LINK_DELAY / 1000,
                  max_delay=EXTERNAL_LINK_DELAY / 1000,
                  **kwargs):
    """Return a path topology with a receiver on node `0` and a source at node
    'n-1'

    Parameters
    ----------
    n : int (>=3)
        The number of nodes
    delay : float
        The link delay in milliseconds

    Returns
    -------
    topology : IcnTopology
        The topology object
    """
    random.seed(0)
    topology = fnss.line_topology(n)
    # set weights and delays on all links
    fnss.set_weights_constant(topology, 1.0)
    fnss.set_delays_constant(topology, min_delay, 'ms')
    routers = topology.nodes()
    # Set the depth of each node to determine which node is the root and the edge
    d = 0
    for i in range(n):
        topology.node[i]['depth'] = d
        d += 1
    # Set the parents of nodes (to make it compatible with the tree topology
    topology.graph['parent'] = [None for x in range(n)]
    topology.graph['type'] = "TREE"
    for u, v in topology.edges_iter():
        if topology.node[u]['depth'] > topology.node[v]['depth']:
            topology.graph['parent'][u] = v
        else:
            topology.graph['parent'][v] = u

        topology.edge[u][v]['type'] = 'internal'
        topology.edge[u][v]['delay'] = delay
        print "Edge between " + repr(u) + " and " + repr(
            v) + " delay: " + repr(topology.edge[u][v]['delay'])

    for v in topology.nodes_iter():
        print "Depth of " + repr(v) + " is " + repr(topology.node[v]['depth'])
    routers = topology.nodes()
    edge_routers = [
        v for v in topology.nodes_iter() if topology.node[v]['depth'] == n - 1
    ]
    topology.graph['icr_candidates'] = set(routers)
    topology.graph['n_classes'] = n_classes
    topology.graph['max_delay'] = 0.0  #[0.0]*n_classes
    topology.graph['min_delay'] = float('inf')  #[0.0]*n_classes
    topology.graph['height'] = n - 1
    topology.graph['link_delay'] = delay
    topology.graph['n_edgeRouters'] = len(edge_routers)
    # Set the receivers (users)
    n_receivers = n_classes
    receivers = ['rec_%d' % i for i in range(n_receivers)]
    root = [
        v for v in topology.nodes_iter() if topology.node[v]['depth'] == 0
    ][0]

    #min_delay = max_delay #this is for number of classes=2; one class has d=0 and the other has d=max
    delays = [None] * n_classes
    for i in range(n_classes):
        #delays[i] = random.uniform(min_delay, max_delay)
        delays[i] = max_delay - i * min_delay
        if delays[i] < 0.0:
            delays[i] = 0.0
        #topology.graph['min_delay'][i] = delays[i]
        #topology.graph['max_delay'][i] = delays[i] + (n)*delay

    # Add receivers (i.e., users) to the topology
    receiver_indx = 0
    for edge_router in edge_routers:
        for j in range(n_classes):
            d = delays[j]
            topology.add_edge(receivers[receiver_indx],
                              edge_router,
                              delay=d,
                              type='internal')
            receiver_indx += 1

    # Set the sources (origin servers)
    n_sources = 1
    sources = ['src_%d' % i for i in range(n_sources)]
    for i in range(n_sources):
        topology.add_edge(sources[i], root, delay=delay, type='internal')

    print "The number of sources: " + repr(n_sources)
    print "The number of receivers: " + repr(n_receivers)

    for v in sources:
        fnss.add_stack(topology, v, 'source')
    for v in receivers:
        fnss.add_stack(topology, v, 'receiver')
    for v in routers:
        fnss.add_stack(topology, v, 'router')
    # label links as internal or external
    for u, v in topology.edges_iter():
        topology.edge[u][v]['type'] = 'internal'

    topology.graph['receivers'] = receivers
    topology.graph['sources'] = sources
    topology.graph['routers'] = routers

    return IcnTopology(topology)