Vanetza
 
Loading...
Searching...
No Matches
gradual_state_machine.hpp
1#ifndef GRADUAL_STATE_MACHINE_HPP_CGPVG4CS
2#define GRADUAL_STATE_MACHINE_HPP_CGPVG4CS
3
4#include <vanetza/common/clock.hpp>
5#include <vanetza/dcc/channel_load.hpp>
6#include <vanetza/dcc/state_machine.hpp>
7#include <set>
8#include <string>
9
10namespace vanetza
11{
12namespace dcc
13{
14
15/**
16 * Reactive Transmit Rate Control (TRC) based on a state machine.
17 *
18 * This implementation complies with ETSI TS 102 687 v1.2.1,
19 * i.e. transitions can only happen gradually between neighbouring states.
20 * No ramping up or cooling down timing behaviour exists (not specified anymore).
21 */
23{
24public:
25 struct State
26 {
27 constexpr State(ChannelLoad limit, Clock::duration off_time) :
28 lower_limit(limit), off_time(off_time) {}
29
30 ChannelLoad lower_limit;
31 Clock::duration off_time;
32
33 bool operator<(const State& other) const { return lower_limit < other.lower_limit; }
34 };
35 using StateContainer = std::set<State>;
36
37 GradualStateMachine(const StateContainer&);
38 GradualStateMachine(StateContainer&&);
39
40 void update(ChannelLoad) override;
41 Clock::duration transmission_interval() const override;
42 std::string state() const;
43
44private:
45 void repair();
46
47 StateContainer m_states;
48 StateContainer::const_iterator m_current;
49};
50
51/**
52 * CBR mapping as per TS 102 687 V1.2.1 Table A.1 (max T_on = 1ms)
53 */
54static const GradualStateMachine::StateContainer etsiStates1ms = {
55 { ChannelLoad(0.00), std::chrono::milliseconds(100) },
56 { ChannelLoad(0.30), std::chrono::milliseconds(200) },
57 { ChannelLoad(0.40), std::chrono::milliseconds(400) },
58 { ChannelLoad(0.50), std::chrono::milliseconds(500) },
59 { ChannelLoad(0.60), std::chrono::milliseconds(1000) }
60};
61
62/**
63 * CBR mapping as per TS 102 686 V1.2.1 Table A.2 (max T_on = 500 us)
64 */
65static const GradualStateMachine::StateContainer etsiStates500us = {
66 { ChannelLoad(0.00), std::chrono::milliseconds(50) },
67 { ChannelLoad(0.30), std::chrono::milliseconds(100) },
68 { ChannelLoad(0.40), std::chrono::milliseconds(200) },
69 { ChannelLoad(0.50), std::chrono::milliseconds(250) },
70 { ChannelLoad(0.65), std::chrono::milliseconds(1000) }
71};
72
73} // namespace dcc
74} // namespace vanetza
75
76#endif /* GRADUAL_STATE_MACHINE_HPP_CGPVG4CS */
77
Clock::duration transmission_interval() const override