def __init__(self, sim_env, ecu_id):
        ''' Constructor
            
            Input:  ecu_id         string                   id of the corresponding AbstractECU
                    sim_env        simpy.Environment        environment of this component
            Output:  -
        '''
        AbstractCommModule.__init__(self, sim_env)

        # local parameters
        self._ecu_id = ecu_id
        self._jitter_in = 1
        self.monitor_list = RefList()
        
        # initialize
        self._init_layers(self.sim_env, self.MessageClass)
        
        # add tags
        self._tags = ["AUTH_SEND_TIME_BEFORE_ENCRYPTION", "AUTH_SEND_TIME_AFTER_ENCRYPTION", "AUTH_RECEIVE_TIME_BEFORE_DECRYPTION", "AUTH_RECEIVE_TIME_AFTER_DECRYPTION"]        
    
        # NEW: Add key pair - public and private
        assymetric_encryption_algorithm = AsymAuthMechEnum.RSA
        assymetric_encryption_key_length = AuKeyLengthEnum.bit_512
        assymetric_encryption_option = 65537
        self.priv_key, self.pub_key = encryption_tools.asy_get_key_pair(assymetric_encryption_algorithm, assymetric_encryption_key_length, assymetric_encryption_option)
        PublicKeyManager().add_key(self._ecu_id, self.pub_key) # make public key available to everybody

        # Create a certificate from root L3 along L3 L31 L311
        [certificate, root_certificates_to_verify_this_certificate, priv_key] = GeneralSpecPreset().certificate_manager.generate_valid_ecu_cert(self._ecu_id, CAEnum.CA_L311, 0, float('inf'))
        self.my_certificate = certificate
        self.my_root_certificates = root_certificates_to_verify_this_certificate
Exemple #2
0
    def connected_bus(self, new_bus):
        ''' if called adds a new port to this 
            gateway. This port has all three layers
            and a whole hardware equipment 
            
            Input:    new_bus    CANBus    bus to be connected to new port
            Output:    -
        '''
        if new_bus != None:

            # create whole layer package per connected Bus
            self._connected_busses.append(new_bus)

            # create layers

            # preset used
            if GeneralSpecPreset().enabled:
                self._transceivers.append(StdTransceiver(self.sim_env))
                self._controller.append(StdCanController(self.sim_env))
                self._physical_layer.append(GeneralSpecPreset().physical_layer(
                    self.sim_env))
                self._datalink_layer.append(GeneralSpecPreset().datalink_layer(
                    self.sim_env))
            else:
                self._transceivers.append(StdTransceiver(self.sim_env))
                self._controller.append(StdCanController(self.sim_env))
                self._physical_layer.append(StdPhysicalLayer(self.sim_env))
                self._datalink_layer.append(StdDatalinkLayer(self.sim_env))

            # interconnect new layers
            self._datalink_layer[-1].controller = self._controller[-1]
            self.sim_env.process(self._datalink_layer[-1].process())
            self._datalink_layer[-1].physical_lay = self._physical_layer[-1]
            self._physical_layer[-1].transceiver = self._transceivers[-1]
            self._physical_layer[
                -1].transceiver.connected_bus = self._connected_busses[-1]

            # intercept gateway methods
            self._override_methods(self._physical_layer[-1].transceiver)

            # activate filter
            if self._filter_values:  # install the fixed filter for all ecus
                self._transceivers[-1].install_filter(self._filter_values)

            if new_bus.comp_id in self._bus_filter_values:  # install the filter for special busses
                self._transceivers[-1].install_filter(
                    self._bus_filter_values[new_bus.comp_id])
    def __init__(self, sim_env):
        ''' Constructor
            
            Input:    sim_env              simpy.Environment                 environment of this component
                      MessageClass         AbstractBusMessage                class that is used for sending and receiving
            Output:   -
        '''
        AbstractCommModule.__init__(self, sim_env)       
         
        # layers
        self.transp_lay = StdTransportLayer(sim_env)  
        self.datalink_lay = StdDatalinkLayer(sim_env)  
        self.physical_lay = StdPhysicalLayer(sim_env) 
        
        # preset used
        if GeneralSpecPreset().enabled: 
            self.transp_lay = GeneralSpecPreset().transport_layer(sim_env, proj.BUS_MSG_CLASS)  
            self.datalink_lay = GeneralSpecPreset().datalink_layer(sim_env)  
            self.physical_lay = GeneralSpecPreset().physical_layer(sim_env) 

        # interconnect layers
        self.datalink_lay.physical_lay = self.physical_lay
        self.transp_lay.datalink_lay = self.datalink_lay
        self.set_settings()
        
        # Timing Variables
        self.STDCM_RECEIVE_PROCESS = time.STDCM_RECEIVE_PROCESS
        self.STDCM_SEND_PROCESS = time.STDCM_SEND_PROCESS
 def __init__(self, sim_env):
     ''' Constructor
         
         Input:  sim_env        simpy.Environment        environment of this component
         Output: -
     '''
     AbstractCommModule.__init__(self, sim_env)       
      
     # initialize layers
     self.transp_lay = FakeSegmentTransportLayer(sim_env, proj.BUS_MSG_CLASS)  
     self.datalink_lay = StdDatalinkLayer(sim_env)  
     self.physical_lay = StdPhysicalLayer(sim_env) 
     
     # preset used
     if GeneralSpecPreset().enabled: 
         self.transp_lay = GeneralSpecPreset().transport_layer(sim_env, proj.BUS_MSG_CLASS)  
         self.datalink_lay = GeneralSpecPreset().datalink_layer(sim_env)  
         self.physical_lay = GeneralSpecPreset().physical_layer(sim_env) 
               
     # connect layers
     self.datalink_lay.physical_lay = self.physical_lay
     self.transp_lay.datalink_lay = self.datalink_lay
