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)
示例#2
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
示例#3
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)
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
 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)
示例#6
0
def topology_four_child_tree(network_cache=0.05, n_contents=100000, seed=None):
    """
    Returns a tree 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
    """
    h = 5  # depth of the tree
    topology = fnss.k_ary_tree_topology(4, h)
    topology.add_node(1365, depth=-1)
    topology.add_path([0, 1365])

    receivers = [
        v for v in topology.nodes_iter() if topology.node[v]['depth'] == h
    ]
    sources = [
        v for v in topology.nodes_iter() if topology.node[v]['depth'] == -1
    ]
    caches = [
        v for v in topology.nodes_iter()
        if topology.node[v]['depth'] >= 0 and topology.node[v]['depth'] < h
    ]
    # 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', {})
    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})
    # 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 topology
示例#7
0
def topology_wide(network_cache=0.05, n_contents=100000, seed=None):
    """
    Return a scenario based on GARR 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
    """
    topology = fnss.parse_topology_zoo(
        path.join(TOPOLOGY_RESOURCES_DIR, 'WideJpn.graphml')).to_undirected()
    # sources are nodes representing neighbouring AS's
    sources = [9, 8, 11, 13, 12, 15, 14, 17, 16, 19, 18]
    # receivers are internal nodes with degree = 1
    receivers = [27, 28, 3, 5, 4, 7]
    # caches are all remaining nodes --> 27 caches
    caches = [n for n in topology.nodes() if n not in receivers + sources]
    # set weights and delays on all links
    fnss.set_weights_constant(topology, 1.0)
    fnss.set_delays_constant(topology, INTERNAL_LINK_DELAY, 'ms')
    # 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', {})
    # label links as internal or external
    for u, v in topology.edges():
        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'
    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
示例#8
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
示例#9
0
def topology_garr(network_cache=0.05, n_contents=100000, seed=None):
    """
    Return a scenario based on GARR 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
    """
    topology = fnss.parse_topology_zoo(path.join(TOPOLOGY_RESOURCES_DIR, 'Garr201201.graphml')).to_undirected()
    # sources are nodes representing neighbouring AS's
    sources = [0, 2, 3, 5, 13, 16, 23, 24, 25, 27, 51, 52, 54]
    # receivers are internal nodes with degree = 1
    receivers = [1, 7, 8, 9, 11, 12, 19, 26, 28, 30, 32, 33, 41, 42, 43, 47, 48, 50, 53, 57, 60]
    # caches are all remaining nodes --> 27 caches
    caches = [n for n in topology.nodes() if n not in receivers + sources]
    # set weights and delays on all links
    fnss.set_weights_constant(topology, 1.0)
    fnss.set_delays_constant(topology, INTERNAL_LINK_DELAY, 'ms')

    # 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', {})
    
    # label links as internal or external
    for u, v in topology.edges():
        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'
    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
示例#10
0
def topology_four_child_tree(network_cache=0.05, n_contents=100000, seed=None):
    """
    Returns a tree 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
    """
    h = 5       # depth of the tree
    topology = fnss.k_ary_tree_topology(4, h)
    topology.add_node(1365, depth=-1)
    topology.add_path([0, 1365])

    receivers = [v for v in topology.nodes_iter()
                 if topology.node[v]['depth'] == h]
    sources = [v for v in topology.nodes_iter()
               if topology.node[v]['depth'] == -1]
    caches = [v for v in topology.nodes_iter()
              if topology.node[v]['depth'] >= 0
              and topology.node[v]['depth'] < h]
    # 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', {})
    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})
    # 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 topology
示例#11
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
示例#12
0
def topology_geant_custom(network_cache=0.05, n_contents=100000, seed=None):
    """
    Return a scenario based on GEANT 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
    """
    topology = fnss.parse_topology_zoo(
        path.join(TOPOLOGY_RESOURCES_DIR,
                  "Geant2012.graphml")).to_undirected()
    topology = list(nx.connected_component_subgraphs(topology))[0]
    deg = nx.degree(topology)

    caches = [v for v in topology.nodes()]  # 38 nodes
    cache_catogory = [
        1, 4, 2, 1, 3, 3, 3, 1, 4, 3, 2, 1, 1, 2, 1, 4, 2, 3, 1, 3, 3, 2, 3, 4,
        4, 2, 3, 1, 3, 1, 3, 1, 3, 1, 1, 3, 1, 1, 4, 1
    ]
    count = 0
    for node in caches:
        fnss.add_stack(topology, node, 'receiver', {})
        count += 1

    # attach sources to topology
    source_attachments = [v for v in topology.nodes()
                          if deg[v] == 2]  # 13 nodes
    sources = []
    for v in source_attachments:
        u = v + 1000  # node ID of source
        topology.add_edge(v, u)
        sources.append(u)
    # randomly allocate contents to sources
    content_placement = uniform_content_placement(topology,
                                                  range(1, n_contents + 1),
                                                  sources,
                                                  seed=seed)
    # add stacks to nodes
    for v in sources:
        fnss.add_stack(topology, v, 'source',
                       {'contents': content_placement[v]})
    # 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'
            # 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'
    # place caches
    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
