rogue
Loading...
Searching...
No Matches
Controller.h
Go to the documentation of this file.
1
17#ifndef __ROGUE_PROTOCOLS_RSSI_CONTROLLER_H__
18#define __ROGUE_PROTOCOLS_RSSI_CONTROLLER_H__
19#include "rogue/Directives.h"
20
21#include <stdint.h>
22
23#include <atomic>
24#include <map>
25#include <memory>
26
28#include "rogue/Logging.h"
29#include "rogue/Queue.h"
32
33namespace rogue {
34namespace protocols {
35namespace rssi {
36
37class Application;
38class Transport;
39class Header;
40
64class Controller : public rogue::EnableSharedFromThis<rogue::protocols::rssi::Controller> {
65 // Hard coded values
66 static const uint8_t Version = 1;
67 static const uint8_t TimeoutUnit = 3; // rssiTime * std::pow(10,-TimeoutUnit) = 3 = ms
68
69 // Local parameters
70 uint32_t locTryPeriod_;
71
72 // Configurable parameters, requested by software
73 uint8_t locMaxBuffers_;
74 uint16_t locMaxSegment_;
75 uint16_t locCumAckTout_;
76 uint16_t locRetranTout_;
77 uint16_t locNullTout_;
78 uint8_t locMaxRetran_;
79 uint8_t locMaxCumAck_;
80
81 // Negotiated parameters
82 uint8_t curMaxBuffers_;
83 uint16_t curMaxSegment_;
84 uint16_t curCumAckTout_;
85 uint16_t curRetranTout_;
86 uint16_t curNullTout_;
87 uint8_t curMaxRetran_;
88 uint8_t curMaxCumAck_;
89
90 // Connection states
91 enum States : uint32_t { StClosed = 0, StWaitSyn = 1, StSendSynAck = 2, StSendSeqAck = 3, StOpen = 4, StError = 5 };
92
93 // Interfaces
94 std::shared_ptr<rogue::protocols::rssi::Transport> tran_;
95 std::shared_ptr<rogue::protocols::rssi::Application> app_;
96
97 std::shared_ptr<rogue::Logging> log_;
98
99 // Is server
100 bool server_;
101
102 // Receive tracking
103 std::atomic<uint32_t> dropCount_;
104 uint8_t nextSeqRx_;
105 uint8_t lastAckRx_;
106 std::atomic<bool> remBusy_;
107 std::atomic<bool> locBusy_;
108
109 // Application queue
111
112 // Sequence Out of Order ("OOO") queue
113 std::map<uint8_t, std::shared_ptr<rogue::protocols::rssi::Header>> oooQueue_;
114
115 // State queue
117
118 // Application tracking
119 uint8_t lastSeqRx_;
120 uint8_t ackSeqRx_;
121
122 // State Tracking
123 std::condition_variable stCond_;
124 std::mutex stMtx_;
125 uint32_t state_;
126 struct timeval stTime_;
127 std::atomic<uint32_t> downCount_;
128 std::atomic<uint32_t> retranCount_;
129 std::atomic<uint32_t> locBusyCnt_;
130 std::atomic<uint32_t> remBusyCnt_;
131 uint32_t locConnId_;
132 uint32_t remConnId_;
133
134 // Transmit tracking
135 std::shared_ptr<rogue::protocols::rssi::Header> txList_[256];
136 std::mutex txMtx_;
137 uint8_t txListCount_;
138 uint8_t lastAckTx_;
139 uint8_t locSequence_;
140 struct timeval txTime_;
141
142 // Time values
143 struct timeval retranToutD1_; // retranTout_ / 1
144 struct timeval tryPeriodD1_; // TryPeriod / 1
145 struct timeval tryPeriodD4_; // TryPeriod / 4
146 struct timeval cumAckToutD1_; // cumAckTout_ / 1
147 struct timeval cumAckToutD2_; // cumAckTout_ / 2
148 struct timeval nullToutD3_; // nullTout_ / 3
149 struct timeval zeroTme_; // 0
150
152 protected:
153 std::thread* thread_ = nullptr;
154 std::atomic<bool> threadEn_{false};
156
157 private:
158 // Application frame transmit timeout
159 struct timeval timeout_;
160
161 public:
178 static std::shared_ptr<rogue::protocols::rssi::Controller> create(
179 uint32_t segSize,
180 std::shared_ptr<rogue::protocols::rssi::Transport> tran,
181 std::shared_ptr<rogue::protocols::rssi::Application> app,
182 bool server);
183
196 Controller(uint32_t segSize,
197 std::shared_ptr<rogue::protocols::rssi::Transport> tran,
198 std::shared_ptr<rogue::protocols::rssi::Application> app,
199 bool server);
200
202 ~Controller();
203
205 void stopQueue();
206
212 std::shared_ptr<rogue::interfaces::stream::Frame> reqFrame(uint32_t size);
213
218 void transportRx(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
219
224 std::shared_ptr<rogue::interfaces::stream::Frame> applicationTx();
225
230 void applicationRx(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
231
236 bool getOpen();
237
242 uint32_t getDownCount();
243
248 uint32_t getDropCount();
249
254 uint32_t getRetranCount();
255
260 bool getLocBusy();
261
266 uint32_t getLocBusyCnt();
267
272 bool getRemBusy();
273
278 uint32_t getRemBusyCnt();
279
284 void setLocTryPeriod(uint32_t val);
289 uint32_t getLocTryPeriod();
290
295 void setLocMaxBuffers(uint8_t val);
300 uint8_t getLocMaxBuffers();
301
306 void setLocMaxSegment(uint16_t val);
311 uint16_t getLocMaxSegment();
312
317 void setLocCumAckTout(uint16_t val);
322 uint16_t getLocCumAckTout();
323
328 void setLocRetranTout(uint16_t val);
333 uint16_t getLocRetranTout();
334
339 void setLocNullTout(uint16_t val);
344 uint16_t getLocNullTout();
345
350 void setLocMaxRetran(uint8_t val);
355 uint8_t getLocMaxRetran();
356
361 void setLocMaxCumAck(uint8_t val);
366 uint8_t getLocMaxCumAck();
367
372 uint8_t curMaxBuffers();
377 uint16_t curMaxSegment();
382 uint16_t curCumAckTout();
387 uint16_t curRetranTout();
392 uint16_t curNullTout();
397 uint8_t curMaxRetran();
402 uint8_t curMaxCumAck();
403
405 void resetCounters();
406
411 void setTimeout(uint32_t timeout);
412
414 void stop();
415
417 void start();
418
419 private:
420 // Method to transit a frame with proper updates
421 void transportTx(std::shared_ptr<rogue::protocols::rssi::Header> head, bool seqUpdate, bool txReset);
422
423 // Method to retransmit a frame
424 int8_t retransmit(uint8_t id);
425
427 static void convTime(struct timeval& tme, uint32_t rssiTime);
428
430 static bool timePassed(struct timeval& lastTime, struct timeval& tme);
431
433 void runThread();
434
436 struct timeval& stateClosedWait();
437
439 struct timeval& stateSendSynAck();
440
442 struct timeval& stateSendSeqAck();
443
445 struct timeval& stateOpen();
446
448 struct timeval& stateError();
449};
450
451// Convenience
452typedef std::shared_ptr<rogue::protocols::rssi::Controller> ControllerPtr;
453
454} // namespace rssi
455} // namespace protocols
456}; // namespace rogue
457
458#endif
Typed shared-from-this helper for Rogue classes.
Thread-safe bounded queue with optional busy threshold.
Definition Queue.h:39
Rogue version query and comparison helpers.
Definition Version.h:35
RSSI protocol controller.
Definition Controller.h:64
uint8_t getLocMaxCumAck()
Gets local max cumulative ACK interval.
void setLocCumAckTout(uint16_t val)
Sets local cumulative ACK timeout.
uint8_t curMaxBuffers()
Gets negotiated max outstanding buffers.
void setLocNullTout(uint16_t val)
Sets local null-segment timeout.
uint16_t curNullTout()
Gets negotiated null-segment timeout.
uint16_t curCumAckTout()
Gets negotiated cumulative ACK timeout.
std::shared_ptr< rogue::interfaces::stream::Frame > reqFrame(uint32_t size)
Allocates a frame for transport-path transmission.
uint8_t getLocMaxBuffers()
Gets local max outstanding buffers parameter.
uint32_t getDownCount()
Returns link down transition counter.
void setLocTryPeriod(uint32_t val)
Sets local connection retry period.
void setLocRetranTout(uint16_t val)
Sets local retransmit timeout.
void applicationRx(std::shared_ptr< rogue::interfaces::stream::Frame > frame)
Processes a frame received from the application side.
uint32_t getLocTryPeriod()
Gets local connection retry period.
uint8_t curMaxCumAck()
Gets negotiated max cumulative ACK interval.
uint16_t curMaxSegment()
Gets negotiated max segment size.
uint16_t getLocRetranTout()
Gets local retransmit timeout.
bool getOpen()
Returns whether the RSSI link is in open state.
void stop()
Stops the RSSI connection and worker thread.
void setLocMaxSegment(uint16_t val)
Sets local max segment size.
void setLocMaxRetran(uint8_t val)
Sets local max retransmit count.
uint16_t getLocNullTout()
Gets local null-segment timeout.
void stopQueue()
Stops internal queues used by controller worker paths.
void setLocMaxCumAck(uint8_t val)
Sets local max cumulative ACK interval.
uint8_t curMaxRetran()
Gets negotiated max retransmit count.
std::shared_ptr< rogue::interfaces::stream::Frame > applicationTx()
Gets next frame to transmit from the application side.
void setLocMaxBuffers(uint8_t val)
Sets local max outstanding buffers parameter.
void setTimeout(uint32_t timeout)
Sets timeout in microseconds for frame transmits.
uint32_t getDropCount()
Returns dropped-frame counter.
uint32_t getRetranCount()
Returns retransmit counter.
~Controller()
Destroys the controller and stops background processing.
uint32_t getLocBusyCnt()
Returns local busy event counter.
uint8_t getLocMaxRetran()
Gets local max retransmit count.
void start()
Starts or restarts RSSI connection establishment.
static std::shared_ptr< rogue::protocols::rssi::Controller > create(uint32_t segSize, std::shared_ptr< rogue::protocols::rssi::Transport > tran, std::shared_ptr< rogue::protocols::rssi::Application > app, bool server)
Factory method to create an RSSI controller.
uint16_t curRetranTout()
Gets negotiated retransmit timeout.
uint32_t getRemBusyCnt()
Returns remote busy event counter.
bool getRemBusy()
Returns remote busy state.
bool getLocBusy()
Returns local busy state.
uint16_t getLocCumAckTout()
Gets local cumulative ACK timeout.
uint16_t getLocMaxSegment()
Gets local max segment size.
void transportRx(std::shared_ptr< rogue::interfaces::stream::Frame > frame)
Processes a frame received from transport.
void resetCounters()
Resets runtime counters.
std::shared_ptr< rogue::protocols::rssi::Controller > ControllerPtr
Definition Controller.h:452