Commit 293d07ce authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Introduce custom typedefs for prrt types.

parent c3b549f4
......@@ -63,7 +63,7 @@ cdef extern from "prrt/block.h":
uint32_t redundancy_count
PrrtCodingParams coding_params
uint32_t largest_data_length
uint16_t base_seqno
uint16_t baseSequenceNumber
List* data_blocks
List* redundancy_blocks
uint8_t is_coded
......@@ -74,9 +74,9 @@ cdef extern from "prrt/packet.h":
cdef struct prrtPacket:
uint8_t type_priority;
uint8_t index;
uint16_t seqno;
uint16_t sequenceNumber;
void* payload;
uint32_t payload_len;
uint32_t payloadLength;
ctypedef prrtPacket PrrtPacket
......@@ -121,7 +121,7 @@ cdef extern from "prrt/socket.h":
ctypedef prrtSocket PrrtSocket
cdef PrrtSocket* PrrtSocket_create(bint is_sender)
cdef PrrtSocket* PrrtSocket_create(bint isSender)
bint PrrtSocket_bind(PrrtSocket *sock_ptr, const_char *ipAddress, const uint16_t port)
int PrrtSocket_close(const PrrtSocket *sock_ptr)
int PrrtSocket_connect(PrrtSocket *sock_ptr, const_char *host, const uint16_t port)
......
......@@ -3,7 +3,7 @@ cimport cprrt
cdef extern from "prrt/stores/forwardPacketTable.c":
int PrrtForwardPacketTable_create(cprrt.PrrtForwardPacketTable* fpt_prt);
int PrrtForwardPacketTable_test_set_is_number_relevant(cprrt.PrrtForwardPacketTable *fpt_ptr, uint16_t seqno);
int PrrtForwardPacketTable_test_set_is_number_relevant(cprrt.PrrtForwardPacketTable *fpt_ptr, uint16_t sequenceNumber);
int PrrtForwardPacketTable_test_is_block_relevant(cprrt.PrrtForwardPacketTable * forwardPacketTable, uint16_t start, uint16_t length);
int PrrtForwardPacketTable_destroy(cprrt.PrrtForwardPacketTable* fpt_prt);
......@@ -42,7 +42,7 @@ cdef extern from "prrt/packet.c":
int PrrtPacket_print(cprrt.PrrtPacket *packet_ptr)
cdef extern from "prrt/socket.c":
cprrt.PrrtSocket* PrrtSocket_create(uint16_t port, uint8_t is_sender)
cprrt.PrrtSocket* PrrtSocket_create(uint16_t port, uint8_t isSender)
cdef extern from "util/bptree.c":
cprrt.BPTreeNode *BPTree_insert(cprrt.BPTreeNode *root, int key, void *value)
......
......@@ -61,7 +61,7 @@ void PrrtBlock_destroy(PrrtBlock *mblock)
free(mblock);
}
PrrtBlock * PrrtBlock_create(const PrrtCodingParams *cpar, uint16_t base_seqno)
PrrtBlock * PrrtBlock_create(const PrrtCodingParams *cpar, prrtSequenceNumber_t baseSequenceNumber)
{
PrrtBlock *block = calloc(1, sizeof(PrrtBlock));
check_mem(block);
......@@ -69,7 +69,7 @@ PrrtBlock * PrrtBlock_create(const PrrtCodingParams *cpar, uint16_t base_seqno)
block->codingParams = *cpar;
block->dataPackets = List_create();
block->redundancyPackets = List_create();
block->baseSequenceNumber = base_seqno;
block->baseSequenceNumber = baseSequenceNumber;
block->largestDataLength = 0;
return block;
......@@ -84,15 +84,15 @@ bool PrrtBlock_insert_data_packet(PrrtBlock *prrtBlock, const PrrtPacket *prrtPa
bool found = false;
LIST_FOREACH(prrtBlock->dataPackets, first, next, cur) {
PrrtPacket *pkt = cur->value;
if(pkt->seqno == prrtPacket->seqno) {
if(pkt->sequenceNumber == prrtPacket->sequenceNumber) {
found = true;
}
}
if(found == false) {
List_push(prrtBlock->dataPackets, prrtPacket);
prrtBlock->largestDataLength = (uint32_t) MAX(prrtBlock->largestDataLength,
prrtPacket->payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
prrtBlock->largestDataLength = (prrtPacketLength_t) MAX(prrtBlock->largestDataLength,
prrtPacket->payloadLength - PRRT_PACKET_DATA_HEADER_SIZE);
return true;
} else {
return false;
......@@ -104,15 +104,15 @@ bool PrrtBlock_insert_redundancy_packet(PrrtBlock *block_ptr, const PrrtPacket *
bool found = false;
LIST_FOREACH(block_ptr->redundancyPackets, first, next, cur) {
PrrtPacket *pkt = cur->value;
if(pkt->seqno == ptr->seqno) {
if(pkt->sequenceNumber == ptr->sequenceNumber) {
found = true;
}
}
if(found == false) {
List_push(block_ptr->redundancyPackets, ptr);
block_ptr->largestDataLength = (uint32_t) MAX(block_ptr->largestDataLength,
ptr->payload_len - PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
block_ptr->largestDataLength = (prrtPacketLength_t) MAX(block_ptr->largestDataLength,
ptr->payloadLength - PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
return true;
} else {
return false;
......@@ -134,14 +134,14 @@ PrrtPacket *PrrtBlock_get_first_data(PrrtBlock *block_ptr)
return List_shift(block_ptr->dataPackets);
}
void PrrtBlock_encode(PrrtBlock *block_ptr, uint16_t *seqno)
void PrrtBlock_encode(PrrtBlock *block_ptr, prrtSequenceNumber_t *seqno)
{
int j = 0;
uint8_t k = block_ptr->codingParams.k;
uint8_t n = block_ptr->codingParams.n;
uint8_t r = block_ptr->codingParams.r;
uint16_t baseSequenceNumber = block_ptr->baseSequenceNumber;
uint32_t length = block_ptr->largestDataLength;
prrtSequenceNumber_t baseSequenceNumber = block_ptr->baseSequenceNumber;
prrtPacketLength_t length = block_ptr->largestDataLength;
PrrtCoder *coder = NULL;
......@@ -154,7 +154,7 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, uint16_t *seqno)
src[j] = calloc(length, sizeof(gf));
check_mem(src[j]);
PrrtPacket *pkt = cur->value;
pkt->index = (uint8_t) ((pkt->seqno - baseSequenceNumber) % SEQNO_SPACE);
pkt->index = (uint8_t) ((pkt->sequenceNumber - baseSequenceNumber) % SEQNO_SPACE);
PrrtPacket_copy_payload_to_buffer(src[j], pkt, PRRT_PACKET_DATA_HEADER_SIZE);
j++;
}
......@@ -168,7 +168,7 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, uint16_t *seqno)
PrrtPacket *red_packet_ptr = PrrtPacket_create_redundancy_packet(0, (void *) fec[j], length, *seqno,
(uint8_t) (k + j), block_ptr->baseSequenceNumber,
block_ptr->codingParams);
*seqno = (uint16_t) ((*seqno + 1) % SEQNO_SPACE);
*seqno = (prrtSequenceNumber_t) ((*seqno + 1) % SEQNO_SPACE);
PrrtBlock_insert_redundancy_packet(block_ptr, red_packet_ptr);
}
......@@ -193,8 +193,8 @@ bool PrrtBlock_decode(PrrtBlock *block_ptr)
int *idx_p = NULL;
uint8_t n = block_ptr->codingParams.n;
uint8_t k = block_ptr->codingParams.k;
uint16_t baseSequenceNumber = block_ptr->baseSequenceNumber;
uint32_t length = block_ptr->largestDataLength;
prrtSequenceNumber_t baseSequenceNumber = block_ptr->baseSequenceNumber;
prrtPacketLength_t length = block_ptr->largestDataLength;
PrrtCoder *coder = NULL;
......@@ -219,7 +219,7 @@ bool PrrtBlock_decode(PrrtBlock *block_ptr)
for(j = 0; j < k; j++) {
if(idx_p[j] >= k) {
PrrtPacket *packet = PrrtPacket_create_data_packet(0, fec[j], length, (uint16_t) (baseSequenceNumber + j));
PrrtPacket *packet = PrrtPacket_create_data_packet(0, fec[j], length, (prrtSequenceNumber_t) (baseSequenceNumber + j));
if(PrrtBlock_insert_data_packet(block_ptr, packet) == false) {
debug("Tried to insert unnecessary packet.");
PrrtPacket_destroy(packet);
......
......@@ -7,8 +7,8 @@
typedef struct prrtBlock {
PrrtCodingParams codingParams;
uint32_t largestDataLength;
uint16_t baseSequenceNumber;
prrtPacketLength_t largestDataLength;
prrtSequenceNumber_t baseSequenceNumber;
List*dataPackets;
List*redundancyPackets;
bool isCoded;
......@@ -18,7 +18,7 @@ typedef struct prrtBlock {
/**
* Allocate space for a block.
*/
PrrtBlock * PrrtBlock_create(const PrrtCodingParams *cpar, uint16_t base_seqno);
PrrtBlock * PrrtBlock_create(const PrrtCodingParams *cpar, prrtSequenceNumber_t baseSequenceNumber);
/**
* Frees the PrrtBlock data structure.
......@@ -33,7 +33,7 @@ bool PrrtBlock_decode_ready(const PrrtBlock *block_ptr);
PrrtPacket *PrrtBlock_get_first_data(PrrtBlock *block_ptr);
void PrrtBlock_encode(PrrtBlock *block_ptr, uint16_t *seqno);
void PrrtBlock_encode(PrrtBlock *block_ptr, prrtSequenceNumber_t *seqno);
bool PrrtBlock_decode(PrrtBlock *block_ptr);
PrrtPacket *PrrtBlock_get_first_red_data(PrrtBlock *block_ptr);
......
......@@ -16,12 +16,12 @@ void PrrtChannelStateInformation_init(PrrtChannelStateInformation *csi)
PERROR("Should not happen.%s","");
}
void PrrtChannelStateInformation_update_rtt(PrrtChannelStateInformation *csi, uint32_t rtt)
void PrrtChannelStateInformation_update_rtt(PrrtChannelStateInformation *csi, prrtTimedelta_t rtt)
{
int32_t delta = rtt - csi->rttMean;
// TODO: ensure that there are no arithemtic problems via rounding etc.
csi->rttMean = (uint16_t) (csi->rttMean + RRT_ALPHA * delta);
csi->rttDev = (uint16_t) (csi->rttDev + RRT_ALPHA * (labs(delta) - csi->rttDev));
csi->rttMean = (prrtTimedelta_t) (csi->rttMean + RRT_ALPHA * delta);
csi->rttDev = (prrtTimedelta_t) (csi->rttDev + RRT_ALPHA * (labs(delta) - csi->rttDev));
}
void PrrtChannelStateInformation_print(PrrtChannelStateInformation *csi)
......
#ifndef PRRT_CHANNELSTATEINFORMATION_H
#define PRRT_CHANNELSTATEINFORMATION_H
#include <stdint.h>
#include "packet.h"
typedef struct prrtChannelStateInformation {
uint16_t rttMean;
uint16_t rttDev;
prrtTimedelta_t rttMean;
prrtTimedelta_t rttDev;
} PrrtChannelStateInformation;
void PrrtChannelStateInformation_init(PrrtChannelStateInformation* csi);
void PrrtChannelStateInformation_update_rtt(PrrtChannelStateInformation* csi, uint32_t rtt);
void PrrtChannelStateInformation_update_rtt(PrrtChannelStateInformation* csi, prrtTimedelta_t rtt);
void PrrtChannelStateInformation_print(PrrtChannelStateInformation *csi);
......
#include <sys/time.h>
#include <stddef.h>
#include "clock.h"
#include "packet.h"
uint32_t PrrtClock_get_current_time(void) {
prrtTimestamp_t PrrtClock_get_current_time(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
uint32_t time_in_micros = (uint32_t) (1000000 * tv.tv_sec + tv.tv_usec);
return time_in_micros;
return (prrtTimestamp_t) (1000000 * tv.tv_sec + tv.tv_usec);
}
#ifndef PRRT_CLOCK_H
#define PRRT_CLOCK_H
#include <stdint.h>
#include "packet.h"
uint32_t PrrtClock_get_current_time(void);
prrtTimestamp_t PrrtClock_get_current_time(void);
#endif //PRRT_CLOCK_H
......@@ -3,6 +3,7 @@
#include <pthread.h>
#include <stdint.h>
#include <stdbool.h>
typedef struct prrtCodingParams {
pthread_mutex_t lock;
......
......@@ -24,9 +24,9 @@ void *decode_redundancy_header(void *dstBuffer, const void *srcBuffer);
void *decode_feedback_header(void *dstBuffer, const void *srcBuffer);
uint8_t PrrtPacket_type(PrrtPacket *packet_ptr)
prrtPacketType_t PrrtPacket_type(PrrtPacket *packet_ptr)
{
return (uint8_t) ((packet_ptr->type_priority >> 4) & 0x0F);
return (prrtPacketType_t) ((packet_ptr->type_priority >> 4) & 0x0F);
}
uint8_t PrrtPacket_priority(PrrtPacket *packet_ptr)
......@@ -34,9 +34,9 @@ uint8_t PrrtPacket_priority(PrrtPacket *packet_ptr)
return (uint8_t) (packet_ptr->type_priority & 0x0F);
}
uint16_t PrrtPacket_size(PrrtPacket *packet_ptr)
prrtPacketLength_t PrrtPacket_size(PrrtPacket *packet_ptr)
{
return (uint16_t) (packet_ptr->payload_len + PRRT_PACKET_GENERAL_HEADER_SIZE);
return (prrtPacketLength_t) (packet_ptr->payloadLength + PRRT_PACKET_GENERAL_HEADER_SIZE);
}
int PrrtPacket_print(PrrtPacket *packet_ptr)
......@@ -44,49 +44,63 @@ int PrrtPacket_print(PrrtPacket *packet_ptr)
printf(" 0 1 2 3\n"
" 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\n"
"+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
uint8_t type = PrrtPacket_type(packet_ptr);
prrtPacketType_t type = PrrtPacket_type(packet_ptr);
printf("| %5u | %5u | %13u | %29u |\n", type, PrrtPacket_priority(packet_ptr), packet_ptr->index,
packet_ptr->seqno);
packet_ptr->sequenceNumber);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
if(type == PACKET_TYPE_DATA) {
PrrtPacketDataPayload *payload = packet_ptr->payload;
printf("| %61u |\n", payload->timestamp);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %29u | %29u |\n", payload->group_round_trip_time, payload->packet_timeout);
printf("| %61u |\n", payload->groupRTT_us);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %29u | %29u |\n", payload->decoding_timeout, payload->feedback_timeout);
printf("| %61u |\n", payload->packetTimeout_us);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->decodingTimeout_us);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->feedbackTimeout_us);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61s |\n", (char *) (packet_ptr->payload + PRRT_PACKET_DATA_HEADER_SIZE));
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
} else if(type == PACKET_TYPE_REDUNDANCY) {
PrrtPacketRedundancyPayload *payload = packet_ptr->payload;
printf("| %29u | %13u | %13u |\n", payload->base_seqno, payload->n, payload->k);
printf("| %29u | %13u | %13u |\n", payload->baseSequenceNumber, payload->n, payload->k);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
} else if(type == PACKET_TYPE_FEEDBACK) {
prrtPacketLength_t i = 0;
PrrtPacketFeedbackPayload *payload = packet_ptr->payload;
struct sockaddr_in receiver;
receiver.sin_addr.s_addr = payload->receiver_addr;
char* address = inet_ntoa(receiver.sin_addr);
receiver.sin_addr.s_addr = payload->receiverAddress;
char *address = inet_ntoa(receiver.sin_addr);
printf("| %61s |\n", address);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->group_round_trip_time);
printf("| %61u |\n", payload->groupRTT_us);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->forward_trip_timestamp);
printf("| %61u |\n", payload->forwardTripTimestamp_us);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->packet_loss_rate);
printf("| %29u | %29u |\n", payload->erasureCount, payload->packetCount);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %29u | %29u |\n", payload->gap, payload->ngap);
printf("| %29u | %29u |\n", payload->gapLength, payload->gapCount);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %29u | %29u |\n", payload->burst, payload->nburst);
printf("| %29u | %29u |\n", payload->burstLength, payload->burstCount);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->bandwidth_estimate);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->buffer_feedback);
printf("| %61u |\n", payload->bandwidthEstimate);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
prrtPacketLength_t remainingSpace = ((prrtPacketLength_t) (packet_ptr->payloadLength -
PRRT_PACKET_FEEDBACK_HEADER_SIZE));
prrtPacketLength_t blockCount = (prrtPacketLength_t) (remainingSpace / sizeof(PrrtIncompleteBlock));
for(i = 0; i < blockCount; ++i) {
PrrtIncompleteBlock block = payload->incompleteBlocks[i];
printf("| %29u | %29u |\n", block.sequenceNumberBase, block.repairCycleIndex);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
}
} else {
printf("| Unhandeled Type |\n");
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
......@@ -99,15 +113,15 @@ PrrtPacket *PrrtPacket_copy(PrrtPacket *original)
{
PrrtPacket *newPacket = calloc(1, sizeof(PrrtPacket));
check_mem(newPacket);
void *payload = calloc(1, original->payload_len);
void *payload = calloc(1, original->payloadLength);
check_mem(payload);
newPacket->payload = payload;
newPacket->payload_len = original->payload_len;
memcpy(newPacket->payload, original->payload, original->payload_len);
newPacket->payloadLength = original->payloadLength;
memcpy(newPacket->payload, original->payload, original->payloadLength);
newPacket->index = original->index;
newPacket->seqno = original->seqno;
newPacket->sequenceNumber = original->sequenceNumber;
newPacket->type_priority = original->type_priority;
......@@ -117,7 +131,7 @@ PrrtPacket *PrrtPacket_copy(PrrtPacket *original)
return NULL;
}
PrrtPacket *create_header(uint8_t priority, uint16_t seqno, uint32_t size, uint8_t type, uint8_t index)
PrrtPacket *create_header(uint8_t priority, prrtSequenceNumber_t seqno, prrtPacketLength_t size, uint8_t type, uint8_t index)
{
PrrtPacket *packet = calloc(1, sizeof(PrrtPacket));
check_mem(packet);
......@@ -125,8 +139,8 @@ PrrtPacket *create_header(uint8_t priority, uint16_t seqno, uint32_t size, uint8
packet->type_priority = type << 4;
packet->type_priority |= priority & 0x0F;
packet->index = index;
packet->seqno = seqno;
packet->payload_len = size;
packet->sequenceNumber = seqno;
packet->payloadLength = size;
return packet;
......@@ -139,11 +153,11 @@ bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr)
{
void *payload = packet_ptr->payload;
check(packet_ptr->payload_len + PRRT_PACKET_GENERAL_HEADER_SIZE <= buf_size, "Buffer too small.");
check(packet_ptr->payloadLength + PRRT_PACKET_GENERAL_HEADER_SIZE <= buf_size, "Buffer too small.");
buf_ptr = encode_general_header(buf_ptr, packet_ptr);
uint8_t type = PrrtPacket_type(packet_ptr);
prrtPacketType_t type = PrrtPacket_type(packet_ptr);
if(type == PACKET_TYPE_DATA) {
buf_ptr = encode_data_header(buf_ptr, payload);
PrrtPacket_copy_payload_to_buffer(buf_ptr, packet_ptr, PRRT_PACKET_DATA_HEADER_SIZE);
......@@ -166,17 +180,17 @@ void *encode_redundancy_header(void *buf_ptr, const void *payload)
{
const PrrtPacketRedundancyPayload *redundancyPayload = payload;
uint16_t *baseSeqNo = (uint16_t *) buf_ptr;
*baseSeqNo = htons(redundancyPayload->base_seqno);
buf_ptr += 2;
prrtSequenceNumber_t *baseSeqNo = (prrtSequenceNumber_t *) buf_ptr;
*baseSeqNo = htons(redundancyPayload->baseSequenceNumber);
buf_ptr += sizeof(prrtSequenceNumber_t);
uint8_t *n = (uint8_t *) buf_ptr;
*n = redundancyPayload->n;
buf_ptr += 1;
buf_ptr += sizeof(uint8_t);
uint8_t *k = (uint8_t *) buf_ptr;
*k = redundancyPayload->k;
buf_ptr += 1;
buf_ptr += sizeof(uint8_t);
return buf_ptr;
}
......@@ -185,46 +199,47 @@ void *encode_feedback_header(void *buf_ptr, const void *payload)
{
const PrrtPacketFeedbackPayload *feedbackPayload = payload;
uint32_t *receiver_ip = (uint32_t *) buf_ptr;
*receiver_ip = feedbackPayload->receiver_addr;
buf_ptr += 4;
uint32_t *receiverAddress = (uint32_t *) buf_ptr;
*receiverAddress = feedbackPayload->receiverAddress;
buf_ptr += sizeof(uint32_t);
uint32_t *group_round_trip_time = (uint32_t *) buf_ptr;
*group_round_trip_time = htonl(feedbackPayload->group_round_trip_time);
buf_ptr += 4;
prrtTimedelta_t *groupRoundTripTime = (prrtTimedelta_t *) buf_ptr;
*groupRoundTripTime = htonl(feedbackPayload->groupRTT_us);
buf_ptr += sizeof(prrtTimedelta_t);
uint32_t *forward_trip_time = (uint32_t *) buf_ptr;
*forward_trip_time = htonl(feedbackPayload->forward_trip_timestamp);
buf_ptr += 4;
prrtTimestamp_t *forwardTripTimestamp = (prrtTimestamp_t *) buf_ptr;
*forwardTripTimestamp = htonl(feedbackPayload->forwardTripTimestamp_us);
buf_ptr += sizeof(prrtTimestamp_t);
uint32_t *packet_loss_rate = (uint32_t *) buf_ptr;
*packet_loss_rate = htonl(feedbackPayload->packet_loss_rate);
buf_ptr += 4;
prrtSequenceNumber_t *erasureCount = (prrtSequenceNumber_t *) buf_ptr;
*erasureCount = htons(feedbackPayload->erasureCount);
buf_ptr += sizeof(prrtSequenceNumber_t);
uint16_t *gap = (uint16_t *) buf_ptr;
*gap = htons(feedbackPayload->gap);
buf_ptr += 2;
prrtSequenceNumber_t *packetCount = (prrtSequenceNumber_t *) buf_ptr;
*packetCount = htons(feedbackPayload->packetCount);
buf_ptr += sizeof(prrtSequenceNumber_t);
uint16_t *ngap = (uint16_t *) buf_ptr;
*ngap = htons(feedbackPayload->ngap);
buf_ptr += 2;
prrtSequenceNumber_t *gap = (prrtSequenceNumber_t *) buf_ptr;
*gap = htons(feedbackPayload->gapLength);
buf_ptr += sizeof(prrtSequenceNumber_t);
uint16_t *burst = (uint16_t *) buf_ptr;
*burst = htons(feedbackPayload->burst);
buf_ptr += 2;
prrtSequenceNumber_t *ngap = (prrtSequenceNumber_t *) buf_ptr;
*ngap = htons(feedbackPayload->gapCount);
buf_ptr += sizeof(prrtSequenceNumber_t);
uint16_t *nburst = (uint16_t *) buf_ptr;
*nburst = htons(feedbackPayload->nburst);
buf_ptr += 2;
prrtSequenceNumber_t *burstLength = (prrtSequenceNumber_t *) buf_ptr;
*burstLength = htons(feedbackPayload->burstLength);
buf_ptr += sizeof(prrtSequenceNumber_t);
uint32_t *bandwidth_estimate = (uint32_t *) buf_ptr;
*bandwidth_estimate = htonl(feedbackPayload->bandwidth_estimate);
buf_ptr += 4;
prrtSequenceNumber_t *burstCount = (prrtSequenceNumber_t *) buf_ptr;
*burstCount = htons(feedbackPayload->burstCount);
buf_ptr += sizeof(prrtSequenceNumber_t);
uint32_t *buffer_feedback = (uint32_t *) buf_ptr;
*buffer_feedback = htonl(feedbackPayload->buffer_feedback);
buf_ptr += 4;
uint32_t *bandwidth_estimate = (uint32_t *) buf_ptr;
*bandwidth_estimate = htonl(feedbackPayload->bandwidthEstimate);
buf_ptr += sizeof(uint32_t);
// TODO: encode variable number of incomplete blocks
return buf_ptr;
}
......@@ -232,25 +247,25 @@ void *encode_data_header(void *buf_ptr, const void *payload)
{
const PrrtPacketDataPayload *data_payload = payload;
uint32_t *timestamp = (uint32_t *) buf_ptr;
prrtTimestamp_t *timestamp = (prrtTimestamp_t *) buf_ptr;
*timestamp = htonl(data_payload->timestamp);
buf_ptr += 4;
buf_ptr += sizeof(prrtTimestamp_t);
uint16_t *group_round_trip_time = (uint16_t *) buf_ptr;
*group_round_trip_time = htons(data_payload->group_round_trip_time);
buf_ptr += 2;
prrtTimedelta_t *group_round_trip_time = (prrtTimedelta_t *) buf_ptr;
*group_round_trip_time = htonl(data_payload->groupRTT_us);
buf_ptr += sizeof(prrtTimedelta_t);
uint16_t *packet_timeout = (uint16_t *) buf_ptr;
*packet_timeout = htons(data_payload->packet_timeout);
buf_ptr += 2;
prrtTimedelta_t *packet_timeout = (prrtTimedelta_t *) buf_ptr;
*packet_timeout = htonl(data_payload->packetTimeout_us);
buf_ptr += sizeof(prrtTimedelta_t);
uint16_t *decoding_timeout = (uint16_t *) buf_ptr;
*decoding_timeout = htons(data_payload->decoding_timeout);
buf_ptr += 2;
prrtTimedelta_t *decoding_timeout = (prrtTimedelta_t *) buf_ptr;
*decoding_timeout = htonl(data_payload->decodingTimeout_us);
buf_ptr += sizeof(prrtTimedelta_t);
uint16_t *feedback_timeout = (uint16_t *) buf_ptr;
*feedback_timeout = htons(data_payload->feedback_timeout);
buf_ptr += 2;
prrtTimedelta_t *feedback_timeout = (prrtTimedelta_t *) buf_ptr;
*feedback_timeout = htonl(data_payload->feedbackTimeout_us);
buf_ptr += sizeof(prrtTimedelta_t);
return buf_ptr;
}
......@@ -258,38 +273,38 @@ void *encode_general_header(void *buf_ptr, const PrrtPacket *packet)
{
uint8_t *type_priority = (uint8_t *) buf_ptr;
*type_priority = packet->type_priority;
buf_ptr += 1;
buf_ptr += sizeof(uint8_t);
uint8_t *index = (uint8_t *) buf_ptr;
*index = packet->index;
buf_ptr += 1;
buf_ptr += sizeof(uint8_t);
uint16_t *seqno = (uint16_t *) buf_ptr;
*seqno = htons(packet->seqno);
buf_ptr += 2;
prrtSequenceNumber_t *seqno = (prrtSequenceNumber_t *) buf_ptr;
*seqno = htons(packet->sequenceNumber);
buf_ptr += sizeof(prrtSequenceNumber_t);
return buf_ptr;
}
bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket)
{
uint32_t payload_len = (uint32_t) (srcBufferSize - PRRT_PACKET_GENERAL_HEADER_SIZE);
prrtPacketLength_t payload_len = (prrtPacketLength_t) (srcBufferSize - PRRT_PACKET_GENERAL_HEADER_SIZE);
targetPacket->type_priority = *(uint8_t *) srcBuffer;
srcBuffer += 1;
uint8_t *index_ptr = (uint8_t *) srcBuffer;
targetPacket->index = *index_ptr;
srcBuffer += 1;
uint16_t *seqno_prt = (uint16_t *) srcBuffer;
targetPacket->seqno = ntohs(*seqno_prt);
srcBuffer += 2;
prrtSequenceNumber_t *seqno_prt = (prrtSequenceNumber_t *) srcBuffer;
targetPacket->sequenceNumber = ntohs(*seqno_prt);
srcBuffer += sizeof(prrtSequenceNumber_t);
void *payload_buffer = calloc(1, payload_len);
check_mem(payload_buffer);
targetPacket->payload = payload_buffer;
targetPacket->payload_len = payload_len;
targetPacket->payloadLength = payload_len;