forward_packet_table.c 1.49 KB
Newer Older
1
2
#include <stdint.h>
#include <string.h>
Andreas Schmidt's avatar
Andreas Schmidt committed
3
4
#include <src/defines.h>
#include <src/prrt/packet.h>
5
#include "forward_packet_table.h"
6

7
8
9
10
void move_start(PrrtForwardPacketTable *fpt_ptr) {
    uint16_t seqno = fpt_ptr->start;
    uint16_t which_byte;
    uint16_t which_bit;
11

12
13
14
    while(1) {
        which_byte = (uint16_t) (seqno / 32);
        which_bit = (uint16_t) (seqno % 32);
15
        if (((fpt_ptr->data[which_byte] >> which_bit ) & 0x01) == 0) {
16
17
18
19
20
            break;
        }
        fpt_ptr->data[which_byte] &= ~(1 << which_bit);
        seqno++;
    }
21

22
23
24
25
26
27
28
29
    fpt_ptr->start = seqno;
}

int PrrtForwardPacketTable_create(PrrtForwardPacketTable *fpt_prt) {
    fpt_prt->start = 1;
    memset(fpt_prt->data, 0, sizeof(fpt_prt->data));
}

30
31
32
33
int PrrtForwardPacketTable_destroy(PrrtForwardPacketTable* fpt_prt) {

}

34
35
36
37
int PrrtForwardPacketTable_test_set_is_number_relevant(PrrtForwardPacketTable *fpt_ptr, uint16_t seqno) {
    uint16_t stop = (uint16_t) (SEQNO_SPACE / 2 + fpt_ptr->start);
    if (fpt_ptr->start < stop && !(fpt_ptr->start <= seqno && seqno <= stop)) {
        return FALSE;
38
    } else if (!(seqno <= stop || fpt_ptr->start <= seqno)) {
39
40
41
42
43
44
45
46
47
48
49
50
51
        return FALSE;
    } else {
        uint16_t which_byte = (uint16_t) (seqno / 32);
        uint16_t which_bit = (uint16_t) (seqno % 32);
        int res = ((fpt_ptr->data[which_byte] >> which_bit) & 0x01) == 0;
        fpt_ptr->data[which_byte] |= 1 << which_bit;

        if(seqno == fpt_ptr->start) {
            move_start(fpt_ptr);
        }

        return res;
    }
52
}