Commit 96b10e47 authored by Andreas Schmidt's avatar Andreas Schmidt

PacketTimeoutTable now manages PacketTimeouts and not full packets.

parent 42cbeadd
Pipeline #1213 failed with stages
in 48 seconds
......@@ -16,6 +16,7 @@ add_library(PRRT ../defines.h
processes/dataTransmitter.c processes/dataTransmitter.h
stores/repairBlockStore.c stores/repairBlockStore.h
stores/packetTimeoutTable.c stores/packetTimeoutTable.h
stores/dataPacketStore.c stores/dataPacketStore.h)
stores/dataPacketStore.c stores/dataPacketStore.h
types/packetTimeout.c types/packetTimeout.h)
target_link_libraries(PRRT rt)
......@@ -99,8 +99,8 @@ static void handle_data_packet(PrrtSocket *sock_ptr, PrrtPacket *packet, struct
sock_ptr->lastSentTimestamp = dataTimestamp;
PrrtClock_update(&sock_ptr->clock, dataTimestamp, payload->groupRTT_us);
PrrtPacket *copiedPacket = PrrtPacket_copy(packet);
check(PrrtPacketTimeoutTable_insert(sock_ptr->packetTimeoutTable, copiedPacket), "Could not insert data packet.");
PrrtPacketTimeout* packetTimeout = PrrtPacketTimeout_create(packet);
check(PrrtPacketTimeoutTable_insert(sock_ptr->packetTimeoutTable, packetTimeout), "Could not insert data packet.");
prrtSequenceNumber_t seqno = packet->sequenceNumber;
......
......@@ -13,6 +13,7 @@
#include "processes/dataTransmitter.h"
#include "processes/dataReceiver.h"
#include "processes/feedbackReceiver.h"
#include "types/packetTimeout.h"
#include "socket.h"
#include "receiver.h"
......@@ -392,11 +393,11 @@ bool PrrtSocket_cleanup(PrrtSocket *socket) {
&socket->clock));
uint32_t expired_count = List_count(expired_packets);
if (expired_count > 0) {
PrrtPacket *first = List_first(expired_packets);
PrrtPacketTimeout *first = List_first(expired_packets);
prrtSequenceNumber_t firstSequenceNumberBase = (prrtSequenceNumber_t) (first->sequenceNumber -
first->index - SEQNO_SPACE / 2);
PrrtPacket *last = List_last(expired_packets);
PrrtPacketTimeout *last = List_last(expired_packets);
prrtSequenceNumber_t lastSequenceNumberBase = (prrtSequenceNumber_t) (last->sequenceNumber -
last->index - 1);
......@@ -414,8 +415,8 @@ bool PrrtSocket_cleanup(PrrtSocket *socket) {
List_destroy(list);
while (List_count(expired_packets) > 0) {
PrrtPacket *packet = (PrrtPacket *) List_shift(expired_packets);
PrrtPacket_destroy(packet);
PrrtPacketTimeout *packetTimeout = (PrrtPacketTimeout *) List_shift(expired_packets);
PrrtPacketTimeout_destroy(packetTimeout);
}
debug(DEBUG_SOCKET, "Cleanup: [%d, %d, %d] expiring %d, data store: %d", firstSequenceNumberBase,
......
#include "../../util/common.h"
#include "../../util/dbg.h"
#include "../clock.h"
#include "../types/packetTimeout.h"
#include "packetTimeoutTable.h"
PrrtPacketTimeoutTable *PrrtPacketTimeoutTable_create(void)
......@@ -8,7 +9,7 @@ PrrtPacketTimeoutTable *PrrtPacketTimeoutTable_create(void)
PrrtPacketTimeoutTable *table = (PrrtPacketTimeoutTable *) calloc(1, sizeof(PrrtPacketTimeoutTable));
check_mem(table);
table->packetList = NULL;
table->packetTimeoutList = NULL;
check(pthread_mutex_init(&table->lock, NULL) == EXIT_SUCCESS, "Init mutex failed.");
......@@ -22,17 +23,16 @@ bool PrrtPacketTimeoutTable_destroy(PrrtPacketTimeoutTable *table)
{
List* list = List_create();
BPTree_get_range(table->packetList, list, 0, MAX_TIMESTAMP);
BPTree_get_range(table->packetTimeoutList, list, 0, MAX_TIMESTAMP);
while (List_count(list) > 0) {
PrrtPacket *packet = List_shift(list);
PrrtPacketDataPayload* payload = packet->payload;
table->packetList = BPTree_delete(table->packetList, payload->packetTimeout_us);
PrrtPacket_destroy(packet);
PrrtPacketTimeout *packetTimeout = List_shift(list);
table->packetTimeoutList = BPTree_delete(table->packetTimeoutList, packetTimeout->timeout_us);
PrrtPacketTimeout_destroy(packetTimeout);
}
List_destroy(list);
if(table->packetList != NULL) {
table->packetList = BPTree_destroy(table->packetList);
if(table->packetTimeoutList != NULL) {
table->packetTimeoutList = BPTree_destroy(table->packetTimeoutList);
}
pthread_mutex_destroy(&table->lock);
......@@ -40,11 +40,10 @@ bool PrrtPacketTimeoutTable_destroy(PrrtPacketTimeoutTable *table)
return true;
}
bool PrrtPacketTimeoutTable_insert(PrrtPacketTimeoutTable *table, PrrtPacket *packet)
bool PrrtPacketTimeoutTable_insert(PrrtPacketTimeoutTable *table, PrrtPacketTimeout *packetTimeout)
{
check(pthread_mutex_lock(&table->lock) == EXIT_SUCCESS, "Lock failed.");
PrrtPacketDataPayload* payload = packet->payload;
table->packetList = BPTree_insert(table->packetList, payload->packetTimeout_us, packet);
table->packetTimeoutList = BPTree_insert(table->packetTimeoutList, packetTimeout->timeout_us, packetTimeout);
check(pthread_mutex_unlock(&table->lock) == EXIT_SUCCESS, "Unlock failed.");
return true;
error:
......@@ -57,19 +56,18 @@ List *PrrtPacketTimeoutTable_expire_packets(PrrtPacketTimeoutTable *table, prrtT
check(pthread_mutex_lock(&table->lock) == EXIT_SUCCESS, "Lock failed.");
List* list = List_create();
if(table->packetList != NULL) {
if(table->packetTimeoutList != NULL) {
if(now > HALF_TIMESTAMP) {
BPTree_get_range(table->packetList, list, now - HALF_TIMESTAMP, now);
BPTree_get_range(table->packetTimeoutList, list, now - HALF_TIMESTAMP, now);
} else {
BPTree_get_range(table->packetList, list, 0, now);
BPTree_get_range(table->packetList, list, now - HALF_TIMESTAMP, MAX_TIMESTAMP);
BPTree_get_range(table->packetTimeoutList, list, 0, now);
BPTree_get_range(table->packetTimeoutList, list, now - HALF_TIMESTAMP, MAX_TIMESTAMP);
}
}
LIST_FOREACH(list, first, next, current) {
PrrtPacket *packet = current->value;
PrrtPacketDataPayload* payload = packet->payload;
table->packetList = BPTree_delete(table->packetList, payload->packetTimeout_us);
PrrtPacketTimeout *packetTimeout = current->value;
table->packetTimeoutList = BPTree_delete(table->packetTimeoutList, packetTimeout->timeout_us);
}
check(pthread_mutex_unlock(&table->lock) == EXIT_SUCCESS, "Unlock failed.");
......@@ -77,15 +75,4 @@ List *PrrtPacketTimeoutTable_expire_packets(PrrtPacketTimeoutTable *table, prrtT
error:
PERROR("Get expired timestamps failed%s.","");
return NULL;
}
PrrtPacket *PrrtPacketTimeoutTable_remove(PrrtPacketTimeoutTable *table, prrtTimestamp_t stamp)
{
check(pthread_mutex_lock(&table->lock) == EXIT_SUCCESS, "Lock failed.");
PrrtPacket *packet = (PrrtPacket *) BPTree_delete(table->packetList, stamp);
check(pthread_mutex_unlock(&table->lock) == EXIT_SUCCESS, "Unlock failed.");
return packet;
error:
PERROR("Get expired timestamps failed%s.","");
return NULL;
}
}
\ No newline at end of file
......@@ -3,17 +3,17 @@
#include <bits/pthreadtypes.h>
#include "../../util/bptree.h"
#include "../types/packetTimeout.h"
#include "../packet.h"
typedef struct prrtPacketTimeoutTable {
pthread_mutex_t lock;
BPTreeNode* packetList;
BPTreeNode* packetTimeoutList;
} PrrtPacketTimeoutTable;
PrrtPacketTimeoutTable* PrrtPacketTimeoutTable_create(void);
bool PrrtPacketTimeoutTable_insert(PrrtPacketTimeoutTable* table, PrrtPacket* packet);
bool PrrtPacketTimeoutTable_insert(PrrtPacketTimeoutTable* table, PrrtPacketTimeout* packet);
List *PrrtPacketTimeoutTable_expire_packets(PrrtPacketTimeoutTable *table, prrtTimestamp_t now);
PrrtPacket *PrrtPacketTimeoutTable_remove(PrrtPacketTimeoutTable *table, prrtTimestamp_t stamp);
bool PrrtPacketTimeoutTable_destroy(PrrtPacketTimeoutTable* table);
#endif //PRRT_PACKETTIMEOUTTABLE_H
#include "../../util/common.h"
#include "../../util/dbg.h"
#include "packetTimeout.h"
PrrtPacketTimeout *PrrtPacketTimeout_create(PrrtPacket *packet) {
PrrtPacketTimeout *packetTimeout = calloc(1, sizeof(PrrtPacketTimeout));
check_mem(packetTimeout);
PrrtPacketDataPayload* payload = packet->payload;
packetTimeout->sequenceNumber = packet->sequenceNumber;
packetTimeout->index = packet->index;
packetTimeout->timeout_us = payload->packetTimeout_us;
return packetTimeout;
error:
PERROR("Not enough memory for packet timeout.%s", "");
return NULL;
}
bool PrrtPacketTimeout_destroy(PrrtPacketTimeout *packetTimeout) {
free(packetTimeout);
return true;
}
#ifndef PRRT_PACKETTIMEOUT_H
#define PRRT_PACKETTIMEOUT_H
#include <prrt/proto/packet.h>
typedef struct prrtPacketTimeout{
prrtSequenceNumber_t sequenceNumber;
prrtIndex_t index;
prrtTimestamp_t timeout_us;
} PrrtPacketTimeout;
PrrtPacketTimeout* PrrtPacketTimeout_create(PrrtPacket* packet);
bool PrrtPacketTimeout_destroy(PrrtPacketTimeout *packetTimeout);
#endif //PRRT_PACKETTIMEOUT_H
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