Example #1
0
    def generate_next_packet(self):
        time_delta = distributions.gamma(settings.GAMMA_SHAPE, settings.GAMMA_SCALE)
        packet = Packet(self.id, Scheduler.time+time_delta)
        self.packets_generated += 1

        if len(self.queue)-1 < settings.BUFFER:                                                     # since the queue adds each packet as it
            # logging                                                                               # is *decided* when it is generated and
            log.success(" ".join([str(self.id), "generated packet", str(packet.id)]))               # not as it *is* generated, one element
            # logging                                                                               # the queue is not counted
            self.queue.append(packet)
            heap_push(Scheduler.events, packet)
        else:
            # logging
            log.error(" ".join([str(self.id), "lost packet", str(packet.id), "(queue full)"]))
            # logging
            self.packets_lost += 1
            packet.is_lost = True
            heap_push(Scheduler.events, packet)                                                     # the packet is pushed into the event
Example #2
0
 def _queue_packet(self, packet):
     packet.is_queued = True
     packet.time = max(self.sending_until, self.receiving_until)                                 # the packet is scheduled for resending
     heap_push(Scheduler.events, packet)                                                         # as soon as the node is free;
     if not packet.is_queued:                                                                    # only enques the packet if it had just
         self.queue.append(packet)                                                               # been generated, avoiding reenqueueing