Vanetza
 
Loading...
Searching...
No Matches
flow_control.hpp
1#ifndef FLOW_CONTROL_HPP_PG7RKD8V
2#define FLOW_CONTROL_HPP_PG7RKD8V
3
4#include <vanetza/common/clock.hpp>
5#include <vanetza/common/hook.hpp>
6#include <vanetza/dcc/data_request.hpp>
7#include <vanetza/dcc/interface.hpp>
8#include <vanetza/dcc/profile.hpp>
9#include <vanetza/dcc/transmission.hpp>
10#include <vanetza/net/chunk_packet.hpp>
11#include <boost/optional/optional.hpp>
13#include <list>
14#include <memory>
15#include <map>
16
17namespace vanetza
18{
19
20// forward declarations
21namespace access { class Interface; }
22class Runtime;
23
24namespace dcc
25{
26
27// forward declarations
28class TransmitRateControl;
29
30/**
31 * FlowControl is a gatekeeper above access layer.
32 *
33 * There is a queue for each access category. Packets might be enqueued
34 * because of exceeded transmission intervals determined by Scheduler.
35 * If a packet's lifetime expires before transmission it will be dropped.
36 */
38{
39public:
42
43 /**
44 * Create FlowControl instance
45 * \param rt Runtime used for timed actions, e.g. packet expiry
46 * \param scheduler Scheduler providing transmission intervals
47 * \param access Interface to access layer
48 */
51
52 /**
53 * Request packet transmission
54 * \param request DCC request parameters
55 * \param packet Packet data
56 */
57 void request(const DataRequest&, std::unique_ptr<ChunkPacket>) override;
58
59 /**
60 * Set callback to be invoked at packet drop. Replaces any previous callback.
61 * \param cb Callback
62 */
63 void set_packet_drop_hook(PacketDropHook::callback_type&&);
64
65 /**
66 * Set callback to be invoked at packet transmission. Replaces any previous callback.
67 * \param cb Callback
68 */
69 void set_packet_transmit_hook(PacketTransmitHook::callback_type&&);
70
71 /**
72 * Set length of each queue
73 *
74 * The first queue element is dropped when the length limit is hit.
75 * \param length Maximum number of queue elements, 0 for unlimited length
76 */
77 void queue_length(std::size_t length);
78
79 /**
80 * Reschedule queued transmissions
81 * This reevaluates TRC restrictions as well, packets may get transmitted earlier.
82 */
83 void reschedule();
84
85private:
87 {
88 PendingTransmission(Clock::time_point expiry, const DataRequest& request, std::unique_ptr<ChunkPacket> packet) :
89 expiry(expiry), request(request), packet(std::move(packet)) {}
90
91 Clock::time_point expiry;
92 DataRequest request;
93 std::unique_ptr<ChunkPacket> packet;
94
95 Profile profile() const override { return request.dcc_profile; }
96 const access::DataRateG5* data_rate() const override { return &access::G5_6Mbps; }
97 std::size_t body_length() const override { return packet ? packet->size() : 0; }
98 };
99
100 using Queue = std::list<PendingTransmission>;
101
102 void enqueue(const DataRequest&, std::unique_ptr<ChunkPacket>);
103 boost::optional<PendingTransmission> dequeue();
104 void transmit(const DataRequest&, std::unique_ptr<ChunkPacket>);
105 bool transmit_immediately(const Transmission&) const;
106 void drop_expired();
107 bool empty() const;
108 void trigger();
109 void schedule_trigger(const Transmission&);
110 PendingTransmission* next_transmission();
111 Queue* next_queue();
112
113 Runtime& m_runtime;
114 TransmitRateControl& m_trc;
115 access::Interface& m_access;
116 std::map<access::AccessCategory, Queue, std::greater<access::AccessCategory>> m_queues;
117 std::size_t m_queue_length;
118 PacketDropHook m_packet_drop_hook;
119 PacketTransmitHook m_packet_transmit_hook;
120};
121
122} // namespace dcc
123} // namespace vanetza
124
125#endif /* FLOW_CONTROL_HPP_PG7RKD8V */
126
void set_packet_drop_hook(PacketDropHook::callback_type &&)
void queue_length(std::size_t length)
void request(const DataRequest &, std::unique_ptr< ChunkPacket >) override
void set_packet_transmit_hook(PacketTransmitHook::callback_type &&)