Example #1
0
    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()
Example #2
0
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)

# create 3 ECUs with specification C (here: same as A)
ecu_spec = RegularECUSpec(["My_Test_ECU_4", "My_Test_ECU_5", "My_Test_ECU_6"], 20000, 20000)
ecu_group_4 = api.set_ecus(sim_env, 3, 'MyProtocolECU', ecu_spec)
 
#===============================================================================
#     Creating Gateways
#===============================================================================

# create the Gateway specification
ecu_spec = SimpleBusCouplerSpec([])
Example #3
0
# 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)
ecu_spec.add_sending_actions(150, 0.3, 16, "TEST STRING B", 50)  # sends at 300, 308, 316, ...
 
ecu_group_1 = api.set_ecus(my_env, 1, 'RegularSecureECU', ecu_spec)
 
 
ecu_spec = SimpleECUSpec(['SEC 1'], 2000, 2000)
ecu_spec.set_ecu_setting('t_ecu_auth_trigger_process', 100)  
ecu_spec.set_ecu_setting('t_ecu_auth_trigger_intervall', 1000)  
 
set_settings_sec_mod(ecu_spec)
sec_mod_group = api.set_ecus(my_env, 1, 'SecLwAuthSecurityModule', ecu_spec)
 
ecu_spec = RegularECUSpec(["TEST ECU 9", "TEST ECU 10"], 2000, 2000)
set_settings_ecu(ecu_spec)
ecu_group_3 = api.set_ecus(my_env, 2, 'RegularSecureECU', ecu_spec)
 
ecu_spec = RegularECUSpec(["TEST ECU 11", "TEST ECU 12"], 2000, 2000)
set_settings_ecu(ecu_spec)
Example #4
0
#===============================================================================
api_log_path = os.path.join(os.path.dirname(__file__), "logs/api.log")
api.show_logging(logging.INFO, api_log_path, True)

# environment
sim_env = api.create_environment(500)
  
# create ECUs: Attention: for Tesla the sending actions defined in  add_sending_actions() must
#              conform the defined MessageStream objects. i.e. if a MessageStream is defined 
#              that starts sending at time t_0 with a message sending interval of t_int then
#              the exact same sending action has to be put in the add_sending_action() method!
ecu_spec = RegularECUSpec(["RegularSecureECU_15"], 20000, 20000)
ecu_spec.set_apply_jitter(0.0000001)
# ecu_spec.set_ecu_setting('t_prf_for_key_legitimation', 0)  # NOTE: If this value has a realistic value this is not working or better to say it works with a extreme delay
# ecu_spec.set_ecu_setting('t_generate_compare_mac', 0)  # NOTE: If this value has a realistic value this is not working or better to say it works with a extreme delay
ecu_spec.add_sending_actions(260, 0.1, can_registration.CAN_TEST_MSG, "TEST STRING B", 50)
ecu_group_1 = api.set_ecus(sim_env, 1, 'TeslaECU', ecu_spec)
  
ecu_spec = RegularECUSpec(["TEST ECU 9", "TEST ECU 10"], 20000, 20000)
ecu_spec.set_apply_jitter(0.0000001)
# ecu_spec.set_ecu_setting('t_prf_for_key_legitimation', 0)  # NOTE: If this value has a realistic value this is not working or better to say it works with a extreme delay
# ecu_spec.set_ecu_setting('t_generate_compare_mac', 0)  # NOTE: If this value has a realistic value this is not working or better to say it works with a extreme delay
ecu_group_3 = api.set_ecus(sim_env, 2, 'TeslaECU', ecu_spec)
 
