packet.c 17.6 KB
Newer Older
1 2 3
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
4
#include <netinet/in.h>
5
#include <stdbool.h>
6 7 8
#include "../../util/common.h"
#include "../../util/dbg.h"
#include "../clock.h"
Andreas Schmidt's avatar
Andreas Schmidt committed
9
#include "packet.h"
10

11
static void *encode_general_header(void *buf_ptr, const PrrtPacket *packet);
12

13
static void *encode_data_header(void *buf_ptr, const void *payload);
14

15
static void *encode_redundancy_header(void *buf_ptr, const void *payload);
16

17
static void *encode_feedback_header(void *buf_ptr, const void *payload);
18

19
static void *decode_data_header(void *dstBuffer, const void *srcBuffer);
Andreas Schmidt's avatar
Andreas Schmidt committed
20

21
static void *decode_redundancy_header(void *dstBuffer, const void *srcBuffer);
22

23
static void *decode_feedback_header(void *dstBuffer, const void *srcBuffer);
Andreas Schmidt's avatar
Andreas Schmidt committed
24

25
prrtPacketType_t PrrtPacket_type(PrrtPacket *packet_ptr) {
26
    return (prrtPacketType_t) ((packet_ptr->type_priority >> 4) & 0x0F);
27 28
}

29
uint8_t PrrtPacket_priority(PrrtPacket *packet_ptr) {
30 31 32
    return (uint8_t) (packet_ptr->type_priority & 0x0F);
}

33
prrtPacketLength_t PrrtPacket_size(PrrtPacket *packet_ptr) {
34
    return (prrtPacketLength_t) (packet_ptr->payloadLength + PRRT_PACKET_ENCODED_GENERAL_HEADER_LENGTH);
35 36
}

37
int PrrtPacket_print(PrrtPacket *packet_ptr) {
38 39
    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"
40
                   "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
41
    prrtPacketType_t type = PrrtPacket_type(packet_ptr);
42

43
    printf("| %5u | %5u | %13u | %29u |\n", type, PrrtPacket_priority(packet_ptr), packet_ptr->index,
44
           packet_ptr->sequenceNumber);
45
    printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
46

47
    if (type == PACKET_TYPE_DATA) {
48
        PrrtPacketDataPayload *payload = packet_ptr->payload;
49 50
        printf("| %61u |\n", payload->timestamp);
        printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
51
        printf("| %61u |\n", payload->groupRTprop_us);
52
        printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
53 54
        printf("| %61u |\n", payload->packetTimeout_us);
        printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
55 56
        printf("| %61s |\n", (char *) (packet_ptr->payload + PRRT_PACKET_DATA_HEADER_SIZE));
        printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
57
    } else if (type == PACKET_TYPE_REDUNDANCY) {
58
        PrrtPacketRedundancyPayload *payload = packet_ptr->payload;
59
        printf("| %29u | %13u | %13u |\n", payload->baseSequenceNumber, payload->n, payload->k);
60
        printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
61
    } else if (type == PACKET_TYPE_FEEDBACK) {
62 63
        prrtPacketLength_t i = 0;

64
        PrrtPacketFeedbackPayload *payload = packet_ptr->payload;
65

66
        printf("| %61u |\n", payload->groupRTT_us);
67
        printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
68
        printf("| %61u |\n", payload->forwardTripTimestamp_us);
69
        printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
70
        printf("| %29u | %29u |\n", payload->erasureCount, payload->packetCount);
71
        printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
72
        printf("| %29u | %29u |\n", payload->gapLength, payload->gapCount);
73
        printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
74
        printf("| %29u | %29u |\n", payload->burstLength, payload->burstCount);
75
        printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
76 77 78 79 80

        prrtPacketLength_t remainingSpace = ((prrtPacketLength_t) (packet_ptr->payloadLength -
                                                                   PRRT_PACKET_FEEDBACK_HEADER_SIZE));
        prrtPacketLength_t blockCount = (prrtPacketLength_t) (remainingSpace / sizeof(PrrtIncompleteBlock));

81
        for (i = 0; i < blockCount; ++i) {
82 83 84 85
            PrrtIncompleteBlock block = payload->incompleteBlocks[i];
            printf("| %29u | %29u |\n", block.sequenceNumberBase, block.repairCycleIndex);
            printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
        }
86
    } else {
87 88
        printf("| Unhandeled Type                                               |\n");
        printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
89 90 91 92 93
    }

    return 0;
}

