Commit dfc23556 authored by Andreas Schmidt's avatar Andreas Schmidt

Timestamps are set when data packets are inserted into queue.

parent a83ad6f1
......@@ -221,7 +221,8 @@ bool PrrtBlock_decode(PrrtBlock *block_ptr)
for(j = 0; j < k; j++) {
if(idx_p[j] >= k) {
PrrtPacket *packet = PrrtPacket_create_data_packet(0, fec[j], length, (prrtSequenceNumber_t) (baseSequenceNumber + j));
PrrtPacket *packet = PrrtPacket_create_data_packet(0, fec[j], length,
(prrtSequenceNumber_t) (baseSequenceNumber + j), 0);
if(PrrtBlock_insert_data_packet(block_ptr, packet) == false) {
debug("Tried to insert unnecessary packet.");
PrrtPacket_destroy(packet);
......
......@@ -424,8 +424,9 @@ int PrrtPacket_destroy(PrrtPacket *packet)
return 0;
}
PrrtPacket *PrrtPacket_create_data_packet(uint8_t priority, const void *payloadPointer, prrtPacketLength_t payloadLength,
prrtSequenceNumber_t sequenceNumber)
PrrtPacket *PrrtPacket_create_data_packet(uint8_t priority, const void *payloadPointer,
prrtPacketLength_t payloadLength, prrtSequenceNumber_t sequenceNumber,
prrtTimedelta_t targetDelay)
{
PrrtPacket *packet = create_header(priority, sequenceNumber,
(prrtPacketLength_t) (payloadLength + PRRT_PACKET_DATA_HEADER_SIZE), PACKET_TYPE_DATA, 0);
......@@ -435,8 +436,8 @@ PrrtPacket *PrrtPacket_create_data_packet(uint8_t priority, const void *payloadP
packet->payload = dataPayload;
dataPayload->timestamp = PrrtClock_get_current_time_us();
dataPayload->packetTimeout_us = dataPayload->timestamp + targetDelay;
dataPayload->groupRTT_us = 0;
dataPayload->packetTimeout_us = 110; // TODO: payload->packetTimeout_us = NOW + maximum delay
dataPayload->decodingTimeout_us = 150; // TODO: payload->decodingTimeout_us
dataPayload->feedbackTimer_us = 170; // TODO: payload->feedback_timer
PrrtPacket_copy_buffer_to_payload(packet, payloadPointer, PRRT_PACKET_DATA_HEADER_SIZE)
......
......@@ -79,7 +79,8 @@ int PrrtPacket_print(PrrtPacket *packet_ptr);
PrrtPacket *PrrtPacket_copy(PrrtPacket *original);
PrrtPacket *PrrtPacket_create_data_packet(uint8_t priority, const void *payloadPointer,
prrtPacketLength_t payloadLength, prrtSequenceNumber_t sequenceNumber);
prrtPacketLength_t payloadLength, prrtSequenceNumber_t sequenceNumber,
prrtTimedelta_t targetDelay);
PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, prrtSequenceNumber_t sequenceNumber,
prrtTimedelta_t groupRTT, prrtSequenceNumber_t gapLength,
......
......@@ -117,9 +117,13 @@ void *receive_data_loop(void *ptr)
check(send_feedback(sock_ptr, remote), "Sending feedback failed.");
// TODO: packet.timestamp + packet.timeout < now: break
if(PrrtForwardPacketTable_test_set_is_number_relevant(sock_ptr->forwardPacketTable,
prrtTimestamp_t now = PrrtClock_get_prrt_time_us(sock_ptr->clock);
if(now > payload->packetTimeout_us) {
debug("LOSS due to %u > %u", now, payload->packetTimeout_us);
// TODO: note this as loss
PrrtPacket_destroy(packet);
}
else if(PrrtForwardPacketTable_test_set_is_number_relevant(sock_ptr->forwardPacketTable,
packet->sequenceNumber) ==
false) {
PrrtPacket_destroy(packet);
......
......@@ -4,7 +4,6 @@
#include <string.h>
#include "../../defines.h"
#include "../block.h"
#include "../clock.h"
#include "../receiver.h"
#include "../socket.h"
#include "../../util/dbg.h"
......@@ -17,16 +16,6 @@ bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet)
uint8_t buf[MAX_PAYLOAD_LENGTH];
memset(buf, 0, sizeof(buf));
prrtPacketLength_t length = PrrtPacket_size(packet);
prrtPacketType_t type = PrrtPacket_type(packet);
if(type == PACKET_TYPE_DATA) {
PrrtPacketDataPayload *ptr = (PrrtPacketDataPayload *) packet->payload;
prrtTimedelta_t targetDelay = PrrtApplicationConstraints_get_target_delay(sock_ptr->applicationConstraints);
prrtTimestamp_t currentTime = PrrtClock_get_current_time_us();
ptr->timestamp = currentTime;
ptr->packetTimeout_us = currentTime + targetDelay;
}
check(PrrtPacket_encode(buf, MAX_PAYLOAD_LENGTH, packet), "Buffer too small.");
......@@ -45,7 +34,7 @@ bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet)
check(hp != NULL, "Could not resolve host '%s'.", recv->host_name)
memcpy((void *) &targetaddr.sin_addr, hp->h_addr_list[0], (size_t) hp->h_length);
// TODO: [LATENCY] By knowing the time for htonl and writing bytes, one could compensate the timestamp.
// TODO: [LATENCY] By knowing the time encoding etc. that happens upfront, one could make an adjustment here.
check(sendto(sock_ptr->dataSocketFd, buf, length, 0, (struct sockaddr *) &targetaddr, sizeof(targetaddr)) ==
length, "Sendto failed.");
usleep(1);
......
......@@ -111,7 +111,7 @@ int PrrtSocket_send(PrrtSocket *sock_ptr, const uint8_t *data, const size_t data
check(sock_ptr->isSender, "Cannot send on receiver socket.")
check(pthread_mutex_lock(&sock_ptr->outQueueFilledMutex) == 0, "Lock failed.");
PrrtPacket *packet = PrrtPacket_create_data_packet(5, data, (prrtPacketLength_t) data_len, 0);
PrrtPacket *packet = PrrtPacket_create_data_packet(5, data, (prrtPacketLength_t) data_len, 0, PrrtApplicationConstraints_get_target_delay(sock_ptr->applicationConstraints));
List_push(sock_ptr->outQueue, packet);
check(pthread_cond_signal(&sock_ptr->outQueueFilledCv) == 0, "Signal failed.");
......
......@@ -109,9 +109,9 @@ TEST_F(PrrtBlockTest, EncodeDecode)
for(uint32_t i = 0; i < 4; i++) {
char data[3];
sprintf(data, "%d", i);
packets[i] = PrrtPacket_create_data_packet(0, data, (prrtPacketLength_t) strlen(data), i+1);
packets[i] = PrrtPacket_create_data_packet(0, data, (prrtPacketLength_t) strlen(data), i + 1, 0);
packets[i]->index = (uint8_t) i;
refPackets[i] = PrrtPacket_create_data_packet(0, data, (prrtPacketLength_t) strlen(data), i+1);
refPackets[i] = PrrtPacket_create_data_packet(0, data, (prrtPacketLength_t) strlen(data), i + 1, 0);
ASSERT_TRUE(PrrtBlock_insert_data_packet(encBlock, packets[i]));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment