def _extract_transmission_times(self): ''' calculates the time the current transmission takes Input: - Output: t_propagation: float time it takes to propagate the message t_sending float time it takes to send the message ''' t_propagation = time.call(self.SCB_PROPAGATION_DELAY, self.avg_dist_between_ecus) # either constant or calculated depending on config t_sending = time.call(self.SCB_SENDING_TIME, self.current_message_length_bit, proj.BUS_ECU_DATARATE) # either constant or calculated depending on config return t_propagation, t_sending
def call_or_const(self, in_var, *args): # static method call if isinstance(in_var, list): try: lst = in_var[0].split('.') le = in_var[0][:-len(lst[-1]) - 1] impo = importlib.import_module(le) obj = impo.__dict__[lst[-1]]() # @UnusedVariable func_name = in_var[1] val = None val = eval("obj." + func_name + "(*args)") return val except: pass # ECULogger().log_traceback() # simple method call if not isinstance(in_var, (int, float, complex)): out_val = call(in_var, *args) # const variable call else: out_val = in_var return out_val
def process(self): ''' this method processes all messages that are in the transmit buffer once a message is in the buffer the message with the highest priority in the buffer is selected and then sent Input: - Output: - ''' message = None while True: # send highest priority if (message == None): # grab message message = yield self.controller.transmit_buffer.get() message = self._get_next_high_prio(message) # wait if self._need_time_message_priority(): yield self.sim_env.timeout(self.STDDLL_GET_MSG_PRIO * self._jitter) # channel free if self.physical_lay.bus_free(): # try sending sending_ok = yield self.sim_env.process( self.physical_lay.put(message) ) # send message and check if sending was successful, else resend if sending_ok: self.transmit_buffer_size -= message.msg_length_in_bit / 8 message = None yield self.physical_lay.transceiver.connected_bus.sync_send.get( ) # bus busy sending else: continue else: # wait until free -> get notification from bus yield self.sim_env.process( self.physical_lay.wake_if_channel_free()) StdDatalinkLayer.CNT += 1 # wait backoff time backoff = time.call(self.STDDLL_BACKOFF_AFTER_COL, self.effective_bittime) G().to_t(self.sim_env, backoff, 'backoff', self.__class__.__name__, self) yield self.sim_env.timeout(backoff)
def _timeout_sending(self, timing, message): ''' timeout that is needed to send this message on this layer Input: timing: boolean optional value for FakeSegmentTransportLayer message object message that needs to be sent Output: time_val float float if this value is not zero else False ''' time_val = time.call(timing, len(message), self.MessageClass.MAX_DATAFIELD_SIZE) if time_val != 0: G().to_t(self.sim_env, time_val * self._jitter, 'SEND_MSG', self.__class__.__name__, self) return time_val return False
def _receive_frame_for_app(self): ''' returns the next frame that is available and completely received (all segments) Input: - Output: next_message message the whole received message (so the object sent) time_value float time it takes to receive the message ''' next_message = self._get_next_available() time_value = time.call(self.SEGTL_RECEIVE_PROCESS, len(next_message[1]), self.MessageClass.MAX_DATAFIELD_SIZE) if time_value != 0: G().to_t(self.sim_env, time_value * self._jitter, 'REC_MSG', self.__class__.__name__, self) return next_message, time_value
def process(self): ''' this method processes all messages that are in the transmit buffer once a message is in the buffer the message with the highest priority in the buffer is selected and then sent Input: - Output: - ''' message = None while True: # send highest priority if(message == None): # grab message message = yield self.controller.transmit_buffer.get() message = self._get_next_high_prio(message) # wait if self._need_time_message_priority(): yield self.sim_env.timeout(self.STDDLL_GET_MSG_PRIO * self._jitter) # channel free if self.physical_lay.bus_free(): # try sending sending_ok = yield self.sim_env.process(self.physical_lay.put(message)) # send message and check if sending was successful, else resend if sending_ok: self.transmit_buffer_size -= message.msg_length_in_bit / 8 message = None yield self.physical_lay.transceiver.connected_bus.sync_send.get() # bus busy sending else: continue else: # wait until free -> get notification from bus yield self.sim_env.process(self.physical_lay.wake_if_channel_free()) StdDatalinkLayer.CNT += 1 # wait backoff time backoff = time.call(self.STDDLL_BACKOFF_AFTER_COL, self.effective_bittime) G().to_t(self.sim_env, backoff, 'backoff', self.__class__.__name__, self) yield self.sim_env.timeout(backoff)
def receive_msg(self): ''' receives segments from the communication module means datalink layer puts them together and then returns it to the application layer once it demands it Input: - Output: message_data object Message that was sent on communication layer of sender side message_id integer message identifier of the received message ''' # return next message to app layer if (len(self.receiving_buffer) != 0): return self._get_next_received() # receive element msg_segment = 0 while msg_segment != None: # receive frame msg_segment = yield self.sim_env.process( self.datalink_lay.pull_msg()) key_1 = str([ msg_segment.sender_id, msg_segment.message_identifier, msg_segment.unique_id ]) # process the frame self._process_frame_type(msg_segment, key_1) # message length as proposed -> end self._try_expand_length(msg_segment) # return the next frame if (len(self.receiving_buffer) != 0): val = self._get_next_available() time_val = time.call(self.FSEGTL_RECEIVE_PROCESS, len(val[1]), self.MessageClass.MAX_DATAFIELD_SIZE) if time_val != 0: G().to_t(self.sim_env, time_val, 'FSEGTL_RECEIVE_PROCESS', self.__class__.__name__, self) self.sim_env.timeout(time_val) return val return [None, None]
def receive_msg(self): ''' receives segments from the communication module means datalink layer puts them together and then returns it to the application layer once it demands it Input: - Output: message_data object Message that was sent on communication layer of sender side message_id integer message identifier of the received message ''' # return next message to app layer if(len(self.receiving_buffer) != 0): return self._get_next_received() # receive element msg_segment = 0 while msg_segment != None: # receive frame msg_segment = yield self.sim_env.process(self.datalink_lay.pull_msg()) key_1 = str([msg_segment.sender_id, msg_segment.message_identifier, msg_segment.unique_id]) # process the frame self._process_frame_type(msg_segment, key_1) # message length as proposed -> end self._try_expand_length(msg_segment) # return the next frame if(len(self.receiving_buffer) != 0): val = self._get_next_available() time_val = time.call(self.FSEGTL_RECEIVE_PROCESS, len(val[1]), self.MessageClass.MAX_DATAFIELD_SIZE) if time_val != 0: G().to_t(self.sim_env, time_val, 'FSEGTL_RECEIVE_PROCESS', self.__class__.__name__, self) self.sim_env.timeout(time_val) return val return [None, None]