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
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)
def test_p_median_unsorted(self): """ Test topology: A ---- C ---- B ----[HIGH DIST] --- E --- D --- F Expected facilities: 1, 4 """ t = fnss.Topology() nx.add_path(t, "ACBEDF") fnss.set_weights_constant(t, 1) fnss.set_weights_constant(t, 2, [("B", "E")]) distances = dict(nx.all_pairs_dijkstra_path_length(t, weight='weight')) allocation, facilities, cost = algorithms.compute_p_median( distances, 2) assert { "A": "C", "B": "C", "C": "C", "D": "D", "E": "D", "F": "D", } == allocation assert set("CD") == facilities assert 4 == cost
def test_p_median(self): """ Test topology: A ---- B ---- C ----[HIGH DIST] --- D --- E --- F Expected facilities: 1, 4 """ t = fnss.Topology() nx.add_path(t, "ABCDEF") fnss.set_weights_constant(t, 1) fnss.set_weights_constant(t, 2, [("C", "D")]) distances = dict(nx.all_pairs_dijkstra_path_length(t, weight='weight')) allocation, facilities, cost = algorithms.compute_p_median( distances, 2) self.assertDictEqual( { "A": "B", "B": "B", "C": "B", "D": "E", "E": "E", "F": "E", }, allocation) self.assertSetEqual(set("BE"), facilities) self.assertEqual(4, cost)
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)
def topology_garr2(**kwargs): """Return a scenario based on GARR topology. Differently from plain GARR, this topology some receivers are appended to routers and only a subset of routers which are actually on the path of some traffic are selected to become ICN routers. These changes make this topology more realistic. Parameters ---------- 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 ] # routers are all remaining nodes --> 27 caches routers = [ n for n in topology.nodes_iter() if n not in receivers + sources ] artificial_receivers = list(range(1000, 1000 + len(routers))) for i in range(len(routers)): topology.add_edge(routers[i], artificial_receivers[i]) receivers += artificial_receivers # Caches to nodes with degree > 3 (after adding artificial receivers) degree = nx.degree(topology) icr_candidates = [n for n in topology.nodes_iter() if degree[n] > 3.5] # set weights and delays on all links fnss.set_weights_constant(topology, 1.0) fnss.set_delays_constant(topology, INTERNAL_LINK_DELAY, 'ms') # Deploy stacks topology.graph['icr_candidates'] = set(icr_candidates) 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(): 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' return IcnTopology(topology)
def topology_fiveNode(**kwargs): """Return a scenario based on Five_Node topology. This functions the similar as the GEANT topology but with only 5 nodes All routers are given caches Sources are added on initilization in addition to the main network to all nodes with 2 connections Parameters ---------- seed : int, optional The seed used for random number generation Returns ------- topology : fnss.Topology The topology object """ # 5 nodes topology = fnss.parse_topology_zoo( path.join(TOPOLOGY_RESOURCES_DIR, 'SixNode.graphml')).to_undirected() topology = list(nx.connected_component_subgraphs(topology))[0] deg = nx.degree(topology) receivers = [v for v in topology.nodes() if deg[v] == 1] # 8 nodes # 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) routers = [v for v in topology.nodes() if v not in sources + receivers] # Put caches in nodes with top betweenness centralities betw = nx.betweenness_centrality(topology) routers = sorted(routers, key=lambda k: betw[k]) # Select as ICR candidates all routers icr_candidates = routers # add stacks to nodes topology.graph['icr_candidates'] = set(icr_candidates) 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' # 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' return IcnTopology(topology)
def topology_geant2(**kwargs): """Return a scenario based on GEANT topology. Differently from plain GEANT, this topology some receivers are appended to routers and only a subset of routers which are actually on the path of some traffic are selected to become ICN routers. These changes make this topology more realistic. Parameters ---------- seed : int, optional The seed used for random number generation Returns ------- topology : fnss.Topology The topology object """ # 53 nodes 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) receivers = [v for v in topology.nodes() if deg[v] == 1] # 8 nodes # 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) routers = [v for v in topology.nodes() if v not in sources + receivers] # Put caches in nodes with top betweenness centralities betw = nx.betweenness_centrality(topology) routers = sorted(routers, key=lambda k: betw[k]) # Select as ICR candidates the top 50% routers for betweenness centrality icr_candidates = routers[len(routers) // 2:] # add stacks to nodes topology.graph['icr_candidates'] = set(icr_candidates) 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' # 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' return IcnTopology(topology)
def topology_ds2os(**kwargs): # pass edge list to create topology (alternatively pass NetworkX object) agents = ['agent' + str(id) for id in range(1, 7)] # [agent1, agent2, ..., agent6] edges = [ # main edges between KAs/rooms ('agent1', 'agent2'), # BedroomChildren, BedroomParents ('agent2', 'agent6'), # BedroomParents, Bathroom ('agent2', 'agent4'), # BedroomParents, Kitchen # ('agent3', 'agent6'), # Dinningroom, Bathroom ('agent4', 'agent5'), # Kitchen, Garage ('agent4', 'agent3'), # Kitchen, Dinningroom ] rooms = [ ['movement1', 'questioningservice1', 'tempin1', 'lightcontrol1'], # ka1, BedroomChildren ['movement2', 'questioningservice2', 'tempin2', 'lightcontrol2'], # ka2, BedroomParents [ 'heatingcontrol1', 'doorlock1', 'questioningservice3', 'movement3', 'tempin3', 'lightcontrol3' ], # ka3, Dinningroom ['tempin4', 'lightcontrol4', 'movement4', 'battery3'], # ka4, Kitchen ['tempin5', 'battery1', 'movement5', 'lightcontrol5', 'battery2'], # ka5, Garage ['tempin6', 'washingmachine1', 'lightcontrol6', 'movement6'], # ka6, Bathroom ] for i, agent in enumerate(agents): connectedServices = rooms[i] # print(agent, 'is connected to', connectedServices) for service in connectedServices: edges.append((agent, service)) # e.g. ('agent1', 'movement1') if not service.startswith('questioningservice' ): # questioningservices only read data edges.append( (service, service + '/source')) # e.g. ('movement1', 'movement1/source') edges.append( (service, service + '/receiver')) # e.g. ('movement1', 'movement1/receiver') topology = fnss.Topology(data=edges) for node in topology.nodes(): stack = 'source' if node.endswith('source') else ( 'receiver' if node.endswith('receiver') else 'router') fnss.add_stack(topology, node, stack) topology.graph['icr_candidates'] = set(agents) # only cache at agents fnss.set_weights_constant(topology, 1.0) fnss.set_delays_constant(topology, INTERNAL_LINK_DELAY, 'ms') return IcnTopology(topology)
def topology_fiveNode(**kwargs): """Return a scenario based on Five_Node topology. This functions the similar as the GEANT topology but with only 5 nodes All routers are given caches Sources are added on initilization in addition to the main network to all nodes with 2 connections Parameters ---------- seed : int, optional The seed used for random number generation Returns ------- topology : fnss.Topology The topology object """ # 5 nodes topology = fnss.parse_topology_zoo(path.join(TOPOLOGY_RESOURCES_DIR, 'SixNode.graphml') ).to_undirected() topology = list(nx.connected_component_subgraphs(topology))[0] deg = nx.degree(topology) receivers = [v for v in topology.nodes() if deg[v] == 1] # 8 nodes # 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) routers = [v for v in topology.nodes() if v not in sources + receivers] # Put caches in nodes with top betweenness centralities betw = nx.betweenness_centrality(topology) routers = sorted(routers, key=lambda k: betw[k]) # Select as ICR candidates all routers icr_candidates = routers # add stacks to nodes topology.graph['icr_candidates'] = set(icr_candidates) 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' # 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' return IcnTopology(topology)
def topology_geant2(**kwargs): """Return a scenario based on GEANT topology. Differently from plain GEANT, this topology some receivers are appended to routers and only a subset of routers which are actually on the path of some traffic are selected to become ICN routers. These changes make this topology more realistic. Parameters ---------- seed : int, optional The seed used for random number generation Returns ------- topology : fnss.Topology The topology object """ # 53 nodes 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) receivers = [v for v in topology.nodes() if deg[v] == 1] # 8 nodes # 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) routers = [v for v in topology.nodes() if v not in sources + receivers] # Put caches in nodes with top betweenness centralities betw = nx.betweenness_centrality(topology) routers = sorted(routers, key=lambda k: betw[k]) # Select as ICR candidates the top 50% routers for betweenness centrality icr_candidates = routers[len(routers)//2:] # add stacks to nodes topology.graph['icr_candidates'] = set(icr_candidates) 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' # 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' return IcnTopology(topology)
def test_clear_weights(self): # create new topology to avoid parameters pollution G = fnss.star_topology(12) fnss.set_weights_constant(G, 3, None) self.assertEqual(G.number_of_edges(), len(nx.get_edge_attributes(G, 'weight'))) fnss.clear_weights(G) self.assertEqual(0, len(nx.get_edge_attributes(G, 'weight')))
def generate_topo(n): topo = nx.powerlaw_cluster_graph(n,2,0.08) # topo = fnss.waxman_1_topology(n=50,alpha=0.6,beta=0.3) # topo = fnss.fat_tree_topology(n) fnss.set_weights_constant(topo,1) fnss.set_delays_constant(topo, 1, 'ms') fnss.set_capacities_edge_betweenness(topo,[100,500,1000],'Mbps') fnss.write_topology(topo,'topo_pl_50.xml')
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
def topology_garr2(**kwargs): """Return a scenario based on GARR topology. Differently from plain GARR, this topology some receivers are appended to routers and only a subset of routers which are actually on the path of some traffic are selected to become ICN routers. These changes make this topology more realistic. Parameters ---------- 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] # routers are all remaining nodes --> 27 caches routers = [n for n in topology.nodes_iter() if n not in receivers + sources] artificial_receivers = list(range(1000, 1000 + len(routers))) for i in range(len(routers)): topology.add_edge(routers[i], artificial_receivers[i]) receivers += artificial_receivers # Caches to nodes with degree > 3 (after adding artificial receivers) degree = nx.degree(topology) icr_candidates = [n for n in topology.nodes_iter() if degree[n] > 3.5] # set weights and delays on all links fnss.set_weights_constant(topology, 1.0) fnss.set_delays_constant(topology, INTERNAL_LINK_DELAY, 'ms') # Deploy stacks topology.graph['icr_candidates'] = set(icr_candidates) 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(): 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' return IcnTopology(topology)
def topology_geant(**kwargs): """Return a scenario based on GEANT 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.parse_topology_zoo( path.join(TOPOLOGY_RESOURCES_DIR, 'Geant2012.graphml')).to_undirected() topology = list(nx.connected_component_subgraphs(topology))[0] deg = nx.degree(topology) receivers = [v for v in topology.nodes() if deg[v] == 1] # 8 nodes icr_candidates = [v for v in topology.nodes() if deg[v] > 2] # 19 nodes # 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) routers = [v for v in topology.nodes() if v not in sources + receivers] # add stacks to nodes topology.graph['icr_candidates'] = set(icr_candidates) 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' # 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' return IcnTopology(topology)
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
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 topology_garr(**kwargs): """Return a scenario based on GARR topology Parameters ---------- 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 routers = [n for n in topology.nodes() if n not in receivers + sources] icr_candidates = routers # set weights and delays on all links fnss.set_weights_constant(topology, 1.0) fnss.set_delays_constant(topology, INTERNAL_LINK_DELAY, 'ms') # Deploy stacks topology.graph['icr_candidates'] = set(icr_candidates) 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(): 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' return IcnTopology(topology)
def test_p_median_3(self): # Test topology: # # A ---- C ---- B ----[HIGH DIST] --- E --- D --- F # # Expected facilities: 1, 4 t = fnss.Topology() nx.add_path(t, "ACBEDF") fnss.set_weights_constant(t, 1) fnss.set_weights_constant(t, 2, [("B", "E")]) distances = dict(nx.all_pairs_dijkstra_path_length(t, weight='weight')) allocation, facilities, cost = algorithms.compute_p_median( distances, 3) assert cost == 3
def parse(topo_path, xml_path, delay, buffer_type): topology = fnss.parse_topology_zoo(topo_path) topology = topology.to_undirected() fnss.set_capacities_edge_betweenness(topology, [200, 500, 1000], 'Mbps') # TODO: hardcode now fnss.set_weights_constant(topology, 1) fnss.set_delays_constant(topology, delay, 'ms') if buffer_type == 'bdp': fnss.set_buffer_sizes_bw_delay_prod(topology, 'packet', 1500) elif buffer_type == 'bw': fnss.set_buffer_sizes_link_bandwidth(topology, buffer_unit='packet') else: fnss.set_buffer_sizes_constant(topology, 1500, 'packet') fnss.write_topology(topology, xml_path)
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
def topology_geant(**kwargs): """Return a scenario based on GEANT 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.parse_topology_zoo(path.join(TOPOLOGY_RESOURCES_DIR, 'Geant2012.graphml') ).to_undirected() topology = list(nx.connected_component_subgraphs(topology))[0] deg = nx.degree(topology) receivers = [v for v in topology.nodes() if deg[v] == 1] # 8 nodes icr_candidates = [v for v in topology.nodes() if deg[v] > 2] # 19 nodes # 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) routers = [v for v in topology.nodes() if v not in sources + receivers] # add stacks to nodes topology.graph['icr_candidates'] = set(icr_candidates) 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' # 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' return IcnTopology(topology)
def topology_tree_HX(k, h, delay=1, **kwargs): """Returns a tree topology, with a source at the root, receivers at the leafs and caches at all intermediate nodes. Parameters ---------- h : int The height of the tree k : int The branching factor of the tree delay : float The link delay in milliseconds Returns ------- topology : IcnTopology The topology object """ topology = fnss.k_ary_tree_topology(k, h) topology.add_path([0, 40]) topology.node[40]['depth'] = -1 receivers = [ v for v in topology.nodes_iter() if topology.node[v]['depth'] == h ] sources = [40] routers = [ v for v in topology.nodes_iter() if topology.node[v]['depth'] >= 0 and topology.node[v]['depth'] < h ] 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, 4, 'ms') fnss.set_delays_constant(topology, 8, 'ms', [(0, 1), (0, 2), (0, 3), (1, 0), (2, 0), (3, 0)]) # label links as internal for u, v in topology.edges_iter(): if u in sources or v in sources: topology.edge[u][v]['type'] = 'external' else: topology.edge[u][v]['type'] = 'internal' return IcnTopology(topology)
def test_p_median_4(self): """ Test topology: A ---- C ---- B ----[HIGH DIST] --- E --- D --- F Expected facilities: 1, 4 """ t = fnss.Topology() nx.add_path(t, "ACBEDF") fnss.set_weights_constant(t, 1) fnss.set_weights_constant(t, 2, [("B", "E")]) distances = dict(nx.all_pairs_dijkstra_path_length(t, weight='weight')) allocation, facilities, cost = algorithms.compute_p_median(distances, 4) self.assertEqual(2, cost)
def test_p_median_4(self): """ Test topology: A ---- C ---- B ----[HIGH DIST] --- E --- D --- F Expected facilities: 1, 4 """ t = fnss.Topology() t.add_path("ACBEDF") fnss.set_weights_constant(t, 1) fnss.set_weights_constant(t, 2, [("B", "E")]) distances = dict(nx.all_pairs_dijkstra_path_length(t, weight='weight')) allocation, facilities, cost = algorithms.compute_p_median(distances, 4) self.assertEqual(2, cost)
def topology_mesh(n, m, delay_int=1, delay_ext=5, **kwargs): """Returns a ring topology This topology is comprised of a mesh of *n* nodes. Each of these nodes is attached to a receiver. In addition *m* router are attached each to a source. Therefore, this topology has in fact 2n + m nodes. Parameters ---------- n : int The number of routers in the ring m : int The number of sources delay_int : float The internal link delay in milliseconds delay_ext : float The external link delay in milliseconds Returns ------- topology : IcnTopology The topology object """ if m > n: raise ValueError("m cannot be greater than n") topology = fnss.full_mesh_topology(n) routers = range(n) receivers = range(n, 2 * n) sources = range(2 * n, 2 * n + m) internal_links = zip(routers, receivers) external_links = zip(routers[:m], sources) for u, v in internal_links: topology.add_edge(u, v, type='internal') for u, v in external_links: topology.add_edge(u, v, type='external') 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_int, 'ms', internal_links) fnss.set_delays_constant(topology, delay_ext, 'ms', external_links) return IcnTopology(topology)
def test_p_median(self): """ Test topology: A ---- B ---- C ----[HIGH DIST] --- D --- E --- F Expected facilities: 1, 4 """ t = fnss.Topology() nx.add_path(t, "ABCDEF") fnss.set_weights_constant(t, 1) fnss.set_weights_constant(t, 2, [("C", "D")]) distances = dict(nx.all_pairs_dijkstra_path_length(t, weight='weight')) allocation, facilities, cost = algorithms.compute_p_median(distances, 2) self.assertDictEqual({"A": "B", "B": "B", "C": "B", "D": "E", "E": "E", "F": "E", }, allocation) self.assertSetEqual(set("BE"), facilities) self.assertEqual(4, cost)
def topology_tree_with_uCache(k, h, delay=1, **kwargs): """Returns a tree topology, with a source at the root, receivers at the leafs and caches at the receivers and routers. Parameters ---------- h : int The height of the tree k : int The branching factor of the tree delay : float The link delay in milliseconds Returns ------- topology : IcnTopology The topology object """ topology = fnss.k_ary_tree_topology(k, h) 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'] == 0 ] routers = [ v for v in topology.nodes_iter() if topology.node[v]['depth'] > 0 and topology.node[v]['depth'] < h ] topology.graph['icr_candidates'] = set(routers) topology.graph['uCache_candidates'] = set(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') # 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 for u, v in topology.edges_iter(): topology.edge[u][v]['type'] = 'internal' return IcnTopology(topology)
def topology_ring(n, delay_int=1, delay_ext=5, **kwargs): """Returns a ring topology This topology is comprised of a ring of *n* nodes. Each of these nodes is attached to a receiver. In addition one router is attached to a source. Therefore, this topology has in fact 2n + 1 nodes. It models the case of a metro ring network, with many receivers and one only source towards the core network. Parameters ---------- n : int The number of routers in the ring delay_int : float The internal link delay in milliseconds delay_ext : float The external link delay in milliseconds Returns ------- topology : IcnTopology The topology object """ topology = fnss.ring_topology(n) topology.graph['type'] = "TREE" routers = range(n) receivers = range(n, 2 * n) source = 2 * n internal_links = zip(routers, receivers) external_links = [(routers[0], source)] for u, v in internal_links: topology.add_edge(u, v, type='internal') for u, v in external_links: topology.add_edge(u, v, type='external') topology.graph['icr_candidates'] = set(routers) fnss.add_stack(topology, source, '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_int, 'ms', internal_links) fnss.set_delays_constant(topology, delay_ext, 'ms', external_links) return IcnTopology(topology)
def topology_wide(**kwargs): """Return a scenario based on GARR topology Parameters ---------- 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 routers = [n for n in topology.nodes() if n not in receivers + sources] # All routers can be upgraded to ICN functionalities icr_candidates = routers # set weights and delays on all links fnss.set_weights_constant(topology, 1.0) fnss.set_delays_constant(topology, INTERNAL_LINK_DELAY, 'ms') # Deploy stacks topology.graph['icr_candidates'] = set(icr_candidates) 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(): if u in sources or v in sources: topology.adj[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.adj[u][v]['type'] = 'internal' return IcnTopology(topology)
def topology_hierarchy(k, h, delay=1, **kwargs): """Returns a tree topology, with a source at the root, receivers at the leafs and caches at all intermediate nodes. Parameters ---------- h : int The height of the tree k : int The branching factor of the tree delay : float The link delay in milliseconds Returns ------- topology : IcnTopology The topology object """ topology = fnss.k_ary_tree_topology(k, h) receivers = [v for v in topology.nodes() if topology.node[v]['depth'] == h] sources = [v for v in topology.nodes() if topology.node[v]['depth'] == 0] routers = [v for v in topology.nodes() if topology.node[v]['depth'] > 0 and topology.node[v]['depth'] < h] 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') # label links as internal for u, v in topology.edges(): topology.adj[u][v]['type'] = 'external' if u in sources or v in sources else 'internal' # for u, v in path_links(routers): # topology.add_edge(u, v, type='internal') # set weights and delays on all links fnss.set_weights_constant(topology, 1.0) fnss.set_delays_constant(topology, delay, 'ms', [(u, v) for u, v in topology.edges() if u in receivers or v in receivers]) fnss.set_delays_constant(topology, 10*delay, 'ms', [(u, v) for u, v in topology.edges() if u in routers and v in routers]) fnss.set_delays_constant(topology, 60*delay, 'ms', [(u, v) for u, v in topology.edges() if u in sources or v in sources]) return IcnTopology(topology)
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)
def my_topology(cls): """Return my topology for testing caching strategies """ # Topology sketch # 0 # / \ # / \ # / \ # 1 2 # / \ / \ # 3 4 5 6 # / \ / \ / \ / \ # 7 8 9 10 11 1213 14 # k = 2 h = 3 delay = 5 topology = IcnTopology(fnss.k_ary_tree_topology(k, h)) 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'] == 0 ] routers = [ v for v in topology.nodes_iter() if topology.node[v]['depth'] > 0 and topology.node[v]['depth'] < h ] topology.graph['icr_candidates'] = set(routers) for v in receivers: fnss.add_stack(topology, v, 'receiver') for v in routers: fnss.add_stack(topology, v, 'router', {'cache_size': 2}) contents = (1, 2, 3) fnss.add_stack(topology, source, 'source', {'contents': contents}) # set weights and delays on all links fnss.set_weights_constant(topology, 1.0) fnss.set_delays_constant(topology, delay, 'ms') fnss.set_delays_constant(topology, 20, 'ms', [(0, 1), (0, 2)]) # label links as internal for u, v in topology.edges_iter(): topology.edge[u][v]['type'] = 'internal' return IcnTopology(topology)
def test_p_median_6(self): """ Test topology: A ---- C ---- B ----[HIGH DIST] --- E --- D --- F Expected facilities: 1, 4 """ t = fnss.Topology() t.add_path("ACBEDF") fnss.set_weights_constant(t, 1) fnss.set_weights_constant(t, 2, [("B", "E")]) distances = nx.all_pairs_dijkstra_path_length(t, weight='weight') allocation, facilities, cost = algorithms.compute_p_median( distances, 6) self.assertDictEqual({i: i for i in "ABCDEF"}, allocation) self.assertSetEqual(set("ABCDEF"), facilities) self.assertEqual(0, cost)
def test_p_median_6(self): """ Test topology: A ---- C ---- B ----[HIGH DIST] --- E --- D --- F Expected facilities: 1, 4 """ t = fnss.Topology() nx.add_path(t, "ACBEDF") fnss.set_weights_constant(t, 1) fnss.set_weights_constant(t, 2, [("B", "E")]) distances = dict(nx.all_pairs_dijkstra_path_length(t, weight='weight')) allocation, facilities, cost = algorithms.compute_p_median( distances, 6) assert {i: i for i in "ABCDEF"} == allocation assert set("ABCDEF") == facilities assert 0 == cost
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 topology_garr(**kwargs): """Return a scenario based on GARR topology Parameters ---------- 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 routers = [n for n in topology.nodes() if n not in receivers + sources] icr_candidates = routers # set weights and delays on all links fnss.set_weights_constant(topology, 1.0) fnss.set_delays_constant(topology, INTERNAL_LINK_DELAY, 'ms') # Deploy stacks topology.graph['icr_candidates'] = set(icr_candidates) 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(): 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' return IcnTopology(topology)
def topology_wide(**kwargs): """Return a scenario based on WIDE topology Parameters ---------- 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 routers = [n for n in topology.nodes() if n not in receivers + sources] # All routers can be upgraded to ICN functionalitirs icr_candidates = routers # set weights and delays on all links fnss.set_weights_constant(topology, 1.0) fnss.set_delays_constant(topology, INTERNAL_LINK_DELAY, 'ms') # Deploy stacks topology.graph['icr_candidates'] = set(icr_candidates) 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(): 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' return IcnTopology(topology)
def test_base_topology_class(self): weight = 2 capacity = 3 delay = 4 buffer_size = 5 topology = fnss.Topology() topology.add_path([1, 2, 3]) fnss.set_weights_constant(topology, weight) fnss.set_capacities_constant(topology, capacity) fnss.set_delays_constant(topology, delay) fnss.set_buffer_sizes_constant(topology, buffer_size) weights = topology.weights() capacities = topology.capacities() delays = topology.delays() buffer_sizes = topology.buffers() for e in topology.edges_iter(): self.assertEqual(weight, weights[e]) self.assertEqual(capacity, capacities[e]) self.assertEqual(delay, delays[e]) self.assertEqual(buffer_size, buffer_sizes[e])
def test_base_topology_class(self): weight = 2 capacity = 3 delay = 4 buffer_size = 5 topology = fnss.Topology() topology.add_path([1, 2, 3]) fnss.set_weights_constant(topology, weight) fnss.set_capacities_constant(topology, capacity) fnss.set_delays_constant(topology, delay) fnss.set_buffer_sizes_constant(topology, buffer_size) weights = topology.weights() capacities = topology.capacities() delays = topology.delays() buffer_sizes = topology.buffers() for e in topology.edges(): self.assertEqual(weight, weights[e]) self.assertEqual(capacity, capacities[e]) self.assertEqual(delay, delays[e]) self.assertEqual(buffer_size, buffer_sizes[e])
def topology_binary_tree(**kwargs): """Returns a tree topology Parameters ---------- 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(2, h) 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'] == 0] routers = [v for v in topology.nodes_iter() if topology.node[v]['depth'] > 0 and topology.node[v]['depth'] < h] 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)
def topology_tree(k, h, delay=1, **kwargs): """Returns a tree topology, with a source at the root, receivers at the leafs and caches at all intermediate nodes. Parameters ---------- h : height The height of the tree k : branching factor The branching factor of the tree delay : float The link delay in milliseconds Returns ------- topology : IcnTopology The topology object """ topology = fnss.k_ary_tree_topology(k, h) 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'] == 0] routers = [v for v in topology.nodes_iter() if topology.node[v]['depth'] > 0 and topology.node[v]['depth'] < h] 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 for u, v in topology.edges_iter(): topology.edge[u][v]['type'] = 'internal' return IcnTopology(topology)
def topology_tree(k, h, delay=1, **kwargs): """Returns a tree topology, with a source at the root, receivers at the leafs and caches at all intermediate nodes. Parameters ---------- h : int The height of the tree k : int The branching factor of the tree delay : float The link delay in milliseconds Returns ------- topology : IcnTopology The topology object """ topology = fnss.k_ary_tree_topology(k, h) receivers = [v for v in topology.nodes() if topology.node[v]["depth"] == h] sources = [v for v in topology.nodes() if topology.node[v]["depth"] == 0] routers = [ v for v in topology.nodes() if topology.node[v]["depth"] > 0 and topology.node[v]["depth"] < h ] 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 for u, v in topology.edges(): topology.adj[u][v]["type"] = "internal" return IcnTopology(topology)
def test_p_median(self): # Test topology: # # A ---- B ---- C ----[HIGH DIST] --- D --- E --- F # # Expected facilities: 1, 4 t = fnss.Topology() nx.add_path(t, "ABCDEF") fnss.set_weights_constant(t, 1) fnss.set_weights_constant(t, 2, [("C", "D")]) distances = dict(nx.all_pairs_dijkstra_path_length(t, weight='weight')) allocation, facilities, cost = algorithms.compute_p_median( distances, 2) assert allocation == { "A": "B", "B": "B", "C": "B", "D": "E", "E": "E", "F": "E", } assert facilities == set("BE") assert cost == 4
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)
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
def test_weights_constant(self): fnss.set_weights_constant(self.topo, 2, self.odd_links) fnss.set_weights_constant(self.topo, 5, self.even_links) self.assertTrue( all(self.topo.adj[u][v]['weight'] in [2, 5] for (u, v) in self.topo.edges()))
""" import fnss import networkx as nx # create a topology with 10 core switches, 20 edge switches and 10 hosts # per switch (i.e. 200 hosts in total) topology = fnss.two_tier_topology(n_core=10, n_edge=20, n_hosts=10) # assign capacities # let's set links connecting servers to edge switches to 1 Gbps # and links connecting core and edge switches to 10 Gbps. # get list of core_edge links and edge_leaf links link_types = nx.get_edge_attributes(topology, 'type') core_edge_links = [link for link in link_types if link_types[link] == 'core_edge'] edge_leaf_links = [link for link in link_types if link_types[link] == 'edge_leaf'] # assign capacities fnss.set_capacities_constant(topology, 1, 'Gbps', edge_leaf_links) fnss.set_capacities_constant(topology, 10, 'Gbps', core_edge_links) # assign weight 1 to all links fnss.set_weights_constant(topology, 1) # assign delay of 10 nanoseconds to each link fnss.set_delays_constant(topology, 10, 'ns') # save topology to a file fnss.write_topology(topology, 'datacenter_topology.xml')
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
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
def topology_grid(nc=0.35, **kwargs): T = 'GRID' # name of the topology topology = fnss.Topology(nx.grid_2d_graph(10,10)) topology = list(nx.connected_component_subgraphs(topology))[0] deg = nx.degree(topology) nodes = topology.nodes() print "Number of NODES #" print len(nodes) receivers = [] routers = [] #sources = [2] source_attachment = random.choice(nodes) source = source_attachment + (1000,1000) topology.add_edge(source_attachment, source) sources = [source] # Random placement of RECEIVERS num_receivers = 30 chosen_receivers = 0 completed = False #print "RECEIVERS" while (completed == False): x = random.choice(nodes) if x == source_attachment: continue else: if x not in receivers: receivers.append(x) chosen_receivers += 1 if chosen_receivers == num_receivers: completed = True # Placement of Routers routers = [v for v in nodes if v not in receivers] print "Number of CLIENTS #" print len(receivers) print "Number of ROUTERS #" print len(routers) 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)
#!/usr/bin/env python # -*- coding: utf-8 -*- #Import the libriraies import fnss import networkx as nx #Create SN #Read the Topology from the BRITE file topology = fnss.parse_brite("bigSN.brite") #Set weight to 1 fnss.set_weights_constant(topology, 1) #Create a Grapth based on the topology read SN = nx.Graph(topology) for n in SN.nodes(): SN.node[n]['sync'] = False SN.node[n]['max_cpu'] = 100 SN.node[n]['cur_cpu'] = 100 SN.node[n]['idle'] = True for u, v in SN.edges(): SN.edge[u][v]['sync'] = False SN.edge[u][v]['max_bw'] = 1000 SN.edge[u][v]['cur_bw'] = 1000 #Create Virtual Network 1 topology = fnss.parse_brite("VN1.brite") #Set weight to 1
def scenario_geant(net_cache=[0.05], n_contents=100000, alpha=[0.6, 0.8, 1.0]): """ Return a scenario based on GARR topology Parameters ---------- scenario_id : str String identifying the scenario (will be in the filename) net_cache : float Size of network cache (sum of all caches) normalized by size of content population n_contents : int Size of content population alpha : float List of alpha of Zipf content distribution """ rate = 12.0 warmup = 9000 duration = 36000 T = 'GEANT' # name of the topology # 240 nodes in the main component topology = fnss.parse_topology_zoo(path.join(scenarios_dir, 'resources/Geant2012.graphml')).to_undirected() topology = nx.connected_component_subgraphs(topology)[0] deg = nx.degree(topology) receivers = [v for v in topology.nodes() if deg[v] == 1] # 8 nodes caches = [v for v in topology.nodes() if deg[v] > 2] # 19 nodes # 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) routers = [v for v in topology.nodes() if v not in caches + sources + receivers] # randomly allocate contents to sources contents = dict([(v, []) for v in sources]) for c in range(1, n_contents + 1): s = choice(sources) contents[s].append(c) for v in sources: fnss.add_stack(topology, v, 'source', {'contents': contents[v]}) 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(): 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' for nc in net_cache: size = (float(nc)*n_contents)/len(caches) # size of a single cache C = str(nc) for v in caches: fnss.add_stack(topology, v, 'cache', {'size': size}) fnss.write_topology(topology, path.join(scenarios_dir, topo_prefix + 'T=%s@C=%s' % (T, C) + '.xml')) print('[WROTE TOPOLOGY] T: %s, C: %s' % (T, C)) for a in alpha: event_schedule = gen_req_schedule(receivers, rate, warmup, duration, n_contents, a) fnss.write_event_schedule(event_schedule, path.join(scenarios_dir, es_prefix + 'T=%s@A=%s' % (T, str(a)) + '.xml')) print('[WROTE SCHEDULE] T: %s, Alpha: %s, Events: %d' % (T, str(a), len(event_schedule)))
def topology_tiscali2(**kwargs): """Return a scenario based on Tiscali topology, parsed from RocketFuel dataset Differently from plain Tiscali, this topology some receivers are appended to routers and only a subset of routers which are actually on the path of some traffic are selected to become ICN routers. These changes make this topology more realistic. 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.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 icr_candidates = [v for v in topology.nodes() if deg[v] >= 6] # 36 nodes # Add remove caches to adapt betweenness centrality of caches for i in [181, 208, 211, 220, 222, 250, 257]: icr_candidates.remove(i) icr_candidates.extend([232, 303, 326, 363, 378]) # 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 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') # deploy stacks topology.graph['icr_candidates'] = set(icr_candidates) 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(): 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' return IcnTopology(topology)
def scenario_tiscali(net_cache=[0.05], n_contents=100000, alpha=[0.6, 0.8, 1.0]): """ Return a scenario based on Tiscali topology, parsed from RocketFuel dataset Parameters ---------- scenario_id : str String identifying the scenario (will be in the filename) net_cache : float Size of network cache (sum of all caches) normalized by size of content population n_contents : int Size of content population alpha : float List of alpha of Zipf content distribution """ rate = 12.0 warmup = 9000 duration = 36000 T = 'TISCALI' # name of the topology # 240 nodes in the main component topology = fnss.parse_rocketfuel_isp_map(path.join(scenarios_dir, 'resources/3257.r0.cch')).to_undirected() topology = nx.connected_component_subgraphs(topology)[0] deg = nx.degree(topology) 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 contents = dict([(v, []) for v in sources]) for c in range(1, n_contents + 1): s = choice(sources) contents[s].append(c) for v in sources: fnss.add_stack(topology, v, 'source', {'contents': contents[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' for nc in net_cache: size = (float(nc)*n_contents)/len(caches) # size of a single cache C = str(nc) for v in caches: fnss.add_stack(topology, v, 'cache', {'size': size}) fnss.write_topology(topology, path.join(scenarios_dir, topo_prefix + 'T=%s@C=%s' % (T, C) + '.xml')) print('[WROTE TOPOLOGY] T: %s, C: %s' % (T, C)) for a in alpha: event_schedule = gen_req_schedule(receivers, rate, warmup, duration, n_contents, a) fnss.write_event_schedule(event_schedule, path.join(scenarios_dir, es_prefix + 'T=%s@A=%s' % (T, str(a)) + '.xml')) print('[WROTE SCHEDULE] T: %s, Alpha: %s, Events: %d' % (T, str(a), len(event_schedule)))
def test_weights_constant(self): fnss.set_weights_constant(self.topo, 2, self.odd_links) fnss.set_weights_constant(self.topo, 5, self.even_links) self.assertTrue(all(self.topo.edge[u][v]['weight'] in [2, 5] for (u, v) in self.topo.edges_iter()))
def scenario_garr(net_cache=[0.01, 0.05], n_contents=100000, alpha=[0.6, 0.8, 1.0]): """ Return a scenario based on GARR topology Parameters ---------- scenario_id : str String identifying the scenario (will be in the filename) net_cache : float Size of network cache (sum of all caches) normalized by size of content population n_contents : int Size of content population alpha : float List of alpha of Zipf content distribution """ rate = 12.0 warmup = 9000 duration = 36000 T = 'GARR' # name of the topology topology = fnss.parse_topology_zoo(path.join(scenarios_dir, 'resources/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 contents = dict([(v, []) for v in sources]) for c in range(1, n_contents + 1): s = choice(sources) contents[s].append(c) for v in sources: fnss.add_stack(topology, v, 'source', {'contents': contents[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' for nc in net_cache: size = (float(nc)*n_contents)/len(caches) # size of a single cache C = str(nc) for v in caches: fnss.add_stack(topology, v, 'cache', {'size': size}) fnss.write_topology(topology, path.join(scenarios_dir, topo_prefix + 'T=%s@C=%s' % (T, C) + '.xml')) print('[WROTE TOPOLOGY] T: %s, C: %s' % (T, C)) for a in alpha: event_schedule = gen_req_schedule(receivers, rate, warmup, duration, n_contents, a) fnss.write_event_schedule(event_schedule, path.join(scenarios_dir, es_prefix + 'T=%s@A=%s' % (T, str(a)) + '.xml')) print('[WROTE SCHEDULE] T: %s, Alpha: %s, Events: %d' % (T, str(a), len(event_schedule)))
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