Commit aeadb41b authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Add naive block check to ForwardPacketTable.

parent ca529ddf
......@@ -4,6 +4,20 @@
#include <src/prrt/packet.h>
#include "forward_packet_table.h"
int check_position(const 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;
} 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;
}
}
void move_start(PrrtForwardPacketTable *fpt_ptr) {
uint16_t seqno = fpt_ptr->start;
uint16_t which_byte;
......@@ -32,21 +46,29 @@ int PrrtForwardPacketTable_destroy(PrrtForwardPacketTable* fpt_prt) {
}
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;
} else if (!(seqno <= stop || fpt_ptr->start <= seqno)) {
return FALSE;
} else {
int res = check_position(fpt_ptr, seqno);
if(res) {
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;
}
int PrrtForwardPacketTable_test_is_block_relevant(PrrtForwardPacketTable * forwardPacketTable, uint16_t start, uint16_t length) {
// TODO: implement efficiently
int res = FALSE;
int i;
return res;
for (i = 0; i < length; i++) {
res = res || check_position(forwardPacketTable, (uint16_t) (start + i));
}
return res;
}
\ No newline at end of file
......@@ -15,6 +15,8 @@ int PrrtForwardPacketTable_create(PrrtForwardPacketTable* fpt_prt);
int PrrtForwardPacketTable_test_set_is_number_relevant(PrrtForwardPacketTable *fpt_ptr, uint16_t seqno);
int PrrtForwardPacketTable_test_is_block_relevant(PrrtForwardPacketTable * forwardPacketTable, uint16_t start, uint16_t length);
int PrrtForwardPacketTable_destroy(PrrtForwardPacketTable* fpt_prt);
#endif //PRRT_FORWARD_PACKET_TABLE_H
......@@ -71,10 +71,17 @@ TEST_F(ForwardPacketTableTest, Sequence) {
ASSERT_EQ(forwardPacketTable->start, 2);
}
TEST_F(ForwardPacketTableTest, ResetToZero) {
for (int i = 1; i < pow(2, 16) + 5; ++i) {
ASSERT_TRUE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, i));
ASSERT_FALSE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, i));
}
}
TEST_F(ForwardPacketTableTest, CheckBlock) {
ASSERT_TRUE(PrrtForwardPacketTable_test_is_block_relevant(forwardPacketTable, 1, 6));
for (int i = 1; i < 7; ++i) {
ASSERT_TRUE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, i));
}
ASSERT_FALSE(PrrtForwardPacketTable_test_is_block_relevant(forwardPacketTable, 1, 6));
}
\ No newline at end of file
Supports Markdown
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