Commit bd35751f authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Rename feedback_timeout to feedback_timer. Add option for adding application constraints.

parent c20b5a8a
......@@ -3,7 +3,7 @@
#include "../util/dbg.h"
#include "applicationContraints.h"
PrrtApplicationConstraints *PrrtNetworkConstraints_create()
PrrtApplicationConstraints *PrrtApplicationConstraints_create()
{
PrrtApplicationConstraints *constraints = calloc(1, sizeof(PrrtApplicationConstraints));
check_mem(constraints);
......@@ -14,13 +14,13 @@ PrrtApplicationConstraints *PrrtNetworkConstraints_create()
return NULL;
}
bool PrrtNetworkConstraints_destroy(PrrtApplicationConstraints *applicationConstraints)
bool PrrtApplicationConstraints_destroy(PrrtApplicationConstraints *applicationConstraints)
{
free(applicationConstraints);
return true;
}
prrtTimedelta_t PrrtNetworkConstraints_get_target_delay(PrrtApplicationConstraints *applicationConstraints)
prrtTimedelta_t PrrtApplicationConstraints_get_target_delay(PrrtApplicationConstraints *applicationConstraints)
{
return applicationConstraints->targetDelay;
}
......@@ -7,9 +7,9 @@ typedef struct applicationConstraints {
prrtTimedelta_t targetDelay;
} PrrtApplicationConstraints;
PrrtApplicationConstraints * PrrtNetworkConstraints_create(void);
bool PrrtNetworkConstraints_destroy(PrrtApplicationConstraints *applicationConstraints);
PrrtApplicationConstraints *PrrtApplicationConstraints_create(void);
bool PrrtApplicationConstraints_destroy(PrrtApplicationConstraints *applicationConstraints);
prrtTimedelta_t PrrtNetworkConstraints_get_target_delay(PrrtApplicationConstraints *applicationConstraints);
prrtTimedelta_t PrrtApplicationConstraints_get_target_delay(PrrtApplicationConstraints *applicationConstraints);
#endif //PRRT_NETWORKCONTRAINTS_H
......@@ -60,7 +60,7 @@ int PrrtPacket_print(PrrtPacket *packet_ptr)
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->decodingTimeout_us);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->feedbackTimeout_us);
printf("| %61u |\n", payload->feedbackTimer_us);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61s |\n", (char *) (packet_ptr->payload + PRRT_PACKET_DATA_HEADER_SIZE));
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
......@@ -264,7 +264,7 @@ void *encode_data_header(void *buf_ptr, const void *payload)
buf_ptr += sizeof(prrtTimedelta_t);
prrtTimedelta_t *feedback_timeout = (prrtTimedelta_t *) buf_ptr;
*feedback_timeout = htonl(data_payload->feedbackTimeout_us);
*feedback_timeout = htonl(data_payload->feedbackTimer_us);
buf_ptr += sizeof(prrtTimedelta_t);
return buf_ptr;
}
......@@ -410,7 +410,7 @@ void *decode_data_header(void *dstBuffer, const void *srcBuffer)
dstBuffer += sizeof(prrtTimedelta_t);
prrtTimedelta_t *feedback_timeout = (prrtTimedelta_t *) dstBuffer;
data_payload->feedbackTimeout_us = ntohl(*feedback_timeout);
data_payload->feedbackTimer_us = ntohl(*feedback_timeout);
dstBuffer += sizeof(prrtTimedelta_t);
return dstBuffer;
}
......@@ -438,7 +438,7 @@ PrrtPacket *PrrtPacket_create_data_packet(uint8_t priority, const void *payloadP
dataPayload->groupRTT_us = 0;
dataPayload->packetTimeout_us = 110; // TODO: payload->packetTimeout_us = NOW + maximum delay
dataPayload->decodingTimeout_us = 150; // TODO: payload->decodingTimeout_us
dataPayload->feedbackTimeout_us = 170; // TODO: payload->feedback_timer
dataPayload->feedbackTimer_us = 170; // TODO: payload->feedback_timer
PrrtPacket_copy_buffer_to_payload(packet, payloadPointer, PRRT_PACKET_DATA_HEADER_SIZE)
return packet;
......
......@@ -40,9 +40,9 @@ typedef struct prrtPacket {
typedef struct prrtPacketDataPayload {
prrtTimestamp_t timestamp;
prrtTimedelta_t groupRTT_us;
prrtTimedelta_t packetTimeout_us;
prrtTimedelta_t decodingTimeout_us;
prrtTimedelta_t feedbackTimeout_us;
prrtTimestamp_t packetTimeout_us;
prrtTimestamp_t decodingTimeout_us;
prrtTimedelta_t feedbackTimer_us;
} PrrtPacketDataPayload;
#define PRRT_PACKET_DATA_HEADER_SIZE sizeof(PrrtPacketDataPayload)
......
......@@ -12,7 +12,8 @@
#include "dataTransmitter.h"
bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
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);
......@@ -22,7 +23,7 @@ bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
// SENDING TO ALL RECEIVERS
LIST_FOREACH(sock_ptr->receivers, first, next, cur) {
PrrtReceiver* recv = cur->value;
PrrtReceiver *recv = cur->value;
struct hostent *hp;
......@@ -37,7 +38,8 @@ bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
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.");
check(sendto(sock_ptr->dataSocketFd, buf, length, 0, (struct sockaddr *) &targetaddr, sizeof(targetaddr)) ==
length, "Sendto failed.");
usleep(1);
}
......@@ -46,18 +48,19 @@ bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
return true;
error:
PERROR("Sending packet failed.%s", "")
return false;
PERROR("Sending packet failed.%s", "")
return false;
}
void * send_data_loop(void *ptr) {
void *send_data_loop(void *ptr)
{
PrrtSocket *sock_ptr = ptr;
PrrtBlock *block = NULL;
PrrtCodingParams *cpar = PrrtCodingParams_create();
while (1) {
while(1) {
check(pthread_mutex_lock(&sock_ptr->outQueueFilledMutex) == 0, "Lock failed.");
while (List_count(sock_ptr->outQueue) == 0) {
while(List_count(sock_ptr->outQueue) == 0) {
check(pthread_mutex_lock(&sock_ptr->closingMutex) == 0, "Lock failed.");
if(sock_ptr->closing) {
PrrtCodingParams_destroy(cpar);
......@@ -69,7 +72,8 @@ void * send_data_loop(void *ptr) {
return NULL;
}
check(pthread_mutex_unlock(&sock_ptr->closingMutex) == 0, "Unlock failed.");
check(pthread_cond_wait(&sock_ptr->outQueueFilledCv, &sock_ptr->outQueueFilledMutex) == 0, "Cond wait failed.");
check(pthread_cond_wait(&sock_ptr->outQueueFilledCv, &sock_ptr->outQueueFilledMutex) == 0,
"Cond wait failed.");
}
if(block == NULL) {
......@@ -80,22 +84,21 @@ void * send_data_loop(void *ptr) {
packet->sequenceNumber = sock_ptr->sequenceNumberSource++;
packet->index = (uint8_t) (packet->sequenceNumber - block->baseSequenceNumber);
PrrtPacketDataPayload* payload = packet->payload;
PrrtPacketDataPayload *payload = packet->payload;
payload->groupRTT_us = PrrtChannelStateInformation_get_rtt(sock_ptr->csi);
payload->packetTimeout_us = PrrtNetworkConstraints_get_target_delay(sock_ptr->applicationConstraints);
PrrtPacket* packetToSend = PrrtPacket_copy(packet);
PrrtPacket *packetToSend = PrrtPacket_copy(packet);
send_packet(sock_ptr, packetToSend);
PrrtBlock_insert_data_packet(block, packet);
// TODO: redundancy should only be sent when necessary
if (PrrtBlock_encode_ready(block) && false) {
if(PrrtBlock_encode_ready(block)) {
uint32_t j = 0;
PrrtBlock_encode(block, &sock_ptr->sequenceNumberRedundancy);
uint32_t redundancyBlocks = List_count(block->redundancyPackets);
for (j = 0; j < redundancyBlocks; j++) {
for(j = 0; j < redundancyBlocks; j++) {
PrrtPacket *red_pkt = PrrtBlock_get_first_red_data(block);
send_packet(sock_ptr, red_pkt);
}
......@@ -108,6 +111,6 @@ void * send_data_loop(void *ptr) {
}
error:
PERROR("Failed to send packet %s", "");
return NULL;
PERROR("Failed to send packet %s", "");
return NULL;
}
......@@ -29,7 +29,7 @@ PrrtSocket *PrrtSocket_create(const bool is_sender)
sock_ptr->sequenceNumberRedundancy = 1;
sock_ptr->csi = PrrtChannelStateInformation_create();
sock_ptr->applicationConstraints = PrrtNetworkConstraints_create();
sock_ptr->applicationConstraints = PrrtApplicationConstraints_create();
sock_ptr->dataStore = NULL;
......@@ -261,7 +261,7 @@ int PrrtSocket_close(PrrtSocket *sock_ptr) {
}
check(PrrtChannelStateInformation_destroy(sock_ptr->csi), "Could not destroy channel state information.")
check(PrrtNetworkConstraints_destroy(sock_ptr->applicationConstraints), "Could not destroy application constraints.")
check(PrrtApplicationConstraints_destroy(sock_ptr->applicationConstraints), "Could not destroy application constraints.")
close(sock_ptr->dataSocketFd);
close(sock_ptr->feedbackSocketFd);
......@@ -312,3 +312,14 @@ PrrtPacket *PrrtSocket_recv_feedback(PrrtSocket *prrtSocket, const size_t length
error:
return NULL;
}
bool PrrtSocket_set_sock_opt(PrrtSocket *sock_ptr, const char *name, const uint32_t value)
{
if(strcmp(name, "targetdelay") == 0) {
sock_ptr->applicationConstraints->targetDelay = value;
} else {
return false;
}
return true;
}
......@@ -57,6 +57,7 @@ typedef struct prrtSocket {
PrrtSocket *PrrtSocket_create(const bool is_sender);
bool PrrtSocket_bind(PrrtSocket *sock_ptr, const char* ipAddress, const uint16_t port);
bool PrrtSocket_set_sock_opt(PrrtSocket *sock_ptr, const char* name, const uint32_t value);
int PrrtSocket_interrupt(PrrtSocket *sock_ptr);
int PrrtSocket_close(PrrtSocket *sock_ptr);
int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port);
......
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