ecu_spec = RegularECUSpec(["TEST ECU 11", "TEST ECU 12"], 20000, 20000)
ecu_spec.set_apply_jitter(0.0000001)
# ecu_spec.set_ecu_setting('t_prf_for_key_legitimation', 0)  # NOTE: If this value has a realistic value this is not working or better to say it works with a extreme delay
# ecu_spec.set_ecu_setting('t_generate_compare_mac', 0)  # NOTE: If this value has a realistic value this is not working or better to say it works with a extreme delay
ecu_spec.add_sending_actions(250, 0.2, can_registration.CAN_TEST_MSG_2, "TEST STRING A", 80)
ecu_group_4 = api.set_ecus(sim_env, 2, 'TeslaECU', ecu_spec)
Example #5
0
from io_processing.result_interpreter.can_bus_interpreter import CanBusInterpreter

#===============================================================================
#     Setup project, ECUs, Gateways, Busses
#===============================================================================
api_log_path = os.path.join(os.path.dirname(__file__), "logs/api.log")
api.show_logging(logging.INFO, api_log_path, True)

# environment
sim_env = api.create_environment(500)
  
# create ECUs: Attention set here TLSECU objects!
ecu_spec = TLSECUSpec(["RegularSecureECU_15"], 20000, 20000)
ecu_spec.set_apply_jitter(0.0001)
ecu_spec.add_sending_actions(20, 0.5, can_registration.CAN_TEST_MSG, "HUHU", 20)
ecu_group_1 = api.set_ecus(sim_env, 1, 'TLSECU', ecu_spec)
  
ecu_spec = TLSECUSpec(["TEST ECU 9", "TEST ECU 10"], 20000, 20000)
ecu_spec.set_apply_jitter(0.0001)
ecu_group_3 = api.set_ecus(sim_env, 2, 'TLSECU', ecu_spec)
 
ecu_spec = TLSECUSpec(["TEST ECU 11", "TEST ECU 12"], 20000, 20000)
ecu_spec.set_apply_jitter(0.0001)
ecu_spec.add_sending_actions(0.4, 0.8, can_registration.CAN_TEST_MSG_2, "A", 20)
ecu_group_4 = api.set_ecus(sim_env, 2, 'TLSECU', ecu_spec)
 
# create gateways
ecu_spec = SimpleBusCouplerSpec([])
ecu_spec.set_ecu_setting('t_transition_process', 2)  # Delay of the gateway
gateway_group_1 = api.set_ecus(sim_env, 1, 'CANGateway', ecu_spec)
gateway_group_2 = api.set_ecus(sim_env, 1, 'CANGateway', ecu_spec)
Example #6
0
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)

# create 3 ECUs with specification C (here: same as A)
ecu_spec = RegularECUSpec(["My_Test_ECU_4", "My_Test_ECU_5", "My_Test_ECU_6"], 20000, 20000)
ecu_group_4 = api.set_ecus(sim_env, 3, 'MyProtocolECU', ecu_spec)
 
#===============================================================================
#     Creating Gateways
#===============================================================================

# create the Gateway specification
ecu_spec = SimpleBusCouplerSpec([])
Example #7
0
ecu_spec.set_apply_jitter(0.000001)

# further settings can be found in the set_settings method of each component e.g. see RegularSecureECU class
ecu_spec.set_ecu_setting('p_stream_hold', False)
ecu_spec.set_ecu_setting('p_stream_req_min_interval', 5)
LWASpecPresets().apply_spec(ecu_spec, 'ecu')

# for a RegularECUSpec define sending actions of the ECU
ecu_spec.add_sending_actions(10, 0.25, can_registration.CAN_TEST_MSG, "TEST STRING A", 50)
ecu_spec.add_sending_actions(10, 0.5, 16, "TEST STRING B", 50)  # sends at 300, 308, 316, ...

# set the ECU already authenticated
ecu_spec.set_authenticated(True)

# generate a ECU group from the specification
ecu_group_1 = api.set_ecus(sim_env, 1, 'RegularSecureECU', ecu_spec)
 
# create further ECU groups
ecu_spec = RegularECUSpec(["RegularSecureECU_1", "RegularSecureECU_10"], 20000, 20000)
ecu_spec.set_apply_jitter(0.0001)
LWASpecPresets().apply_spec(ecu_spec, 'ecu')
ecu_group_3 = api.set_ecus(sim_env, 2, 'RegularSecureECU', ecu_spec)
 
