Commit 7d401f41 authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Estimating RTT as closely as possible.

parent 55ec359d
......@@ -75,7 +75,7 @@ int PrrtPacket_print(PrrtPacket *packet_ptr)
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->group_round_trip_time);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->forward_trip_time);
printf("| %61u |\n", payload->forward_trip_timestamp);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->packet_loss_rate);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
......@@ -194,7 +194,7 @@ void *encode_feedback_header(void *buf_ptr, const void *payload)
buf_ptr += 4;
uint32_t *forward_trip_time = (uint32_t *) buf_ptr;
*forward_trip_time = htonl(feedbackPayload->forward_trip_time);
*forward_trip_time = htonl(feedbackPayload->forward_trip_timestamp);
buf_ptr += 4;
uint32_t *packet_loss_rate = (uint32_t *) buf_ptr;
......@@ -339,7 +339,7 @@ void *decode_feedback_header(void *dstBuffer, const void *srcBuffer)
dstBuffer += 4;
uint32_t *forwardTripTime = (uint32_t *) dstBuffer;
feedback_payload->forward_trip_time = ntohl(*forwardTripTime);
feedback_payload->forward_trip_timestamp = ntohl(*forwardTripTime);
dstBuffer += 4;
uint32_t *packetLossRate = (uint32_t *) dstBuffer;
......@@ -456,9 +456,9 @@ PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *payloadP
}
PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t sequenceNumber,
uint32_t roundTripTime, uint32_t forwardTripTime, uint32_t packetLossRate,
uint16_t gap, uint16_t ngap, uint16_t burst, uint16_t nburst,
uint32_t bandwidth, uint32_t bufferFeedback)
uint32_t roundTripTime, uint32_t packetLossRate, uint16_t gap,
uint16_t ngap, uint16_t burst, uint16_t nburst, uint32_t bandwidth,
uint32_t bufferFeedback)
{
PrrtPacket *packet = create_header(priority, sequenceNumber, PRRT_PACKET_FEEDBACK_HEADER_SIZE, PACKET_TYPE_FEEDBACK,
index);
......@@ -469,7 +469,7 @@ PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, u
payload->receiver_addr = inet_addr("10.0.0.1");
payload->group_round_trip_time = roundTripTime;
payload->forward_trip_time = forwardTripTime;
payload->forward_trip_timestamp = 0;
payload->packet_loss_rate = packetLossRate;
payload->gap = gap;
payload->ngap = ngap;
......
......@@ -25,6 +25,7 @@ typedef struct prrtPacket {
uint32_t payload_len;
} PrrtPacket;
#define PRRT_PACKET_GENERAL_HEADER_SIZE 8
#define PRRT_PACKET_ENCODED_GENERAL_HEADER_LENGTH 4
#define SEQNO_SPACE 65536 // 2**16 as seqno is uint16_t
......@@ -47,7 +48,7 @@ typedef struct prrtPacketRedundancyPayload {
typedef struct prrtPacketFeedbackPayload {
uint32_t receiver_addr;
uint32_t group_round_trip_time;
uint32_t forward_trip_time;
uint32_t forward_trip_timestamp;
uint32_t packet_loss_rate;
uint16_t gap;
uint16_t ngap;
......@@ -66,8 +67,8 @@ PrrtPacket *PrrtPacket_copy(PrrtPacket *original);
PrrtPacket * PrrtPacket_create_data_packet(uint8_t priority, const void *payloadPointer, uint32_t payloadLength, uint16_t sequenceNumber);
PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t sequenceNumber, uint32_t roundTripTime,
uint32_t forwardTripTime, uint32_t packetLossRate, uint16_t gap,
PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t sequenceNumber,
uint32_t roundTripTime, uint32_t packetLossRate, uint16_t gap,
uint16_t ngap, uint16_t burst, uint16_t nburst, uint32_t bandwidth,
uint32_t bufferFeedback);
......
......@@ -62,13 +62,16 @@ bool send_feedback(const PrrtSocket *sock_ptr, struct sockaddr_in remote)
hp = gethostbyname(remote_host);
memcpy((void *) &targetaddr.sin_addr, hp->h_addr_list[0], (size_t) hp->h_length);
uint32_t forwardTripTime = PrrtClock_get_current_time() + sock_ptr->lastSentTimestamp - sock_ptr->lastReceivedTimestamp;
PrrtPacket *feedback_pkt_ptr = PrrtPacket_create_feedback_packet(0, 19, 4715, 3, forwardTripTime, 50, 4, 6, 8, 9, 5, 1);
PrrtPacket *feedback_pkt_ptr = PrrtPacket_create_feedback_packet(0, 19, 4715, 3, 50, 4, 6, 8, 9, 5, 1);
uint32_t length = PrrtPacket_size(feedback_pkt_ptr);
void *buf = calloc(1, length);
check_mem(buf);
check(PrrtPacket_encode(buf, MAX_PAYLOAD_LENGTH, feedback_pkt_ptr), "Buffer for encoding feedback is too small");
uint32_t forwardTripTime = htonl(PrrtClock_get_current_time() + sock_ptr->lastSentTimestamp - sock_ptr->lastReceivedTimestamp);
((PrrtPacketFeedbackPayload*) (buf + PRRT_PACKET_ENCODED_GENERAL_HEADER_LENGTH))->forward_trip_timestamp = forwardTripTime;
// TODO: [LATENCY] By knowing the time for htonl and writing bytes, one could compensate the timestamp.
check(sendto(sock_ptr->feedbackSocketFd, buf, length, 0, (struct sockaddr *) &targetaddr, sizeof(targetaddr)) ==
length, "Sending feedback failed.");
free(buf);
......
......@@ -16,6 +16,7 @@ bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
uint8_t buf[MAX_PAYLOAD_LENGTH];
memset(buf, 0, sizeof(buf));
uint32_t length = PrrtPacket_size(packet);
uint8_t type = PrrtPacket_type(packet);
check(PrrtPacket_encode(buf, MAX_PAYLOAD_LENGTH, packet), "Buffer too small.");
......@@ -34,7 +35,8 @@ 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: to minimize impact of processing delay to the RTT measurement, the timestamp should be taken and saved here
if(type == PACKET_TYPE_DATA) { ((PrrtPacketDataPayload*) buf + PRRT_PACKET_ENCODED_GENERAL_HEADER_LENGTH)->timestamp = htonl(PrrtClock_get_current_time()); }
// TODO: [LATENCY] By knowing the time for htonl and writing bytes, one could compensate the timestamp.
check(sendto(sock_ptr->dataSocketFd, buf, length, 0, (struct sockaddr *) &targetaddr, sizeof(targetaddr)) == length, "Sendto failed.");
usleep(1);
}
......@@ -75,10 +77,6 @@ void * send_data_loop(void *ptr) {
}
PrrtPacket *packet = List_shift(sock_ptr->outQueue);
PrrtPacketDataPayload* dataPayload = packet->payload;
dataPayload->timestamp = PrrtClock_get_current_time();
packet->seqno = sock_ptr->sequenceNumberSource++;
packet->index = (uint8_t) (packet->seqno - block->baseSequenceNumber);
......
......@@ -270,19 +270,19 @@ PrrtPacket *PrrtSocket_recv_feedback(const PrrtSocket *sock_ptr, const size_t le
if (n == 0) {
return NULL;
}
uint32_t receive_time = PrrtClock_get_current_time();
n = recvfrom(sock_ptr->feedbackSocketFd, bufin, length, 0, (struct sockaddr *) &remote, &addrlen);
check(n >= 0, "Receiving feedback failed.");
uint32_t receive_time = PrrtClock_get_current_time();
//uint16_t remote_port = ntohs(remote.sin_port);
//char *remote_host = inet_ntoa(remote.sin_addr);
//debug("Received feedback %s:%d", remote_host, remote_port);
PrrtPacket *packet_ptr = calloc(1, sizeof(PrrtPacket));
check_mem(packet_ptr);
PrrtPacket_decode(bufin, (uint16_t) n, packet_ptr);
PrrtPacketFeedbackPayload* feedbackPayload = packet_ptr->payload;
printf("FTT Timestamp: %d\n", feedbackPayload->forward_trip_timestamp);
printf("RTT: %d\n", receive_time - feedbackPayload->forward_trip_timestamp);
return packet_ptr;
error:
......
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