def test_waxman_2_topology_no_seed(self): a = fnss.waxman_2_topology(100, alpha=0.5, beta=0.6, domain=(-1, -2, 1, 2)) b = fnss.waxman_2_topology(100, alpha=0.5, beta=0.6, domain=(-1, -2, 1, 2)) self.assertNotEqual(set(a.edges()), set(b.edges()))
def test_waxman_2_topology(self): self.assertRaises(ValueError, fnss.waxman_2_topology, 0, 0.5, 0.6) self.assertRaises(ValueError, fnss.waxman_2_topology, 10, 0, 0.5) self.assertRaises(ValueError, fnss.waxman_2_topology, 10, 0.4, 0) self.assertRaises(ValueError, fnss.waxman_2_topology, 10, 0.5, 0.3, (1.2, -2, 1, 2)) self.assertRaises(ValueError, fnss.waxman_2_topology, 10, 0.5, 0.3, (-1, 3, 1, 2)) self.assertRaises(ValueError, fnss.waxman_2_topology, 10, 0.5, 0.3, (-1, -2, 1, 2, 5)) self.assertRaises(ValueError, fnss.waxman_2_topology, 10, 0.5, 0.3, (-1, -2, 1)) topology = fnss.waxman_2_topology(200, alpha=0.5, beta=0.6, domain=(-1, -2, 1, 2)) self.assertEqual(200, topology.number_of_nodes()) # test all nodes have longitude and latitude attribute x = nx.get_node_attributes(topology, 'longitude') y = nx.get_node_attributes(topology, 'latitude') self.assertEqual(topology.number_of_nodes(), len(x)) self.assertEqual(topology.number_of_nodes(), len(y)) # test all edges have length attribute length = nx.get_edge_attributes(topology, 'length') self.assertEqual(topology.number_of_edges(), len(length)) # test node coordinates are within predefined domain self.assertLessEqual(-1, min(x.values())) self.assertLessEqual(-2, min(y.values())) self.assertGreaterEqual(1, max(x.values())) self.assertGreaterEqual(2, max(y.values()))
def test_waxman_2_topology_constant_seed(self): a = fnss.waxman_2_topology(100, alpha=0.5, beta=0.6, domain=(-1, -2, 1, 2), seed=1) b = fnss.waxman_2_topology(100, alpha=0.5, beta=0.6, domain=(-1, -2, 1, 2), seed=2) c = fnss.waxman_2_topology(100, alpha=0.5, beta=0.6, domain=(-1, -2, 1, 2), seed=1) self.assertEqual(set(a.edges()), set(c.edges())) self.assertNotEqual(set(a.edges()), set(b.edges()))
def test_delays_geo_distance(self): specific_delay = 1.2 L = 5 G_len = fnss.waxman_1_topology(100, L=L) G_xy = fnss.waxman_2_topology(100, domain=(0, 0, 3, 4)) # leave only node coordinate to trigger failure for u, v in G_xy.edges_iter(): del G_xy.edge[u][v]['length'] self.assertRaises(ValueError, fnss.set_delays_geo_distance, G_len, 2, delay_unit='Km') self.assertRaises(ValueError, fnss.set_delays_geo_distance, G_xy, specific_delay, None, 'ms') fnss.set_delays_geo_distance(G_len, specific_delay, None, 'ms', links=None) delays = nx.get_edge_attributes(G_len, 'delay') self.assertEqual(G_len.number_of_edges(), len(delays)) self.assertGreaterEqual(specific_delay*L, max(delays.values())) self.assertLessEqual(0, min(delays.values()))
def waxman2(self, order, alpha, beta, minx, miny, maxx, maxy, **kwargs): """ Creates a random network following a power law distribution. Args: order (int): Number of nodes. alpha (float): Must be in (0,1]. Higher alpha increase difference between density of long and short links. Waxman found 0.3 to be a good value for this. beta (float): Must be in (0; 1]. Regulates link density, higher beta higher link density. minx (int): Minimal x-coordinate on grid. miny (int): Minimal y-coordinate on grid. maxx (int): Maximal x-coordinate on grid. maxy (int): Maximal y-coordinate on grid. args (dict): Attributes for property generation: min_bw (int): Minimal value for bandwidth on edge. max_bw (int): Maximal value for bandwidth on edge. bandwidth (string): {uniform, power} - How bandwidth should be generated. If uniform is chosen distribution follows uniform distribution, if power is chosen distribution follows a power law. min_cpu (int): Minimal value for CPU capacity. max_cpu (int): Maximal value for CPU capacity. delay (float, optional): Delay per kilometer of cable length. substrate (optional, bool): Whether it is a substrate network. Returns: FNSS object """ unconnected = True vnr = None while unconnected: vnr = fnss.waxman_2_topology( n=order, alpha=beta, # This is confusing, in paper and literature beta= alpha, # alpha and beta usually are reversed to FNSS terminology! domain=(minx, miny, maxx, maxy)) unconnected = not nx.is_connected(vnr) self.remove_unnecessary_attributes(kwargs) self.generate_attributes(vnr, **kwargs) vnr.graph['model'] = literals.NETWORK_MODEL_WAXMAN return vnr
def test_waxman_2_topology_zero_seed(self): a = fnss.waxman_2_topology(100, alpha=0.5, beta=0.6, domain=(-1, -2, 1, 2), seed=0) b = fnss.waxman_2_topology(100, alpha=0.5, beta=0.6, domain=(-1, -2, 1, 2), seed=0) self.assertEqual(set(a.edges()), set(b.edges()))