ecu_spec = RegularECUSpec(["RegularSecureECU_18", "Any_ECU_Name"], 20000, 20000)
ecu_spec.set_apply_jitter(0.0001)
# ecu_spec.set_startup_delay(140)  # start this ecu with delay of 15

LWASpecPresets().apply_spec(ecu_spec, 'ecu')
ecu_group_4 = api.set_ecus(sim_env, 3, 'RegularSecureECU', ecu_spec)
 
#===============================================================================
# ===============================================================================
api_log_path = os.path.join(os.path.dirname(__file__), "logs/api.log")
api.show_logging(logging.INFO, api_log_path, True)

# environment
sim_env = api.create_environment(500)

# create ECUs: Attention: for Tesla the sending actions defined in  add_sending_actions() must
#              conform the defined MessageStream objects. i.e. if a MessageStream is defined
#              that starts sending at time t_0 with a message sending interval of t_int then
#              the exact same sending action has to be put in the add_sending_action() method!
ecu_spec = RegularECUSpec(["RegularSecureECU_15"], 20000, 20000)
TeslaSpecPresets().apply_spec(ecu_spec)
ecu_spec.set_apply_jitter(0.0000001)
ecu_spec.add_sending_actions(260, 0.1, can_registration.CAN_TEST_MSG, "TEST STRING B", 50)
ecu_group_1 = api.set_ecus(sim_env, 1, "TeslaECU", ecu_spec)

ecu_spec = RegularECUSpec(["TEST ECU 9", "TEST ECU 10"], 20000, 20000)
TeslaSpecPresets().apply_spec(ecu_spec)
ecu_spec.set_apply_jitter(0.0000001)
ecu_group_3 = api.set_ecus(sim_env, 2, "TeslaECU", ecu_spec)

ecu_spec = RegularECUSpec(["TEST ECU 11", "TEST ECU 12"], 20000, 20000)
ecu_spec.set_apply_jitter(0.0000001)
TeslaSpecPresets().apply_spec(ecu_spec)
ecu_spec.add_sending_actions(250, 0.2, can_registration.CAN_TEST_MSG_2, "TEST STRING A", 80)
ecu_group_4 = api.set_ecus(sim_env, 2, "TeslaECU", ecu_spec)

# create gateways
ecu_spec = SimpleBusCouplerSpec([])
ecu_spec.set_ecu_setting("t_transition_process", 2)
Example #9
0
    def prepare_configuration(self, simpy_env, life_time):
        ''' this method prepares the configuration on the side of the 
            ECU simulation. It sets up the defined environment by mapping
            the ECU Ids as they are defined in the battery management system
            on the ECUs and the defined specs. So the constellation used is
            implemented here.
            
            Input:  simpy_env    simpy.Environment        environment used in the battery management system
                    life_time    float                    life time of the simulation
            Output: -
        '''
        # lifetime
        life_time = 50000
                
        # logging