Exemple #5
0
class SecModStdCommModule(AbstractCommModule):
    ''' simple communication module in this case used for the 
        application with a security module'''
    def __init__(self, sim_env):
        ''' Constructor
            
            Input:  sim_env        simpy.Environment        environment of this component
            Output: -
        '''
        AbstractCommModule.__init__(self, sim_env)

        # initialize layers
        self.transp_lay = FakeSegmentTransportLayer(sim_env,
                                                    proj.BUS_MSG_CLASS)
        self.datalink_lay = StdDatalinkLayer(sim_env)
        self.physical_lay = StdPhysicalLayer(sim_env)

        # preset used
        if GeneralSpecPreset().enabled:
            self.transp_lay = GeneralSpecPreset().transport_layer(
                sim_env, proj.BUS_MSG_CLASS)
            self.datalink_lay = GeneralSpecPreset().datalink_layer(sim_env)
            self.physical_lay = GeneralSpecPreset().physical_layer(sim_env)

        # connect layers
        self.datalink_lay.physical_lay = self.physical_lay
        self.transp_lay.datalink_lay = self.datalink_lay

    def send_msg(self, sender_id, message_id, message):
        ''' send the message that was passed by further pushing it
            to the next layer
            
            Input:  sender_id    string        id of the ecu that wants to send the message
                    message_id   integer       identifier of the message that is to be sent
                    message      object        message that will be sent
            Output: -
            Output:    -
        '''
        yield self.sim_env.process(
            self.transp_lay.send_msg(sender_id, message_id, message))
class SecModStdCommModule(AbstractCommModule):
    ''' simple communication module in this case used for the 
        application with a security module'''

    def __init__(self, sim_env):
        ''' Constructor
            
            Input:  sim_env        simpy.Environment        environment of this component
            Output: -
        '''
        AbstractCommModule.__init__(self, sim_env)       
         
        # initialize layers
        self.transp_lay = FakeSegmentTransportLayer(sim_env, proj.BUS_MSG_CLASS)  
        self.datalink_lay = StdDatalinkLayer(sim_env)  
        self.physical_lay = StdPhysicalLayer(sim_env) 
        
        # preset used
        if GeneralSpecPreset().enabled: 
            self.transp_lay = GeneralSpecPreset().transport_layer(sim_env, proj.BUS_MSG_CLASS)  
            self.datalink_lay = GeneralSpecPreset().datalink_layer(sim_env)  
            self.physical_lay = GeneralSpecPreset().physical_layer(sim_env) 
                  
        # connect layers
        self.datalink_lay.physical_lay = self.physical_lay
        self.transp_lay.datalink_lay = self.datalink_lay

    
    def send_msg(self, sender_id, message_id, message):
        ''' send the message that was passed by further pushing it
            to the next layer
            
            Input:  sender_id    string        id of the ecu that wants to send the message
                    message_id   integer       identifier of the message that is to be sent
                    message      object        message that will be sent
            Output: -
            Output:    -
        '''
        yield self.sim_env.process(self.transp_lay.send_msg(sender_id, message_id, message))
Exemple #7
0
    def __init__(self, sim_env):
        ''' Constructor
            
            Input:  sim_env        simpy.Environment        environment of this component
            Output: -
        '''
        AbstractCommModule.__init__(self, sim_env)

        # initialize layers
        self.transp_lay = FakeSegmentTransportLayer(sim_env,
                                                    proj.BUS_MSG_CLASS)
        self.datalink_lay = StdDatalinkLayer(sim_env)
        self.physical_lay = StdPhysicalLayer(sim_env)

        # preset used
        if GeneralSpecPreset().enabled:
            self.transp_lay = GeneralSpecPreset().transport_layer(
                sim_env, proj.BUS_MSG_CLASS)
            self.datalink_lay = GeneralSpecPreset().datalink_layer(sim_env)
            self.physical_lay = GeneralSpecPreset().physical_layer(sim_env)

        # connect layers
        self.datalink_lay.physical_lay = self.physical_lay
        self.transp_lay.datalink_lay = self.datalink_lay
