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#include <vector>
27
29#include "rogue/Logging.h"
30#include "rogue/Queue.h"
33
34namespace rogue {
35namespace protocols {
36namespace rssi {
37
38class Application;
39class Transport;
40class Header;
41
65class Controller : public rogue::EnableSharedFromThis<rogue::protocols::rssi::Controller> {
66 // Hard coded values
67 static const uint8_t Version = 1;
68 static const uint8_t TimeoutUnit = 3; // rssiTime * std::pow(10,-TimeoutUnit) = 3 = ms
69
70 // Local parameters
71 uint32_t locTryPeriod_;
72
73 // Configurable parameters, requested by software
74 uint8_t locMaxBuffers_;
75 uint16_t locMaxSegment_;
76 uint16_t locCumAckTout_;
77 uint16_t locRetranTout_;
78 uint16_t locNullTout_;
79 uint8_t locMaxRetran_;
80 uint8_t locMaxCumAck_;
81
82 // Negotiated parameters
83 uint8_t curMaxBuffers_;
84 uint16_t curMaxSegment_;
85 uint16_t curCumAckTout_;
86 uint16_t curRetranTout_;
87 uint16_t curNullTout_;
88 uint8_t curMaxRetran_;
89 uint8_t curMaxCumAck_;
90
91 // Connection states
92 enum States : uint32_t { StClosed = 0, StWaitSyn = 1, StSendSynAck = 2, StSendSeqAck = 3, StOpen = 4, StError = 5 };
93
94 // Interfaces
95 std::shared_ptr<rogue::protocols::rssi::Transport> tran_;
96 std::shared_ptr<rogue::protocols::rssi::Application> app_;
97
98 std::shared_ptr<rogue::Logging> log_;
99
100 // Is server
101 bool server_;
102
103 // Receive tracking
104 std::atomic<uint32_t> dropCount_;
105 uint8_t nextSeqRx_;
106 uint8_t lastAckRx_;
107 std::atomic<bool> remBusy_;
108 std::atomic<bool> locBusy_;
109
110 // Application queue
112
113 // Sequence Out of Order ("OOO") queue
114 std::map<uint8_t, std::shared_ptr<rogue::protocols::rssi::Header>> oooQueue_;
115
116 // State queue
118
119 // Application tracking
120 uint8_t lastSeqRx_;
121 uint8_t ackSeqRx_;
122
123 // State Tracking
124 std::condition_variable stCond_;
125 std::mutex stMtx_;
126 uint32_t state_;
127 struct timeval stTime_;
128 std::atomic<uint32_t> downCount_;
129 std::atomic<uint32_t> retranCount_;
130 std::atomic<uint32_t> locBusyCnt_;
131 std::atomic<uint32_t> remBusyCnt_;
132 uint32_t locConnId_;
133 uint32_t remConnId_;
134
135 // Transmit tracking
136 std::shared_ptr<rogue::protocols::rssi::Header> txList_[256];
137 std::mutex txMtx_;
138 uint8_t txListCount_;
139 uint8_t lastAckTx_;
140 uint8_t locSequence_;
141 struct timeval txTime_;
142
143 // Time values
144 struct timeval retranToutD1_; // retranTout_ / 1
145 struct timeval tryPeriodD1_; // TryPeriod / 1
146 struct timeval tryPeriodD4_; // TryPeriod / 4
147 struct timeval cumAckToutD1_; // cumAckTout_ / 1
148 struct timeval cumAckToutD2_; // cumAckTout_ / 2
149 struct timeval nullToutD3_; // nullTout_ / 3
150 struct timeval zeroTme_; // 0
151
153 protected:
154 std::thread* thread_ = nullptr;
155 std::atomic<bool> threadEn_{false};
157
158 private:
159 // Application frame transmit timeout
160 struct timeval timeout_;
161
162 public:
179 static std::shared_ptr<rogue::protocols::rssi::Controller> create(
180 uint32_t segSize,
181 std::shared_ptr<rogue::protocols::rssi::Transport> tran,
182 std::shared_ptr<rogue::protocols::rssi::Application> app,
183 bool server);
184
197 Controller(uint32_t segSize,
198 std::shared_ptr<rogue::protocols::rssi::Transport> tran,
199 std::shared_ptr<rogue::protocols::rssi::Application> app,
200 bool server);
201
203 ~Controller();
204
206 void stopQueue();
207
213 std::shared_ptr<rogue::interfaces::stream::Frame> reqFrame(uint32_t size);
214
219 void transportRx(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
220
225 std::shared_ptr<rogue::interfaces::stream::Frame> applicationTx();
226
231 void applicationRx(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
232
237 bool getOpen();
238
243 uint32_t getDownCount();
244
249 uint32_t getDropCount();
250
255 uint32_t getRetranCount();
256
261 bool getLocBusy();
262
267 uint32_t getLocBusyCnt();
268
273 bool getRemBusy();
274
279 uint32_t getRemBusyCnt();
280
285 void setLocTryPeriod(uint32_t val);
290 uint32_t getLocTryPeriod();
291
296 void setLocMaxBuffers(uint8_t val);
301 uint8_t getLocMaxBuffers();
302
307 void setLocMaxSegment(uint16_t val);
312 uint16_t getLocMaxSegment();
313
318 void setLocCumAckTout(uint16_t val);
323 uint16_t getLocCumAckTout();
324
329 void setLocRetranTout(uint16_t val);
334 uint16_t getLocRetranTout();
335
340 void setLocNullTout(uint16_t val);
345 uint16_t getLocNullTout();
346
351 void setLocMaxRetran(uint8_t val);
356 uint8_t getLocMaxRetran();
357
362 void setLocMaxCumAck(uint8_t val);
367 uint8_t getLocMaxCumAck();
368
373 uint8_t curMaxBuffers();
378 uint16_t curMaxSegment();
383 uint16_t curCumAckTout();
388 uint16_t curRetranTout();
393 uint16_t curNullTout();
398 uint8_t curMaxRetran();
403 uint8_t curMaxCumAck();
404
406 void resetCounters();
407
412 void setTimeout(uint32_t timeout);
413
415 void stop();
416
418 void start();
419
420 private:
421 // Release retransmit headers, taking the GIL when Python is running.
422 // Must be called with txMtx_ released.
423 void releaseHeaders(std::vector<std::shared_ptr<rogue::protocols::rssi::Header> >& heads);
424
425 // Method to transit a frame with proper updates
426 void transportTx(std::shared_ptr<rogue::protocols::rssi::Header> head, bool seqUpdate, bool txReset);
427
428 // Method to retransmit a frame
429 int8_t retransmit(uint8_t id);
430
432 static void convTime(struct timeval& tme, uint32_t rssiTime);
433
435 static bool timePassed(struct timeval& lastTime, struct timeval& tme);
436
438 void runThread();
439
441 struct timeval& stateClosedWait();
442
444 struct timeval& stateSendSynAck();
445
447 struct timeval& stateSendSeqAck();
448
450 struct timeval& stateOpen();
451
453 struct timeval& stateError();
454};
455
456// Convenience
457typedef std::shared_ptr<rogue::protocols::rssi::Controller> ControllerPtr;
458
459} // namespace rssi
460} // namespace protocols
461}; // namespace rogue
462
463#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:36
RSSI protocol controller.
Definition Controller.h:65
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:457