Commit 5da95b6b authored by Andreas Schmidt's avatar Andreas Schmidt

Properly creating redundancy packets.

parent 898492fb
......@@ -2,11 +2,15 @@
#include <stdio.h>
#include "block.h"
#include "../defines.h"
#include "coding_params.h"
#include "vdmcode/block_code.h"
#include "packet.h"
#include "../util/common.h"
void clear_list(gf *const *src, uint8_t k) {
int j = 0;
for(j = 0; j < k; j++) {
free(src[j]);
}
}
void PrrtBlock_free(PrrtBlock **mblock) {
......@@ -28,6 +32,11 @@ int PrrtBlock_insert_data_packet(PrrtBlock *block_ptr, PrrtPacket *packet_ptr) {
block_ptr->largest_data_length = MAX(block_ptr->largest_data_length, packet_ptr->payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
return 0;
}
int PrrtBlock_insert_redundancy_packet(PrrtBlock *block_ptr, PrrtPacket *ptr) {
List_push(block_ptr->redundancy_blocks, ptr);
block_ptr->redundancy_count++;
return 0;
}
int PrrtBlock_ready(PrrtBlock *block_ptr) {
return (block_ptr->data_count == block_ptr->coding_params.k) ? TRUE : FALSE;
......@@ -43,7 +52,9 @@ void PrrtBlock_code(PrrtBlock *block_ptr) {
int j = 0, m = 0;
int k = block_ptr->coding_params.k;
int n = block_ptr->coding_params.n;
int length = block_ptr->largest_data_length;
int r = block_ptr->coding_params.r;
uint8_t index = 0;
uint32_t length = block_ptr->largest_data_length;
PrrtCoder* coder = NULL;
......@@ -57,27 +68,29 @@ void PrrtBlock_code(PrrtBlock *block_ptr) {
PrrtPacket* pkt = cur->value;
PrrtPacket_print(pkt);
PrrtPacketDataPayload *payload = pkt->payload;
memcpy(src[j], payload + PRRT_PACKET_DATA_HEADER_SIZE, pkt->payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
memcpy(src[j], pkt->payload + PRRT_PACKET_DATA_HEADER_SIZE, pkt->payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
j++;
}
for(j = 0; j < k; j++) {
print_gf(src[j], length);
}
PrrtPacket *first_packet = (PrrtPacket*) block_ptr->data_blocks->first->value;
uint16_t base_seqno = first_packet->seqno;
return;
gf** fec = malloc(sizeof(gf*) * n);
for(j = 0; j < n; j++) {
gf** fec = malloc(sizeof(gf*) * r);
for(j = 0; j < r; j++) {
fec[j] = malloc(sizeof(gf) * length);
memset(fec[j], 0, sizeof(gf) * length);
PrrtCoder_encode(coder, src, fec[j], j, 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
print_gf(fec[j], length);
}
PrrtPacket* red_packet_ptr = PrrtPacket_create_redundancy_packet(0, (void*) fec[j], length, 0, index, base_seqno, block_ptr->coding_params);
PrrtBlock_insert_redundancy_packet(block_ptr, red_packet_ptr);
}
clear_list(src, k);
free(src);
}
PrrtPacket *PrrtBlock_get_red_data(PrrtBlock *block_ptr) {
return NULL;
PrrtPacket *PrrtBlock_get_first_red_data(PrrtBlock *block_ptr) {
block_ptr->redundancy_count--;
return List_shift(block_ptr->redundancy_blocks);
}
\ No newline at end of file
......@@ -34,6 +34,6 @@ PrrtPacket *PrrtBlock_get_first_data(PrrtBlock *block_ptr);
void PrrtBlock_code(PrrtBlock *block_ptr);
PrrtPacket *PrrtBlock_get_red_data(PrrtBlock *block_ptr);
PrrtPacket *PrrtBlock_get_first_red_data(PrrtBlock *block_ptr);
#endif //PRRT_BLOCK_H
......@@ -6,14 +6,15 @@
#define PRRT_CODING_PARAMS_H
#include <pthread.h>
#include <stdint.h>
typedef struct {
pthread_mutex_t lock;
int k;
int r;
int n;
int n_p;
uint8_t k;
uint8_t r;
uint8_t n;
uint8_t n_p;
} PrrtCodingParams;
#endif //PRRT_CODING_PARAMS_H
......
......@@ -64,12 +64,14 @@ void *send_data_loop(void *ptr) {
int j = 0;
PrrtBlock_code(block);
for (j = 0; j < (block)->data_count; j++) {
uint32_t pkt_count = (block)->data_count;
for (j = 0; j < pkt_count; j++) {
PrrtPacket *data_pkt = PrrtBlock_get_first_data(block);
send_packet(sock_ptr, data_pkt);
}
for (j = 0; j < (block)->redundancy_count; j++) {
PrrtPacket *red_pkt = PrrtBlock_get_red_data(block);
uint32_t red_count = (block)->redundancy_count;
for (j = 0; j < red_count; j++) {
PrrtPacket *red_pkt = PrrtBlock_get_first_red_data(block);
send_packet(sock_ptr, red_pkt);
}
}
......
......@@ -5,6 +5,7 @@
#include <netinet/in.h>
#include <assert.h>
#include "packet.h"
#include "coding_params.h"
void *encode_general_header(void *buf_ptr, const PrrtPacket *packet);
......@@ -43,6 +44,8 @@ int PrrtPacket_print(PrrtPacket *packet_ptr) {
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %29u | %29u |\n", payload->group_round_trip_time, payload->packet_timeout);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %29u | %29u |\n", payload->decoding_timeout, payload->feedback_timeout);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
}
else if(type == PACKET_TYPE_FEEDBACK) {
PrrtPacketFeedbackPayload * payload = packet_ptr->payload;
......@@ -288,7 +291,7 @@ int PrrtPacket_destroy(PrrtPacket *packet_ptr) {
// PACKET SPECIFIC CODE
int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, const void *data_ptr,
unsigned long data_len, int seqno) {
uint32_t data_len, int seqno) {
uint32_t payload_length = (uint32_t) (data_len + sizeof(PrrtPacketDataPayload));
packet_ptr->type_priority = PACKET_TYPE_DATA << 4;
......@@ -318,6 +321,33 @@ int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, cons
return 0;
}
PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *data_ptr, uint32_t data_len,
uint16_t seqno, uint8_t index, uint16_t base_seqno, PrrtCodingParams codingParams) {
uint32_t payload_length = (uint32_t) (data_len + sizeof(PrrtPacketRedundancyPayload));
PrrtPacket* packet_ptr = malloc(sizeof(PrrtPacket));
assert(packet_ptr != NULL);
packet_ptr->type_priority = PACKET_TYPE_REDUNDANCY;
packet_ptr->type_priority |= priority & 0x0F;
packet_ptr->index = index;
packet_ptr->seqno = seqno;
void *content_buf = malloc(sizeof(PrrtPacketRedundancyPayload) + data_len);
assert(content_buf != NULL);
PrrtPacketRedundancyPayload *redundancy_payload = content_buf;
redundancy_payload->base_seqno = base_seqno;
redundancy_payload->k =codingParams.k;
redundancy_payload->n =codingParams.n;
packet_ptr->payload = content_buf;
memcpy(content_buf + sizeof(PrrtPacketRedundancyPayload), data_ptr, data_len);
packet_ptr->payload_len = payload_length;
return packet_ptr;
}
PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t seqno, uint32_t round_trip_time,
uint32_t forward_trip_time, uint32_t packet_loss_rate, uint16_t gap,
uint16_t ngap,
......
......@@ -2,6 +2,7 @@
#define PRRT_FRAME_H
#include <stdint.h>
#include "coding_params.h"
#define PACKET_TYPE_DATA 0
#define PACKET_TYPE_REPETITION 1
......@@ -28,6 +29,13 @@ typedef struct {
uint16_t feedback_timeout;
} PrrtPacketDataPayload;
#define PRRT_PACKET_REDUNDANCY_HEADER_SIZE 4
typedef struct {
uint16_t base_seqno;
uint8_t n;
uint8_t k;
} PrrtPacketRedundancyPayload;
# define PRRT_PACKET_FEEDBACK_HEADER_SIZE 32
typedef struct {
uint32_t receiver_addr;
......@@ -54,13 +62,16 @@ int PrrtPacket_print(PrrtPacket *packet_ptr);
int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, const void *data_ptr,
unsigned long data_len, int seqno);
uint32_t data_len, int seqno);
PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t seqno, uint32_t round_trip_time,
uint32_t forward_trip_time, uint32_t packet_loss_rate, uint16_t gap,
uint16_t ngap, uint16_t burst, uint16_t nburst, uint32_t bandwidth,
uint32_t buffer_feedback);
PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *data_ptr, uint32_t data_len,
uint16_t seqno, uint8_t index, uint16_t base_seqno, PrrtCodingParams codingParams);
int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr);
int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr);
int PrrtPacket_destroy(PrrtPacket *packet_ptr);
......
......@@ -19,11 +19,11 @@ int main(int argc, char* const argv) {
return 0;
}
char *remote_host = "localhost";
char *remote_host = "127.0.0.1";
uint16_t remote_port = 5000;
PrrtSocket_connect(&sock, remote_host, remote_port);
char *remote_host2 = "localhost";
char *remote_host2 = "127.0.0.1";
uint16_t remote_port2 = 5004;
PrrtSocket_connect(&sock, remote_host2, remote_port2);
......
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