Commit c20b5a8a authored by Andreas Schmidt's avatar Andreas Schmidt

Channel state information is now a normal object. Add application constraints.

parent 220d1945
add_library(PRRT ../defines.h socket.c block.c block.h packet.c packet.h receiver.c receiver.h clock.c clock.h channelStateInformation.c channelStateInformation.h processes/feedbackReceiver.c processes/feedbackReceiver.h processes/dataTransmitter.c processes/dataTransmitter.h codingParams.c codingParams.h vdmcode/block_code.c vdmcode/block_code.h codingParams.c codingParams.h stores/forwardPacketTable.c stores/forwardPacketTable.h processes/dataReceiver.c processes/dataReceiver.h)
add_library(PRRT ../defines.h socket.c block.c block.h packet.c packet.h receiver.c receiver.h clock.c clock.h channelStateInformation.c channelStateInformation.h processes/feedbackReceiver.c processes/feedbackReceiver.h processes/dataTransmitter.c processes/dataTransmitter.h codingParams.c codingParams.h applicationContraints.c applicationContraints.h vdmcode/block_code.c vdmcode/block_code.h codingParams.c codingParams.h stores/forwardPacketTable.c stores/forwardPacketTable.h processes/dataReceiver.c processes/dataReceiver.h)
set_property(TARGET PRRT PROPERTY C_STANDARD 99)
\ No newline at end of file
#include <malloc.h>
#include "../util/common.h"
#include "../util/dbg.h"
#include "applicationContraints.h"
PrrtApplicationConstraints *PrrtNetworkConstraints_create()
{
PrrtApplicationConstraints *constraints = calloc(1, sizeof(PrrtApplicationConstraints));
check_mem(constraints);
return constraints;
error:
PERROR("Not enough memory%s.","");
return NULL;
}
bool PrrtNetworkConstraints_destroy(PrrtApplicationConstraints *applicationConstraints)
{
free(applicationConstraints);
return true;
}
prrtTimedelta_t PrrtNetworkConstraints_get_target_delay(PrrtApplicationConstraints *applicationConstraints)
{
return applicationConstraints->targetDelay;
}
#ifndef PRRT_NETWORKCONTRAINTS_H
#define PRRT_NETWORKCONTRAINTS_H
#include "packet.h"
typedef struct applicationConstraints {
prrtTimedelta_t targetDelay;
} PrrtApplicationConstraints;
PrrtApplicationConstraints * PrrtNetworkConstraints_create(void);
bool PrrtNetworkConstraints_destroy(PrrtApplicationConstraints *applicationConstraints);
prrtTimedelta_t PrrtNetworkConstraints_get_target_delay(PrrtApplicationConstraints *applicationConstraints);
#endif //PRRT_NETWORKCONTRAINTS_H
......@@ -4,22 +4,26 @@
#include "../util/dbg.h"
#include "channelStateInformation.h"
void PrrtChannelStateInformation_init(PrrtChannelStateInformation *csi)
// TODO: LOCKS
PrrtChannelStateInformation * PrrtChannelStateInformation_create()
{
check(csi != NULL, "Input should not be NULL.");
PrrtChannelStateInformation *csi = calloc(1, sizeof(PrrtChannelStateInformation));
check_mem(csi);
csi->rttMean = 0;
csi->rttDev = 0;
return;
return csi;
error:
PERROR("Should not happen.%s","");
return NULL;
}
void PrrtChannelStateInformation_update_rtt(PrrtChannelStateInformation *csi, prrtTimedelta_t rtt)
{
int32_t delta = rtt - csi->rttMean;
// TODO: ensure that there are no arithemtic problems via rounding etc.
// TODO: ensure that there are no arithemtic problems via rounding etc.
csi->rttMean = (prrtTimedelta_t) (csi->rttMean + RRT_ALPHA * delta);
csi->rttDev = (prrtTimedelta_t) (csi->rttDev + RRT_ALPHA * (labs(delta) - csi->rttDev));
}
......@@ -32,4 +36,15 @@ void PrrtChannelStateInformation_print(PrrtChannelStateInformation *csi)
return;
error:
PERROR("Should not happen.%s","");
}
\ No newline at end of file
}
prrtTimedelta_t PrrtChannelStateInformation_get_rtt(PrrtChannelStateInformation *csi)
{
return csi->rttMean;
}
bool PrrtChannelStateInformation_destroy(PrrtChannelStateInformation *csi)
{
free(csi);
return true;
}
......@@ -8,8 +8,10 @@ typedef struct prrtChannelStateInformation {
prrtTimedelta_t rttDev;
} PrrtChannelStateInformation;
void PrrtChannelStateInformation_init(PrrtChannelStateInformation* csi);
PrrtChannelStateInformation* PrrtChannelStateInformation_create(void);
void PrrtChannelStateInformation_update_rtt(PrrtChannelStateInformation* csi, prrtTimedelta_t rtt);
prrtTimedelta_t PrrtChannelStateInformation_get_rtt(PrrtChannelStateInformation* csi);
bool PrrtChannelStateInformation_destroy(PrrtChannelStateInformation* csi);
void PrrtChannelStateInformation_print(PrrtChannelStateInformation *csi);
......
......@@ -81,8 +81,8 @@ void * send_data_loop(void *ptr) {
packet->index = (uint8_t) (packet->sequenceNumber - block->baseSequenceNumber);
PrrtPacketDataPayload* payload = packet->payload;
// TODO: should lock here !
payload->groupRTT_us = sock_ptr->csi.rttMean;
payload->groupRTT_us = PrrtChannelStateInformation_get_rtt(sock_ptr->csi);
payload->packetTimeout_us = PrrtNetworkConstraints_get_target_delay(sock_ptr->applicationConstraints);
PrrtPacket* packetToSend = PrrtPacket_copy(packet);
send_packet(sock_ptr, packetToSend);
......
......@@ -28,7 +28,8 @@ PrrtSocket *PrrtSocket_create(const bool is_sender)
sock_ptr->sequenceNumberSource = 1;
sock_ptr->sequenceNumberRedundancy = 1;
PrrtChannelStateInformation_init(&sock_ptr->csi);
sock_ptr->csi = PrrtChannelStateInformation_create();
sock_ptr->applicationConstraints = PrrtNetworkConstraints_create();
sock_ptr->dataStore = NULL;
......@@ -259,6 +260,9 @@ int PrrtSocket_close(PrrtSocket *sock_ptr) {
free(sock_ptr->address);
}
check(PrrtChannelStateInformation_destroy(sock_ptr->csi), "Could not destroy channel state information.")
check(PrrtNetworkConstraints_destroy(sock_ptr->applicationConstraints), "Could not destroy application constraints.")
close(sock_ptr->dataSocketFd);
close(sock_ptr->feedbackSocketFd);
debug("Socket closed.");
......@@ -301,7 +305,7 @@ PrrtPacket *PrrtSocket_recv_feedback(PrrtSocket *prrtSocket, const size_t length
printf("%s\n", inet_ntoa(a));
prrtTimestamp_t forwardTripTimestamp = ((PrrtPacketFeedbackPayload*) prrtPacket->payload)->forwardTripTimestamp_us;
PrrtChannelStateInformation_update_rtt(&prrtSocket->csi, receiveTime - forwardTripTimestamp);
PrrtChannelStateInformation_update_rtt(prrtSocket->csi, receiveTime - forwardTripTimestamp);
return prrtPacket;
......
......@@ -7,6 +7,7 @@
#include "../util/list.h"
#include "../util/bptree.h"
#include "channelStateInformation.h"
#include "applicationContraints.h"
typedef struct prrtSocket {
......@@ -48,7 +49,9 @@ typedef struct prrtSocket {
prrtTimestamp_t lastSentTimestamp;
prrtTimestamp_t lastReceivedTimestamp;
PrrtChannelStateInformation csi;
PrrtChannelStateInformation* csi;
PrrtApplicationConstraints *applicationConstraints;
} PrrtSocket;
......
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