def main(database=None, config_file=None, mdl_file=None, constraints=None): """ Connects to OrientDB database, discovers the 'TxOp' Children of 'RadioLinks', and modifies the start and end times :param (str) database: the name of the OrientDB database :param (str) config_file: path to the config file for OrientDB :return: """ print( '**************** Calling and Restting OrientDB ****************' ) mdl_full_path = os.path.abspath(mdl_file) importer = MDLImporter(database, mdl_full_path, config_file) importer.import_xml() processor = BrassOrientDBHelper(database, config_file) processor.open_database(over_write=False) reset_orientdb_central_fq(processor) TxOp_nodes = processor.get_nodes_by_type('TxOp') # Brass process of applying constraints happens here updated_frequency = 4943000000 new_fqhz = condition_str('CenterFrequencyHz', str(updated_frequency), '=') print(new_fqhz) TxOp_nodes = processor.get_nodes_by_type('TxOp') RANConfiguration_nodes = processor.get_nodes_by_type('RANConfiguration') for txop_node in TxOp_nodes: print(txop_node) print( '**************** Updating TxOp Node {0} ****************' .format(txop_node._rid)) processor.update_node(txop_node._rid, new_fqhz) for ran_node in RANConfiguration_nodes: print(ran_node) print( '**************** Updating RANConfiguration Node {0} ****************' .format(ran_node._rid)) processor.update_node(ran_node._rid, new_fqhz) # print('Post Modification') # TxOp_nodes = processor.get_nodes_by_type('TxOp') # RANConfiguration_nodes = processor.get_nodes_by_type('RANConfiguration') # # for txop_node in TxOp_nodes: # print(txop_node) # # for ran_node in RANConfiguration_nodes: # print(ran_node) processor.close_database() export = MDLExporter(database, "Scenario_2_Export.xml", config_file) export.export_xml()
class FrequencyModifierTest(unittest.TestCase): def setUp(self): import_mdl(GeneralTestData.database_name, GeneralTestData.config_file, GeneralTestData.mdl_file) self.orientdb_helper = BrassOrientDBHelper( database_name=GeneralTestData.database_name, config_file=GeneralTestData.config_file) self.orientdb_helper.open_database(over_write=False) self.frequency = FrequencyModifier(self.orientdb_helper, FrequencyModifierTestData.value) def tearDown(self): self.orientdb_helper.close_database() def test_adjust_frequency(self): self.frequency.adjust_frequency() valid = False txop_nodes = self.orientdb_helper.get_nodes_by_type('TxOp') for node in txop_nodes: if int(node.CenterFrequencyHz) == FrequencyModifierTestData.value: valid = True else: valid = False break self.assertTrue(valid) def test_adjust_frequency_no_nodes(self): txop_nodes = self.orientdb_helper.get_nodes_by_type('TxOp') txop_rids = [] for node in txop_nodes: txop_rids.append(node._rid) # There are 6 TxOp nodes in Scenario 1's MDL file, which is what is in # the test database self.assertEqual(len(txop_rids), 6) self.orientdb_helper.delete_nodes_by_rid(txop_rids) try: self.frequency.adjust_frequency() except Exception: self.fail( 'Adjusting frequency with 0 TxOp nodes raised an exception unexpectedly' )
def main(database=None, config_file=None, mdl_file=None): mdl_full_path = os.path.abspath(mdl_file) importer = MDLImporter(database, mdl_full_path, config_file) importer.import_xml() processor = BrassOrientDBHelper(database, config_file) processor.open_database(over_write=False) new_schedule = create_new_schedule() print("Final Schedule:\n") for c in new_schedule: c.print_transmission() processor.close_database() export = MDLExporter(database, "Scenario_4_Export.xml", config_file) export.export_xml()
def main(database=None, config_file=None): """ Connects to OrientDB database, discovers the 'TxOp' Children of 'RadioLinks', and modifies the start and end times :param (str) database: the name of the OrientDB database :param (str) config_file: path to the config file for OrientDB :return: """ print( '**************** Update RadioLink Schedule ****************' ) processor = BrassOrientDBHelper(database, config_file) processor.open_database(over_write=False) select_radio = sql.select_sql('RadioLink') RadioLink_nodes = processor.run_query(select_radio) for node in RadioLink_nodes: print('>>>>>>> {0} : {1}'.format(node._rid, node.Name)) printOrientRecord(node) select_radio = '(' + select_radio + ')' traverse_radio = sql.traverse_sql(select_radio, direction='in', edgetype='Containment') TxOp_conditional = sql.condition_str(lh='class', rh='TxOp', op='=') TxOp_select = sql.select_sql(traverse_radio, [TxOp_conditional]) TxOp_nodes = processor.run_query(TxOp_select) # TxOp_nodes = processor.get_nodes_by_type('TxOp') for node in TxOp_nodes: print(node) new_startusec = sql.condition_str('StartUSec', str(int(node.StartUSec) + 105), '=') new_stopusec = sql.condition_str('StopUSec', str(int(node.StopUSec) + 105), '=') processor.update_node(node._rid, new_startusec, new_stopusec) print('Post Modification') TxOp_nodes = processor.get_nodes_by_type('TxOp') for node in TxOp_nodes: print(node) processor.close_database()
def main(database=None, config_file=None, mdl_file=None, constraints=None): """ Instantiates a Processor object and passes in the orientDB database name. Instantiates a Constraints_Database object and passes in the orientDB database name for the system constraints. Pulls down constraints for simulation from the database Overwrites mdl in database with source mdl Calls create_new_schedule() Update database with new schedule Export new MLD :param database: name of an OrientDB :param config_file: location of the config file used to import :return: """ # Open databases for MDL and System Constraints processor = BrassOrientDBHelper(database, config_file) constraints_database = BrassOrientDBHelper(constraints, config_file) constraints_database.open_database(over_write=False) scenarios = constraints_database.get_nodes_by_type("TestScenario") for scenario in scenarios: if scenario.name == "Test Scenario 1": scenario_1 = scenario constraints_list = constraints_database.get_child_nodes( scenario_1._rid, edgetype='HasConstraint') for constraint in constraints_list: if constraint.name == 'system wide constraint': system_constraints = constraint.constraint_data break constraints_database.close_database() # MDL Import Step mdl_full_path = os.path.abspath((mdl_file)) importer = MDLImporter(database, mdl_full_path, config_file) importer.import_xml() # importer.import_mdl() processor.open_database(over_write=False) # Create new Schedule new_schedule, final_fitness = create_new_schedule( system_constraints=system_constraints) print("Final Schedule:\n") for c in new_schedule: c.print_transmission() # Begin Updating MDL Database txop_verties = processor.get_nodes_by_type("TxOp") radio_link_vertices = processor.get_nodes_by_type("RadioLink") radio_link_up_name = "GndRadio_to_TA" radio_link_down_name = "TA_to_GndRadio" for r in radio_link_vertices: if r.Name == radio_link_up_name: radio_link_up = r elif r.Name == radio_link_down_name: radio_link_down = r print(txop_verties) old_txop_list = [op._rid for op in txop_verties] processor.delete_nodes_by_rid(old_txop_list) txop_rids = [] for TxOp in new_schedule: txop_properties = { "StopUSec": TxOp.get_end_time(), "TxOpTimeout": 255, "CenterFrequencyHz": 4919500000, "StartUSec": TxOp.get_start_time() } processor.create_node("TxOp", txop_properties) new_txop = processor.get_nodes_by_type("TxOp") for op in new_txop: if op._rid not in txop_rids: txop_rids.append(op._rid) new_op_rid = op._rid if TxOp.link_direction == 'down': radio_rid = radio_link_down._rid elif TxOp.link_direction == 'up': radio_rid = radio_link_up._rid processor.set_containment_relationship(parent_rid=radio_rid, child_rid=new_op_rid) processor.close_database() print("Fitness: {0}".format(final_fitness)) print("Total Transmission Time: {0} microseconds per epoch".format( total_transmission_time(new_schedule))) print("Final Schedule:\n") for c in new_schedule: c.print_transmission() # Export Updated MDL # export = MDLExporter(database, config_file) export = MDLExporter(database, "Scenario_1_Export.xml", config_file) export.export_xml()