def test_get_event_queues(self): scenario = scs.VneScenario( if_input=datamodel.ConnectionManager(self.data_source_config), if_output=None, num_runs=2, substrate_generation_settings=self.substrate_setting, vnr_generation_settings=self.network_generation_setting, algorithm=self.algo_setting, arrival_process=self.ap_setting, service_process=self.sp_setting, gurobi_settings=None, learning_model_settings=self.learning_model ) arrival_process = scenario._get_process(self.ap_setting) service_process = scenario._get_process(self.sp_setting) virtual_network_generation = scenario._get_network_generation_settings( self.network_generation_setting ) event_generation = scenario._get_event_generation( service_process=service_process, arrival_process=arrival_process, network_generation=virtual_network_generation ) queues = scenario._get_event_queues( service_process=service_process, arrival_process=arrival_process, network_generation=virtual_network_generation, event_generation=event_generation ) ids1 = [q.identifier for q in queues] self.assertEqual(len(ids1), self.num_runs) queues2 = scenario._get_event_queues( service_process=service_process, arrival_process=arrival_process, network_generation=virtual_network_generation, event_generation=event_generation ) ids2 = [q.identifier for q in queues2] self.assertEqual(len(ids2), self.num_runs) self.assertListEqual(ids1, ids2) num_events = datamodel.Event.select().count() num_vnrs = datamodel.Network.select() \ .where(datamodel.Network.subclass_type == literals.CLASS_VIRTUAL_NETWORK)\ .count() self.assertEqual(num_events, self.num_runs * self.ap_setting['num_requests']) self.assertEqual(num_events, num_vnrs) orders = range( self.network_generation_setting['min_order'], self.network_generation_setting['max_order'] ) for vnr in datamodel.Network.select().where(datamodel.Network.subclass_type == literals.CLASS_VIRTUAL_NETWORK).execute(): self.assertIn(vnr.num_nodes, orders) self.assertEqual(vnr.model, literals.NETWORK_MODEL_ERDOES_RENYI, 'model was not ER but {}'.format(vnr.model))
def test_simulation_configuration(self): scenario1 = scs.VneScenario( if_input=datamodel.ConnectionManager(self.data_source_config), if_output=None, num_runs=self.num_runs, substrate_generation_settings=self.substrate_setting.copy(), vnr_generation_settings=self.network_generation_setting.copy(), algorithm=self.algo_setting.copy(), arrival_process=self.ap_setting.copy(), service_process=self.sp_setting.copy(), gurobi_settings=self.gurobi_setting.copy(), learning_model_settings=self.learning_model.copy() ) scenario2 = scs.VneScenario( if_input=datamodel.ConnectionManager(self.data_source_config), if_output=None, num_runs=self.num_runs, substrate_generation_settings=self.substrate_setting, vnr_generation_settings=self.network_generation_setting, algorithm=self.algo_setting, arrival_process=self.ap_setting, service_process=self.sp_setting, gurobi_settings=self.gurobi_setting, learning_model_settings=self.learning_model ) scenario1.configure_simulations(literals.WRITE_AT_END_STRATEGY) scenario2.configure_simulations(literals.WRITE_AT_END_STRATEGY) num_runs = datamodel.RunConfiguration.select().count() num_substrates = datamodel.Network.select().where( datamodel.Network.subclass_type == literals.CLASS_PHYSICAL_NETWORK ).count() num_queues = datamodel.EventHeap.select().count() self.assertEqual(num_runs, self.num_runs) self.assertEqual(num_substrates, self.num_runs) self.assertEqual(num_queues, self.num_runs) self.assertEqual( len(scenario1.simulation_config), len(scenario2.simulation_config) ) for i in range(len(scenario1.simulation_config)): self.assertDictEqual( scenario1.simulation_config[i], scenario2.simulation_config[i] )
def test_get_substrates(self): scenario = scs.VneScenario( if_input=datamodel.ConnectionManager(self.data_source_config), if_output=None, num_runs=2, substrate_generation_settings=self.substrate_setting, vnr_generation_settings=self.network_generation_setting, algorithm=self.algo_setting, arrival_process=self.ap_setting, service_process=self.sp_setting, gurobi_settings=None, learning_model_settings=self.learning_model ) sids = scenario._get_substrates() sids = [s.identifier for s in sids] self.assertEqual(len(sids), self.num_runs) sids2 = scenario._get_substrates() sids2 = [s.identifier for s in sids2] self.assertListEqual(sids, sids2)
def test_get_algorithm(self): scenario = scs.VneScenario( if_input=datamodel.ConnectionManager(self.data_source_config), if_output=None, num_runs=2, substrate_generation_settings=self.substrate_setting, vnr_generation_settings=self.network_generation_setting, algorithm=self.algo_setting, arrival_process=self.ap_setting, service_process=self.sp_setting, gurobi_settings=None, learning_model_settings=self.learning_model ) algorithm = scenario._get_algorithm() self.assertEqual(algorithm.identifier, self.algo_setting_record.algorithm_setting_id) algo_setting = { 'name': literals.ALGORITHM_MELO_SDP, "alpha": 0.5, "beta": 0.5, "timeout": 600 } scenario._algorithm = algo_setting algorithm2 = scenario._get_algorithm() self.assertNotEqual(algorithm.identifier, algorithm2.identifier)
def test_get_process(self): scenario = scs.VneScenario( if_input=datamodel.ConnectionManager(self.data_source_config), if_output=None, num_runs=2, substrate_generation_settings=self.substrate_setting, vnr_generation_settings=self.network_generation_setting, algorithm=self.algo_setting, arrival_process=self.ap_setting, service_process=self.sp_setting, gurobi_settings=None, learning_model_settings=self.learning_model ) process = scenario._get_process(self.ap_setting.copy()) self.assertEqual(process.identifier, self.ap_setting_record.process_setting_id) self.assertEqual(process.arrival_rate, self.ap_setting['arrival_rate']) self.assertEqual(process.distribution, self.ap_setting['distribution']) self.assertEqual(process.type, self.ap_setting['type']) self.assertEqual(process.num_requests, self.ap_setting['num_requests']) process = scenario._get_process(self.sp_setting.copy()) self.assertEqual(process.identifier, self.sp_setting_record.process_setting_id) ap_setting = self.ap_setting.copy() ap_setting['arrival_rate'] = 10 sp_setting = self.sp_setting.copy() sp_setting['arrival_rate'] = 2000 process = scenario._get_process(ap_setting.copy()) self.assertNotEqual(process.identifier, self.ap_setting_record.process_setting_id) process = scenario._get_process(sp_setting.copy()) self.assertNotEqual(process.identifier, self.sp_setting_record.process_setting_id) count = datamodel.ProcessSetting.select().count() self.assertEqual(count, 4)
def test_get_network_generation_settings(self): scenario = scs.VneScenario( if_input=datamodel.ConnectionManager(self.data_source_config), if_output=None, num_runs=2, substrate_generation_settings=self.substrate_setting, vnr_generation_settings=self.network_generation_setting, algorithm=self.algo_setting, arrival_process=self.ap_setting, service_process=self.sp_setting, gurobi_settings=None, learning_model_settings=self.learning_model ) ngid = scenario._get_network_generation_settings(self.substrate_setting.copy()) self.assertEqual( ngid.identifier, self.substrate_setting_record.network_generation_setting_id ) substrate_setting = { 'model': 'ER', 'connectivity': 0.3, 'order': 50, 'min_capacity': 50, 'max_capacity': 100, 'min_cpu': 50, 'max_cpu': 100, 'capacity_generation': 'uniform', 'is_substrate': True, 'delay_per_km': 0.05 } ngid2 = scenario._get_network_generation_settings(substrate_setting) self.assertNotEqual( ngid.identifier, ngid2.identifier )
def setUpClass(cls): cls.logger = logging.getLogger(str(cls.__class__)) cls.logger.setLevel(logging.DEBUG) input_if = datamodel.ConnectionManager(cls.data_source_config) input_if.connect() with datamodel.db.atomic() as txn: try: datamodel.db.create_tables([ datamodel.AlgorithmSetting, datamodel.ProcessSetting, datamodel.NetworkGenerationSetting, datamodel.EventGenerationSetting, datamodel.ProcessToEventSetting, datamodel.Network, datamodel.Node, datamodel.Edge, datamodel.EventHeap, datamodel.Experiment, datamodel.LearningModel, datamodel.NetworkGenerationToNetwork, datamodel.Event, datamodel.Scenario, datamodel.RunConfiguration, datamodel.RunExecution, datamodel.EventOccurrence, datamodel.Embedding, datamodel.SubstrateState, datamodel.NodeEmbedding, datamodel.EdgeEmbedding, datamodel.EdgeEmbeddingPart, datamodel.NodeState, datamodel.EdgeState ], safe=True) except Exception as e: raise e try: cls.ap_setting_record = datamodel.ProcessSetting.create( **cls.ap_setting) cls.sp_setting_record = datamodel.ProcessSetting.create( **cls.sp_setting) cls.network_generation_setting_record = datamodel.NetworkGenerationSetting.create( **cls.network_generation_setting.copy()) cls.event_generation_setting = { #'arrival_process_setting': ap_setting.process_setting_id, #'service_process_Setting': sp_setting.process_setting_id, 'network_setting': cls.network_generation_setting_record. network_generation_setting_id } cls.event_generation_setting_record = datamodel.EventGenerationSetting.create( **cls.event_generation_setting) datamodel.ProcessToEventSetting.create( event_generation_setting=cls. event_generation_setting_record, process_setting=cls.ap_setting_record) datamodel.ProcessToEventSetting.create( event_generation_setting=cls. event_generation_setting_record, process_setting=cls.sp_setting_record) cls.substrate_setting_record = datamodel.NetworkGenerationSetting.create( **cls.substrate_setting.copy()) cls.learning_model_record = datamodel.LearningModel.create( **cls.learning_model) parameter = {"alpha": 0.5, "beta": 0.5, "timeout": 300} cls.algo_setting_record = datamodel.AlgorithmSetting.create( name=cls.algo_setting['name'], parameter=str(parameter)) cls.experiment = datamodel.Experiment.create( description= 'Created for test purposes from setup method of unittest') txn.commit() except Exception as e: txn.rollback() cls.tearDownClass() raise e cls.scenario = concrete_scenarios.VneScenario( if_input=datamodel.ConnectionManager(cls.data_source_config), if_output=None, num_runs=cls.num_runs, substrate_generation_settings=cls.substrate_setting.copy(), vnr_generation_settings=cls.network_generation_setting.copy(), algorithm=cls.algo_setting.copy(), arrival_process=cls.ap_setting.copy(), service_process=cls.sp_setting.copy(), gurobi_settings=cls.gurobi_setting.copy(), learning_model_settings=cls.learning_model.copy()) try: cls.scenario.configure_simulations(literals.WRITE_AT_END_STRATEGY) except RuntimeError: pass
def test_get_event_generation(self): scenario = scs.VneScenario( if_input=datamodel.ConnectionManager(self.data_source_config), if_output=None, num_runs=2, substrate_generation_settings=self.substrate_setting, vnr_generation_settings=self.network_generation_setting, algorithm=self.algo_setting, arrival_process=self.ap_setting, service_process=self.sp_setting, gurobi_settings=None, learning_model_settings=self.learning_model ) arrival_process = scenario._get_process(self.ap_setting) service_process = scenario._get_process(self.sp_setting) virtual_network_generation = scenario._get_network_generation_settings( self.network_generation_setting ) record = scenario._get_event_generation( service_process=service_process, arrival_process=arrival_process, network_generation=virtual_network_generation ) local_ap = self.ap_setting.copy() local_ap['arrival_rate'] = 10 local_sp = self.sp_setting.copy() local_sp['arrival_rate'] = 2000 netgen = self.network_generation_setting.copy() netgen['min_order'] = 20 netgen['max_order'] = 30 arrival_process2 = scenario._get_process(local_ap) service_process2 = scenario._get_process(local_sp) virtual_network_generation2 = scenario._get_network_generation_settings(netgen) ids = [record.identifier] record2 = scenario._get_event_generation( service_process=service_process2, arrival_process=arrival_process, network_generation=virtual_network_generation ) self.assertNotIn(record2.identifier, ids) ids.append(record2.identifier) record3 = scenario._get_event_generation( service_process=service_process, arrival_process=arrival_process2, network_generation=virtual_network_generation ) self.assertNotIn(record3.identifier, ids) ids.append(record3.identifier) record4 = scenario._get_event_generation( service_process=service_process, arrival_process=arrival_process, network_generation=virtual_network_generation2 ) self.assertNotIn(record4.identifier, ids) ids.append(record2.identifier) count = datamodel.EventGenerationSetting.select().count() self.assertEqual(count, 4)