Commit 1f4889cc authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Refactor forward packet table to make use of bitmap.

parent 0441ee3e
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -12,6 +12,8 @@ set(CMAKE_CXX_FLAGS_RELEASE "-Os -Wall" )
enable_testing()

find_package (Threads)
find_library(M_LIB m)


include_directories(${CMAKE_CURRENT_SOURCE_DIR})

+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ typedef struct prrtPacket {
#define PRRT_PACKET_GENERAL_HEADER_SIZE 8
#define PRRT_PACKET_ENCODED_GENERAL_HEADER_LENGTH 4

#define SEQNO_SPACE 65536 // 2**16 as seqno is uint16_t
#define SEQNO_SPACE UINT16_MAX // 2**16 as seqno is uint16_t

typedef struct prrtPacketDataPayload {
    uint32_t timestamp;
+8 −15
Original line number Diff line number Diff line
#include <stdint.h>
#include <string.h>
#include "../../defines.h"
#include "../packet.h"
#include "forward_packet_table.h"
@@ -12,37 +11,34 @@ int is_position_relevant(const PrrtForwardPacketTable *fpt_ptr, uint16_t seqno)
    } else if (!(seqno <= stop || fpt_ptr->start <= seqno)) {
        return false;
    } else {
        uint16_t which_byte = (uint16_t) (seqno / 32);
        uint16_t which_bit = (uint16_t) (seqno % 32);
        return ((fpt_ptr->data[which_byte] >> which_bit) & 0x01) == 0;
        return Bitmap_get(fpt_ptr->bitmap, seqno);
    }
}

void move_start(PrrtForwardPacketTable *fpt_ptr) {
    uint16_t seqno = fpt_ptr->start;
    uint16_t which_byte;
    uint16_t which_bit;

    while(1) {
        which_byte = (uint16_t) (seqno / 32);
        which_bit = (uint16_t) (seqno % 32);
        if (((fpt_ptr->data[which_byte] >> which_bit ) & 0x01) == 0) {
        if (Bitmap_get(fpt_ptr->bitmap, seqno)) {
            break;
        }
        fpt_ptr->data[which_byte] &= ~(1 << which_bit);
        Bitmap_set(fpt_ptr->bitmap, seqno, true);
        seqno++;
    }

    // TODO: make more efficient by using the Bitmap_set_range function

    fpt_ptr->start = seqno;
}

int PrrtForwardPacketTable_create(PrrtForwardPacketTable *fpt_prt) {
    fpt_prt->start = 1;
    memset(fpt_prt->data, 0, sizeof(fpt_prt->data));
    fpt_prt->bitmap = Bitmap_create(true, SEQNO_SPACE);
    return EXIT_SUCCESS;
}

bool PrrtForwardPacketTable_destroy(PrrtForwardPacketTable* fpt_prt) {
    Bitmap_destroy(fpt_prt->bitmap);
    free(fpt_prt);
    return true;
}
@@ -51,10 +47,7 @@ int PrrtForwardPacketTable_test_set_is_number_relevant(PrrtForwardPacketTable *f
    int res = is_position_relevant(fpt_ptr, seqno);

    if(res) {
        uint16_t which_byte = (uint16_t) (seqno / 32);
        uint16_t which_bit = (uint16_t) (seqno % 32);
        fpt_ptr->data[which_byte] |= 1 << which_bit;

        Bitmap_set(fpt_ptr->bitmap, seqno, false);
        if(seqno == fpt_ptr->start) {
            move_start(fpt_ptr);
        }
+2 −4
Original line number Diff line number Diff line
@@ -3,13 +3,11 @@

#include <stdint.h>
#include <stdbool.h>

#define FORWARD_PACKET_TABLE_LENGTH 2048  // sequence number space is 2**16 and we have 32 bit so: 2048
#include "../../util/bitmap.h"

typedef struct {
    uint32_t data[FORWARD_PACKET_TABLE_LENGTH];
    uint16_t start;

    Bitmap* bitmap;
} PrrtForwardPacketTable;

int PrrtForwardPacketTable_create(PrrtForwardPacketTable* fpt_prt);
+1 −0
Original line number Diff line number Diff line
add_library(UTIL ../defines.h common.c common.h list.c list.h dbg.h bptree.c bptree.h bitmap.c bitmap.h)
set_property(TARGET UTIL PROPERTY C_STANDARD 99)
target_link_libraries(UTIL ${M_LIB})
 No newline at end of file