Commit b654b1d6 authored by Andreas Schmidt's avatar Andreas Schmidt

Wokring on encoding/decoding test.

parent 8b5538db
......@@ -9,7 +9,7 @@
#include "coding_params.h"
#include "packet.h"
void gather_data_packets(const PrrtBlock *block_ptr, gf *const *fec, int *idx_p);
void gather_data_packets(PrrtBlock *block_ptr, gf *const *fec, int *idx_p);
void clear_list(gf *const *src, uint8_t k) {
int j = 0;
......@@ -27,9 +27,12 @@ int PrrtBlock_alloc(PrrtBlock **mblock, const PrrtCodingParams *cpar) {
check_mem(mblock);
(*mblock)->coding_params = *cpar;
(*mblock)->data_count = 0;
(*mblock)->data_blocks =List_create();
(*mblock)->redundancy_count = 0;
(*mblock)->redundancy_blocks =List_create();
return 0;
error:
PNOTIMPLEMENTED("TODO");
......@@ -111,8 +114,7 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, uint16_t *seqno) {
}
void PrrtBlock_decode(PrrtBlock *block_ptr) {
printf("__________________ DECODE_____________--");
int j;
int i, j;
uint8_t n = block_ptr->coding_params.n;
uint8_t k = block_ptr->coding_params.k;
......@@ -123,6 +125,10 @@ void PrrtBlock_decode(PrrtBlock *block_ptr) {
PrrtCoder_get_coder(&coder, n, k);
gf** fec = calloc(n, sizeof(gf*));
for (i = 0; i < n; i++) {
fec[i] = calloc(block_ptr->largest_data_length, sizeof(gf));
}
int *idx_p = calloc(k,sizeof(int));
gather_data_packets(block_ptr, fec, idx_p);
......@@ -138,27 +144,28 @@ void PrrtBlock_decode(PrrtBlock *block_ptr) {
PrrtCoder_decode(coder, fec, idx_p, length);
for(j = 0; j < k; j++) {
printf("Dec (%d) ", idx_p[j]);
print_gf(fec[j], length);
// TODO: write back packets !!!
PrrtPacket *packet = calloc(1, sizeof(PrrtPacket));
PrrtPacket_create_data_packet(packet, 0, fec[j], length, 0);
PrrtBlock_insert_data_packet(block_ptr, packet);
}
clear_list(fec, n);
free(fec);
clear_list(idx_p, k);
free(idx_p);
}
void gather_data_packets(const PrrtBlock *block_ptr, gf *const *fec, int *idx_p) {
void gather_data_packets(PrrtBlock *block_ptr, gf *const *fec, int *idx_p) {
int m = 0;
LIST_FOREACH(block_ptr->data_blocks, first, next, cur) {
PrrtPacket* packet = cur->value;
uint32_t count = block_ptr->data_count;
for (m = 0; m < count; ++m) {
PrrtPacket* packet = List_shift(block_ptr->data_blocks);
PrrtPacketDataPayload* dataPayload = packet->payload;
memcpy(fec[m], dataPayload + PRRT_PACKET_DATA_HEADER_SIZE, packet->payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
idx_p[m] = packet->index;
m++;
}
block_ptr->data_count = 0;
// TODO: this setting of data count is horrible and should be fixed
}
PrrtPacket *PrrtBlock_get_first_red_data(PrrtBlock *block_ptr) {
......
......@@ -83,9 +83,9 @@ void *receive_data_loop(void *ptr) {
redundancyPayload = packet->payload;
if(!PrrtForwardPacketTable_test_is_block_relevant(sock_ptr->forwardPacketTable, redundancyPayload->base_seqno, redundancyPayload->n)) {
printf("-------- IRRELEVANT -----------------------\n");
PrrtPacket_print(packet);
printf("-------- IRRELEVANT -----------------------\n");
//printf("-------- IRRELEVANT -----------------------\n");
//PrrtPacket_print(packet);
//printf("-------- IRRELEVANT -----------------------\n");
PrrtPacket_destroy(packet);
break;
}
......
......@@ -24,7 +24,7 @@ int main(int argc, char* const argv[]) {
unsigned char buffer[MAX_PAYLOAD_LENGTH];
int n = PrrtSocket_recv(&sock, buffer);
buffer[n] = '\0';
printf("[B (n: %d, i: %2d)] %s", n, i, buffer);
printf("[B (n: %d, i: %3d)] %s", n, i, buffer);
i++;
usleep(1);
}
......
......@@ -11,7 +11,7 @@ protected:
virtual void SetUp() {
encBlock = NULL;
decBlock = NULL;
PrrtCodingParams *cpar = (PrrtCodingParams *) malloc(sizeof(PrrtCodingParams));
PrrtCodingParams *cpar = (PrrtCodingParams *) calloc(1, sizeof(PrrtCodingParams));
PrrtCodingParams_init(cpar);
PrrtBlock_alloc(&encBlock, cpar);
PrrtBlock_alloc(&decBlock, cpar);
......@@ -24,11 +24,10 @@ protected:
TEST_F(PrrtBlockTest, Encode) {
uint16_t base = 0;
PrrtPacket packets[2];
PrrtPacket redPackets[2];
for (int i = 1; i < 3; ++i) {
for (int i = 1; i < 3; i++) {
char data[3];
sprintf(data, "%d", i);
PrrtPacket *ptr = &packets[i - 1];
......@@ -61,7 +60,13 @@ TEST_F(PrrtBlockTest, Encode) {
PrrtBlock_decode(decBlock);
for (int k = 0; k < 2; ++k) {
PrrtPacket_print(PrrtBlock_get_first_data(decBlock));
PrrtPacket *ptr = PrrtBlock_get_first_data(decBlock);
const char *s1 = (const char*) (packets[k].payload + PRRT_PACKET_DATA_HEADER_SIZE);
const char *s2 = (const char*) (ptr->payload + PRRT_PACKET_DATA_HEADER_SIZE);
ASSERT_STREQ(s1, s2);
PrrtPacket_print(ptr);
// TODO: check for proper data
}
......
......@@ -64,5 +64,4 @@ TEST_F(BPlusTreeTest, FindRange) {
list = List_create();
BPTree_get_range(root, list, 1, 3);
ASSERT_EQ(List_count(list), 3);
BPTree_print(root);
}
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