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

Wrote retransmission timeout handler.

parent b292742f
Pipeline #3047 failed with stages
in 2910 minutes and 31 seconds
...@@ -16,6 +16,7 @@ typedef struct prrtBlock { ...@@ -16,6 +16,7 @@ typedef struct prrtBlock {
bool isCoded; bool isCoded;
pthread_mutex_t lock; pthread_mutex_t lock;
PrrtCoder *coder; PrrtCoder *coder;
uint16_t inRound;
} PrrtBlock; } PrrtBlock;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <string.h> #include <string.h>
#include "../../defines.h" #include "../../defines.h"
#include "../block.h" #include "../block.h"
#include "../timer.h"
#include "../receiver.h" #include "../receiver.h"
#include "../socket.h" #include "../socket.h"
#include "../../util/dbg.h" #include "../../util/dbg.h"
...@@ -124,6 +125,40 @@ static bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) { ...@@ -124,6 +125,40 @@ static bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
return false; return false;
} }
void block_timeout(void* arg);
typedef struct timer_arg {
PrrtSocket* socket;
PrrtBlock* block;
} RetransmissionTimerArgs;
void retransmission_round_handler(void *arg) {
int j;
RetransmissionTimerArgs* args = (RetransmissionTimerArgs*) arg;
uint32_t redundancyPackets = args->block->codingParams->n_cycle[args->block->inRound];
for (j = 0; j < redundancyPackets; j++) {
PrrtPacket *red_pkt = PrrtBlock_get_first_red_data(args->block);
send_packet(args->socket, red_pkt);
}
args->block->inRound++;
if (args->block->inRound >= args->block->codingParams->c) {
PrrtBlock_destroy(args->block);
free(arg);
} else {
PrrtTimerTask task = {
.arg = arg,
.fun = retransmission_round_handler
};
// TODO: Chose one RTT + a bit.
uint32_t waittime_us = PrrtSocket_get_rtprop_fwd(args->socket);
prrtTimerDate deadline = abstime_from_now(waittime_us);
PrrtTimer_submit(args->socket->timer, &deadline, &task);
}
}
void *send_data_loop(void *ptr) { void *send_data_loop(void *ptr) {
PrrtSocket *sock_ptr = ptr; PrrtSocket *sock_ptr = ptr;
PrrtBlock *block = NULL; PrrtBlock *block = NULL;
...@@ -159,7 +194,6 @@ void *send_data_loop(void *ptr) { ...@@ -159,7 +194,6 @@ void *send_data_loop(void *ptr) {
PrrtBlock_insert_data_packet(block, packet); PrrtBlock_insert_data_packet(block, packet);
// TODO: redundancy should only be sent when necessary
if (PrrtBlock_encode_ready(block)) { if (PrrtBlock_encode_ready(block)) {
uint32_t j = 0; uint32_t j = 0;
unsigned int redundancy_seqno = sock_ptr->sequenceNumberRedundancy; unsigned int redundancy_seqno = sock_ptr->sequenceNumberRedundancy;
...@@ -167,13 +201,11 @@ void *send_data_loop(void *ptr) { ...@@ -167,13 +201,11 @@ void *send_data_loop(void *ptr) {
PrrtBlock_encode(block, &sock_ptr->sequenceNumberRedundancy); PrrtBlock_encode(block, &sock_ptr->sequenceNumberRedundancy);
XlapTimeStampCycle(sock_ptr, ts_redundancy_packet, redundancy_seqno, PrrtEncodeEnd); XlapTimeStampCycle(sock_ptr, ts_redundancy_packet, redundancy_seqno, PrrtEncodeEnd);
uint32_t redundancyPackets = List_count(block->redundancyPackets); RetransmissionTimerArgs* args = (RetransmissionTimerArgs*) calloc(1, sizeof(RetransmissionTimerArgs));
for (j = 0; j < redundancyPackets; j++) { args->block = block;
PrrtPacket *red_pkt = PrrtBlock_get_first_red_data(block); args->socket = sock_ptr;
send_packet(sock_ptr, red_pkt); retransmission_round_handler(args);
}
PrrtBlock_destroy(block);
block = NULL; block = NULL;
} }
} }
......
...@@ -38,18 +38,6 @@ static inline prrtPacketLength_t deliver_packet(const PrrtSocket *s, void *buffe ...@@ -38,18 +38,6 @@ static inline prrtPacketLength_t deliver_packet(const PrrtSocket *s, void *buffe
return len; return len;
} }
struct timespec abstime_from_now(prrtTimedelta_t wait_time) {
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
struct timespec deadline;
prrtTimedelta_t diff_s = wait_time / 1000000;
prrtTimedelta_t diff_ns = (wait_time % 1000000) * 1000;
deadline.tv_sec = diff_s + now.tv_sec;
deadline.tv_nsec = diff_ns + now.tv_nsec;
return deadline;
}
PrrtSocket *PrrtSocket_create(prrtByteCount_t mtu, prrtTimedelta_t target_delay_us) { PrrtSocket *PrrtSocket_create(prrtByteCount_t mtu, prrtTimedelta_t target_delay_us) {
assert(sizeof(float) == 4); assert(sizeof(float) == 4);
PrrtSocket *s = (PrrtSocket *) calloc(1, sizeof(PrrtSocket)); PrrtSocket *s = (PrrtSocket *) calloc(1, sizeof(PrrtSocket));
...@@ -66,6 +54,8 @@ PrrtSocket *PrrtSocket_create(prrtByteCount_t mtu, prrtTimedelta_t target_delay_ ...@@ -66,6 +54,8 @@ PrrtSocket *PrrtSocket_create(prrtByteCount_t mtu, prrtTimedelta_t target_delay_
s->isBound = false; s->isBound = false;
s->receiver = NULL; s->receiver = NULL;
s->timer = PrrtTimer_create(0);
uint8_t n_cycle[1] = { N_START - K_START }; uint8_t n_cycle[1] = { N_START - K_START };
s->codingParameters = PrrtCodingConfiguration_create(K_START, N_START, 1, n_cycle); s->codingParameters = PrrtCodingConfiguration_create(K_START, N_START, 1, n_cycle);
s->coder = PrrtCoder_create(s->codingParameters); s->coder = PrrtCoder_create(s->codingParameters);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "types/lossStatistics.h" #include "types/lossStatistics.h"
#include "types/packet.h" #include "types/packet.h"
#include "clock.h" #include "clock.h"
#include "timer.h"
#include "xlap.h" #include "xlap.h"
#include "receiver.h" #include "receiver.h"
...@@ -79,6 +80,8 @@ typedef struct prrtSocket { ...@@ -79,6 +80,8 @@ typedef struct prrtSocket {
atomic_bool isThreadPinning; atomic_bool isThreadPinning;
prrtByteCount_t mtu; prrtByteCount_t mtu;
PrrtTimer* timer;
} PrrtSocket; } PrrtSocket;
......
...@@ -35,3 +35,16 @@ void pin_thread_to_core(pthread_attr_t *ap, int core) ...@@ -35,3 +35,16 @@ void pin_thread_to_core(pthread_attr_t *ap, int core)
CPU_SET(core, &cpuset); CPU_SET(core, &cpuset);
pthread_attr_setaffinity_np(ap, sizeof(cpu_set_t), &cpuset); pthread_attr_setaffinity_np(ap, sizeof(cpu_set_t), &cpuset);
} }
struct timespec abstime_from_now(prrtTimedelta_t wait_time) {
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
struct timespec deadline;
prrtTimedelta_t diff_s = wait_time / 1000000;
prrtTimedelta_t diff_ns = (wait_time % 1000000) * 1000;
deadline.tv_sec = diff_s + now.tv_sec;
deadline.tv_nsec = diff_ns + now.tv_nsec;
return deadline;
}
...@@ -3,11 +3,13 @@ ...@@ -3,11 +3,13 @@
#include <sched.h> #include <sched.h>
#include <pthread.h> #include <pthread.h>
#include "../proto/types/packet.h"
#include "../proto/vdmcode/block_code.h" #include "../proto/vdmcode/block_code.h"
int print_buffer(const char *buf, const int length); int print_buffer(const char *buf, const int length);
void print_gf(const gf *start, const int len); void print_gf(const gf *start, const int len);
void pin_thread_to_core(pthread_attr_t *ap, int core); void pin_thread_to_core(pthread_attr_t *ap, int core);
struct timespec abstime_from_now(prrtTimedelta_t wait_time);
#define PERROR(fmt, args...) \ #define PERROR(fmt, args...) \
printf("PRRT ERROR: \n" fmt, ## args); printf("PRRT ERROR: \n" fmt, ## args);
......
Supports Markdown
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