Vanetza
 
Loading...
Searching...
No Matches
location_table.hpp
1#ifndef LOCATION_TABLE_HPP_EMPVZSHQ
2#define LOCATION_TABLE_HPP_EMPVZSHQ
3
4#include <vanetza/common/object_container.hpp>
5#include <vanetza/geonet/address.hpp>
6#include <vanetza/geonet/mib.hpp>
7#include <vanetza/geonet/position_vector.hpp>
8#include <vanetza/geonet/soft_state_map.hpp>
9#include <vanetza/geonet/station_type.hpp>
10#include <boost/range/adaptor/filtered.hpp>
11#include <boost/range/adaptor/map.hpp>
12
13namespace vanetza
14{
15namespace geonet
16{
17
19{
20public:
21 LocationTableEntry(const Runtime& rt);
22
23 const Address& geonet_address() const;
24 const MacAddress& link_layer_address() const;
25 StationType station_type() const;
26
27 /**
28 * Get packed data rate (PDR) of corresponding source.
29 * \return PDR in bytes per second, might be not-a-number
30 */
31 double get_pdr() const { return m_pdr; }
32
33 /**
34 * Update packet data rate.
35 * See Annex B of EN 302 636-4-1 for details.
36 * \param packet_size received number of bytes
37 * \param beta weight factor for exponential moving average ]0; 1[
38 */
39 void update_pdr(std::size_t packet_size, double beta = 0.5);
40
41 /**
42 * Check if position vector has been set before
43 * \return false after entry initialization
44 * true after set_position_vector invocations
45 */
46 bool has_position_vector() const { return m_has_position_vector; }
47
48 /**
49 * Get stored position vector
50 * \return position vector (empty until set_position_vector invocation)
51 */
52 const LongPositionVector& get_position_vector() const { return m_position_vector; }
53
54 /**
55 * Update stored position vector (only after time stamp check)
56 * \param pv source position vector
57 * \return true if position vector passed time stamp check
58 */
60
61 /**
62 * Check if this entry belongs to a direct neighbour
63 * \return true if direct neighbour
64 */
65 bool is_neighbour() const;
66
67 /**
68 * Set neighbour relation
69 * \param flag true if entry represents a direct neighbour
70 */
71 void set_neighbour(bool flag);
72
73 /**
74 * Set neighbour relation with expiry
75 * \param flag true if entry represents a direct neighbour
76 * \param expiry reset neighbour relation to false after expiry
77 */
78 void set_neighbour(bool flag, Clock::duration expiry);
79
80 ObjectContainer extensions;
81
82private:
83 /**
84 * Set stored position vector (without timestamp check)
85 * \param pv source position vector
86 */
88
89 const Runtime& m_runtime;
90 Clock::time_point m_is_neighbour;
91 bool m_has_position_vector;
92 LongPositionVector m_position_vector;
93 double m_pdr; /*< packet data rate in bytes per second */
94 Clock::time_point m_pdr_update;
95};
96
98{
99public:
100 LocationTableEntryCreator(const Runtime& rt) : m_runtime(rt) {}
101 LocationTableEntry operator()() { return LocationTableEntry(m_runtime); }
102
103private:
104 const Runtime& m_runtime;
105};
106
107/**
108 * GeoNetworking LocationTable
109 * See section 7.1 of EN 302 636-4-1 for details.
110 */
112{
113public:
115 using entry_visitor = std::function<void(const MacAddress&, const LocationTableEntry&)>;
116 using entry_predicate = std::function<bool(const MacAddress&, const LocationTableEntry&)>;
117 using entry_range =
118 boost::select_second_const_range<
119 boost::filtered_range<
120 std::function<bool(const typename table_type::value_type&)>,
121 const typename table_type::map_range>>;
122 using neighbour_range = entry_range;
123
124 LocationTable(const MIB&, Runtime&);
125 bool has_entry(const Address&) const;
127 LocationTableEntry& get_or_create_entry(const Address&);
128 LocationTableEntry& get_or_create_entry(const MacAddress&);
129 const LocationTableEntry* get_entry(const Address&) const;
130 const LocationTableEntry* get_entry(const MacAddress&) const;
131 const LongPositionVector* get_position(const Address&) const;
132 const LongPositionVector* get_position(const MacAddress&) const;
133 bool has_neighbours() const;
134 neighbour_range neighbours() const;
135 entry_range filter(const entry_predicate&) const;
136 void visit(const entry_visitor&) const;
137 void drop_expired() { m_table.drop_expired(); }
138
139private:
140 table_type m_table;
141};
142
143} // namespace geonet
144} // namespace vanetza
145
146#endif /* LOCATION_TABLE_HPP_EMPVZSHQ */
147
void update_pdr(std::size_t packet_size, double beta=0.5)
bool update_position_vector(const LongPositionVector &pv)
const LongPositionVector & get_position_vector() const
bool set_position_vector(const LongPositionVector &pv)