#         api_log_path = os.path.join(os.path.dirname(__file__), "../logs/api.log")
#         api.show_logging(logging.INFO, api_log_path, True)
        
        # create environment
        sim_env = api.create_environment(life_time)
        sim_env.set_env(simpy_env)
        ecu_list = []
        
        # generate a ecu from the ECU specs setting the adapter
        for ecu_id in self.available_can_adapters():            
            # logging.info("ECU ID %s: " % ecu_id)
            
            # define individual ECU Spec 
            ecu_spec = copy.deepcopy(self._ecu_spec)
            ecu_class_name = self._ecu_class_name
            if ecu_id in self._individual_spec:
                ecu_spec = self._individual_spec[ecu_id][0]
                ecu_class_name = self._individual_spec[ecu_id][1]
            ecu_spec.ecu_id_list = [str(ecu_id)]
            
            # create ecu            
            ecu = api.set_ecus(sim_env, 1, ecu_class_name, ecu_spec)[0]
            ecu_list += [ecu]
            
            # connect ecu to adapter
            ecu.connect_adapter(self.can_bus_adapter[ecu_id])
        
        # add security module
        # create ECU specification
        ecu_spec = SimpleECUSpec(['SEC 1'], 200000, 200000)  # 200 KB
        ecu_spec.set_ecu_setting('t_ecu_auth_trigger_process', 0)  
        ecu_spec.set_ecu_setting('t_ecu_auth_trigger_intervall', 80000)  
        ecu_spec.set_apply_jitter(0.0001)
        sec_mod_group = api.set_ecus(sim_env, 1, 'SecLwAuthSecurityModule', ecu_spec)
        security_module = sec_mod_group[0]
        
        # connect to one bus
        # create the bus specifications
        bus_spec = SimpleBusSpec(['CAN_0'])
        api.set_busses(sim_env, 1, 'StdCANBus', bus_spec)
        api.connect_bus_by_obj(sim_env, 'CAN_0', ecu_list + sec_mod_group) 
                
        # security constellation
        all_ecu_groups = [ecu_list]
        api.register_ecu_groups_to_secmod(sim_env, sec_mod_group[0].ecu_id, all_ecu_groups)         
        certificate_manager = api.create_cert_manager()
        all_created_ecus = api.ecu_list_from_groups([all_ecu_groups])
        ecu_ids = [str(ecu.ecu_id) for ecu in all_created_ecus]        
        for ecu_id in ecu_ids:
            api.generate_valid_ecu_cert_cfg(certificate_manager, ecu_id, CAEnum.CA_L313, security_module.ecu_id, 0, float('inf'))
        api.generate_valid_sec_mod_cert_cfg(certificate_manager, security_module.ecu_id, CAEnum.CA_L313, ecu_ids, 0, float('inf'))
        api.apply_certification(sim_env, certificate_manager)
         
        # define allowed streams -------------------------------------------------------------- TODO very IMPORTANT
        for broadcast_stream_id in [0x0080, 0x0081, 0x0082, 0x0083, 0x0012, 0x0013, 0x0020, 0x00A0, 0x00A1 ]:
            for ecu_id in ecu_ids:
                lst = copy.deepcopy(ecu_ids)
                lst.remove(ecu_id)                
                stream = MessageStream(ecu_id, lst, broadcast_stream_id, float('inf'), 0, float('inf'))
                api.add_allowed_stream(sim_env, security_module.ecu_id, stream)
        #  -------------------------------------------------------------- TODO very IMPORTANT
        
        # set gateways
        api.autoset_gateway_filters(sim_env, sec_mod_group[0].ecu_id)

        # set timing functions
        function_set = TimingFunctionSet()        
        ecu_func_set = StdSecurLwSecModTimingFunctions(main_library_tag='CyaSSL')        
        ecu_func_set.library_tags['t_ecu_auth_reg_msg_validate_cert'] = 'Crypto_Lib_SW'
        function_set.set_mapping_from_function_set(security_module.ecu_id, ecu_func_set)
        api.apply_timing_functions_set(sim_env, security_module.ecu_id, function_set)
        function_set_2 = TimingFunctionSet() 
        ecu_func_set = StdSecurECUTimingFunctions(main_library_tag='CyaSSL')
        ecu_func_set.library_tags['t_adv_msg_secmodcert_enc'] = 'Crypto_Lib_SW'
        for ecu_id in ecu_ids:
            function_set_2.set_mapping_from_function_set(ecu_id, ecu_func_set) 
            api.apply_timing_functions_set(sim_env, ecu_id, function_set_2)
             
        # add monitor
        if self._monitor and self._result_reader:
            api.connect_monitor(sim_env, self._monitor, 0.5)  
            api.connect_result_reader(sim_env, self._monitor, self._result_reader)
             
            # run view if defined 
            if self._view:
                self._view.show(self._result_reader, self._view_options, self.q_application)                

        # run simulation
        api.open_simulation_stop_button(sim_env)
        api.build_simulation(sim_env)
        api.run_simulation(sim_env)