cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
state_table.cpp
Go to the documentation of this file.
1 
17 
43 
56 #include "state_table.hpp"
57 
58 using namespace hls;
59 
60 
64 #ifndef __SYNTHESIS__
65  extern bool gTraceEvent;
66 #endif
67 
68 #define THIS_NAME "TOE/STt"
69 
70 #define TRACE_OFF 0x0000
71 #define TRACE_STT 1 << 1
72 #define TRACE_ALL 0xFFFF
73 
74 #define DEBUG_LEVEL (TRACE_OFF)
75 
76 
77 
100  stream<StateQuery> &siRXe_SessStateQry,
101  stream<TcpState> &soRXe_SessStateRep,
102  stream<StateQuery> &siTAi_ConnectStateQry,
103  stream<TcpState> &soTAi_ConnectStateRep,
104  stream<SessionId> &siTAi_StreamStateReq,
105  stream<TcpState> &soTAi_StreamStateRep,
106  stream<SessionId> &siTIm_SessCloseCmd,
107  stream<SessionId> &soSLc_SessReleaseCmd)
108 {
109  //-- DIRECTIVES FOR THIS PROCESS -------------------------------------------
110  #pragma HLS PIPELINE II=1 enable_flush
111  #pragma HLS INLINE off
112 
113  //-- STATIC ARRAYS ---------------------------------------------------------
114  static TcpState SESS_STATE_TABLE[TOE_MAX_SESSIONS];
115  #pragma HLS RESOURCE variable=SESS_STATE_TABLE core=RAM_2P_BRAM
116  #pragma HLS DEPENDENCE variable=SESS_STATE_TABLE inter false
117 
118  //-- STATIC CONTROL VARIABLES (with RESET) ---------------------------------
119  static bool stt_rxWait=false;
120  #pragma HLS RESET variable=stt_rxWait
121  static bool stt_txWait=false;
122  #pragma HLS RESET variable=stt_txWait
123  static bool stt_rxSessionLocked=false;
124  #pragma HLS RESET variable=stt_rxSessionLocked
125  static bool stt_txSessionLocked=false;
126  #pragma HLS RESET variable=stt_txSessionLocked
127  static bool stt_closeWait=false;
128  #pragma HLS RESET variable=stt_closeWait
129 
130  //-- STATIC DATAFLOW VARIABLES ---------------------------------------------
131  static StateQuery stt_txAccess;
132  static StateQuery stt_rxAccess;
133  static SessionId stt_txSessionID;
134  static SessionId stt_rxSessionID;
135  static SessionId stt_closeSessionID;
136 
137  if(!siTAi_ConnectStateQry.empty() && !stt_txWait) {
138  //-------------------------------------------------
139  //-- Request from TAi/Connect
140  //-------------------------------------------------
141  siTAi_ConnectStateQry.read(stt_txAccess);
142  if ((stt_txAccess.sessionID == stt_rxSessionID) && stt_rxSessionLocked) {
143  stt_txWait = true;
144  }
145  else {
146  if (stt_txAccess.write) {
147  SESS_STATE_TABLE[stt_txAccess.sessionID] = stt_txAccess.state;
148  stt_txSessionLocked = false;
149  if (DEBUG_LEVEL & TRACE_STT) {
150  printInfo(THIS_NAME, "TAi is requesting to set SESS_STATE_TABLE[%d] = %s.\n", \
151  stt_txAccess.sessionID.to_uint(), \
152  getTcpStateName(stt_txAccess.state));
153  }
154  }
155  else {
156  soTAi_ConnectStateRep.write(SESS_STATE_TABLE[stt_txAccess.sessionID]);
157  // Lock on every read
158  stt_txSessionID = stt_txAccess.sessionID;
159  stt_txSessionLocked = true;
160  }
161  }
162  }
163  else if (!siTAi_StreamStateReq.empty()) {
164  //-------------------------------------------------
165  //-- Request from TAi/Stream
166  //-------------------------------------------------
167  SessionId sessionID;
168  siTAi_StreamStateReq.read(sessionID);
169  soTAi_StreamStateRep.write(SESS_STATE_TABLE[sessionID]);
170  }
171  else if(!siRXe_SessStateQry.empty() && !stt_rxWait) {
172  //-------------------------------------------------
173  //-- Request from RxEngine
174  //-------------------------------------------------
175  siRXe_SessStateQry.read(stt_rxAccess);
176  if ((stt_rxAccess.sessionID == stt_txSessionID) && stt_txSessionLocked) {
177  stt_rxWait = true;
178  }
179  else {
180  if (stt_rxAccess.write) {
181  if (stt_rxAccess.state == CLOSED) {
182  // [TODO] Do we need to check if already closed?
183  // [TODO] && state_table[stt_rxAccess.sessionID] != CLOSED)
184  soSLc_SessReleaseCmd.write(stt_rxAccess.sessionID);
185  }
186  SESS_STATE_TABLE[stt_rxAccess.sessionID] = stt_rxAccess.state;
187  stt_rxSessionLocked = false;
188  if (DEBUG_LEVEL & TRACE_STT) {
189  printInfo(THIS_NAME, "RXe is requesting to set SESS_STATE_TABLE[%d] = %s.\n", \
190  stt_rxAccess.sessionID.to_uint(), \
191  getTcpStateName(stt_rxAccess.state));
192  }
193  }
194  else {
195  soRXe_SessStateRep.write(SESS_STATE_TABLE[stt_rxAccess.sessionID]);
196  stt_rxSessionID = stt_rxAccess.sessionID;
197  stt_rxSessionLocked = true;
198  }
199  }
200  }
201  else if (!siTIm_SessCloseCmd.empty() && !stt_closeWait) {
202  //-------------------------------------------------
203  //-- Request to close connection from Timers
204  //-------------------------------------------------
205  siTIm_SessCloseCmd.read(stt_closeSessionID);
206  if (((stt_closeSessionID == stt_rxSessionID) && stt_rxSessionLocked) || \
207  ((stt_closeSessionID == stt_txSessionID) && stt_txSessionLocked)) {
208  // The session is currently locked
209  stt_closeWait = true;
210  }
211  else {
212  SESS_STATE_TABLE[stt_closeSessionID] = CLOSED;
213  soSLc_SessReleaseCmd.write(stt_closeSessionID);
214  if (DEBUG_LEVEL & TRACE_STT) {
215  printWarn(THIS_NAME, "TIm is requesting to close connection with SessId=%d.\n",
216  stt_closeSessionID.to_uint());
217  }
218  }
219  }
220  else if (stt_txWait) {
221  //-------------------------------------------------
222  //-- Tx Wait
223  //-------------------------------------------------
224  if ((stt_txAccess.sessionID != stt_rxSessionID) || !stt_rxSessionLocked) {
225  if (stt_txAccess.write) {
226  SESS_STATE_TABLE[stt_txAccess.sessionID] = stt_txAccess.state;
227  stt_txSessionLocked = false;
228  }
229  else {
230  soTAi_ConnectStateRep.write(SESS_STATE_TABLE[stt_txAccess.sessionID]);
231  stt_txSessionID = stt_txAccess.sessionID;
232  stt_txSessionLocked = true;
233  }
234  stt_txWait = false;
235  }
236  }
237  else if (stt_rxWait) {
238  //-------------------------------------------------
239  //-- Rx Wait
240  //-------------------------------------------------
241  if ((stt_rxAccess.sessionID != stt_txSessionID) || !stt_txSessionLocked) {
242  if (stt_rxAccess.write) {
243  if (stt_rxAccess.state == CLOSED) {
244  soSLc_SessReleaseCmd.write(stt_rxAccess.sessionID);
245  }
246  SESS_STATE_TABLE[stt_rxAccess.sessionID] = stt_rxAccess.state;
247  stt_rxSessionLocked = false;
248  }
249  else {
250  soRXe_SessStateRep.write(SESS_STATE_TABLE[stt_rxAccess.sessionID]);
251  stt_rxSessionID = stt_rxAccess.sessionID;
252  stt_rxSessionLocked = true;
253  }
254  stt_rxWait = false;
255  }
256  }
257  else if (stt_closeWait) {
258  //-------------------------------------------------
259  //-- Close Wait
260  //-------------------------------------------------
261  if (((stt_closeSessionID != stt_rxSessionID) || !stt_rxSessionLocked) && \
262  ((stt_closeSessionID != stt_txSessionID) || !stt_txSessionLocked)) {
263  SESS_STATE_TABLE[stt_closeSessionID] = CLOSED;
264  soSLc_SessReleaseCmd.write(stt_closeSessionID);
265  stt_closeWait = false;
266  }
267  }
268 }
269 
RdWrBit write
Definition: toe.hpp:352
TcpState state
Definition: toe.hpp:351
SessionId sessionID
Definition: toe.hpp:350
#define TRACE_STT
Definition: state_table.cpp:71
void state_table(stream< StateQuery > &siRXe_SessStateQry, stream< TcpState > &soRXe_SessStateRep, stream< StateQuery > &siTAi_ConnectStateQry, stream< TcpState > &soTAi_ConnectStateRep, stream< SessionId > &siTAi_StreamStateReq, stream< TcpState > &soTAi_StreamStateRep, stream< SessionId > &siTIm_SessCloseCmd, stream< SessionId > &soSLc_SessReleaseCmd)
State Table (STt)
Definition: state_table.cpp:99
bool gTraceEvent
Definition: tb_nal.cpp:151
#define THIS_NAME
Definition: state_table.cpp:68
#define DEBUG_LEVEL
Definition: state_table.cpp:74
ap_uint< 16 > SessionId
Definition: nts_types.hpp:136
TcpState
Definition: nts_types.hpp:296
const char * getTcpStateName(TcpState tcpState)
Returns the name of an enum-based TCP-State as a user friendly string.
Definition: nts_utils.cpp:272
#define printInfo(callerName, format,...)
A macro to print an information message.
Definition: nts_utils.hpp:169
#define printWarn(callerName, format,...)
A macro to print a warning message.
Definition: nts_utils.hpp:182
@ CLOSED
Definition: nts_types.hpp:296
: State Table (STt) for the TCP Offload Engine (TOE)