Commit 41d6d26f authored by Andreas Schmidt's avatar Andreas Schmidt

Sequence numbers for redundancy are properly set.

parent d3b878b5
......@@ -8,7 +8,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
find_package (Threads)
add_subdirectory(prrt)
add_library(PRRT defines.h prrt/socket.c prrt/block.c prrt/block.h prrt/packet.c prrt/packet.h prrt/processes/feedback_receiver.c prrt/processes/feedback_receiver.h prrt/processes/data_transmitter.c prrt/processes/data_transmitter.h prrt/coding_params.c prrt/coding_params.h prrt/vdmcode/block_code.c prrt/vdmcode/block_code.h prrt/coding_params.c prrt/coding_params.h prrt/collections/in_buffer.c prrt/collections/in_buffer.h)
add_library(PRRT defines.h prrt/socket.c prrt/block.c prrt/block.h prrt/packet.c prrt/packet.h prrt/processes/feedback_receiver.c prrt/processes/feedback_receiver.h prrt/processes/data_transmitter.c prrt/processes/data_transmitter.h prrt/coding_params.c prrt/coding_params.h prrt/vdmcode/block_code.c prrt/vdmcode/block_code.h prrt/coding_params.c prrt/coding_params.h prrt/collections/in_buffer.c prrt/collections/in_buffer.h prrt/stores/forward_packet_table.c prrt/stores/forward_packet_table.h)
add_library(UTIL defines.h util/common.c util/common.h util/list.c util/list.h)
add_executable(sender sender.c)
......
......@@ -45,11 +45,11 @@ PrrtPacket *PrrtBlock_get_first_data(PrrtBlock *block_ptr) {
return List_shift(block_ptr->data_blocks);
}
void PrrtBlock_code(PrrtBlock *block_ptr) {
void PrrtBlock_code(PrrtBlock *block_ptr, uint16_t *seqno) {
int j = 0, m = 0;
int k = block_ptr->coding_params.k;
int n = block_ptr->coding_params.n;
int r = block_ptr->coding_params.r;
uint8_t k = block_ptr->coding_params.k;
uint8_t n = block_ptr->coding_params.n;
uint8_t r = block_ptr->coding_params.r;
uint8_t index = 0;
uint32_t length = block_ptr->largest_data_length;
......@@ -75,11 +75,14 @@ void PrrtBlock_code(PrrtBlock *block_ptr) {
fec[j] = malloc(sizeof(gf) * length);
memset(fec[j], 0, sizeof(gf) * length);
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, 0, index, base_seqno, block_ptr->coding_params);
PrrtPacket* red_packet_ptr = PrrtPacket_create_redundancy_packet(0, (void*) fec[j], length, *seqno, index, base_seqno, block_ptr->coding_params);
*seqno = *seqno+1 % SEQNO_SPACE;
PrrtPacket_print(red_packet_ptr);
PrrtBlock_insert_redundancy_packet(block_ptr, red_packet_ptr);
}
block_ptr->is_coded = TRUE;
clear_list(src, k);
free(src);
}
......
......@@ -32,7 +32,7 @@ int PrrtBlock_ready(const PrrtBlock *block_ptr);
PrrtPacket *PrrtBlock_get_first_data(PrrtBlock *block_ptr);
void PrrtBlock_code(PrrtBlock *block_ptr);
void PrrtBlock_code(PrrtBlock *block_ptr, uint16_t *seqno);
PrrtPacket *PrrtBlock_get_first_red_data(PrrtBlock *block_ptr);
......
#include "in_buffer.h"
\ No newline at end of file
......@@ -20,6 +20,8 @@ typedef struct {
uint32_t payload_len;
} PrrtPacket;
#define SEQNO_SPACE 66536 // 2**16 as seqno is uint16_t
#define PRRT_PACKET_DATA_HEADER_SIZE 12
typedef struct {
uint32_t timestamp;
......
......@@ -62,7 +62,7 @@ void *send_data_loop(void *ptr) {
if (PrrtBlock_ready(block)) {
int j = 0;
PrrtBlock_code(block);
PrrtBlock_code(block, &sock_ptr->seqnoRedundancy);
uint32_t pkt_count = (block)->data_count;
for (j = 0; j < pkt_count; j++) {
......
......@@ -13,6 +13,7 @@
int PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t is_sender) {
sock_ptr->seqno_source = 1;
sock_ptr->seqnoRedundancy = 1;
// Create Data Socket
if((sock_ptr->fd_data = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
......@@ -143,6 +144,15 @@ uint32_t PrrtSocket_recv(const PrrtSocket *sock_ptr, void *buf_ptr) {
switch(PrrtPacket_type(packet)) {
case PACKET_TYPE_DATA:
// packet.timestamp + packet.timeout < now: break
// if (FTP_is_irrelevant(packet)): break;
// check incomplete_prrt_blocks for this seqno: insert if found
// else: insert in data_packet_store
// forward to application layer
memcpy(buf_ptr, packet->payload + PRRT_PACKET_DATA_HEADER_SIZE, packet->payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
return packet->payload_len - PRRT_PACKET_DATA_HEADER_SIZE;
default:
......
......@@ -7,6 +7,7 @@
#include "../defines.h"
#include "packet.h"
#include "../util/list.h"
#include "stores/forward_packet_table.h"
#include <pthread.h>
typedef struct {
......@@ -24,12 +25,14 @@ typedef struct {
pthread_cond_t out_queue_filled_cv;
List *out_queue;
PrrtForwardPacketTable* forwardPacketTable;
PrrtReceiver receivers[PRRT_MAX_RECEIVER_COUNT];
int receiver_len;
uint16_t packets_count;
uint16_t seqno_source;
uint16_t seqno_repetition;
uint16_t seqno_parity;
uint16_t seqnoRedundancy;
uint16_t seqno_feedback;
} PrrtSocket;
......
//
// Created by andreas on 16.02.16.
//
#include "forward_packet_table.h"
#ifndef PRRT_FORWARD_PACKET_TABLE_H
#define PRRT_FORWARD_PACKET_TABLE_H
typedef struct {
} PrrtForwardPacketTable;
int PrrtForwardPacketTable_create(PrrtForwardPacketTable* fpt_prt);
int PrrtForwardPacketTable_destroy(PrrtForwardPacketTable* fpt_prt);
#endif //PRRT_FORWARD_PACKET_TABLE_H
......@@ -510,9 +510,9 @@ static void init_fec(PrrtCoder *cod) {
* and then transforming it into a systematic matrix.
*/
int prrt_coder_create(PrrtCoder **cod, int k, int n);
int prrt_coder_create(PrrtCoder **cod, uint8_t k, uint8_t n);
int PrrtCoder_get_coder(PrrtCoder **cod, int n, int k) {
int PrrtCoder_get_coder(PrrtCoder **cod, uint8_t n, uint8_t k) {
int err = 0;
if (*cod == 0 ||
......@@ -545,7 +545,7 @@ void PrrtCoder_destroy(PrrtCoder *cod) {
free(cod);
}
int prrt_coder_create(PrrtCoder **cod, int k, int n) {
int prrt_coder_create(PrrtCoder **cod, uint8_t k, uint8_t n) {
int row, col;
gf *p, *tmp_m;
int err = 0;
......
......@@ -96,7 +96,7 @@ typedef struct PrrtCoder {
* \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, int n, int k);
int PrrtCoder_get_coder(PrrtCoder **cod, uint8_t n, uint8_t k);
/**
* Free the coder object.
......
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