Пример #1
0
    def broadcast_phase(self):
        """
		After the waiting phase, a vehicle has to decide whether or not to relay the received message.
		Here we perform the decision process and, if positive, we send the message to all our radio neighbors (infect)
		"""

        # Decide whether to relay or not. If the CBF algorithm is being used, it just
        # counts how many messages it has received and broadcasts if they are lower than the threshold.
        if config.use_CBF:
            # Here -1 since len(self.messages) is always >=1, because it will always contain the
            # message that infected this vehicle. The message threshold refers to how many messages
            # are received during the waiting phase, so not considering this first message.
            bcast = len(self.messages) - 1 < config.CBF_msg_thresh
        else:
            bcast = self.evaluate_positions(self.messages, self.pos)

        if bcast:
            # Take the first message in the list of incoming messages (the first message generated the infection)
            # and modify it to be ready for broadcast
            msg_recv = self.messages[0]
            msg = self.modify_msg(msg_recv)

            # Don't broadcast if the message reached its hop limit
            if msg.hop == msg.ttl:
                return

            # Update simulator statistics
            self.sim.sent_messages += 1
            self.sim.network_traffic += msg.size()  #EPIC
            #self.sim.network_traffic += len(msg.text)  #probabilistic

            # Send the message by scheduling an event for the simulator (this implements some network delay)
            #self.send_msg_to_neighbors(msg)
            bcast_event = Events.BroadcastEvent(self, msg)
            self.sim.schedule_event(bcast_event)

        # Change state to recovered and update simulation statistics, either the vehicle has broadcasted or not
        self.messages.clear()
        self.sim.infected_counter -= 1
        self.state = State.RECOVERED