def setUpClass(cls): # set up topology used for all traffic matrix tests cls.G = fnss.glp_topology(n=50, m=1, m0=10, p=0.2, beta=-2, seed=1) fnss.set_capacities_random(cls.G, { 10: 0.5, 20: 0.3, 40: 0.2 }, capacity_unit='Mbps') fnss.set_delays_constant(cls.G, 2, delay_unit='ms') fnss.set_weights_inverse_capacity(cls.G) for node in [2, 4, 6]: fnss.add_stack(cls.G, node, 'tcp', { 'protocol': 'cubic', 'rcvwnd': 1024 }) for node in [2, 4]: fnss.add_application(cls.G, node, 'client', { 'rate': 100, 'user-agent': 'fnss' }) fnss.add_application(cls.G, 2, 'server', { 'port': 80, 'active': True, 'user-agent': 'fnss' })
def test_add_stack_kw_attr(self): fnss.add_stack(self.topo, 1, 's_name', att1='val1') self.assertEqual(fnss.get_stack(self.topo, 1, data=False), 's_name') self.assertEqual(fnss.get_stack(self.topo, 1, data=True), ('s_name', { 'att1': 'val1' }))
def large_line_topology(): topology = fnss.line_topology(11) fnss.add_stack(topology, 0, 'receiver') for i in range(1, 10): fnss.add_stack(topology, i, 'router') topology.graph['icr_candidates'] = [2, 3, 4, 5] return topology
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 test_add_stack_mixed_attr(self): fnss.add_stack(self.topo, 1, 's_name', {'att1': 'val1'}, att2='val2') self.assertEqual(fnss.get_stack(self.topo, 1, data=False), 's_name') self.assertEqual(fnss.get_stack(self.topo, 1, data=True), ('s_name', { 'att1': 'val1', 'att2': 'val2' }))
def setUpClass(cls): # set up topology used for all traffic matrix tests cls.G = fnss.glp_topology(n=50, m=1, m0=10, p=0.2, beta=-2, seed=1) fnss.set_capacities_random(cls.G, {10: 0.5, 20: 0.3, 40: 0.2}, capacity_unit='Mbps') fnss.set_delays_constant(cls.G, 2, delay_unit='ms') fnss.set_weights_inverse_capacity(cls.G) for node in [2, 4, 6]: fnss.add_stack(cls.G, node, 'tcp', {'protocol': 'cubic', 'rcvwnd': 1024}) for node in [2, 4]: fnss.add_application(cls.G, node, 'client', {'rate': 100, 'user-agent': 'fnss'}) fnss.add_application(cls.G, 2, 'server', {'port': 80, 'active': True, 'user-agent': 'fnss'})
def test_weighted_content_placement(): t = fnss.line_topology(4) fnss.add_stack(t, 0, 'router') fnss.add_stack(t, 1, 'source') fnss.add_stack(t, 2, 'source') fnss.add_stack(t, 3, 'receiver') contentplacement.weighted_content_placement(t, range(10), {1: 0.7, 2: 0.3}) c1 = t.node[1]['stack'][1]['contents'] if 'contents' in t.node[1]['stack'][1] else set() c2 = t.node[2]['stack'][1]['contents'] if 'contents' in t.node[2]['stack'][1] else set() assert len(c1) + len(c2) == 10
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)
def test_uniform(self): t = fnss.line_topology(4) fnss.add_stack(t, 0, "router") fnss.add_stack(t, 1, "source") fnss.add_stack(t, 2, "source") fnss.add_stack(t, 3, "receiver") contentplacement.weighted_content_placement(t, range(10), {1: 0.7, 2: 0.3}) c1 = t.node[1]["stack"][1]["contents"] if "contents" in t.node[1]["stack"][1] else set() c2 = t.node[2]["stack"][1]["contents"] if "contents" in t.node[2]["stack"][1] else set() self.assertEqual(len(c1) + len(c2), 10)
def test_uniform_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].get('contents', set()) c2 = t.node[2]['stack'][1].get('contents', set()) self.assertEqual(len(c1) + len(c2), 10)
def test_uniform(self): t = fnss.line_topology(4) fnss.add_stack(t, 0, "router") fnss.add_stack(t, 1, "source") fnss.add_stack(t, 2, "source") fnss.add_stack(t, 3, "receiver") contentplacement.uniform_content_placement(t, range(10)) c1 = t.node[1]["stack"][1]["contents"] c2 = t.node[2]["stack"][1]["contents"] self.assertEqual(len(c1) + len(c2), 10)
def test_uniform(self): t = fnss.line_topology(4) fnss.add_stack(t, 0, 'router') fnss.add_stack(t, 1, 'source') fnss.add_stack(t, 2, 'source') fnss.add_stack(t, 3, 'receiver') contentplacement.weighted_content_placement(t, range(10), {1: 0.7, 2: 0.3}) c1 = t.node[1]['stack'][1]['contents'] if 'contents' in t.node[1]['stack'][1] else set() c2 = t.node[2]['stack'][1]['contents'] if 'contents' in t.node[2]['stack'][1] else set() self.assertEqual(len(c1) + len(c2), 10)
def test_weighted_content_placement(): t = fnss.line_topology(4) fnss.add_stack(t, 0, "router") fnss.add_stack(t, 1, "source") fnss.add_stack(t, 2, "source") fnss.add_stack(t, 3, "receiver") contentplacement.weighted_content_placement(t, range(10), {1: 0.7, 2: 0.3}) c1 = (t.node[1]["stack"][1]["contents"] if "contents" in t.node[1]["stack"][1] else set()) c2 = (t.node[2]["stack"][1]["contents"] if "contents" in t.node[2]["stack"][1] else set()) assert len(c1) + len(c2) == 10
def setup_method(self): # # s1 s2 # | | # c1-----c2----c3 # / \ / | \ \ # r1 r2 r3 r4 r5 r6 # topo = fnss.Topology() icr_candidates = ["c1", "c2", "c3"] nx.add_path(topo, icr_candidates) topo.add_edge("c2", "s1") topo.add_edge("c2", "s2") topo.add_edge("c1", "r1") topo.add_edge("c1", "r2") topo.add_edge("c2", "r3") topo.add_edge("c2", "r4") topo.add_edge("c2", "r5") topo.add_edge("c3", "r6") topo.graph["icr_candidates"] = set(icr_candidates) for router in icr_candidates: fnss.add_stack(topo, router, "router") for src in ["s1"]: fnss.add_stack(topo, src, "source") for rcv in ["r1", "r2", "r3", "r4", "r5", "r6"]: fnss.add_stack(topo, rcv, "receiver") self.topo = cacheplacement.IcnTopology(topo)
def off_path_topology(): """Return topology for testing off-path caching strategies """ # Topology sketch # # --------- 5 ---------- # / \ # / \ # 0 ---- 1 ---- 2 ---- 3 ---- 4 # | # | # 6 # topology = fnss.ring_topology(6) topology.add_edge(2, 6) topology.add_edge(1, 7) source = 4 receivers = (0, 6, 7) caches = (1, 2, 3, 5) contents = caches fnss.add_stack(topology, source, 'source', {'contents': contents}) for v in caches: fnss.add_stack(topology, v, 'cache', {'size': 1}) for v in receivers: fnss.add_stack(topology, v, 'receiver', {}) topology.graph['cache_policy'] = 'FIFO' return 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 nrr_topology(cls): """Return topology for testing NRR caching strategies """ # Topology sketch # # 0 ---- 2----- 4 # | \ # | s # | / # 1 ---- 3 ---- 5 # topology = IcnTopology(fnss.Topology()) nx.add_path(topology, [0, 2, 4, "s", 5, 3, 1]) topology.add_edge(2, 3) receivers = (0, 1) source = "s" caches = (2, 3, 4, 5) contents = (1, 2, 3, 4) fnss.add_stack(topology, source, 'source', {'contents': contents}) for v in caches: fnss.add_stack(topology, v, 'router', {'cache_size': 1}) for v in receivers: fnss.add_stack(topology, v, 'receiver', {}) fnss.set_delays_constant(topology, 1, 'ms') return topology
def off_path_topology(): """Return topology for testing off-path caching strategies """ # Topology sketch # # --------- 5 ---------- # / \ # / \ # 0 ---- 1 ---- 2 ---- 3 ---- 4 # | # | # 6 # topology = fnss.ring_topology(6) topology.add_edge(2, 6) topology.add_edge(1, 7) source = 4 receivers = (0, 6, 7) caches = (1, 2, 3, 5) contents = caches fnss.add_stack(topology, source, 'source', {'contents': contents}) for v in caches: fnss.add_stack(topology, v, 'router', {'cache_size': 1}) for v in receivers: fnss.add_stack(topology, v, 'receiver', {}) return topology
def setUp(self): # # -- s1 -- # / | \ # c1-----c2----c3 # / \ / | \ \ # r1 r2 r3 r4 r5 r6 # topo = fnss.Topology() icr_candidates = ["c1", "c2", "c3"] nx.add_path(topo, icr_candidates) topo.add_edge("c1", "s1") topo.add_edge("c2", "s1") topo.add_edge("c3", "s1") topo.add_edge("c1", "r1") topo.add_edge("c1", "r2") topo.add_edge("c2", "r3") topo.add_edge("c2", "r4") topo.add_edge("c2", "r5") topo.add_edge("c3", "r6") topo.graph['icr_candidates'] = set(icr_candidates) for router in icr_candidates: fnss.add_stack(topo, router, 'router') for src in ['s1']: fnss.add_stack(topo, src, 'source') for rcv in ['r1', 'r2', 'r3', 'r4', 'r5', 'r6']: fnss.add_stack(topo, rcv, 'receiver') self.topo = cacheplacement.IcnTopology(topo)
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 partition_topology(cls): # # +-- s1 --+ # / | \ # c1-----[]----c2 # / \ # r1 r2 # topo = fnss.Topology() icr_candidates = ["c1", "router", "c2"] nx.add_path(topo, icr_candidates) topo.add_edge("r1", "router") topo.add_edge("r2", "router") topo.add_edge("c1", "s1") topo.add_edge("c2", "s1") topo.graph['icr_candidates'] = set(icr_candidates) contents = (1, 2, 3, 4) for router in icr_candidates: if router in ("c1", "c2"): props = {'cache_size': 1} fnss.add_stack(topo, router, 'router', **props) for src in ['s1']: fnss.add_stack(topo, src, 'source', {'contents': contents}) for rcv in ['r1', 'r2']: fnss.add_stack(topo, rcv, 'receiver') topo.graph['cache_assignment'] = {"r1": "c1", "r2": "c2"} return IcnTopology(topo)
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_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 setUp(self): # # -- s1 -- # / | \ # c1-----c2----c3 # / \ / | \ \ # r1 r2 r3 r4 r5 r6 # topo = fnss.Topology() icr_candidates = ["c1", "c2", "c3"] topo.add_path(icr_candidates) topo.add_edge("c1", "s1") topo.add_edge("c2", "s1") topo.add_edge("c3", "s1") topo.add_edge("c1", "r1") topo.add_edge("c1", "r2") topo.add_edge("c2", "r3") topo.add_edge("c2", "r4") topo.add_edge("c2", "r5") topo.add_edge("c3", "r6") topo.graph['icr_candidates'] = set(icr_candidates) for router in icr_candidates: fnss.add_stack(topo, router, 'router') for src in ['s1']: fnss.add_stack(topo, src, 'source') for rcv in ['r1', 'r2', 'r3', 'r4', 'r5', 'r6']: fnss.add_stack(topo, rcv, 'receiver') self.topo = cacheplacement.IcnTopology(topo)
def topology_generic_rocketfuel_latency(asn, source_ratio, ext_delay, **kwargs): """Parse a generic RocketFuel topology with annotated latencies To each node of the parsed topology it is attached an artificial receiver node. To the routers with highest degree it is also attached a source node. Parameters ---------- asn : int AS number source_ratio : float Ratio between number of source nodes (artificially attached) and routers ext_delay : float Delay on external nodes """ if source_ratio < 0 or source_ratio > 1: raise ValueError('source_ratio must be comprised between 0 and 1') f_topo = path.join(TOPOLOGY_RESOURCES_DIR, 'rocketfuel-latency', str(asn), 'latencies.intra') topology = fnss.parse_rocketfuel_isp_latency(f_topo).to_undirected() topology = list(nx.connected_component_subgraphs(topology))[0] # First mark all current links as inernal for u,v in topology.edges_iter(): topology.edge[u][v]['type'] = 'internal' # Note: I don't need to filter out nodes with degree 1 cause they all have # a greater degree value but we compute degree to decide where to attach sources routers = topology.nodes() # Source attachment n_sources = int(source_ratio*len(routers)) sources = ['src_%d' % i for i in range(n_sources)] deg = nx.degree(topology) # Attach sources based on their degree purely, but they may end up quite clustered # routers = sorted(routers, key=lambda k: deg[k], reverse=True) # Onur: change the order of sorting to attach sources to low-degree routers routers = sorted(routers, key=lambda k: deg[k]) for i in range(len(sources)): topology.add_edge(sources[i], routers[i], delay=ext_delay, type='external') # Here let's try attach them via cluster # clusters = compute_clusters(topology, n_sources, distance=None, n_iter=1000) # source_attachments = [max(cluster, key=lambda k: deg[k]) for cluster in clusters] # for i in range(len(sources)): # topology.add_edge(sources[i], source_attachments[i], delay=ext_delay, type='external') # attach artificial receiver nodes to ICR candidates receivers = ['rec_%d' % i for i in range(len(routers))] for i in range(len(routers)): topology.add_edge(receivers[i], routers[i], delay=0, type='internal') # Set weights to latency values for u, v in topology.edges_iter(): topology.edge[u][v]['weight'] = topology.edge[u][v]['delay'] # Deploy stacks on nodes 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') return IcnTopology(topology)
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_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 setUp(self): self.topo = fnss.line_topology(6) fnss.add_stack(self.topo, 0, 'receiver') self.topo.graph['icr_candidates'] = [] for i in range(1, 5): self.topo.graph['icr_candidates'].append(i) fnss.add_stack(self.topo, i, 'router') fnss.add_stack(self.topo, 5, 'source')
def test_uniform(self): t = fnss.line_topology(4) fnss.add_stack(t, 0, 'router') fnss.add_stack(t, 1, 'source') fnss.add_stack(t, 2, 'source') fnss.add_stack(t, 3, 'receiver') contentplacement.weighted_content_placement(t, list(range(10)), { 1: 0.7, 2: 0.3 }) c1 = t.node[1]['stack'][1]['contents'] if 'contents' in t.node[1][ 'stack'][1] else set() c2 = t.node[2]['stack'][1]['contents'] if 'contents' in t.node[2][ 'stack'][1] else set() self.assertEqual(len(c1) + len(c2), 10)
def setup_method(self): self.topo = fnss.line_topology(6) fnss.add_stack(self.topo, 0, "receiver") self.topo.graph["icr_candidates"] = [] for i in range(1, 5): self.topo.graph["icr_candidates"].append(i) fnss.add_stack(self.topo, i, "router") fnss.add_stack(self.topo, 5, "source")
def topology_rocketfuel_latency(asn, source_ratio=1.0, ext_delay=EXTERNAL_LINK_DELAY, **kwargs): """Parse a generic RocketFuel topology with annotated latencies To each node of the parsed topology it is attached an artificial receiver node. To the routers with highest degree it is also attached a source node. Parameters ---------- asn : int AS number source_ratio : float Ratio between number of source nodes (artificially attached) and routers ext_delay : float Delay on external nodes """ if source_ratio < 0 or source_ratio > 1: raise ValueError('source_ratio must be comprised between 0 and 1') f_topo = path.join(TOPOLOGY_RESOURCES_DIR, 'rocketfuel-latency', str(asn), 'latencies.intra') topology = fnss.parse_rocketfuel_isp_latency(f_topo).to_undirected() topology = list(nx.connected_component_subgraphs(topology))[0] # First mark all current links as inernal for u, v in topology.edges_iter(): topology.edge[u][v]['type'] = 'internal' # Note: I don't need to filter out nodes with degree 1 cause they all have # a greater degree value but we compute degree to decide where to attach sources routers = topology.nodes() # Source attachment n_sources = int(source_ratio * len(routers)) sources = ['src_%d' % i for i in range(n_sources)] deg = nx.degree(topology) # Attach sources based on their degree purely, but they may end up quite clustered routers = sorted(routers, key=lambda k: deg[k], reverse=True) for i in range(len(sources)): topology.add_edge(sources[i], routers[i], delay=ext_delay, type='external') # Here let's try attach them via cluster # clusters = compute_clusters(topology, n_sources, distance=None, n_iter=1000) # source_attachments = [max(cluster, key=lambda k: deg[k]) for cluster in clusters] # for i in range(len(sources)): # topology.add_edge(sources[i], source_attachments[i], delay=ext_delay, type='external') # attach artificial receiver nodes to ICR candidates receivers = ['rec_%d' % i for i in range(len(routers))] for i in range(len(routers)): topology.add_edge(receivers[i], routers[i], delay=0, type='internal') # Set weights to latency values for u, v in topology.edges_iter(): topology.edge[u][v]['weight'] = topology.edge[u][v]['delay'] # Deploy stacks on nodes 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') return IcnTopology(topology)
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 setup_method(self): # # 0 -- 1 -- 2 -- 3 -- 4 -- 5 # self.topo = fnss.line_topology(6) fnss.add_stack(self.topo, 0, 'receiver') fnss.add_stack(self.topo, 5, 'source') self.topo.graph['icr_candidates'] = {1, 2, 3, 4} for i in self.topo.graph['icr_candidates']: fnss.add_stack(self.topo, i, 'router')
def setup_method(self): # # 0 -- 1 -- 2 -- 3 -- 4 -- 5 # self.topo = fnss.line_topology(6) fnss.add_stack(self.topo, 0, "receiver") fnss.add_stack(self.topo, 5, "source") self.topo.graph["icr_candidates"] = {1, 2, 3, 4} for i in self.topo.graph["icr_candidates"]: fnss.add_stack(self.topo, i, "router")
def setup_method(self): # # 0 -- 1 -- 2 -- 3 -- 4 # | # 5 self.topo = fnss.line_topology(5) fnss.add_stack(self.topo, 0, 'receiver') fnss.add_stack(self.topo, 4, 'source') self.topo.add_edge(2, 5) self.topo.graph['icr_candidates'] = {1, 2, 3, 5} for i in self.topo.graph['icr_candidates']: fnss.add_stack(self.topo, i, 'router')
def setup_method(self): # # 0 -- 1 -- 2 -- 3 -- 4 # | # 5 self.topo = fnss.line_topology(5) fnss.add_stack(self.topo, 0, "receiver") fnss.add_stack(self.topo, 4, "source") self.topo.add_edge(2, 5) self.topo.graph["icr_candidates"] = {1, 2, 3, 5} for i in self.topo.graph["icr_candidates"]: fnss.add_stack(self.topo, i, "router")
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_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