Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LARN
PRRT
Commits
1f4889cc
Commit
1f4889cc
authored
Mar 14, 2016
by
Andreas Schmidt
Browse files
Refactor forward packet table to make use of bitmap.
parent
0441ee3e
Changes
5
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
1f4889cc
...
...
@@ -5,13 +5,15 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
set
(
CMAKE_LIBRARY_OUTPUT_DIRECTORY
${
CMAKE_BINARY_DIR
}
/build
)
set
(
CMAKE_RUNTIME_OUTPUT_DIRECTORY
${
CMAKE_BINARY_DIR
}
/bin
)
set
(
CMAKE_CXX_FLAGS
"-fstack-protector -fstack-protector-all -Wall -pedantic"
)
set
(
CMAKE_CXX_FLAGS
"-fstack-protector -fstack-protector-all -Wall -pedantic
"
)
set
(
CMAKE_CXX_FLAGS_DEBUG
"-O2 -Wall -ggdb"
)
set
(
CMAKE_CXX_FLAGS_RELEASE
"-Os -Wall"
)
enable_testing
()
find_package
(
Threads
)
find_library
(
M_LIB m
)
include_directories
(
${
CMAKE_CURRENT_SOURCE_DIR
}
)
...
...
src/prrt/packet.h
View file @
1f4889cc
...
...
@@ -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
;
...
...
src/prrt/stores/forward_packet_table.c
View file @
1f4889cc
#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
);
}
...
...
src/prrt/stores/forward_packet_table.h
View file @
1f4889cc
...
...
@@ -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
);
...
...
src/util/CMakeLists.txt
View file @
1f4889cc
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment