Commit 90004e7a authored by Andreas Schmidt's avatar Andreas Schmidt

Properly decoding redundancy and data packets.

parent b654b1d6
...@@ -9,7 +9,28 @@ ...@@ -9,7 +9,28 @@
#include "coding_params.h" #include "coding_params.h"
#include "packet.h" #include "packet.h"
void gather_data_packets(PrrtBlock *block_ptr, gf *const *fec, int *idx_p); void gather_redundancy_packets(const PrrtBlock *block_ptr, gf *const *fec, int *idx_p) {
int m = block_ptr->data_count;
LIST_FOREACH(block_ptr->redundancy_blocks, first, next, cur) {
PrrtPacket* packet = cur->value;
memcpy(fec[m], packet->payload + PRRT_PACKET_REDUNDANCY_HEADER_SIZE, packet->payload_len - PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
idx_p[m] = packet->index;
m++;
}
}
void gather_data_packets(PrrtBlock *block_ptr, gf *const *fec, int *idx_p) {
int m = 0;
uint32_t count = block_ptr->data_count;
for (m = 0; m < count; ++m) {
PrrtPacket* packet = List_shift(block_ptr->data_blocks);
memcpy(fec[m], packet->payload + 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
}
void clear_list(gf *const *src, uint8_t k) { void clear_list(gf *const *src, uint8_t k) {
int j = 0; int j = 0;
...@@ -100,7 +121,7 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, uint16_t *seqno) { ...@@ -100,7 +121,7 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, uint16_t *seqno) {
PrrtCoder_encode(coder, src, fec[j], j+k, length); // gf **src, gf *fec, int index, int sz PrrtCoder_encode(coder, src, fec[j], j+k, length); // gf **src, gf *fec, int index, int sz
PrrtPacket* red_packet_ptr = PrrtPacket_create_redundancy_packet(0, (void*) fec[j], length, *seqno, PrrtPacket* red_packet_ptr = PrrtPacket_create_redundancy_packet(0, (void*) fec[j], length, *seqno,
(uint8_t) (k + j), base_seqno, block_ptr->coding_params); (uint8_t) (k + j), base_seqno, block_ptr->coding_params);
*seqno = *seqno+1 % SEQNO_SPACE; *seqno = (uint16_t) (*seqno + 1 % SEQNO_SPACE);
PrrtBlock_insert_redundancy_packet(block_ptr, red_packet_ptr); PrrtBlock_insert_redundancy_packet(block_ptr, red_packet_ptr);
} }
...@@ -131,18 +152,11 @@ void PrrtBlock_decode(PrrtBlock *block_ptr) { ...@@ -131,18 +152,11 @@ void PrrtBlock_decode(PrrtBlock *block_ptr) {
int *idx_p = calloc(k,sizeof(int)); int *idx_p = calloc(k,sizeof(int));
gather_redundancy_packets(block_ptr, fec, idx_p);
gather_data_packets(block_ptr, fec, idx_p); gather_data_packets(block_ptr, fec, idx_p);
int m = block_ptr->data_count;
LIST_FOREACH(block_ptr->redundancy_blocks, first, next, cur) {
PrrtPacket* packet = cur->value;
PrrtPacketRedundancyPayload*redundancyPayload = packet->payload;
memcpy(fec[m], redundancyPayload + PRRT_PACKET_REDUNDANCY_HEADER_SIZE, packet->payload_len - PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
idx_p[m] = packet->index;
m++;
}
PrrtCoder_decode(coder, fec, idx_p, length); PrrtCoder_decode(coder, fec, idx_p, length);
for(j = 0; j < k; j++) { for(j = 0; j < k; j++) {
PrrtPacket *packet = calloc(1, sizeof(PrrtPacket)); PrrtPacket *packet = calloc(1, sizeof(PrrtPacket));
PrrtPacket_create_data_packet(packet, 0, fec[j], length, 0); PrrtPacket_create_data_packet(packet, 0, fec[j], length, 0);
...@@ -154,20 +168,6 @@ void PrrtBlock_decode(PrrtBlock *block_ptr) { ...@@ -154,20 +168,6 @@ void PrrtBlock_decode(PrrtBlock *block_ptr) {
free(idx_p); free(idx_p);
} }
void gather_data_packets(PrrtBlock *block_ptr, gf *const *fec, int *idx_p) {
int m = 0;
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) { PrrtPacket *PrrtBlock_get_first_red_data(PrrtBlock *block_ptr) {
block_ptr->redundancy_count--; block_ptr->redundancy_count--;
return List_shift(block_ptr->redundancy_blocks); return List_shift(block_ptr->redundancy_blocks);
......
...@@ -50,6 +50,8 @@ int PrrtPacket_print(PrrtPacket *packet_ptr) { ...@@ -50,6 +50,8 @@ int PrrtPacket_print(PrrtPacket *packet_ptr) {
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"); printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %29u | %29u |\n", payload->decoding_timeout, payload->feedback_timeout); printf("| %29u | %29u |\n", payload->decoding_timeout, payload->feedback_timeout);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"); printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61s |\n", (char *) (packet_ptr->payload + PRRT_PACKET_DATA_HEADER_SIZE));
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
} else if (type == PACKET_TYPE_REDUNDANCY) { } else if (type == PACKET_TYPE_REDUNDANCY) {
PrrtPacketRedundancyPayload *payload = packet_ptr->payload; PrrtPacketRedundancyPayload *payload = packet_ptr->payload;
printf("| %29u | %13u | %13u |\n", payload->base_seqno, payload->n, payload->k); printf("| %29u | %13u | %13u |\n", payload->base_seqno, payload->n, payload->k);
...@@ -104,7 +106,7 @@ int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) ...@@ -104,7 +106,7 @@ int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr)
return 0; return 0;
error: error:
return -1; return -1;
} }
void *encode_redundancy_header(void *buf_ptr, const void *payload) { void *encode_redundancy_header(void *buf_ptr, const void *payload) {
...@@ -232,9 +234,10 @@ int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) ...@@ -232,9 +234,10 @@ int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr)
if (PrrtPacket_type(packet_ptr) == PACKET_TYPE_DATA) { if (PrrtPacket_type(packet_ptr) == PACKET_TYPE_DATA) {
buf_ptr = decode_data_header(buf_ptr, payload_buffer); buf_ptr = decode_data_header(buf_ptr, payload_buffer);
memcpy(payload_buffer + PRRT_PACKET_DATA_HEADER_SIZE, buf_ptr, payload_len - PRRT_PACKET_DATA_HEADER_SIZE); memcpy(payload_buffer + PRRT_PACKET_DATA_HEADER_SIZE, buf_ptr, payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
} else if(PrrtPacket_type(packet_ptr)) { } else if (PrrtPacket_type(packet_ptr)) {
buf_ptr = decode_redundancy_header(buf_ptr, payload_buffer); buf_ptr = decode_redundancy_header(buf_ptr, payload_buffer);
memcpy(payload_buffer + PRRT_PACKET_REDUNDANCY_HEADER_SIZE, buf_ptr, payload_len - PRRT_PACKET_REDUNDANCY_HEADER_SIZE); memcpy(payload_buffer + PRRT_PACKET_REDUNDANCY_HEADER_SIZE, buf_ptr,
payload_len - PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
} else if (PrrtPacket_type(packet_ptr) == PACKET_TYPE_FEEDBACK) { } else if (PrrtPacket_type(packet_ptr) == PACKET_TYPE_FEEDBACK) {
buf_ptr = decode_feedback_header(buf_ptr, payload_buffer); buf_ptr = decode_feedback_header(buf_ptr, payload_buffer);
memcpy(payload_buffer + PRRT_PACKET_FEEDBACK_HEADER_SIZE, buf_ptr, memcpy(payload_buffer + PRRT_PACKET_FEEDBACK_HEADER_SIZE, buf_ptr,
...@@ -245,11 +248,11 @@ int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) ...@@ -245,11 +248,11 @@ int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr)
return 0; return 0;
error: error:
return EXIT_FAILURE; return EXIT_FAILURE;
} }
void *decode_redundancy_header(void *buf_ptr, const void *payload_ptr) { void *decode_redundancy_header(void *buf_ptr, const void *payload_ptr) {
PrrtPacketRedundancyPayload* redundancyPayload = (PrrtPacketRedundancyPayload *) payload_ptr; PrrtPacketRedundancyPayload *redundancyPayload = (PrrtPacketRedundancyPayload *) payload_ptr;
uint16_t *baseSeqNo = (uint16_t *) buf_ptr; uint16_t *baseSeqNo = (uint16_t *) buf_ptr;
redundancyPayload->base_seqno = ntohs(*baseSeqNo); redundancyPayload->base_seqno = ntohs(*baseSeqNo);
...@@ -374,7 +377,7 @@ int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, cons ...@@ -374,7 +377,7 @@ int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, cons
packet_ptr->payload_len = payload_length; packet_ptr->payload_len = payload_length;
error: error:
return -1; return -1;
} }
PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *data_ptr, uint32_t data_len, PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *data_ptr, uint32_t data_len,
...@@ -406,7 +409,7 @@ PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *data_ptr ...@@ -406,7 +409,7 @@ PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *data_ptr
return packet_ptr; return packet_ptr;
error: error:
return NULL; return NULL;
} }
PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t seqno, uint32_t round_trip_time, PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t seqno, uint32_t round_trip_time,
...@@ -440,5 +443,5 @@ PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, u ...@@ -440,5 +443,5 @@ PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, u
return packet_ptr; return packet_ptr;
error: error:
return NULL; return NULL;
} }
\ No newline at end of file
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include <src/util/dbg.h> #include <src/util/dbg.h>
#include <src/prrt/socket.h> #include <src/prrt/socket.h>
#include <src/prrt/block.h> #include <src/prrt/block.h>
#include <src/prrt/packet.h>
#include "data_receiver.h" #include "data_receiver.h"
int send_feedback(const PrrtSocket *sock_ptr, const char *remote_host, const int remote_port) { int send_feedback(const PrrtSocket *sock_ptr, const char *remote_host, const int remote_port) {
......
...@@ -51,6 +51,10 @@ TEST_F(PrrtBlockTest, Encode) { ...@@ -51,6 +51,10 @@ TEST_F(PrrtBlockTest, Encode) {
redPackets[j] = *red_pkt; redPackets[j] = *red_pkt;
} }
printf("------------------------\n");
// DECODING // DECODING
PrrtBlock_insert_data_packet(decBlock, &packets[0]); PrrtBlock_insert_data_packet(decBlock, &packets[0]);
PrrtBlock_insert_redundancy_packet(decBlock, &redPackets[0]); PrrtBlock_insert_redundancy_packet(decBlock, &redPackets[0]);
...@@ -61,11 +65,13 @@ TEST_F(PrrtBlockTest, Encode) { ...@@ -61,11 +65,13 @@ TEST_F(PrrtBlockTest, Encode) {
for (int k = 0; k < 2; ++k) { for (int k = 0; k < 2; ++k) {
PrrtPacket *ptr = PrrtBlock_get_first_data(decBlock); PrrtPacket *ptr = PrrtBlock_get_first_data(decBlock);
PrrtPacket_print(ptr);
PrrtPacket_print(&packets[k]);
const char *s1 = (const char*) (packets[k].payload + PRRT_PACKET_DATA_HEADER_SIZE); 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); const char *s2 = (const char*) (ptr->payload + PRRT_PACKET_DATA_HEADER_SIZE);
ASSERT_STREQ(s1, s2); ASSERT_STREQ(s1, s2);
PrrtPacket_print(ptr); PrrtPacket_print(ptr);
// TODO: check for proper data // TODO: check for proper data
......
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