Vanetza
 
Loading...
Searching...
No Matches
fully_meshed_state_machine.hpp
1#ifndef FULLY_MESHED_STATE_MACHINE_HPP_YPE958OH
2#define FULLY_MESHED_STATE_MACHINE_HPP_YPE958OH
3
4#include <vanetza/common/clock.hpp>
5#include <vanetza/dcc/channel_load.hpp>
6#include <vanetza/dcc/state_machine.hpp>
7#include <boost/circular_buffer.hpp>
8#include <boost/optional.hpp>
9
10namespace vanetza
11{
12namespace dcc
13{
14
15// constants
16static constexpr Clock::duration NDL_minDccSampling = std::chrono::milliseconds(100);
17
18
19class State
20{
21public:
22 virtual Clock::duration transmission_interval() const = 0;
23 virtual const char* name() const = 0;
24 virtual ~State() {}
25};
26
27class Relaxed : public State
28{
29public:
30 Clock::duration transmission_interval() const override;
31 const char* name() const override;
32};
33
34class Active : public State
35{
36public:
37 Active();
38 void update(double min, double max);
39 Clock::duration transmission_interval() const override;
40 const char* name() const override;
41
42private:
43 static const std::size_t sc_substates;
44 std::size_t m_substate;
45};
46
47class Restrictive : public State
48{
49public:
50 Clock::duration transmission_interval() const override;
51 const char* name() const override;
52};
53
54/**
55 * Fully meshed TRC state machine as per TS 102 687 v1.1.1
56 *
57 * States are modelled according to C2C-CC DCC Whitepaper / BSP v1.2
58 * State transitions are deferred internally for ramping up and cooling down over time.
59 */
61{
62public:
65
66 /**
67 * Notify state machine about current channel load.
68 * This method expects to be called in regular intervals
69 * of NDL_minDccSampling length.
70 */
71 void update(ChannelLoad channel_load);
72
73 /**
74 * Get currently allowed maximum message rate depending on state
75 * \return messages per second
76 */
77 double message_rate() const;
78
79 /**
80 * Get advised transmission interval between consecutive messages
81 * \return message transmission interval
82 */
83 Clock::duration transmission_interval() const;
84
85 /**
86 * Get state machine's active state
87 */
88 const State& state() const;
89
90private:
91 double max_channel_load() const;
92 double min_channel_load() const;
93
94 Relaxed m_relaxed;
95 Active m_active;
96 Restrictive m_restrictive;
97 State* m_state;
98 boost::circular_buffer<ChannelLoad> m_channel_loads;
99};
100
101} // namespace dcc
102} // namespace vanetza
103
104#endif /* FULLY_MESHED_STATE_MACHINE_HPP_YPE958OH */
105