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 <map>
24#include <memory>
25
27#include "rogue/Logging.h"
28#include "rogue/Queue.h"
31
32namespace rogue {
33namespace protocols {
34namespace rssi {
35
36class Application;
37class Transport;
38class Header;
39
63class Controller : public rogue::EnableSharedFromThis<rogue::protocols::rssi::Controller> {
64 // Hard coded values
65 static const uint8_t Version = 1;
66 static const uint8_t TimeoutUnit = 3; // rssiTime * std::pow(10,-TimeoutUnit) = 3 = ms
67
68 // Local parameters
69 uint32_t locTryPeriod_;
70
71 // Configurable parameters, requested by software
72 uint8_t locMaxBuffers_;
73 uint16_t locMaxSegment_;
74 uint16_t locCumAckTout_;
75 uint16_t locRetranTout_;
76 uint16_t locNullTout_;
77 uint8_t locMaxRetran_;
78 uint8_t locMaxCumAck_;
79
80 // Negotiated parameters
81 uint8_t curMaxBuffers_;
82 uint16_t curMaxSegment_;
83 uint16_t curCumAckTout_;
84 uint16_t curRetranTout_;
85 uint16_t curNullTout_;
86 uint8_t curMaxRetran_;
87 uint8_t curMaxCumAck_;
88
89 // Connection states
90 enum States : uint32_t { StClosed = 0, StWaitSyn = 1, StSendSynAck = 2, StSendSeqAck = 3, StOpen = 4, StError = 5 };
91
92 // Interfaces
93 std::shared_ptr<rogue::protocols::rssi::Transport> tran_;
94 std::shared_ptr<rogue::protocols::rssi::Application> app_;
95
96 std::shared_ptr<rogue::Logging> log_;
97
98 // Is server
99 bool server_;
100
101 // Receive tracking
102 uint32_t dropCount_;
103 uint8_t nextSeqRx_;
104 uint8_t lastAckRx_;
105 bool remBusy_;
106 bool locBusy_;
107
108 // Application queue
110
111 // Sequence Out of Order ("OOO") queue
112 std::map<uint8_t, std::shared_ptr<rogue::protocols::rssi::Header>> oooQueue_;
113
114 // State queue
116
117 // Application tracking
118 uint8_t lastSeqRx_;
119 uint8_t ackSeqRx_;
120
121 // State Tracking
122 std::condition_variable stCond_;
123 std::mutex stMtx_;
124 uint32_t state_;
125 struct timeval stTime_;
126 uint32_t downCount_;
127 uint32_t retranCount_;
128 uint32_t locBusyCnt_;
129 uint32_t remBusyCnt_;
130 uint32_t locConnId_;
131 uint32_t remConnId_;
132
133 // Transmit tracking
134 std::shared_ptr<rogue::protocols::rssi::Header> txList_[256];
135 std::mutex txMtx_;
136 uint8_t txListCount_;
137 uint8_t lastAckTx_;
138 uint8_t locSequence_;
139 struct timeval txTime_;
140
141 // Time values
142 struct timeval retranToutD1_; // retranTout_ / 1
143 struct timeval tryPeriodD1_; // TryPeriod / 1
144 struct timeval tryPeriodD4_; // TryPeriod / 4
145 struct timeval cumAckToutD1_; // cumAckTout_ / 1
146 struct timeval cumAckToutD2_; // cumAckTout_ / 2
147 struct timeval nullToutD3_; // nullTout_ / 3
148 struct timeval zeroTme_; // 0
149
150 // State thread
151 std::thread* thread_;
152 bool threadEn_;
153
154 // Application frame transmit timeout
155 struct timeval timeout_;
156
157 public:
174 static std::shared_ptr<rogue::protocols::rssi::Controller> create(
175 uint32_t segSize,
176 std::shared_ptr<rogue::protocols::rssi::Transport> tran,
177 std::shared_ptr<rogue::protocols::rssi::Application> app,
178 bool server);
179
192 Controller(uint32_t segSize,
193 std::shared_ptr<rogue::protocols::rssi::Transport> tran,
194 std::shared_ptr<rogue::protocols::rssi::Application> app,
195 bool server);
196
198 ~Controller();
199
201 void stopQueue();
202
208 std::shared_ptr<rogue::interfaces::stream::Frame> reqFrame(uint32_t size);
209
214 void transportRx(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
215
220 std::shared_ptr<rogue::interfaces::stream::Frame> applicationTx();
221
226 void applicationRx(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
227
232 bool getOpen();
233
238 uint32_t getDownCount();
239
244 uint32_t getDropCount();
245
250 uint32_t getRetranCount();
251
256 bool getLocBusy();
257
262 uint32_t getLocBusyCnt();
263
268 bool getRemBusy();
269
274 uint32_t getRemBusyCnt();
275
280 void setLocTryPeriod(uint32_t val);
285 uint32_t getLocTryPeriod();
286
291 void setLocMaxBuffers(uint8_t val);
296 uint8_t getLocMaxBuffers();
297
302 void setLocMaxSegment(uint16_t val);
307 uint16_t getLocMaxSegment();
308
313 void setLocCumAckTout(uint16_t val);
318 uint16_t getLocCumAckTout();
319
324 void setLocRetranTout(uint16_t val);
329 uint16_t getLocRetranTout();
330
335 void setLocNullTout(uint16_t val);
340 uint16_t getLocNullTout();
341
346 void setLocMaxRetran(uint8_t val);
351 uint8_t getLocMaxRetran();
352
357 void setLocMaxCumAck(uint8_t val);
362 uint8_t getLocMaxCumAck();
363
368 uint8_t curMaxBuffers();
373 uint16_t curMaxSegment();
378 uint16_t curCumAckTout();
383 uint16_t curRetranTout();
388 uint16_t curNullTout();
393 uint8_t curMaxRetran();
398 uint8_t curMaxCumAck();
399
401 void resetCounters();
402
407 void setTimeout(uint32_t timeout);
408
410 void stop();
411
413 void start();
414
415 private:
416 // Method to transit a frame with proper updates
417 void transportTx(std::shared_ptr<rogue::protocols::rssi::Header> head, bool seqUpdate, bool txReset);
418
419 // Method to retransmit a frame
420 int8_t retransmit(uint8_t id);
421
423 static void convTime(struct timeval& tme, uint32_t rssiTime);
424
426 static bool timePassed(struct timeval& lastTime, struct timeval& tme);
427
429 void runThread();
430
432 struct timeval& stateClosedWait();
433
435 struct timeval& stateSendSynAck();
436
438 struct timeval& stateSendSeqAck();
439
441 struct timeval& stateOpen();
442
444 struct timeval& stateError();
445};
446
447// Convenience
448typedef std::shared_ptr<rogue::protocols::rssi::Controller> ControllerPtr;
449
450} // namespace rssi
451} // namespace protocols
452}; // namespace rogue
453
454#endif
Typed shared-from-this helper for Rogue classes.
Thread-safe bounded queue with optional busy threshold.
Definition Queue.h:38
Rogue version query and comparison helpers.
Definition Version.h:35
RSSI protocol controller.
Definition Controller.h:63
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:448