Commit e3ca8b96 authored by Pablo Gil Pereira's avatar Pablo Gil Pereira
Browse files

Merge branch 'fix/red_package_encoding' into develop

parents 1d7c9d8b 8b8e6efb
Pipeline #4634 failed with stages
in 59 seconds
......@@ -18,7 +18,14 @@ static void gather_redundancy_packets(const PrrtBlock *block_ptr, gf *const *fec
m++;
}
PrrtPacket_copy_payload_to_buffer(fec[m], packet, PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
// Take the data payload out of the redundancy payload and
// decode/deserialize it into the fec matrix
PrrtPacket_decode_payload(
packet->payload + PRRT_PACKET_REDUNDANCY_HEADER_SIZE,
PACKET_TYPE_DATA,
fec[m],
packet->payloadLength
);
idx_p[m] = packet->index;
PrrtPacket_destroy(packet);
}
......@@ -219,7 +226,7 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, prrtSequenceNumber_t *seqno)
check_mem(src[j]);
PrrtPacket *pkt = cur->value;
pkt->index = (uint8_t) ((pkt->sequenceNumber - baseSequenceNumber) % SEQNO_SPACE);
PrrtPacket_copy_payload_to_buffer(src[j], pkt, 0);
PrrtPacket_encode_payload(src[j], pkt);
j++;
}
......@@ -228,6 +235,9 @@ 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]);
// Encode/Serialize the payload and store it in the fec matrix
// A simple copy does not suffice, as the payload is send 'as is'
// over the wire. It however has to conform the protocol specification.
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,
......@@ -276,15 +286,19 @@ bool PrrtBlock_decode(PrrtBlock *block_ptr)
idx_p[i] = -1;
}
// Store the data payload with header in the fec matrix
gather_data_packets(block_ptr, fec, idx_p);
// Store the data payload with header from the redundancy packets in the fec matrix
gather_redundancy_packets(block_ptr, fec, idx_p);
// Decode the fec matrix in place
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) {
// The content of fec[j] is correctly deserialized and can be
// cast into a payload struct
PrrtPacketDataPayload* packet_and_payload = (PrrtPacketDataPayload *) fec[j];
PrrtPacket *packet = PrrtPacket_reconstruct_data_packet(packet_and_payload, j,
(prrtSequenceNumber_t) (baseSequenceNumber + j));
debug(DEBUG_BLOCK, "Reconstructed [D]: %d", packet->sequenceNumber);
......
......@@ -128,27 +128,30 @@ create_header(uint8_t priority, prrtSequenceNumber_t seqno, prrtPacketLength_t s
return NULL;
}
bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) {
void *payload = packet_ptr->payload;
check(packet_ptr->payloadLength + PRRT_PACKET_ENCODED_GENERAL_HEADER_LENGTH <= buf_size, "Buffer too small.");
buf_ptr = encode_general_header(buf_ptr, packet_ptr);
bool PrrtPacket_encode_payload(void *buf_ptr, PrrtPacket *packet_ptr) {
prrtPacketType_t type = PrrtPacket_type(packet_ptr);
if (type == PACKET_TYPE_DATA) {
buf_ptr = encode_data_header(buf_ptr, payload);
buf_ptr = encode_data_header(buf_ptr, packet_ptr->payload);
PrrtPacket_copy_payload_to_buffer(buf_ptr, packet_ptr, PRRT_PACKET_DATA_HEADER_SIZE);
} else if (type == PACKET_TYPE_REDUNDANCY) {
buf_ptr = encode_redundancy_header(buf_ptr, payload);
buf_ptr = encode_redundancy_header(buf_ptr, packet_ptr->payload);
PrrtPacket_copy_payload_to_buffer(buf_ptr, packet_ptr, PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
} else if (type == PACKET_TYPE_FEEDBACK) {
encode_feedback_header(buf_ptr, payload);
encode_feedback_header(buf_ptr, packet_ptr->payload);
} else {
perror("NOT IMPLEMENTED");
return false;
}
return true;
}
bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) {
check(packet_ptr->payloadLength + PRRT_PACKET_ENCODED_GENERAL_HEADER_LENGTH <= buf_size, "Buffer too small.");
buf_ptr = encode_general_header(buf_ptr, packet_ptr);
return PrrtPacket_encode_payload(buf_ptr, packet_ptr);
error:
return false;
......@@ -216,6 +219,22 @@ void *encode_general_header(void *buf_ptr, const PrrtPacket *packet) {
return buf_ptr;
}
bool PrrtPacket_decode_payload(void *srcBuffer, prrtPacketType_t packetType, void *payload, uint32_t payload_len) {
if (packetType == PACKET_TYPE_DATA) {
srcBuffer = decode_data_header(srcBuffer, payload);
memcpy(payload + PRRT_PACKET_DATA_HEADER_SIZE, srcBuffer, payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
} else if (packetType == PACKET_TYPE_REDUNDANCY) {
srcBuffer = decode_redundancy_header(srcBuffer, payload);
memcpy(payload + PRRT_PACKET_REDUNDANCY_HEADER_SIZE, srcBuffer, payload_len - PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
} else if (packetType == PACKET_TYPE_FEEDBACK) {
decode_feedback_header(srcBuffer, payload);
} else {
perror("NOT IMPLEMENTED\n");
return false;
}
return true;
}
bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket) {
// targetPacket is uninitialized, so we need to set the reference count
......@@ -238,18 +257,7 @@ bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targ
targetPacket->payloadLength = payload_len;
prrtPacketType_t packetType = PrrtPacket_type(targetPacket);
if (packetType == PACKET_TYPE_DATA) {
srcBuffer = decode_data_header(srcBuffer, payload_buffer);
PrrtPacket_copy_buffer_to_payload(targetPacket, srcBuffer, PRRT_PACKET_DATA_HEADER_SIZE);
} else if (packetType == PACKET_TYPE_REDUNDANCY) {
srcBuffer = decode_redundancy_header(srcBuffer, payload_buffer);
PrrtPacket_copy_buffer_to_payload(targetPacket, srcBuffer, PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
} else if (packetType == PACKET_TYPE_FEEDBACK) {
decode_feedback_header(srcBuffer, payload_buffer);
} else {
printf("NOT IMPLEMENTED\n");
}
return true;
return PrrtPacket_decode_payload(srcBuffer, packetType, payload_buffer, payload_len);
error:
return false;
......
......@@ -162,8 +162,10 @@ PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *payloadP
PrrtCodingConfiguration *codingParams);
bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket);
bool PrrtPacket_decode_payload(void *srcBuffer, prrtPacketType_t packetType, void *payload, uint32_t payload_len);
bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr);
bool PrrtPacket_encode_payload(void *buf_ptr, PrrtPacket *packet_ptr);
int PrrtPacket_destroy(PrrtPacket *packet);
......
Supports Markdown
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