94
PrrtPacket *PrrtPacket_copy(PrrtPacket *original) {
95 96
    PrrtPacket *newPacket = calloc(1, sizeof(PrrtPacket));
    check_mem(newPacket);
97
    void *payload = calloc(1, original->payloadLength);
98 99 100
    check_mem(payload);

    newPacket->payload = payload;
101 102
    newPacket->payloadLength = original->payloadLength;
    memcpy(newPacket->payload, original->payload, original->payloadLength);
103 104

    newPacket->index = original->index;
105
    newPacket->sequenceNumber = original->sequenceNumber;
106 107 108 109 110
    newPacket->type_priority = original->type_priority;


    return newPacket;
    error:
111
    PERROR("Not enough memory for packet copies.%s", "");
Andreas Schmidt's avatar
Andreas Schmidt committed
112
    return NULL;
113 114
}

115 116
static PrrtPacket *
create_header(uint8_t priority, prrtSequenceNumber_t seqno, prrtPacketLength_t size, uint8_t type, uint8_t index) {
Andreas Schmidt's avatar
Andreas Schmidt committed
117 118 119 120 121 122
    PrrtPacket *packet = calloc(1, sizeof(PrrtPacket));
    check_mem(packet);

    packet->type_priority = type << 4;
    packet->type_priority |= priority & 0x0F;
    packet->index = index;
123 124
    packet->sequenceNumber = seqno;
    packet->payloadLength = size;
Andreas Schmidt's avatar
Andreas Schmidt committed
125 126 127 128 129

    return packet;

    error:
    PERROR("Could not create packet.%s", "");
Andreas Schmidt's avatar
Andreas Schmidt committed
130
    return NULL;
Andreas Schmidt's avatar
Andreas Schmidt committed
131 132
}

