Exemple #1
0
def test_hirate_packet_roundtrip():
    packet = packet_classes.FilePacket(file_id=99,
                                       packet_number=1,
                                       total_packet_number=10,
                                       payload="the payload is long")
    packet2 = packet_classes.FilePacket(buffer=packet.to_buffer())
    assert packet.file_id == packet2.file_id
    assert packet.payload_crc == packet2.payload_crc
    assert packet.payload_length == packet2.payload_length
    assert packet.payload == packet2.payload
    assert packet.packet_number == packet2.packet_number
    assert packet.total_packet_number == packet2.total_packet_number
Exemple #2
0
def test_long_hirate_packet():
    with assert_raises(ValueError):
        packet = packet_classes.FilePacket(
            file_id=12,
            packet_number=1,
            total_packet_number=8,
            payload='a' * (packet_classes.FilePacket._max_payload_size + 1))
Exemple #3
0
def put_data_into_packets(buffer, file_id, packet_size=1000):
    packets = []
    num_packets = int(np.ceil(len(buffer) / packet_size))
    for i in range(num_packets):
        msg = buffer[(i * packet_size):((i + 1) * packet_size)]
        packet = packet_classes.FilePacket(file_id=file_id,
                                           packet_number=i,
                                           total_packet_number=num_packets,
                                           payload=msg)
        packets.append(packet)
    return packets
Exemple #4
0
    def run_through_good_test(self):
        # Tests filepacket
        packets = []
        packet_size = 1000
        num_packets = int(np.ceil(len(self.random_msg) / packet_size))
        for i in range(num_packets):
            msg = self.random_msg[(i * packet_size):((i + 1) * packet_size)]
            packet = packet_classes.FilePacket(file_id=0,
                                               packet_number=i,
                                               total_packet_number=num_packets,
                                               payload=msg)
            packets.append(packet)

        buffer = ''
        for packet in packets:
            buffer += packet.to_buffer()
        packets_after, remainder = packet_classes.get_packets_from_buffer(
            buffer,
            packet_class=packet_classes.FilePacket,
            start_byte=packet_classes.FilePacket._valid_start_byte)
        data_buffer = ''.join([packet.payload for packet in packets_after])
        assert (data_buffer == self.random_msg)
Exemple #5
0
 def put_data_into_queue(self,
                         buffer,
                         file_id,
                         packet_size=1000,
                         preempt=False):
     logger.debug('Buffer length: %d in downlink %s' %
                  (len(buffer), self.name))
     packets = []
     num_packets = int(np.ceil(len(buffer) / packet_size))
     for i in range(num_packets):
         msg = buffer[(i * packet_size):((i + 1) * packet_size)]
         packet = packet_classes.FilePacket(file_id=file_id,
                                            packet_number=i,
                                            total_packet_number=num_packets,
                                            payload=msg)
         packets.append(packet)
     packet_length_debug_string = ','.join(
         [str(packet.payload_length) for packet in packets])
     logger.debug('Packet payload lengths: %s for downlink %s' %
                  (packet_length_debug_string, self.name))
     if preempt:
         self.packets_to_send = packets + self.packets_to_send
     else:
         self.packets_to_send = self.packets_to_send + packets
Exemple #6
0
def test_invalid_packet_number():
    with assert_raises(ValueError):
        packet = packet_classes.FilePacket(file_id=12,
                                           packet_number=10,
                                           total_packet_number=3,
                                           payload='hello')