示例#13
0
def topology_tiscali(network_cache=0.05, n_contents=100000, seed=None):
    """
    Return a scenario based on Tiscali topology, parsed from RocketFuel dataset
    
    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.parse_rocketfuel_isp_map(
        path.join(TOPOLOGY_RESOURCES_DIR, '3257.r0.cch')).to_undirected()
    topology = list(nx.connected_component_subgraphs(topology))[0]
    # degree of nodes
    deg = nx.degree(topology)
    # nodes with degree = 1
    onedeg = [v for v in topology.nodes() if deg[v] == 1]  # they are 80
    # we select as caches nodes with highest degrees
    # we use as min degree 6 --> 36 nodes
    # If we changed min degrees, that would be the number of caches we would have:
    # Min degree    N caches
    #  2               160
    #  3               102
    #  4                75
    #  5                50
    #  6                36
    #  7                30
    #  8                26
    #  9                19
    # 10                16
    # 11                12
    # 12                11
    # 13                 7
    # 14                 3
    # 15                 3
    # 16                 2
    caches = [v for v in topology.nodes() if deg[v] >= 6]  # 36 nodes
    # sources are node with degree 1 whose neighbor has degree at least equal to 5
    # we assume that sources are nodes connected to a hub
    # they are 44
    sources = [
        v for v in onedeg if deg[list(topology.edge[v].keys())[0]] > 4.5
    ]  # they are
    # receivers are node with degree 1 whose neighbor has degree at most equal to 4
    # we assume that receivers are nodes not well connected to the network
    # they are 36
    receivers = [
        v for v in onedeg if deg[list(topology.edge[v].keys())[0]] < 4.5
    ]
    # we set router stacks because some strategies will fail if no stacks
    # are deployed
    routers = [
        v for v in topology.nodes() if v not in caches + sources + receivers
    ]

    # set weights and delays on all links
    fnss.set_weights_constant(topology, 1.0)
    fnss.set_delays_constant(topology, INTERNAL_LINK_DELAY, 'ms')
    # 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', {})
    for v in routers:
        fnss.add_stack(topology, v, 'router', {})

    # label links as internal or external
    for u, v in topology.edges():
        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'

    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
示例#14
0
def topology_tiscali(network_cache=0.05, n_contents=100000, seed=None):
    """
    Return a scenario based on Tiscali topology, parsed from RocketFuel dataset
    
    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.parse_rocketfuel_isp_map(path.join(TOPOLOGY_RESOURCES_DIR,
                                                       '3257.r0.cch')
                                             ).to_undirected()
    topology = nx.connected_component_subgraphs(topology)[0]
    # degree of nodes
    deg = nx.degree(topology)
    # nodes with degree = 1
    onedeg = [v for v in topology.nodes() if deg[v] == 1] # they are 80
    # we select as caches nodes with highest degrees
    # we use as min degree 6 --> 36 nodes
    # If we changed min degrees, that would be the number of caches we would have:
    # Min degree    N caches
    #  2               160
    #  3               102
    #  4                75
    #  5                50
    #  6                36
    #  7                30
    #  8                26
    #  9                19
    # 10                16
    # 11                12
    # 12                11
    # 13                 7
    # 14                 3
    # 15                 3
    # 16                 2
    caches = [v for v in topology.nodes() if deg[v] >= 6] # 36 nodes
    # sources are node with degree 1 whose neighbor has degree at least equal to 5
    # we assume that sources are nodes connected to a hub
    # they are 44
    sources = [v for v in onedeg if deg[list(topology.edge[v].keys())[0]] > 4.5] # they are 
    # receivers are node with degree 1 whose neighbor has degree at most equal to 4
    # we assume that receivers are nodes not well connected to the network
    # they are 36   
    receivers = [v for v in onedeg if deg[list(topology.edge[v].keys())[0]] < 4.5]
    # we set router stacks because some strategies will fail if no stacks
    # are deployed 
    routers = [v for v in topology.nodes() if v not in caches + sources + receivers]

    # set weights and delays on all links
    fnss.set_weights_constant(topology, 1.0)
    fnss.set_delays_constant(topology, INTERNAL_LINK_DELAY, 'ms')
    # 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', {})
    for v in routers:
        fnss.add_stack(topology, v, 'router', {})

    # label links as internal or external
    for u, v in topology.edges():
        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'
            
    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
