Vanetza
Loading...
Searching...
No Matches
gbc_memory.hpp
1
#
ifndef
GBC_MEMORY_HPP_032N8PRJ
2
#
define
GBC_MEMORY_HPP_032N8PRJ
3
4
#
include
<
vanetza
/
geonet
/
cbf_packet_identifier
.
hpp
>
5
#
include
<
boost
/
multi_index_container
.
hpp
>
6
#
include
<
boost
/
multi_index
/
hashed_index
.
hpp
>
7
#
include
<
boost
/
multi_index
/
sequenced_index
.
hpp
>
8
9
namespace
vanetza
10
{
11
namespace
geonet
12
{
13
14
/**
15
* GbcMemory remembers previously seens GBC packets.
16
*
17
* GBC packets are identified by their (GN addr, sequence number) tuple.
18
* The size of GbcMemory is bounded, i.e. it will forget old packets in favour of recent ones.
19
*/
20
class
GbcMemory
21
{
22
public
:
23
using
PacketIdentifier = CbfPacketIdentifier;
24
25
/**
26
* Forget a packet if memory exceeds upper limit of stored identifiers
27
* \param num upper limit of remembered packets
28
*/
29
void
capacity
(std::size_t num);
30
31
/**
32
* Number of currently known packets
33
* \return number of packets
34
*/
35
std::size_t
size
()
const
;
36
37
/**
38
* Remember a particular packet
39
* \param id packet identifier
40
* \return true if packet is already known
41
*/
42
bool
remember
(
const
PacketIdentifier& id);
43
44
/**
45
* Check if a particular packet is known
46
* \param id packet identifier
47
* \return true if packet is known
48
*/
49
bool
knows
(
const
PacketIdentifier& id)
const
;
50
51
private
:
52
std::size_t m_capacity = 1;
53
54
struct
by_packet
{};
55
using
packet_index
=
boost
::
multi_index
::
hashed_unique
<
56
boost
::
multi_index
::
tag
<
by_packet
>,
57
boost
::
multi_index
::
identity
<
PacketIdentifier
>,
58
std
::
hash
<
PacketIdentifier
>
59
>;
60
struct
by_queue
{};
61
using
queue_index
=
boost
::
multi_index
::
sequenced
<
boost
::
multi_index
::
tag
<
by_queue
>>;
62
63
using
container_type
=
boost
::
multi_index_container
<
PacketIdentifier
,
64
boost
::
multi_index
::
indexed_by
<
queue_index
,
packet_index
>>;
65
container_type m_identifiers;
66
};
67
68
}
// namespace geonet
69
}
// namespace vanetza
70
71
#
endif
/* GBC_MEMORY_HPP_032N8PRJ */
vanetza::geonet::GbcMemory
Definition
gbc_memory.hpp:21
vanetza::geonet::GbcMemory::remember
bool remember(const PacketIdentifier &id)
Definition
gbc_memory.cpp:24
vanetza::geonet::GbcMemory::knows
bool knows(const PacketIdentifier &id) const
Definition
gbc_memory.cpp:46
vanetza::geonet::GbcMemory::size
std::size_t size() const
Definition
gbc_memory.cpp:19
vanetza::geonet::GbcMemory::capacity
void capacity(std::size_t num)
Definition
gbc_memory.cpp:8
vanetza::geonet::GbcMemory::by_packet
Definition
gbc_memory.hpp:54
vanetza::geonet::GbcMemory::by_queue
Definition
gbc_memory.hpp:60
vanetza
geonet
gbc_memory.hpp
Generated on
for Vanetza by
1.16.1