class StdCommModule(AbstractCommModule):
    ''' This class implements a secure communication
        module, that enables secure communication between
        several ECUs '''
    
    def __init__(self, sim_env):
        ''' Constructor
            
            Input:    sim_env              simpy.Environment                 environment of this component
                      MessageClass         AbstractBusMessage                class that is used for sending and receiving
            Output:   -
        '''
        AbstractCommModule.__init__(self, sim_env)       
         
        # layers
        self.transp_lay = StdTransportLayer(sim_env)  
        self.datalink_lay = StdDatalinkLayer(sim_env)  
        self.physical_lay = StdPhysicalLayer(sim_env) 
        
        # preset used
        if GeneralSpecPreset().enabled: 
            self.transp_lay = GeneralSpecPreset().transport_layer(sim_env, proj.BUS_MSG_CLASS)  
            self.datalink_lay = GeneralSpecPreset().datalink_layer(sim_env)  
            self.physical_lay = GeneralSpecPreset().physical_layer(sim_env) 

        # interconnect layers
        self.datalink_lay.physical_lay = self.physical_lay
        self.transp_lay.datalink_lay = self.datalink_lay
        self.set_settings()
        
        # Timing Variables
        self.STDCM_RECEIVE_PROCESS = time.STDCM_RECEIVE_PROCESS
        self.STDCM_SEND_PROCESS = time.STDCM_SEND_PROCESS

    
    def set_settings(self):      
        ''' sets the initial setting association between the settings variables
            and the actual parameter
        
            Input:   -
            Output:  -
        '''  
        self.settings = {}
        
        self.settings['t_send_process'] = 'STDCM_SEND_PROCESS'
        self.settings['t_receive_process'] = 'STDCM_RECEIVE_PROCESS'
        
    
    def receive_msg(self):
        ''' simply receives the messages from the transport layer, adds
            a delay to it and then pushes it to the application layer
            
            Input:        -
            Output:    message_data         object         Message that was sent on communication layer of sender side
                       message_id           integer        message identifier of the received message
            
        '''
        if self.STDCM_RECEIVE_PROCESS != 0:
            G().to_t(self.sim_env, self.STDCM_RECEIVE_PROCESS * self._jitter, 'STDCM_RECEIVE_PROCESS', self.__class__.__name__)
            yield self.sim_env.timeout(self.STDCM_RECEIVE_PROCESS * self._jitter)   
        [msg_id, msg_data] = yield self.sim_env.process(self.transp_lay.receive_msg())        
        
        return [msg_id, msg_data]
    
    
    def send_msg(self, sender_id, message_id, message):
        ''' send the message that was passed by further pushing it
            to the next layer and adding a delay
            
            Input:      sender_id      string        id of the sending component
                        message_id     integer        message identifier of the message that will be sent
                        message        object        Message that will be send on to the datalink layer
            Output:        -
        '''
        if self.STDCM_SEND_PROCESS != 0:
            G().to_t(self.sim_env, self.STDCM_SEND_PROCESS * self._jitter, 'STDCM_SEND_PROCESS', self.__class__.__name__)
            yield self.sim_env.timeout(self.STDCM_SEND_PROCESS * self._jitter)   
        yield self.sim_env.process(self.transp_lay.send_msg(sender_id, message_id, message))
Exemple #9
0
LWASpecPresets().ecu_certificate_spec = [HashMechEnum.MD5, AsymAuthMechEnum.RSA, AuKeyLengthEnum.bit_512, 65537, 1, 1000]  # ecu certificate info

LWASpecPresets().confirmation_part = [100]  # confirmation message size

LWASpecPresets().ecu_key_info = [SymAuthMechEnum.AES, AuKeyLengthEnum.bit_128, SymAuthMechEnum.ECB]  # ecu key specification
LWASpecPresets().hold_rule = [False, 10]  # hold on/off; minimal interval between two stream requests

LWASpecPresets().request_spec = [100, 9999999999]  # size of request message and timeout maximum

LWASpecPresets().deny_spec = [100]  # deny message size
LWASpecPresets().grant_spec = [100]  # grant message size

LWASpecPresets().session_key_info = [SymAuthMechEnum.AES, AuKeyLengthEnum.bit_128, SymAuthMechEnum.ECB]  # session key information

# set further layer specifications
GeneralSpecPreset().enable()
GeneralSpecPreset().physical_layer = StdPhysicalLayer
GeneralSpecPreset().datalink_layer = StdDatalinkLayer  # datalink layer that is used in all ECUs that implement this option
GeneralSpecPreset().transport_layer = FakeSegmentTransportLayer

TimingDBMap().enable_fallback_message = True

#===============================================================================
#     Setting up a project
#===============================================================================

# register ECUs that are located outside of the usual folders
# usual folders: components.base.ecu.types and components.security.ecu.types
#api.register_ecu_classes(r"C:\Users\artur.mrowca\workspace\ECUSimulation\components\base\gateways")

# setup the logging
Exemple #10
0
#     -> 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)

#===========================================================================
#     Create Certificate Manager
#===========================================================================
GeneralSpecPreset().certificate_manager = api.create_cert_manager()

#===============================================================================
#     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)