示例#15
0
def topology_single_cache(network_cache=0.05, n_contents=100000, seed=None):
    """
        Return a scenario based on GEANT 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.parse_topology_zoo(path.join(TOPOLOGY_RESOURCES_DIR,
    #                                             'Geant2012.graphml')
    #                                   ).to_undirected()
    
    numnodes = 2
    topology = fnss.topologies.simplemodels.line_topology(numnodes)
    
    topology = nx.connected_component_subgraphs(topology)[0]
    deg = nx.degree(topology)
    nodes = topology.nodes()
    
    #receivers = [v for v in topology.nodes() if deg[v] == 1] # 8 nodes
    receivers = []
    receivers.append(nodes[0])
    
    #caches = [v for v in topology.nodes() if deg[v] > 2] # 19 nodes
    caches = []
    caches.append(nodes[1])
    
    
    # attach sources to topology
    #source_attachments = [v for v in topology.nodes() if deg[v] == 2] # 13 nodes
    source_attachment = caches[0]
    
    #sources = []
    #for v in source_attachments:
    #    u = v + 1000 # node ID of source
    #    topology.add_edge(v, u)
    #    sources.append(u)
    sources = []
    u = source_attachment + 1000
    sources.append(u)
    topology.add_edge(source_attachment, sources[0])
    
    #routers = [v for v in topology.nodes() if v not in caches + sources + receivers]
    #router = nodes[1]
    
    # randomly allocate contents to sources
    #content_placement = uniform_content_placement(topology, range(1, n_contents+1), sources, seed=seed)
    content_placement = uniform_content_placement(topology, range(1, n_contents+1), sources, seed=seed)
    
    # add stacks to nodes
    for v in sources:
        fnss.add_stack(topology, v, 'source', {'contents': content_placement[v]})
    for v in receivers:
        fnss.add_stack(topology, v, 'receiver', {})

    #fnss.add_stack(topology, source, 'source', {'contents': content_placement[source]})
    #fnss.add_stack(topology, receiver, 'receiver', {})
    #fnss.add_stack(topology, router, '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'
            # 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'

    #topology.edge[source_attachment][source]['type'] = 'external'
    #fnss.set_weights_constant(topology, 1000.0, [(source_attachment, source)])
    #fnss.set_delays_constant(topology, external_link_delay, 'ms', [(source_attachment, source)])
    #topology.edge[receiver][cache]['type'] = 'internal'
    #topology.edge[router][cache]['type'] = 'internal'
    
    
    # place caches
    #cache_placement = uniform_cache_placement(topology, network_cache*n_contents, caches)
    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
示例#16
0
def topology_grid(network_cache=0.35, n_contents=100000, seed=None):
    # This gives you a 2D grid topology 3x2
    topology = fnss.Topology(nx.grid_2d_graph(10,10))
    # If you want a 3D grid topology, use this command instead
    # This create a 4x3x2 3D grid
    # topology = fnss.Topology(nx.grid_graph([4,3,2]))
    # TODO: Here place caches, content sources, receivers.
    # See other topology generators as examples
    topology = nx.connected_component_subgraphs(topology)[0]
    deg = nx.degree(topology)
    nodes = topology.nodes()
    num_sources = 4
    num_receivers = 30
    source_attachments = []
    sources = []
    receivers = []
    caches = []

    chosen_attachments = 0
    chosen_receivers = 0

    # Random pacement of SOURCES
    completed = False
    while (completed == False):
        x = random.choice(nodes)
        if x in source_attachments:
            continue
        else:
            source_attachments.append(x)
            chosen_attachments += 1
        if chosen_attachments == num_attachments:
            completed = True

    for v in source_attachments:
        u = v + 1000 # node ID of source
        topology.add_edge(v, u)
        sources.append(u)

    # Random placement of RECEIVERS
    completed = False
    while (completed == False):
        x = random.choice(nodes)
        if x in source_attachments:
            continue
        else:
            receivers.append(x)
            chosen_receivers += 1
        if chosen_receivers == num_receivers:
            completed = True

    # Placement of RECEIVERS
    caches = [v for v in nodes if v not in receivers]

    # randomly allocate contents to sources
    content_placement = uniform_content_placement(topology, range(1, n_contents+1), sources, seed=seed)

    # add stacks to nodes
    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'
            # 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'
                
    # place caches
    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
示例#17
0
def topology_geant_custom(network_cache=0.05, n_contents=100000, seed=None):
    """
    Return a scenario based on GEANT 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
    """
    topology = fnss.parse_topology_zoo(path.join(TOPOLOGY_RESOURCES_DIR,
                                                 "Geant2012.graphml")
                                       ).to_undirected()
    topology = list(nx.connected_component_subgraphs(topology))[0]
    deg = nx.degree(topology)

    caches = [v for v in topology.nodes()]  # 38 nodes
    cache_catogory = [1,4,2,1,3,3,3,1,4,3,2,1,1,2,1,4,2,3,1,3,3,2,3,4,4,2,3,1,3,1,3,1,3,1,1,3,1,1,4,1]
    count = 0
    for node in caches:
        fnss.add_stack(topology, node, 'receiver', {})
        count += 1

    # attach sources to topology
    source_attachments = [v for v in topology.nodes() if deg[v] == 2]  # 13 nodes
    sources = []
    for v in source_attachments:
        u = v + 1000  # node ID of source
        topology.add_edge(v, u)
        sources.append(u)
    # randomly allocate contents to sources
    content_placement = uniform_content_placement(topology, range(1, n_contents+1), sources, seed=seed)
    # add stacks to nodes
    for v in sources:
        fnss.add_stack(topology, v, 'source', {'contents': content_placement[v]})
    # 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'
            # 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'
    # place caches 
    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