def create_aut_env(self): # Spaeter on Button Click z.B. ''' this method creates the simulation''' api_log_path = os.path.join(os.path.dirname(__file__), "../logs/api.log") api.show_logging(logging.INFO, api_log_path, True) my_env = api.create_environment(2500) ecu_spec = SimpleECUSpec([], 200, 200) ecu_group_1 = api.set_ecus(my_env, 10, 'SecureECU', ecu_spec) ecu_spec = SimpleECUSpec(['SEC 1'], 200, 200) ecu_spec.set_ecu_setting('t_ecu_auth_trigger_process', 100) ecu_spec.set_ecu_setting('t_ecu_auth_trigger_intervall', 1000) sec_mod_group = api.set_ecus(my_env, 1, 'SecLwAuthSecurityModule', ecu_spec) bus_spec = SimpleBusSpec(['CAN_0']) bus_group = api.set_busses(my_env, 1, 'StdCANBus', bus_spec) api.connect_bus_by_obj(my_env, 'CAN_0', ecu_group_1 + sec_mod_group) api.register_ecu_groups_to_secmod(my_env, sec_mod_group[0].ecu_id, [ecu_group_1]) certeros = api.create_cert_manager() for ecu in APICore()._ecu_list_from_groups([[ecu_group_1]]): # UNINTENDED HACK api.generate_valid_ecu_cert_cfg(certeros, ecu.ecu_id, CAEnum.CA_L313, 'SEC 1', 0, float('inf')) api.generate_valid_sec_mod_cert_cfg(certeros, 'SEC 1', CAEnum.CA_L313, 0, float('inf')) api.apply_certification(my_env, certeros) stream_1 = MessageStream(my_env.get_env(), 'SecureECU_0', ['SecureECU_1', 'SecureECU_4', 'SecureECU_5'], 13, float('inf'), 0, float('inf')) stream_2 = MessageStream(my_env.get_env(), 'SecureECU_1', ['SecureECU_3', 'SecureECU_2', 'SecureECU_5'], 12, float('inf'), 0, float('inf')) stream_3 = MessageStream(my_env.get_env(), 'SecureECU_0', ['SecureECU_4', 'SecureECU_1', 'SecureECU_5'], 222, float('inf'), 0, float('inf')) stream_4 = MessageStream(my_env.get_env(), 'SecureECU_3', ['SecureECU_0', 'SecureECU_1', 'SecureECU_5'], 11, float('inf'), 0, float('inf')) stream_5 = MessageStream(my_env.get_env(), 'SecureECU_4', ['SecureECU_2', 'SecureECU_1', 'SecureECU_3'], 500, float('inf'), 0, float('inf')) api.add_allowed_stream(my_env, 'SEC 1', stream_1) api.add_allowed_stream(my_env, 'SEC 1', stream_2) api.add_allowed_stream(my_env, 'SEC 1', stream_3) api.add_allowed_stream(my_env, 'SEC 1', stream_4) api.add_allowed_stream(my_env, 'SEC 1', stream_5) t_set = TimingFunctionSet() ecu_func_set = StdSecurLwSecModTimingFunctions(main_library_tag='CyaSSL') t_set.set_mapping_from_function_set('SEC 1', ecu_func_set) api.apply_timing_functions_set(my_env, 'SEC 1', t_set) t_set2 = TimingFunctionSet() ecu_func_set = StdSecurECUTimingFunctions(main_library_tag='CyaSSL') for ecu in APICore()._ecu_list_from_groups([[ecu_group_1]]): # UNINTENDED HACK t_set2.set_mapping_from_function_set(ecu.ecu_id, ecu_func_set) api.apply_timing_functions_set(my_env, ecu.ecu_id, t_set2) api.connect_monitor(my_env, self.monitor, 50) api.build_simulation(my_env) ''' start this in a new thread''' sim = SimulationThread(self, my_env) sim.start()
from io_processing.result_interpreter.eventline_interpreter import EventlineInterpreter from io_processing.result_interpreter.checkpoint_interpreter import CheckpointInterpreter from io_processing.result_interpreter.buffer_interpreter import BufferInterpreter from io_processing.surveillance_handler import InputHandlerChain, EventlineHandler # @UnusedImport #=============================================================================== # -> Register folder with our new ECU # -> Setup logging # -> Create Environment #=============================================================================== api.register_ecu_classes(os.path.join(os.path.dirname(__file__), "ecus")) # setup the logging api_log_path = os.path.join(os.path.dirname(__file__), "logs/api.log") api.show_logging(logging.INFO, api_log_path, True) # create an empty environment specification for the environment sim_env = api.create_environment(200) #=============================================================================== # Creating ECUs #=============================================================================== # create ECU with specification A ecu_spec = RegularECUSpec(["My_Test_ECU_1"], 20000, 20000) ecu_spec.add_sending_actions(2, 0.5, 16, "TEST STRING B", 50) # sends a at time 10, 10.5, 11... message id 16, content test string b and size 50 ecu_group_1 = api.set_ecus(sim_env, 1, 'MyProtocolECU', ecu_spec) # create 2 ECUs with specification B (here: same as A) ecu_spec = RegularECUSpec(["My_Test_ECU_2", "My_Test_ECU_3"], 20000, 20000) ecu_group_3 = api.set_ecus(sim_env, 2, 'MyProtocolECU', ecu_spec)
ecu_spec.set_ecu_setting('p_ecu_auth_cert_hash_signed_size', EncryptionSize().output_size(16, AsymAuthMechEnum.RSA, AuKeyLengthEnum.bit_1024, 'HASH')) '''=========================================================================== ECU Authentication ===========================================================================''' ecu_spec.set_ecu_setting('p_ecu_sym_key_alg', SymAuthMechEnum.AES) ecu_spec.set_ecu_setting('p_ecu_sym_key_keylen', AuKeyLengthEnum.bit_128) '''=========================================================================== Stream Authorization -> Optional ===========================================================================''' # register_ecu_classes(r"C:\Users\artur.mrowca\workspace\ECUSimulation\components\base\gateways") api_log_path = os.path.join(os.path.dirname(__file__), "logs/api.log") api.show_logging(logging.INFO, api_log_path, True) my_env = api.create_environment(180) # Simple ECU CREATION # ecu_spec = SimpleECUSpec([], 200, 200) # set_settings_ecu(ecu_spec) # ecu_group_0 = api.set_ecus(my_env, 7, 'SecureECU', ecu_spec) # Sending ECU: Sends data in fixed intervals ecu_spec = RegularECUSpec(["RegularSecureECU_15"], 2000, 2000) set_settings_ecu(ecu_spec) ecu_spec.set_ecu_setting('p_stream_hold', False) # Define holding behavior per ECU ecu_spec.set_ecu_setting('p_stream_req_min_interval', 5) ecu_spec.add_sending_actions(150, 0.6, can_registration.CAN_TEST_MSG, "TEST STRING A", 50)