def setUpClass(cls): cls.topo = fnss.glp_topology(n=100, m=1, m0=10, p=0.2, beta=-2, seed=1) fnss.set_capacities_random_uniform(cls.topo, [10, 20, 40]) odd_links = [(u, v) for (u, v) in cls.topo.edges() if (u + v) % 2 == 1] even_links = [(u, v) for (u, v) in cls.topo.edges() if (u + v) % 2 == 0] fnss.set_delays_constant(cls.topo, 2, 'ms', odd_links) fnss.set_delays_constant(cls.topo, 5, 'ms', even_links) cls.capacities = [12, 25, 489, 1091]
def setUpClass(cls): # set up topology used for all traffic matrix tests cls.topo = fnss.k_ary_tree_topology(3, 4) cls.capacities = [10, 20] cls.odd_links = [(u, v) for (u, v) in cls.topo.edges() if (u + v) % 2 == 1] cls.even_links = [(u, v) for (u, v) in cls.topo.edges() if (u + v) % 2 == 0] fnss.set_capacities_random_uniform(cls.topo, cls.capacities) fnss.set_delays_constant(cls.topo, 3, 'ms', cls.odd_links) fnss.set_delays_constant(cls.topo, 12, 'ms', cls.even_links)
def setUpClass(cls): # set up topology used for all traffic matrix tests cls.topo = fnss.k_ary_tree_topology(3, 4) cls.capacities = [10, 20] cls.odd_links = [(u, v) for (u, v) in cls.topo.edges_iter() if (u + v) % 2 == 1] cls.even_links = [(u, v) for (u, v) in cls.topo.edges_iter() if (u + v) % 2 == 0] fnss.set_capacities_random_uniform(cls.topo, cls.capacities) fnss.set_delays_constant(cls.topo, 3, 'ms', cls.odd_links) fnss.set_delays_constant(cls.topo, 12, 'ms', cls.even_links)
def setUp(self): self.connection_params = { 'db_name': 'TestDb', 'host': 'localhost', 'port': 3366, 'user': '******', 'password': '******' } vne_interface.DbManager.set_connection_parameter( **self.connection_params) vne_interface.DbManager.connect() with vne_interface.dm.db.transaction() as txn: try: vne_interface.dm.db.create_tables([ vne_interface.dm.EventGenerationSetting, vne_interface.dm.VnrGenerationSetting, vne_interface.dm.AlgorithmSetting, vne_interface.dm.Network, vne_interface.dm.Node, vne_interface.dm.Edge, vne_interface.dm.NetworkAttribute, vne_interface.dm.SubstrateGenerationSetting, vne_interface.dm.EventHeap, vne_interface.dm.Experiment, vne_interface.dm.LearningModel, vne_interface.dm.Setup ]) self.algo_setting = vne_interface.dm.AlgorithmSetting.create( parameter= '{"alpha": 0.5, "beta": 0.5, "name": "melo_sdp", "timeout": 65.0}' ) self.event_setting = vne_interface.dm.EventGenerationSetting.create( parameter= '{"model": "erdoes_renyi", "lmbd": 10, "num_requests": 5, "avg_life_time": 1000}' ) self.vnr_setting = vne_interface.dm.VnrGenerationSetting.create( parameter= '{"min_bw": 0, "max_cpu": 50, "maxy": 100, "miny": 0, ' '"min_cpu": 0, "max_bw": 50, "minx": 0, "connectivity": 0.5, ' '"bandwidth": "uniform", "max_num_nodes": 22, ' '"min_num_nodes": 8, "max_distance": 501, ' '"min_distance": 500, "maxx": 100}') self.substrate_setting = vne_interface.dm.SubstrateGenerationSetting.create( parameter='{"min_bw": 50, "max_cpu": 100, "maxy": 100, ' '"substrate": true, "miny": 0, "min_cpu": 50, ' '"bandwidth": "uniform", "num_nodes": 43, "minx": 0, ' '"connectivity": 0.5, "max_bw": 100, "max_distance": 50, ' '"model": "erdoes_renyi", "min_distance": 1, "maxx": 100}') substrate = fnss.erdos_renyi_topology(43, 0.5) fnss.set_capacities_random_uniform(substrate, range(50, 100)) for attributes in substrate.node.itervalues(): attributes['cpu'] = np.random.uniform(50, 100) networkif = vne_interface.Network.from_fnss_topology(substrate) self.substrate = networkif.network_model self.learning_model = vne_interface.dm.LearningModel.create( type='testmode', serialized_model='/path/to/model.pkl', aux_params='empty', comment= 'This model is created from setup method of unittest') self.experiment = vne_interface.dm.Experiment.create( description= 'Created for test purposes from setup method of unittest') self.event_heaps = [] for i in range(5): self.event_heaps.append( vne_interface.dm.EventHeap.create( event_generation_setting_id=self.event_setting. event_generation_setting_id, vnr_generation_setting_id=self.vnr_setting. vnr_generation_setting_id)) self.setups = [] for heap in self.event_heaps: self.setups.append( vne_interface.dm.Setup.create( event_generation_setting=self.event_setting, vnr_generation_setting=self.vnr_setting, substrate_generation_setting=self. substrate_setting, algorithm_setting=self.algo_setting, experiment=self.experiment, event_heap=heap, description= 'Test Setup created from unittest setup method', substrate=self.substrate, learning_model_id=self.learning_model. learning_model_id)) txn.commit() except Exception as e: logging.exception(e) txn.rollback()
def test_capacities_random_uniform(self): fnss.set_capacities_random_uniform(self.topo, self.capacities) self.assertTrue( all(self.topo.edge[u][v]['capacity'] in self.capacities for (u, v) in self.topo.edges_iter()))
def test_capacities_random_uniform(self): fnss.set_capacities_random_uniform(self.topo, self.capacities) self.assertTrue(all(self.topo.edge[u][v]['capacity'] in self.capacities for (u, v) in self.topo.edges_iter()))
def generate_attributes(self, vnr, min_capacity, max_capacity, capacity_generation, min_cpu, max_cpu, min_edge_distance=None, max_edge_distance=None, delay_per_km=0.005, is_substrate=False, minx=None, maxx=None, miny=None, maxy=None, **kwargs): """ Sets the following edge attributes: * capacity [Mb/s] * delay [ms] * length [km] * mapping - zero if substrate else empty list * free_capacity if substrate is True Delay is calculated based on attribute delay and length of edge. Sets the following node attributes: * cpu * mapping * free_cpu if substrate is True If the network was created using the Waxman2 method, a longitude and latitude attribute will be present for the nodes Args: vnr (Vnr): Object of type Vnr. 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. min_distance (int): Minimal length of an edge. max_distance (int): Maximal length of an edge. delay (float, optional): Delay per kilometer of cable length substrate (optional, bool): Whether it is a substrate network or not """ if delay_per_km is None: delay_per_km = 0.05 if 'distance_unit' not in vnr.graph: vnr.graph['distance_unit'] = 'km' bws = range(int(min_capacity), int(max_capacity) + 1) if capacity_generation == 'uniform': fnss.set_capacities_random_uniform(topology=vnr, capacities=bws) elif capacity_generation == 'power': fnss.set_capacities_random_power_law(topology=vnr, capacities=bws) for attributes in vnr.node.itervalues(): attributes['cpu'] = int(np.random.uniform(min_cpu, max_cpu)) attributes['mapping'] = 0 if is_substrate: attributes['free_cpu'] = attributes['cpu'] attributes['total_mapped'] = 0 attributes['currently_mapped'] = 0 if ('latitude' not in attributes) and (minx is not None) and ( maxx is not None): attributes['latitude'] = np.random.uniform(minx, maxx) if ('longitude' not in attributes) and (minx is not None) and ( maxx is not None): attributes['longitude'] = np.random.uniform(miny, maxy) for i, j, attr in vnr.edges(data=True): if 'length' not in attr: if 'longitude' in vnr.node[i] and 'latitude' in vnr.node[i]: attr['length'] = np.sqrt( np.square(vnr.node[i]['latitude'] - vnr.node[j]['latitude']) + np.square(vnr.node[i]['longitude'] - vnr.node[j]['longitude'])) else: if (min_edge_distance is None) and (max_edge_distance is None): pass else: attr['length'] = np.random.uniform( min_edge_distance, max_edge_distance) attr['mapping'] = 0 if is_substrate else [] if is_substrate: attr['free_capacity'] = attr['capacity'] attr['total_mapped'] = 0 attr['currently_mapped'] = 0 fnss.set_delays_geo_distance(vnr, specific_delay=delay_per_km) fnss.set_weights_delays(vnr)