Commit 51c616ab authored by Andreas Schmidt's avatar Andreas Schmidt

Merge branch 'develop' into feature/congestionControl

parents faee8a34 6191755a
Pipeline #2158 failed with stages
in 1 minute and 12 seconds
......@@ -26,18 +26,17 @@ cdef extern from "proto/channelStateInformation.h":
ctypedef prrtChannelStateInformation PrrtChannelStateInformation
cdef extern from "proto/codingParams.h":
ctypedef struct prrtCodingParams:
ctypedef struct prrtCodingConfiguration:
uint8_t k
uint8_t r
uint8_t n
uint8_t c
uint8_t *n_cycle
ctypedef prrtCodingParams PrrtCodingParams
PrrtCodingParams *PrrtCodingParams_create()
PrrtCodingParams *PrrtCodingParams_copy(PrrtCodingParams *cpar)
bint PrrtCodingParams_update(PrrtCodingParams *cpar, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle)
bint PrrtCodingParams_destroy(PrrtCodingParams *cpar)
ctypedef prrtCodingConfiguration PrrtCodingConfiguration
PrrtCodingConfiguration *PrrtCodingConfiguration_create()
PrrtCodingConfiguration *PrrtCodingConfiguration_copy(PrrtCodingConfiguration *cpar)
bint PrrtCodingConfiguration_destroy(PrrtCodingConfiguration *cpar)
cdef extern from "util/list.h":
cdef struct list:
......@@ -62,7 +61,7 @@ cdef extern from "proto/block.h":
cdef struct prrtBlock:
uint32_t data_count
uint32_t redundancy_count
PrrtCodingParams coding_params
PrrtCodingConfiguration coding_params
uint32_t largest_data_length
uint16_t baseSequenceNumber
List* data_blocks
......@@ -138,7 +137,7 @@ cdef extern from "proto/socket.h":
bint PrrtSocket_set_sock_opt(PrrtSocket *sock_ptr, const_char *name, const uint32_t value)
uint32_t PrrtSocket_get_sock_opt(PrrtSocket *sock_ptr, const_char *name)
bint PrrtSocket_set_coding_parameters(PrrtSocket *s, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle)
PrrtCodingParams *PrrtSocket_get_coding_parameters(PrrtSocket *s)
PrrtCodingConfiguration *PrrtSocket_get_coding_parameters(PrrtSocket *s)
bint PrrtSocket_uses_thread_pinning(PrrtSocket *socket)
uint32_t PrrtSocket_get_rtprop(PrrtSocket *socket)
......
......@@ -5,6 +5,13 @@
# define __builtin_ia32_rdtsc() (0)
#endif
#ifndef __cplusplus
# include <stdatomic.h>
#else
# include <atomic>
# define _Atomic(X) std::atomic< X >
#endif
#ifndef MAX
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#endif
......
......@@ -57,6 +57,14 @@ bool PrrtBlock_destroy(PrrtBlock *block_ptr)
PrrtPacket_destroy(pkt);
}
if(block_ptr->coder != NULL) {
PrrtCoder_destroy(block_ptr->coder);
}
if(block_ptr->codingParams != NULL) {
PrrtCodingConfiguration_destroy(block_ptr->codingParams);
}
List_destroy(block_ptr->dataPackets);
List_destroy(block_ptr->redundancyPackets);
free(block_ptr);
......@@ -68,17 +76,17 @@ bool PrrtBlock_destroy(PrrtBlock *block_ptr)
return false;
}
PrrtBlock * PrrtBlock_create(PrrtCodingParams *cpar, prrtSequenceNumber_t baseSequenceNumber)
PrrtBlock * PrrtBlock_create(PrrtCodingConfiguration *cpar, PrrtCoder* coder, prrtSequenceNumber_t baseSequenceNumber)
{
PrrtBlock *block_ptr = calloc(1, sizeof(PrrtBlock));
check_mem(block_ptr);
block_ptr->coder = coder;
block_ptr->codingParams = cpar;
block_ptr->dataPackets = List_create();
block_ptr->redundancyPackets = List_create();
block_ptr->baseSequenceNumber = baseSequenceNumber;
block_ptr->largestPayloadLength = 0;
block_ptr->coder = NULL;
pthread_mutexattr_t attr;
check(pthread_mutexattr_init(&attr) == EXIT_SUCCESS, "Mutex attr init failed.");
......@@ -184,8 +192,6 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, prrtSequenceNumber_t *seqno)
prrtSequenceNumber_t baseSequenceNumber = block_ptr->baseSequenceNumber;
prrtPacketLength_t length = block_ptr->largestPayloadLength;
PrrtCoder *coder = block_ptr->codingParams->coder;
gf **src = calloc(k, sizeof(gf *));
check_mem(src);
......@@ -203,7 +209,7 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, prrtSequenceNumber_t *seqno)
for(j = 0; j < r; j++) {
fec[j] = calloc(length, sizeof(gf));
check_mem(fec[j]);
PrrtCoder_encode(coder, src, fec[j], j + k, length);
PrrtCoder_encode(block_ptr->coder, src, fec[j], j + k, length);
PrrtPacket *red_packet_ptr = PrrtPacket_create_redundancy_packet(0, (void *) fec[j], length, *seqno,
(uint8_t) (k + j), block_ptr->baseSequenceNumber,
block_ptr->codingParams);
......@@ -237,8 +243,6 @@ bool PrrtBlock_decode(PrrtBlock *block_ptr)
prrtSequenceNumber_t baseSequenceNumber = block_ptr->baseSequenceNumber;
prrtPacketLength_t length = block_ptr->largestPayloadLength;
PrrtCoder *coder = block_ptr->codingParams->coder;
fec = calloc(k, sizeof(gf *));
check_mem(fec);
for(i = 0; i < k; i++) {
......@@ -254,7 +258,7 @@ bool PrrtBlock_decode(PrrtBlock *block_ptr)
gather_data_packets(block_ptr, fec, idx_p);
gather_redundancy_packets(block_ptr, fec, idx_p);
check(PrrtCoder_decode(coder, fec, idx_p, length) == EXIT_SUCCESS, "Could not decode current block.");
check(PrrtCoder_decode(block_ptr->coder, fec, idx_p, length) == EXIT_SUCCESS, "Could not decode current block.");
for(j = 0; j < k; j++) {
if(idx_p[j] >= k) {
......
......@@ -8,21 +8,21 @@
#include "vdmcode/block_code.h"
typedef struct prrtBlock {
PrrtCodingParams* codingParams;
PrrtCodingConfiguration* codingParams;
prrtPacketLength_t largestPayloadLength;
prrtSequenceNumber_t baseSequenceNumber;
List*dataPackets;
List*redundancyPackets;
bool isCoded;
PrrtCoder *coder;
pthread_mutex_t lock;
PrrtCoder *coder;
} PrrtBlock;
/**
* Allocate space for a block.
*/
PrrtBlock * PrrtBlock_create(PrrtCodingParams *cpar, prrtSequenceNumber_t baseSequenceNumber);
PrrtBlock * PrrtBlock_create(PrrtCodingConfiguration *cpar, PrrtCoder* coder, prrtSequenceNumber_t baseSequenceNumber);
/**
* Frees the PrrtBlock data structure.
......
......@@ -2,70 +2,37 @@
#include "../util/common.h"
#include "../util/dbg.h"
#include "../defines.h"
#include "codingParams.h"
PrrtCodingParams *PrrtCodingParams_create(void)
{
PrrtCodingParams *cpar = calloc(1, sizeof(PrrtCodingParams));
check_mem(cpar);
pthread_mutex_init(&cpar->lock, NULL);
cpar->coder = NULL;
uint8_t* n_cycle = calloc(1, sizeof(uint8_t));
n_cycle[0] = N_START - K_START;
PrrtCodingParams_update(cpar, K_START, N_START, 1, n_cycle);
PrrtCodingConfiguration *PrrtCodingConfiguration_create(uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle)
{
PrrtCodingConfiguration *cc = calloc(1, sizeof(PrrtCodingConfiguration));
check_mem(cc);
cc->k = k;
cc->n = n;
cc->r = cc->n - cc->k;
cc->c = c;
if(n_cycle != NULL) {
cc->n_cycle = (uint8_t*) realloc(cc->n_cycle, cc->c * sizeof(int8_t));
memcpy(cc->n_cycle, n_cycle, cc->c * sizeof(int8_t));
}
return cpar;
return cc;
error:
PERROR("Memory issue.%s","");
return NULL;
}
bool PrrtCodingParams_update(PrrtCodingParams *cpar, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle) {
cpar->k = k;
cpar->n = n;
cpar->r = cpar->n - cpar->k;
cpar->c = c;
if(cpar->n_cycle != NULL) {
free(cpar->n_cycle);
}
cpar->n_cycle = n_cycle;
PrrtCoder_get_coder(&cpar->coder, n, k);
return true;
PrrtCodingConfiguration *PrrtCodingConfiguration_copy(PrrtCodingConfiguration *codingConfiguration) {
return PrrtCodingConfiguration_create(codingConfiguration->k, codingConfiguration->n, codingConfiguration->c, codingConfiguration->n_cycle);
}
PrrtCodingParams* PrrtCodingParams_copy(PrrtCodingParams *cpar) {
PrrtCodingParams *result = PrrtCodingParams_create();
check(pthread_mutex_lock(&cpar->lock) == EXIT_SUCCESS, "Lock failed.");
result->k = cpar->k;
result->n = cpar->n;
result->r = cpar->r;
result->c = cpar->c;
result->n_cycle = (uint8_t*) realloc(result->n_cycle, result->c * sizeof(int8_t));
memcpy(result->n_cycle, cpar->n_cycle, result->c * sizeof(int8_t));
// PrrtCoder_get_coder(&result->coder, result->n, result->k); // TODO
check(pthread_mutex_unlock(&cpar->lock) == EXIT_SUCCESS, "Unlock failed");
return result;
error:
PERROR("Could not copy%s", "");
return NULL;
}
bool PrrtCodingParams_destroy(PrrtCodingParams * cpar) {
pthread_mutex_destroy(&cpar->lock);
PrrtCoder_destroy(cpar->coder);
if(cpar->n_cycle != NULL) {
free(cpar->n_cycle);
bool PrrtCodingConfiguration_destroy(PrrtCodingConfiguration *codingConfiguration) {
if(codingConfiguration->n_cycle != NULL) {
free(codingConfiguration->n_cycle);
}
free(cpar);
free(codingConfiguration);
return true;
}
......@@ -4,23 +4,17 @@
#include <pthread.h>
#include <stdint.h>
#include <stdbool.h>
#include "vdmcode/block_code.h"
typedef struct prrtCodingParams {
pthread_mutex_t lock;
typedef struct prrtCodingConfiguration {
uint8_t k;
uint8_t r;
uint8_t n;
uint8_t c;
uint8_t* n_cycle;
} PrrtCodingConfiguration;
PrrtCoder* coder;
} PrrtCodingParams;
PrrtCodingParams * PrrtCodingParams_create(void);
PrrtCodingParams * PrrtCodingParams_copy(PrrtCodingParams *cpar);
bool PrrtCodingParams_update(PrrtCodingParams * cpar, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle);
bool PrrtCodingParams_destroy(PrrtCodingParams * cpar);
PrrtCodingConfiguration *PrrtCodingConfiguration_create(uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle);
PrrtCodingConfiguration *PrrtCodingConfiguration_copy(PrrtCodingConfiguration *codingConfiguration);
bool PrrtCodingConfiguration_destroy(PrrtCodingConfiguration *codingConfiguration);
#endif //PRRT_CODING_PARAMS_H
......@@ -183,9 +183,10 @@ static void handle_redundancy_packet(PrrtSocket *socket, PrrtPacket *packet) {
PrrtBlock *block = PrrtRepairBlockStore_get_block(socket->repairBlockStore,
redundancyPayload->baseSequenceNumber);
if (block == NULL) {
PrrtCodingParams_update(socket->codingParameters, redundancyPayload->k, redundancyPayload->n, 0, NULL);
PrrtCodingConfiguration* codingParams = PrrtCodingConfiguration_create(redundancyPayload->k,
redundancyPayload->n, 0, NULL);
block = PrrtBlock_create(socket->codingParameters, redundancyPayload->baseSequenceNumber);
block = PrrtBlock_create(codingParams, PrrtSocket_get_matching_coder(socket, codingParams), redundancyPayload->baseSequenceNumber);
PrrtRepairBlockStore_insert(socket->repairBlockStore, block);
}
......
......@@ -181,7 +181,7 @@ void *send_data_loop(void *ptr) {
XlapTimeStampClock(sock_ptr, ts_data_packet, packet->sequenceNumber, PrrtTransmitStart);
XlapTimeStampCycle(sock_ptr, ts_data_packet, packet->sequenceNumber, PrrtTransmitStart);
if (block == NULL) {
block = PrrtBlock_create(sock_ptr->codingParameters, packet->sequenceNumber);
block = PrrtBlock_create(PrrtCodingConfiguration_copy(sock_ptr->codingParameters), PrrtCoder_copy(sock_ptr->coder), packet->sequenceNumber);
}
packet->index = (uint8_t) (packet->sequenceNumber - block->baseSequenceNumber);
......
......@@ -73,7 +73,9 @@ PrrtSocket *PrrtSocket_create(const bool is_sender, prrtTimedelta_t target_delay
s->isBound = false;
s->receiver = NULL;
s->codingParameters = PrrtCodingParams_create();
uint8_t n_cycle[1] = { N_START - K_START };
s->codingParameters = PrrtCodingConfiguration_create(K_START, N_START, 1, n_cycle);
s->coder = PrrtCoder_create(s->codingParameters);
s->sequenceNumberSource = 1;
s->sequenceNumberRedundancy = 1;
......@@ -475,7 +477,11 @@ int PrrtSocket_close(PrrtSocket *s) {
}
if (s->codingParameters) {
check(PrrtCodingParams_destroy(s->codingParameters), "Could not destroy coding parameters.")
check(PrrtCodingConfiguration_destroy(s->codingParameters), "Could not destroy coding parameters.")
}
if(s->coder) {
check(PrrtCoder_destroy(s->coder), "Could not destroy coder.")
}
if (s->sendDataThreadAttr != NULL) {
......@@ -522,12 +528,16 @@ bool PrrtSocket_set_sock_opt(PrrtSocket *s, const char *name, const uint32_t val
}
bool PrrtSocket_set_coding_parameters(PrrtSocket *s, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle) {
PrrtCodingParams_update(s->codingParameters, k, n, c, n_cycle);
if(s->codingParameters != NULL) {
PrrtCodingConfiguration_destroy(s->codingParameters);
}
s->codingParameters = PrrtCodingConfiguration_create(k, n, c, n_cycle);
s->coder = PrrtCoder_create(s->codingParameters);
return true;
}
PrrtCodingParams *PrrtSocket_get_coding_parameters(PrrtSocket *s) {
return PrrtCodingParams_copy(s->codingParameters);
PrrtCodingConfiguration *PrrtSocket_get_coding_parameters(PrrtSocket *s) {
return s->codingParameters;
}
......@@ -656,3 +666,14 @@ uint32_t PrrtSocket_get_bbr_app_limited(PrrtSocket *s) {
bool PrrtSocket_get_bbr_round_start(PrrtSocket *s) {
return BBR_getRoundStart(s->receiver->bbr);
}
PrrtCoder *PrrtSocket_get_matching_coder(PrrtSocket *s, PrrtCodingConfiguration *codingParams) {
if (s->coder == NULL || PrrtCoder_get_k(s->coder) != codingParams->k ||
PrrtCoder_get_n(s->coder) != codingParams->n) {
if (s->coder != NULL) {
PrrtCoder_destroy(s->coder);
}
s->coder = PrrtCoder_create(codingParams);
}
return PrrtCoder_copy(s->coder);
};
\ No newline at end of file
#ifndef PRRT_SOCKET_H
#define PRRT_SOCKET_H
#include <stdatomic.h>
#include "../defines.h"
#include "../util/list.h"
#include "../util/pipe.h"
......@@ -75,7 +74,8 @@ typedef struct prrtSocket {
PrrtApplicationConstraints *applicationConstraints;
PrrtCodingParams *codingParameters;
PrrtCodingConfiguration *codingParameters;
PrrtCoder *coder;
_Atomic (XlapTimestampTable *) tstable[2];
......@@ -104,7 +104,9 @@ uint32_t PrrtSocket_get_sock_opt(PrrtSocket *s, const char *name);
bool PrrtSocket_set_coding_parameters(PrrtSocket *s, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle);
PrrtCodingParams *PrrtSocket_get_coding_parameters(PrrtSocket *s);
PrrtCodingConfiguration *PrrtSocket_get_coding_parameters(PrrtSocket *s);
PrrtCoder *PrrtSocket_get_matching_coder(PrrtSocket *s, PrrtCodingConfiguration *codingParams);
int PrrtSocket_interrupt(PrrtSocket *s);
......
#include <pthread.h>
#include <stdatomic.h>
#include "../../defines.h"
#include "../types/packet.h"
#include "../../util/common.h"
#include "../../util/dbg.h"
......
......@@ -7,7 +7,7 @@ PrrtReceptionTable *PrrtReceptionTable_create(void) {
PrrtReceptionTable* t = calloc(1, sizeof(PrrtReceptionTable));
check_mem(t);
t->start = 0;
t->maxNumberInWindow = 0;
t->nextNumberAfterWindow = 0;
t->windowSize = 1000;
t->bitmap = Bitmap_create(false, SEQNO_SPACE);
......@@ -33,12 +33,12 @@ bool PrrtReceptionTable_destroy(PrrtReceptionTable *t) {
bool PrrtReceptionTable_mark_received(PrrtReceptionTable *t, prrtSequenceNumber_t markedNumber) {
check(pthread_mutex_lock(&t->lock) == EXIT_SUCCESS, "Lock failed.");
prrtSequenceNumber_t markedNumber_relative = (prrtSequenceNumber_t) (markedNumber - t->start);
prrtSequenceNumber_t maxNumberInWindow_relative = (prrtSequenceNumber_t) (t->maxNumberInWindow - t->start);
prrtSequenceNumber_t maxNumberInWindow_relative = (prrtSequenceNumber_t) (t->nextNumberAfterWindow - t->start);
if (markedNumber_relative < t->windowSize) {
Bitmap_set_1(t->bitmap, markedNumber);
if(markedNumber_relative > maxNumberInWindow_relative) {
t->maxNumberInWindow = markedNumber;
t->nextNumberAfterWindow = (prrtSequenceNumber_t) (markedNumber + 1);
}
}
......@@ -58,7 +58,16 @@ bool PrrtReceptionTable_mark_received(PrrtReceptionTable *t, prrtSequenceNumber_
PrrtLossStatistics PrrtReceptionTable_calculate_statistics(PrrtReceptionTable *t) {
check(pthread_mutex_lock(&t->lock) == EXIT_SUCCESS, "Lock failed.");
prrtSequenceNumber_t length = (prrtSequenceNumber_t) ((t->maxNumberInWindow - t->start) + 1);
if(t->nextNumberAfterWindow == t->start) {
return (PrrtLossStatistics) {
.erasureCount = 0,
.packetCount = 0,
.gapCount = 0,
.burstCount = 0,
};
}
prrtSequenceNumber_t length = (prrtSequenceNumber_t) ((t->nextNumberAfterWindow - t->start));
bool x0 = Bitmap_get(t->bitmap, t->start) == false;
PrrtLossStatistics statistics = {
.erasureCount = (uint16_t) x0,
......
......@@ -11,7 +11,7 @@
typedef struct {
prrtSequenceNumber_t start;
Bitmap* bitmap;
prrtSequenceNumber_t maxNumberInWindow;
prrtSequenceNumber_t nextNumberAfterWindow;
prrtSequenceNumber_t windowSize;
pthread_mutex_t lock;
} PrrtReceptionTable;
......
......@@ -444,7 +444,7 @@ PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *payloadP
prrtPacketLength_t payloadLength,
prrtSequenceNumber_t sequenceNumber, uint8_t index,
prrtSequenceNumber_t baseSequenceNumber,
PrrtCodingParams *codingParams) {
PrrtCodingConfiguration *codingParams) {
PrrtPacket *packet = create_header(priority, sequenceNumber,
(prrtPacketLength_t) (payloadLength + PRRT_PACKET_REDUNDANCY_HEADER_SIZE),
PACKET_TYPE_REDUNDANCY, index);
......
......@@ -112,7 +112,7 @@ PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *payloadP
prrtPacketLength_t payloadLength,
prrtSequenceNumber_t sequenceNumber, uint8_t index,
prrtSequenceNumber_t baseSequenceNumber,
PrrtCodingParams *codingParams);
PrrtCodingConfiguration *codingParams);
bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket);
......
......@@ -510,76 +510,63 @@ static void init_fec(PrrtCoder *cod) {
* and then transforming it into a systematic matrix.
*/
int prrt_coder_create(PrrtCoder **cod, uint8_t k, uint8_t n);
bool PrrtCoder_destroy(PrrtCoder *cod) {
if(cod->references > 1) {
cod->references--;
} else {
int k;
int n;
gf *enc_matrix;
int PrrtCoder_get_coder(PrrtCoder **cod, uint8_t n, uint8_t k) {
int err = EXIT_SUCCESS;
enc_matrix = cod->params.enc_matrix;
k = cod->params.k;
n = cod->params.n;
if (*cod == NULL ||
(*cod)->params.n != n ||
(*cod)->params.k != k) {
PrrtCoder_destroy(*cod);
err = prrt_coder_create(cod, k, n);
if (cod->params.magic != (((FEC_MAGIC ^ k) ^ n) ^ (uintptr_t) (enc_matrix))) {
PERROR("bad parameters to fec_free%s\n", "");
return false;
}
free(enc_matrix);
free(cod);
}
return err;
return true;
}
void PrrtCoder_destroy(PrrtCoder *cod) {
int k;
int n;
gf *enc_matrix;
if (cod == 0)
return;
enc_matrix = cod->params.enc_matrix;
k = cod->params.k;
n = cod->params.n;
if (cod->params.magic != (((FEC_MAGIC ^ k) ^ n) ^ (uintptr_t) (enc_matrix))) {
PERROR("bad parameters to fec_free%s\n", "");
return;
}
free(enc_matrix);
free(cod);
}
PrrtCoder *PrrtCoder_create(PrrtCodingConfiguration *params) {
int prrt_coder_create(PrrtCoder **cod, uint8_t k, uint8_t n) {
int row, col;
gf *p, *tmp_m;
int err = 0;
uint8_t k = params->k;
uint8_t n = params->n;
if (k > GF_SIZE + 1 || n > GF_SIZE + 1 || k > n) {
PERROR("Invalid parameters k %d n %d GF_SIZE %d\n", k, n, GF_SIZE);
return -1;
return NULL;
}
*cod = malloc(sizeof(PrrtCoder));
if (!(*cod)) {
PERROR("Not enough memory for coder!%s\n", "");
return -2;
}
PrrtCoder *cod = calloc(1, sizeof(PrrtCoder));
cod->references = 1;
/*set fec parameter*/
(*cod)->params.k = k;
(*cod)->params.n = n;
(*cod)->params.enc_matrix = NEW_GF_MATRIX(n, k);
if (!(*cod)->params.enc_matrix) {
(*cod)->params.enc_matrix = 0;
cod->params.k = k;
cod->params.n = n;
cod->params.enc_matrix = NEW_GF_MATRIX(n, k);
if (!cod->params.enc_matrix) {
cod->params.enc_matrix = 0;
PERROR("Could not allocate enc_matrix for coder%s\n", "");
err = -2;
goto error;
}
(*cod)->params.magic = ((FEC_MAGIC ^ k) ^ n) ^ (uintptr_t) ((*cod)->params.enc_matrix);
cod->params.magic = ((FEC_MAGIC ^ k) ^ n) ^ (uintptr_t) cod->params.enc_matrix;
/*init tables*/
init_fec(*cod);
init_fec(cod);
/*init auxiliary*/
(*cod)->count_num = 0;
(*cod)->tot_encoding_time = 0;
cod->count_num = 0;
cod->tot_encoding_time = 0;
tmp_m = NEW_GF_MATRIX(n, k);
if (!tmp_m) {
......@@ -597,7 +584,7 @@ int prrt_coder_create(PrrtCoder **cod, uint8_t k, uint8_t n) {
}
for (p = tmp_m + k, row = 0; row < n - 1; row++, p += k) {
for (col = 0; col < k; col++) {
p[col] = (*cod)->gf_exp[modnn(row * col)];
p[col] = cod->gf_exp[modnn(row * col)];
}
}
......@@ -606,29 +593,41 @@ int prrt_coder_create(PrrtCoder **cod, uint8_t k, uint8_t n) {
* k*k vandermonde matrix, multiply right the bottom n-k rows
* by the inverse, and construct the identity matrix at the top.
*/
err = invert_vdm(*cod, tmp_m, k); /* much faster than invert_mat */
err = invert_vdm(cod, tmp_m, k); /* much faster than invert_mat */
if (err < 0) {
PERROR("Could not invert vdm matrix\n");
err = -2;
goto error;
}
matmul(*cod, tmp_m + k * k, tmp_m, (*cod)->params.enc_matrix + k * k, n - k, k, k);
matmul(cod, tmp_m + k * k, tmp_m, cod->params.enc_matrix + k * k, n - k, k, k);
/*
* the upper matrix is I so do not bother with a slow multiply
*/
memset((*cod)->params.enc_matrix, 0x0, k * k * sizeof(gf));
for (p = (*cod)->params.enc_matrix, col = 0; col < k; col++, p += k + 1) {
memset(cod->params.enc_matrix, 0x0, k * k * sizeof(gf));
for (p = cod->params.enc_matrix, col = 0; col < k; col++, p += k + 1) {
*p = 1;
}
free(tmp_m);
return 0;
return cod;
error:
free(*cod);
free((*cod)->params.enc_matrix);
return err;
free(cod->params.enc_matrix);
free(cod);
return NULL;
}
uint8_t PrrtCoder_get_n(PrrtCoder* coder) {
return (uint8_t) coder->params.n;
}
uint8_t PrrtCoder_get_k(PrrtCoder* coder) {
return (uint8_t) coder->params.k;
}
PrrtCoder *PrrtCoder_copy(PrrtCoder* coder) {
coder->references++;
return coder;
}
/*
......
......@@ -40,6 +40,7 @@
#endif
#include <linux/types.h>
#include <stdint.h>
#include "../../proto/codingParams.h"
/*
* You should not need to change anything beyond this point.
......@@ -88,20 +89,20 @@ typedef struct prrtCoder {
#endif
int count_num;
uint64_t tot_encoding_time;
uint64_t references;
} PrrtCoder;
/**
* This functions updates the coder with the new parameters.
* \param k number of data packets in one block
* \param n overall number of packets in one block
* \return 0 on success, -1 if parameters are invalid, -2 if no memory
*/
int PrrtCoder_get_coder(PrrtCoder **cod, uint8_t n, uint8_t k);
PrrtCoder *PrrtCoder_create(PrrtCodingConfiguration *params);
PrrtCoder *PrrtCoder_copy(PrrtCoder* coder);
uint8_t PrrtCoder_get_n(PrrtCoder* coder);
uint8_t PrrtCoder_get_k(PrrtCoder* coder);
/**
* Free the coder object.
*/
void PrrtCoder_destroy(PrrtCoder *cod) ;
bool PrrtCoder_destroy(PrrtCoder *cod) ;
/**
* This function creates an encoded packet from some given packets.
......
......@@ -96,13 +96,20 @@ cdef extern from "util/windowedFilter.c":
pass
class PrrtCodingConfiguration:
def __init__(self, n, k, n_cycle):
# TODO: Validity checks
# n >= k
# sum(n_cycle) == n - k
def __init__(self, n, k, n_cycle=None):
if n < k:
raise ValueError("n must be greater or equal k.")
self.n = n
self.k = k
self.n_cycle = n_cycle
self.r = n - k
if self.r != 0:
if n_cycle is None:
raise ValueError("n_cycle cannot be None if n == k.")
elif sum(n_cycle) != (n-k):
raise ValueError("The elements in n_cycle must sum up to n-k.")
self.n_cycle = n_cycle if n_cycle is not None else [0]
def __repr__(self):
return "PrrtCodingConfiguration(n={},k={},n_cycle={})".format(self.n, self.k, self.n_cycle)
......@@ -110,9 +117,6 @@ class PrrtCodingConfiguration:
def __repr__(self):
return "({},{},{})".format(self.n, self.k, self.n_cycle)
#property n_cycle:
# def __get__(self):
# return list(<uint8_t[:self._c_config.c]> self._c_config.n_cycle)
cdef class PrrtSocket:
cdef cprrt.PrrtSocket* _c_socket
......@@ -164,13 +168,11 @@ cdef class PrrtSocket:
return cprrt.PrrtSocket_get_rtprop(self._c_socket) * 0.000001
property coding_configuration:
def __get__(self):
if not self.isSender:
raise Exception("Not a sender.")
cdef cprrt.PrrtCodingParams *params = cprrt.PrrtSocket_get_coding_parameters(self._c_socket)
result = PrrtCodingConfiguration(params.n, params.k, list(<uint8_t[:params.c]> params.n_cycle))
return result
cdef cprrt.PrrtCodingConfiguration *params = cprrt.PrrtSocket_get_coding_parameters(self._c_socket)