def produce(cls, problem_type, interface_config=None): """ Args: problem_type (string): Type of problem. interface_config (input_output.data_interface.interface_config.DataInterfaceConfig): subclass of this. Returns: interface """ if problem_type == 'vne': if interface_config.storage_type == literals.STORAGE_PEEWEE: interface = vne_interface.ConnectionManager( input_config=interface_config) #interface.connect() else: raise errorbrewer.StorageTypeNotKnownError( 'storage type is unknown') # =============================== # Interface factory does not know # =============================== else: raise errorbrewer.ProblemNotKnownError( 'InterfaceFactory knows: cpp,hpp,dhpp,vne') return interface
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 setUpClass(cls): cls.connection_params = { 'database': 'TestDb', 'host': '127.0.0.1', 'port': 3306, 'user': '******', 'passwd': 'root' } cls.input_if = datamodel.ConnectionManager(interface_config.PeeweeInterfaceConfig(**cls.connection_params)) cls.input_if.connect() cls._num_runs = 2 cls._setup_database() cls.logger = logging.getLogger(str(cls.__class__)) cls.logger.setLevel(logging.DEBUG)
def setUpClass(cls): cls.data_source_config = interface_config.PeeweeInterfaceConfig( database='TestDb', host='127.0.0.1', port=3306, user='******', passwd='root' ) cls.input_if = datamodel.ConnectionManager(cls.data_source_config) cls.input_if.connect() cls.num_runs = 2 cls._setup_database() cls.logger = logging.getLogger(str(cls.__class__)) cls.logger.setLevel(logging.DEBUG)
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 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
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_system_with_filter(self): """ Note: You may have to adapt the vne_system_test.ini in configfiles filter and no filter test cannot be run on the same config file! """ sys.argv.pop(1) aux_params = {} aux_params['aux_params'] = {"output_transfer": "sigmoid", "loss": "bern_ces", "din": 36, "dout": 1, "hlayers": [200], "std": [276.27385142857145, 92.18768, 0.295015214980061, 0.3631751462266762, 0.704984785019939, 0.6367967254413526, 8534.136525714286, 3488.8932114285712, 3.9736228571428573, 0.06870467349371139, 4.6791124927119006, 5.977485714285714, 3.7552, 0.6059714181064139, 0.134753835108421, 0.056255779895266846, 49.09024, 112.61675428571428, 4.216223542872942, -2.894577396290225, 49.08989714285714, 3.9641405439939077, 0.8587628969263279, -129.8747618294985, 2.066026733747659, 0.10348107556069695, 0.6266068257683556, 0.09412178921378062, 124.03708223833604, 9.347017142857142, 121.85962774692571, 2.678280928287532, 3.8316342857142858, 9.340022857142857, 0.042615318823466156, 21.76272], "hidden_transfer": ["tanh"], "optimizer": ["rmsprop", {"momentum": 0.7, "step_rate": 0.001, "decay": 0.9}], "mean": [276.27385142857145, 92.18768, 0.295015214980061, 0.3631751462266762, 0.704984785019939, 0.6367967254413526, 8534.136525714286, 3488.8932114285712, 3.9736228571428573, 0.06870467349371139, 4.6791124927119006, 5.977485714285714, 3.7552, 0.6059714181064139, 0.134753835108421, 0.056255779895266846, 49.09024, 112.61675428571428, 4.216223542872942, -2.894577396290225, 49.08989714285714, 3.9641405439939077, 0.8587628969263279, -129.8747618294985, 2.066026733747659, 0.10348107556069695, 0.6266068257683556, 0.09412178921378062, 124.03708223833604, 9.347017142857142, 121.85962774692571, 2.678280928287532, 3.8316342857142858, 9.340022857142857, 0.042615318823466156, 21.76272]} aux_params['successor_name'] = 'SDP' aux_params['serialized_model'] = '/home/patrick/Documents/GitHub/lkn/deep-sdn/models/breze_rnn_eo50_eorq.pkl' aux_params['timeout'] = 10 aux_params['alpha'] = 0.5 aux_params['beta'] = 0.5 aux_params['type'] = 'breze_rnn' connection = datamodel.ConnectionManager(input_config=self.data_source_config) connection.connect() datamodel.AlgorithmSetting.create( name='RNN_FILTER', parameter=AbstractImplementor(None).serialize(aux_params) ) connection.disconnect() control = ctrl.Control( configurationfile=os.path.join( os.path.dirname(__file__), 'configfiles', 'vne_system_test.ini' ) ) control.start() self.assertEqual( datamodel.NetworkGenerationToNetwork.select().count(), 4 ) self.assertEqual( datamodel.Scenario.select().count(), 2 ) self.assertEqual( datamodel.RunConfiguration.select().count(), 4 ) self.assertEqual( datamodel.RunExecution.select().count(), 4 ) self.assertEqual( datamodel.Network.select().where(datamodel.Network.subclass_type == literals.CLASS_PHYSICAL_NETWORK).count(), 4 ) self.assertEqual(datamodel.AlgorithmSetting.select().count(), 1) self.assertEqual(datamodel.ProcessSetting.select().count(), 2) self.assertEqual(datamodel.EventGenerationSetting.select().count(), 1) self.assertEqual(datamodel.ProcessToEventSetting.select().count(), 2) print 'System test finished'
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)