133
bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) {
134
    void *payload = packet_ptr->payload;
135

136
    check(packet_ptr->payloadLength + PRRT_PACKET_ENCODED_GENERAL_HEADER_LENGTH <= buf_size, "Buffer too small.");
137

138 139
    buf_ptr = encode_general_header(buf_ptr, packet_ptr);

140
    prrtPacketType_t type = PrrtPacket_type(packet_ptr);
141
    if (type == PACKET_TYPE_DATA) {
142
        buf_ptr = encode_data_header(buf_ptr, payload);
143
        PrrtPacket_copy_payload_to_buffer(buf_ptr, packet_ptr, PRRT_PACKET_DATA_HEADER_SIZE);
144
    } else if (type == PACKET_TYPE_REDUNDANCY) {
145
        buf_ptr = encode_redundancy_header(buf_ptr, payload);
146
        PrrtPacket_copy_payload_to_buffer(buf_ptr, packet_ptr, PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
147
    } else if (type == PACKET_TYPE_FEEDBACK) {
148
        encode_feedback_header(buf_ptr, payload);
149 150
    } else {
        perror("NOT IMPLEMENTED");
151
        return false;
152
    }
153
    return true;
154 155

    error:
156
    return false;
157 158
}

159
#define identity(x) (x)
160

161 162 163 164 165 166
#define PrrtPacketField_encode(payload, buf_ptr, field_t, field, conversion) \
    do { \
        field_t *ptr = (field_t *) (buf_ptr); \
        *ptr = conversion((payload)->field); \
        (buf_ptr) += sizeof(field_t); \
    } while (false)
167

168 169
void *encode_redundancy_header(void *buf_ptr, const void *payload) {
    const PrrtPacketRedundancyPayload *redundancyPayload = payload;
170

171 172 173 174
    PrrtPacketField_encode(redundancyPayload, buf_ptr, prrtSequenceNumber_t, baseSequenceNumber, htons);
    PrrtPacketField_encode(redundancyPayload, buf_ptr, prrtTimestamp_t, timestamp, htonl);
    PrrtPacketField_encode(redundancyPayload, buf_ptr, uint8_t, n, identity);
    PrrtPacketField_encode(redundancyPayload, buf_ptr, uint8_t, k, identity);
175 176 177 178

    return buf_ptr;
}

179
void *encode_feedback_header(void *buf_ptr, const void *payload) {
180
    const PrrtPacketFeedbackPayload *feedbackPayload = payload;
181

182 183 184 185 186 187 188 189 190 191
    PrrtPacketField_encode(feedbackPayload, buf_ptr, prrtTimedelta_t, groupRTT_us, htonl);
    PrrtPacketField_encode(feedbackPayload, buf_ptr, prrtTimestamp_t, forwardTripTimestamp_us, htonl);
    PrrtPacketField_encode(feedbackPayload, buf_ptr, prrtSequenceNumber_t, erasureCount, htons);
    PrrtPacketField_encode(feedbackPayload, buf_ptr, prrtSequenceNumber_t, packetCount, htons);
    PrrtPacketField_encode(feedbackPayload, buf_ptr, prrtSequenceNumber_t, gapLength, htons);
    PrrtPacketField_encode(feedbackPayload, buf_ptr, prrtSequenceNumber_t, gapCount, htons);
    PrrtPacketField_encode(feedbackPayload, buf_ptr, prrtSequenceNumber_t, burstLength, htons);
    PrrtPacketField_encode(feedbackPayload, buf_ptr, prrtSequenceNumber_t, burstCount, htons);
    PrrtPacketField_encode(feedbackPayload, buf_ptr, prrtPacketType_t, ackPacketType, identity);
    PrrtPacketField_encode(feedbackPayload, buf_ptr, prrtSequenceNumber_t, ackSequenceNumber, htons);
192

193 194 195
    return buf_ptr;
}

196
void *encode_data_header(void *buf_ptr, const void *payload) {
197
    const PrrtPacketDataPayload *data_payload = payload;
198

199 200 201 202
    PrrtPacketField_encode(data_payload, buf_ptr, prrtPacketLength_t, dataLength, htonl);
    PrrtPacketField_encode(data_payload, buf_ptr, prrtTimestamp_t, timestamp, htonl);
    PrrtPacketField_encode(data_payload, buf_ptr, prrtTimedelta_t, groupRTprop_us, htonl);
    PrrtPacketField_encode(data_payload, buf_ptr, prrtTimedelta_t, packetTimeout_us, htonl);
203 204 205 206

    return buf_ptr;
}

207
void *encode_general_header(void *buf_ptr, const PrrtPacket *packet) {
208

209 210 211
    PrrtPacketField_encode(packet, buf_ptr, uint8_t, type_priority, identity);
    PrrtPacketField_encode(packet, buf_ptr, uint8_t, index, identity);
    PrrtPacketField_encode(packet, buf_ptr, prrtSequenceNumber_t, sequenceNumber, htons);
212

213
    return buf_ptr;
214 215
}

216
bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket) {
217
    prrtPacketLength_t payload_len = (prrtPacketLength_t) (srcBufferSize - PRRT_PACKET_ENCODED_GENERAL_HEADER_LENGTH);
Andreas Schmidt's avatar
Andreas Schmidt committed
218 219 220 221 222
    targetPacket->type_priority = *(uint8_t *) srcBuffer;
    srcBuffer += 1;
    uint8_t *index_ptr = (uint8_t *) srcBuffer;
    targetPacket->index = *index_ptr;
    srcBuffer += 1;
223 224 225
    prrtSequenceNumber_t *seqno_prt = (prrtSequenceNumber_t *) srcBuffer;
    targetPacket->sequenceNumber = ntohs(*seqno_prt);
    srcBuffer += sizeof(prrtSequenceNumber_t);
226

Andreas Schmidt's avatar
Andreas Schmidt committed
227
    void *payload_buffer = calloc(1, payload_len);
228 229
    check_mem(payload_buffer);

Andreas Schmidt's avatar
Andreas Schmidt committed
230
    targetPacket->payload = payload_buffer;
231
    targetPacket->payloadLength = payload_len;
Andreas Schmidt's avatar
Andreas Schmidt committed
232

233
    prrtPacketType_t packetType = PrrtPacket_type(targetPacket);
234
    if (packetType == PACKET_TYPE_DATA) {
Andreas Schmidt's avatar
Andreas Schmidt committed
235 236
        srcBuffer = decode_data_header(srcBuffer, payload_buffer);
        PrrtPacket_copy_buffer_to_payload(targetPacket, srcBuffer, PRRT_PACKET_DATA_HEADER_SIZE);
237
    } else if (packetType == PACKET_TYPE_REDUNDANCY) {
Andreas Schmidt's avatar
Andreas Schmidt committed
238 239
        srcBuffer = decode_redundancy_header(srcBuffer, payload_buffer);
        PrrtPacket_copy_buffer_to_payload(targetPacket, srcBuffer, PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
240
    } else if (packetType == PACKET_TYPE_FEEDBACK) {
241
        decode_feedback_header(srcBuffer, payload_buffer);
Andreas Schmidt's avatar
Andreas Schmidt committed
242
    } else {
243
        printf("NOT IMPLEMENTED\n");
Andreas Schmidt's avatar
Andreas Schmidt committed
244
    }
245
    return true;
246 247

    error:
248
    return false;
Andreas Schmidt's avatar
Andreas Schmidt committed
249
}
250

251 252 253 254 255 256 257
#define PrrtPacketField_decode(payload, buf_ptr, field_t, field, conversion) \
    do { \
        field_t *PrrtPacketField_decode_ptr = (field_t *) (buf_ptr); \
        (payload)->field = conversion(*PrrtPacketField_decode_ptr); \
        (buf_ptr) += sizeof(field_t); \
    } while (false)

258
void *decode_redundancy_header(void *dstBuffer, const void *srcBuffer) {
Andreas Schmidt's avatar
Andreas Schmidt committed
259
    PrrtPacketRedundancyPayload *redundancyPayload = (PrrtPacketRedundancyPayload *) srcBuffer;
260

261 262 263 264
    PrrtPacketField_decode(redundancyPayload, dstBuffer, prrtSequenceNumber_t, baseSequenceNumber, ntohs);
    PrrtPacketField_decode(redundancyPayload, dstBuffer, prrtTimestamp_t, timestamp, ntohl);
    PrrtPacketField_decode(redundancyPayload, dstBuffer, uint8_t, n, identity);
    PrrtPacketField_decode(redundancyPayload, dstBuffer, uint8_t, k, identity);
265

Andreas Schmidt's avatar
Andreas Schmidt committed
266
    return dstBuffer;
267 268
}

269
void *decode_feedback_header(void *dstBuffer, const void *srcBuffer) {
Andreas Schmidt's avatar
Andreas Schmidt committed
270
    PrrtPacketFeedbackPayload *feedback_payload = (PrrtPacketFeedbackPayload *) srcBuffer;
271

272 273 274 275 276 277 278 279 280 281
    PrrtPacketField_decode(feedback_payload, dstBuffer, prrtTimedelta_t, groupRTT_us, ntohl);
    PrrtPacketField_decode(feedback_payload, dstBuffer, prrtTimestamp_t, forwardTripTimestamp_us, ntohl);
    PrrtPacketField_decode(feedback_payload, dstBuffer, prrtSequenceNumber_t, erasureCount, ntohs);
    PrrtPacketField_decode(feedback_payload, dstBuffer, prrtSequenceNumber_t, packetCount, ntohs);
    PrrtPacketField_decode(feedback_payload, dstBuffer, prrtSequenceNumber_t, gapLength, ntohs);
    PrrtPacketField_decode(feedback_payload, dstBuffer, prrtSequenceNumber_t, gapCount, ntohs);
    PrrtPacketField_decode(feedback_payload, dstBuffer, prrtSequenceNumber_t, burstLength, ntohs);
    PrrtPacketField_decode(feedback_payload, dstBuffer, prrtSequenceNumber_t, burstCount, ntohs);
    PrrtPacketField_decode(feedback_payload, dstBuffer, prrtPacketType_t, ackPacketType, identity);
    PrrtPacketField_decode(feedback_payload, dstBuffer, prrtSequenceNumber_t, ackSequenceNumber, ntohs);
282

Andreas Schmidt's avatar
Andreas Schmidt committed
283
    return dstBuffer;
Andreas Schmidt's avatar
Andreas Schmidt committed
284 285
}

286
void *decode_data_header(void *dstBuffer, const void *srcBuffer) {
Andreas Schmidt's avatar
Andreas Schmidt committed
287
    PrrtPacketDataPayload *data_payload = (PrrtPacketDataPayload *) srcBuffer;
Andreas Schmidt's avatar
Andreas Schmidt committed
288

289 290 291 292
    PrrtPacketField_decode(data_payload, dstBuffer, prrtPacketLength_t, dataLength, ntohl);
    PrrtPacketField_decode(data_payload, dstBuffer, prrtTimestamp_t, timestamp, ntohl);
    PrrtPacketField_decode(data_payload, dstBuffer, prrtTimedelta_t, groupRTprop_us, ntohl);
    PrrtPacketField_decode(data_payload, dstBuffer, prrtTimedelta_t, packetTimeout_us, ntohl);
Andreas Schmidt's avatar
Andreas Schmidt committed
293

Andreas Schmidt's avatar
Andreas Schmidt committed
294
    return dstBuffer;
295 296
}

297 298
int PrrtPacket_destroy(PrrtPacket *packet) {
    if (packet->payload != NULL) {
Andreas Schmidt's avatar
Andreas Schmidt committed
299
        free(packet->payload);
300
    }
Andreas Schmidt's avatar
Andreas Schmidt committed
301
    free(packet);
302 303 304
    return 0;
}

305
PrrtPacket *PrrtPacket_create_data_packet(uint8_t priority, const void *payloadPointer,
rna's avatar
rna committed
306
                                          prrtPacketLength_t dataLength, prrtSequenceNumber_t sequenceNumber,
307
                                          prrtTimedelta_t targetDelay) {
Andreas Schmidt's avatar
Andreas Schmidt committed
308
    PrrtPacket *packet = create_header(priority, sequenceNumber,
309 310
                                       (prrtPacketLength_t) (dataLength + PRRT_PACKET_DATA_HEADER_SIZE),
                                       PACKET_TYPE_DATA, 0);
311

312
    PrrtPacketDataPayload *dataPayload = calloc(1, packet->payloadLength);
Andreas Schmidt's avatar
Andreas Schmidt committed
313 314
    check_mem(dataPayload);
    packet->payload = dataPayload;
315

rna's avatar
rna committed
316
    dataPayload->dataLength = dataLength;
317
    dataPayload->timestamp = PrrtClock_get_current_time_us();
318
    dataPayload->packetTimeout_us = dataPayload->timestamp + targetDelay;
319
    dataPayload->groupRTprop_us = 0;
Andreas Schmidt's avatar
Andreas Schmidt committed
320
    PrrtPacket_copy_buffer_to_payload(packet, payloadPointer, PRRT_PACKET_DATA_HEADER_SIZE)
321

Andreas Schmidt's avatar
Andreas Schmidt committed
322
    return packet;
323

324
    error:
325
    PERROR("Could not create packet.%s", "");
Andreas Schmidt's avatar
Andreas Schmidt committed
326
    return NULL;
327 328
}

329 330
PrrtPacket *PrrtPacket_reconstruct_data_packet(PrrtPacketDataPayload *payload, prrtIndex_t index,
                                               prrtSequenceNumber_t sequenceNumber) {
rna's avatar
rna committed
331 332 333
    prrtPacketLength_t dataLength = payload->dataLength;

    PrrtPacket *packet = create_header(0, sequenceNumber,
334 335
                                       (prrtPacketLength_t) (dataLength + PRRT_PACKET_DATA_HEADER_SIZE),
                                       PACKET_TYPE_DATA, index);
rna's avatar
rna committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349

    PrrtPacketDataPayload *dataPayload = calloc(1, packet->payloadLength);
    check_mem(dataPayload);
    packet->payload = dataPayload;

    PrrtPacket_copy_buffer_to_payload(packet, payload, 0)

    return packet;
    error:
    PERROR("Could not reconstruct packet.%s", "");
    return NULL;

}

350 351 352
PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *payloadPointer,
                                                prrtPacketLength_t payloadLength,
                                                prrtSequenceNumber_t sequenceNumber, uint8_t index,
353
                                                prrtSequenceNumber_t baseSequenceNumber,
354
                                                PrrtCodingConfiguration *codingParams) {
Andreas Schmidt's avatar
Andreas Schmidt committed
355
    PrrtPacket *packet = create_header(priority, sequenceNumber,
356
                                       (prrtPacketLength_t) (payloadLength + PRRT_PACKET_REDUNDANCY_HEADER_SIZE),
Andreas Schmidt's avatar
Andreas Schmidt committed
357
                                       PACKET_TYPE_REDUNDANCY, index);
358

359
    PrrtPacketRedundancyPayload *redundancyPayload = calloc(1, packet->payloadLength);
Andreas Schmidt's avatar
Andreas Schmidt committed
360 361
    check_mem(redundancyPayload);
    packet->payload = redundancyPayload;
362

363
    redundancyPayload->baseSequenceNumber = baseSequenceNumber;
364
    redundancyPayload->timestamp = PrrtClock_get_current_time_us();
365 366
    redundancyPayload->k = codingParams->k;
    redundancyPayload->n = codingParams->n;
Andreas Schmidt's avatar
Andreas Schmidt committed
367
    PrrtPacket_copy_buffer_to_payload(packet, payloadPointer, PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
368

Andreas Schmidt's avatar
Andreas Schmidt committed
369
    return packet;
370 371

    error:
372
    PERROR("Out of memory%s.", "");
373
    return NULL;
374 375
}

376 377 378 379 380 381 382
PrrtPacket *
PrrtPacket_create_feedback_packet(uint8_t priority, prrtSequenceNumber_t sequenceNumber, prrtTimedelta_t groupRTT,
                                  prrtSequenceNumber_t gapLength, prrtSequenceNumber_t gapCount,
                                  prrtSequenceNumber_t burstLength, prrtSequenceNumber_t burstCount,
                                  prrtTimestamp_t forwardTripTime, prrtSequenceNumber_t erasureCount,
                                  prrtSequenceNumber_t packetCount, prrtSequenceNumber_t ackSequenceNumber,
                                  prrtPacketType_t ackPacketType) {
Andreas Schmidt's avatar
Andreas Schmidt committed
383
    PrrtPacket *packet = create_header(priority, sequenceNumber, PRRT_PACKET_FEEDBACK_HEADER_SIZE, PACKET_TYPE_FEEDBACK,
384
                                       0);
Andreas Schmidt's avatar
Andreas Schmidt committed
385

386
    PrrtPacketFeedbackPayload *payload = calloc(1, packet->payloadLength);
387
    check_mem(payload);
Andreas Schmidt's avatar
Andreas Schmidt committed
388
    packet->payload = payload;
389

390 391
    payload->groupRTT_us = groupRTT;
    payload->forwardTripTimestamp_us = forwardTripTime;
Andreas Schmidt's avatar
Andreas Schmidt committed
392 393
    payload->erasureCount = erasureCount;
    payload->packetCount = packetCount;
394 395 396 397
    payload->gapLength = gapLength;
    payload->gapCount = gapCount;
    payload->burstLength = burstLength;
    payload->burstCount = burstCount;
398 399
    payload->ackSequenceNumber = ackSequenceNumber;
    payload->ackPacketType = ackPacketType;
400

Andreas Schmidt's avatar
Andreas Schmidt committed
401
    return packet;
402 403

    error:
404
    return NULL;
405
}