cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
session_lookup_controller.cpp
Go to the documentation of this file.
1 
17 
43 
57 
58 using namespace hls;
59 
60 
64 #ifndef __SYNTHESIS__
65  extern bool gTraceEvent;
66 #endif
67 
68 #define THIS_NAME "TOE/SLc"
69 
70 #define TRACE_OFF 0x0000
71 #define TRACE_LRH 1 << 1
72 #define TRACE_RLT 1 << 2
73 #define TRACE_SIM 1 << 3
74 #define TRACE_URH 1 << 4
75 #define TRACE_URS 1 << 5
76 
77 #define DEBUG_LEVEL (TRACE_OFF)
78 
79 
80 
90  stream<RtlSessId> &siUrs_FreeId,
91  stream<RtlSessId> &soLrh_FreeList)
92 {
93  //-- DIRECTIVES FOR THIS PROCESS -------------------------------------------
94  #pragma HLS PIPELINE II=1 enable_flush
95  #pragma HLS INLINE off
96 
97  const char *myName = concat3(THIS_NAME, "/", "Sim");
98 
99  //-- STATIC CONTROL VARIABLES (with RESET) ---------------------------------
100  static RtlSessId sim_counter=0;
101  #pragma HLS reset variable=sim_counter
102 
103  if (sim_counter < TOE_MAX_SESSIONS) {
104  // Initialize the free list after a reset
105  soLrh_FreeList.write(sim_counter);
106  sim_counter++;
107  }
108  else if (!siUrs_FreeId.empty()) {
109  // Recycle the incoming session ID
110  RtlSessId rtlSessId;
111  siUrs_FreeId.read(rtlSessId);
112  soLrh_FreeList.write(rtlSessId);
113  }
114 }
115 
116 
141  stream<CamSessionLookupRequest> &soCAM_SessLookupReq,
142  stream<CamSessionLookupReply> &siCAM_SessLookupRep,
143  stream<CamSessionUpdateReply> &siUrh_SessUpdateRsp,
144  stream<SessionLookupQuery> &siRXe_SessLookupReq,
145  stream<SessionLookupReply> &soRXe_SessLookupRep,
146  stream<SocketPair> &siTAi_SessLookupReq,
147  stream<SessionLookupReply> &soTAi_SessLookupRep,
148  stream<RtlSessId> &siSim_FreeList,
149  stream<CamSessionUpdateRequest> &soUrs_InsertSessReq,
150  stream<SLcReverseLkp> &soRlt_ReverseLkpRsp)
151 {
152  //-- DIRECTIVES FOR THIS PROCESS -------------------------------------------
153  #pragma HLS PIPELINE II=1 enable_flush
154  #pragma HLS INLINE off
155 
156  const char *myName = concat3(THIS_NAME, "/", "Lrh");
157 
158  //-- LOCAL STREAMS --------------------------------------------------------
159  static stream<SLcFourTuple> ssInsertPipe ("ssInsertPipe");
160  #pragma HLS STREAM variable=ssInsertPipe depth=4
161 
162  static stream<SLcQuery> ssLookupPipe ("ssLookupPipe");
163  #pragma HLS STREAM variable=ssLookupPipe depth=8
164 
165  //-- STATIC CONTROL VARIABLES (with RESET) ---------------------------------
166  static enum FsmStates { WAIT_FOR_SESS_LKP_REQ=0, WAIT_FOR_CAM_LKP_REP, WAIT_FOR_CAM_UPD_REP } \
167  lrh_fsmState=WAIT_FOR_SESS_LKP_REQ;
168  #pragma HLS RESET variable=lrh_fsmState
169 
170  switch (lrh_fsmState) {
171  case WAIT_FOR_SESS_LKP_REQ:
172  if (!siTAi_SessLookupReq.empty()) {
173  SocketPair sockPair = siTAi_SessLookupReq.read();
174  fourTuple toeTuple = fourTuple(byteSwap32(sockPair.src.addr), byteSwap32(sockPair.dst.addr),
175  byteSwap16(sockPair.src.port), byteSwap16(sockPair.dst.port));
176  // Create internal query { myIp, TheirIp, myPort, theirPort}
177  SLcQuery slcQuery = SLcQuery(SLcFourTuple(
178  toeTuple.srcIp, toeTuple.dstIp,
179  toeTuple.srcPort, toeTuple.dstPort), true, FROM_TAi);
180  soCAM_SessLookupReq.write(CamSessionLookupRequest(slcQuery.tuple, slcQuery.source));
181  ssLookupPipe.write(slcQuery);
182  lrh_fsmState = WAIT_FOR_CAM_LKP_REP;
183  }
184  else if (!siRXe_SessLookupReq.empty()) {
185  SessionLookupQuery query = siRXe_SessLookupReq.read();
186  // Create internal query { myIp, TheirIp, myPort, theirPort}
187  SLcQuery slcQuery = SLcQuery(SLcFourTuple(
188  query.tuple.dst.addr, query.tuple.src.addr,
189  query.tuple.dst.port, query.tuple.src.port),
190  query.allowCreation, FROM_RXe);
191  soCAM_SessLookupReq.write(CamSessionLookupRequest(slcQuery.tuple, slcQuery.source));
192  ssLookupPipe.write(slcQuery);
193  lrh_fsmState = WAIT_FOR_CAM_LKP_REP;
194  }
195  break;
196  case WAIT_FOR_CAM_LKP_REP:
197  if(!siCAM_SessLookupRep.empty() && !ssLookupPipe.empty()) {
198  CamSessionLookupReply lupReply = siCAM_SessLookupRep.read();
199  SLcQuery slcQuery = ssLookupPipe.read();
200  if (!lupReply.hit && slcQuery.allowCreation && !siSim_FreeList.empty()) {
201  RtlSessId freeID = siSim_FreeList.read();
202  // Request to insert a new session into the CAM
203  soUrs_InsertSessReq.write(CamSessionUpdateRequest(slcQuery.tuple, freeID, INSERT, lupReply.source));
204  ssInsertPipe.write(slcQuery.tuple);
205  lrh_fsmState = WAIT_FOR_CAM_UPD_REP;
206  }
207  else {
208  // We have a HIT
209  if (lupReply.source == FROM_RXe) {
210  soRXe_SessLookupRep.write(SessionLookupReply(lupReply.sessionID, lupReply.hit));
211  }
212  else {
213  soTAi_SessLookupRep.write(SessionLookupReply(lupReply.sessionID, lupReply.hit));
214  }
215  lrh_fsmState = WAIT_FOR_SESS_LKP_REQ;
216  }
217  }
218  break;
219  case WAIT_FOR_CAM_UPD_REP:
220  if (!siUrh_SessUpdateRsp.empty() && !ssInsertPipe.empty()) {
221  CamSessionUpdateReply insertReply = siUrh_SessUpdateRsp.read();
222  SLcFourTuple tuple = ssInsertPipe.read();
223  if (insertReply.source == FROM_RXe) {
224  soRXe_SessLookupRep.write(SessionLookupReply(insertReply.sessionID, true));
225  }
226  else {
227  soTAi_SessLookupRep.write(SessionLookupReply(insertReply.sessionID, true));
228  }
229  soRlt_ReverseLkpRsp.write(SLcReverseLkp(insertReply.sessionID, tuple));
230  lrh_fsmState = WAIT_FOR_SESS_LKP_REQ;
231  }
232  break;
233  }
234 } // End of: pLookupReplyHandler
235 
236 
254  stream<CamSessionUpdateRequest> &siLrh_InsertSessReq,
255  stream<CamSessionUpdateRequest> &siRlt_SessDeleteReq,
256  stream<CamSessionUpdateRequest> &soCAM_SessUpdateReq,
257  stream<RtlSessId> &soSim_FreeId,
258  stream<ap_uint<16> > &soSssRelCnt,
259  stream<ap_uint<16> > &soSssRegCnt)
260 {
261  //-- DIRECTIVES FOR THIS PROCESS -------------------------------------------
262  #pragma HLS PIPELINE II=1 enable_flush
263  #pragma HLS INLINE off
264 
265  const char *myName = concat3(THIS_NAME, "/", "Urs");
266 
267  //-- STATIC CONTROL VARIABLES (with RESET) ---------------------------------
268  static ap_uint<16> urs_insertedSessions=0;
269  #pragma HLS RESET variable=urs_insertedSessions
270  static ap_uint<16> urs_releasedSessions=0;
271  #pragma HLS RESET variable=urs_releasedSessions
272 
273  if (!siLrh_InsertSessReq.empty()) {
274  soCAM_SessUpdateReq.write(siLrh_InsertSessReq.read());
275  urs_insertedSessions++;
276  }
277  else if (!siRlt_SessDeleteReq.empty()) {
278  CamSessionUpdateRequest request;
279  siRlt_SessDeleteReq.read(request);
280  soCAM_SessUpdateReq.write(request);
281  soSim_FreeId.write(request.value);
282  urs_releasedSessions++;
283  }
284  // Always
285  if (!soSssRegCnt.full()) {
286  soSssRegCnt.write(urs_insertedSessions);
287  }
288  if (!soSssRelCnt.full()) {
289  soSssRelCnt.write(urs_releasedSessions);
290  }
291 }
292 
293 
294 
301  stream<CamSessionUpdateReply> &siCAM_SessUpdateRep,
302  stream<CamSessionUpdateReply> &soLrh_SessUpdateRsp)
303 {
304  //-- DIRECTIVES FOR THIS PROCESS -------------------------------------------
305  #pragma HLS PIPELINE II=1 enable_flush
306  #pragma HLS INLINE off
307 
308  const char *myName = concat3(THIS_NAME, "/", "Urh");
309 
310  if (!siCAM_SessUpdateRep.empty()) {
311  CamSessionUpdateReply upReply;
312  siCAM_SessUpdateRep.read(upReply);
313  if (upReply.op == INSERT)
314  soLrh_SessUpdateRsp.write(upReply);
315  }
316 }
317 
318 
335  stream<SLcReverseLkp> &siLrh_ReverseLkpRsp,
336  stream<SessionId> &siSTt_SessReleaseCmd,
337  stream<SessionId> &siTXe_ReverseLkpReq,
338  stream<fourTuple> &soTXe_ReverseLkpRep,
339  stream<TcpPort> &soPRt_ClosePortCmd,
340  stream<CamSessionUpdateRequest> &soUrs_SessDeleteReq)
341 {
342  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
343  #pragma HLS PIPELINE II=1 enable_flush
344  #pragma HLS INLINE off
345 
346  const char *myName = concat3(THIS_NAME, "/", "Rlt");
347 
348  //-- STATIC ARRAYS --------------------------------------------------------
349  static SLcFourTuple REVERSE_LOOKUP_TABLE[TOE_MAX_SESSIONS];
350  #pragma HLS RESOURCE variable=REVERSE_LOOKUP_TABLE core=RAM_T2P_BRAM
351  #pragma HLS DEPENDENCE variable=REVERSE_LOOKUP_TABLE inter false
352  static ValBool TUPLE_VALID_TABLE[TOE_MAX_SESSIONS];
353  #pragma HLS DEPENDENCE variable=TUPLE_VALID_TABLE inter false
354 
355  //-- STATIC CONTROL VARIABLES (with RESET) --------------------------------
356  static bool rlt_isInit=false;
357  #pragma HLS reset variable=rlt_isInit
358  static RtlSessId rlt_counter=0;
359  #pragma HLS reset variable=rlt_counter
360 
361  if (!rlt_isInit) {
362  // The two tables must be cleared upon reset
363  TUPLE_VALID_TABLE[rlt_counter] = false;
364  if (rlt_counter < TOE_MAX_SESSIONS) {
365  rlt_counter++;
366  }
367  else {
368  rlt_isInit = true;
369  }
370  }
371  else {
372  // Normal operation
373  if (!siLrh_ReverseLkpRsp.empty()) {
374  // Update the two TABLEs
375  SLcReverseLkp insert = siLrh_ReverseLkpRsp.read();
376  REVERSE_LOOKUP_TABLE[insert.key] = insert.value;
377  TUPLE_VALID_TABLE[insert.key] = true;
378  }
379  else if (!siSTt_SessReleaseCmd.empty()) {
380  // Release a session
381  SessionId sessionId = siSTt_SessReleaseCmd.read();
382  SLcFourTuple releaseTuple = REVERSE_LOOKUP_TABLE[sessionId];
383  if (TUPLE_VALID_TABLE[sessionId]) { // if valid
384  soPRt_ClosePortCmd.write(releaseTuple.myPort);
385  soUrs_SessDeleteReq.write(CamSessionUpdateRequest(releaseTuple, sessionId, DELETE, FROM_RXe));
386  }
387  TUPLE_VALID_TABLE[sessionId] = false;
388  }
389  else if (!siTXe_ReverseLkpReq.empty()) {
390  // Return 4-tuple corresponding to a given session Id
391  SessionId sessionId = siTXe_ReverseLkpReq.read();
392  soTXe_ReverseLkpRep.write(fourTuple(
393  REVERSE_LOOKUP_TABLE[sessionId].myIp,
394  REVERSE_LOOKUP_TABLE[sessionId].theirIp,
395  REVERSE_LOOKUP_TABLE[sessionId].myPort,
396  REVERSE_LOOKUP_TABLE[sessionId].theirPort));
397  }
398  }
399 }
400 
401 
431  stream<SessionLookupQuery> &siRXe_SessLookupReq,
432  stream<SessionLookupReply> &soRXe_SessLookupRep,
433  stream<SessionId> &siSTt_SessReleaseCmd,
434  stream<TcpPort> &soPRt_ClosePortCmd,
435  stream<SocketPair> &siTAi_SessLookupReq,
436  stream<SessionLookupReply> &soTAi_SessLookupRep,
437  stream<SessionId> &siTXe_ReverseLkpReq,
438  stream<fourTuple> &soTXe_ReverseLkpRep,
439  stream<CamSessionLookupRequest> &soCAM_SessLookupReq,
440  stream<CamSessionLookupReply> &siCAM_SessLookupRep,
441  stream<CamSessionUpdateRequest> &soCAM_SessUpdateReq,
442  stream<CamSessionUpdateReply> &siCAM_SessUpdateRep,
443  stream<ap_uint<16> > &soSssRelCnt,
444  stream<ap_uint<16> > &soSssRegCnt)
445 {
446  //-- DIRECTIVES FOR THIS PROCESS -------------------------------------------
447  #pragma HLS INLINE
448 
449  //--------------------------------------------------------------------------
450  //-- LOCAL SIGNALS AND STREAMS
451  //-- (Sorted by the name of the modules which generate them)
452  //--------------------------------------------------------------------------
453 
454  // Session Id Manager (Sim) ------------------------------------------------
455  static stream<RtlSessId> ssSimToLrh_FreeList ("ssSimToLrh_FreeList");
456  #pragma HLS stream variable=ssSimToLrh_FreeList depth=16384 // 0x4000 [FIXME - Can we replace 16384 with MAX_SESSIONS]
457 
458  // Lookup Reply Handler (Lrh) ----------------------------------------------
459  static stream<RtlSessId> ssUrsToSim_FreeId ("ssUrsToSim_FreeId");
460  #pragma HLS stream variable=ssUrsToSim_FreeId depth=2
461 
462  static stream<CamSessionUpdateRequest> ssLrhToUrs_InsertSessReq ("ssLrhToUrs_InsertSessReq");
463  #pragma HLS STREAM variable=ssLrhToUrs_InsertSessReq depth=4
464 
465  static stream<SLcReverseLkp> ssLrhToRlt_ReverseLkpRsp ("ssLrhToRlt_ReverseLkpRsp");
466  #pragma HLS STREAM variable=ssLrhToRlt_ReverseLkpRsp depth=4
467 
468  // Update Reply Handler
469  static stream<CamSessionUpdateReply> ssUrhToLrh_SessUpdateRsp ("ssUrhToLrh_SessUpdateRsp");
470  #pragma HLS STREAM variable=ssUrhToLrh_SessUpdateRsp depth=4
471 
472  // Reverse Lookup Table (Rlt) ----------------------------------------------
473  static stream<CamSessionUpdateRequest> ssRltToUrs_SessDeleteReq ("ssRltToUrs_SessDeleteReq");
474  #pragma HLS STREAM variable=ssRltToUrs_SessDeleteReq depth=4
475 
476  //--------------------------------------------------------------------------
477  //-- PROCESS FUNCTIONS
478  //--------------------------------------------------------------------------
479 
481  ssUrsToSim_FreeId,
482  ssSimToLrh_FreeList);
483 
485  soCAM_SessLookupReq,
486  siCAM_SessLookupRep,
487  ssUrhToLrh_SessUpdateRsp,
488  siRXe_SessLookupReq,
489  soRXe_SessLookupRep,
490  siTAi_SessLookupReq,
491  soTAi_SessLookupRep,
492  ssSimToLrh_FreeList,
493  ssLrhToUrs_InsertSessReq,
494  ssLrhToRlt_ReverseLkpRsp);
495 
497  ssLrhToUrs_InsertSessReq,
498  ssRltToUrs_SessDeleteReq,
499  soCAM_SessUpdateReq,
500  ssUrsToSim_FreeId,
501  soSssRelCnt,
502  soSssRegCnt);
503 
505  siCAM_SessUpdateRep,
506  ssUrhToLrh_SessUpdateRsp);
507 
509  ssLrhToRlt_ReverseLkpRsp,
510  siSTt_SessReleaseCmd,
511  siTXe_ReverseLkpReq,
512  soTXe_ReverseLkpRep,
513  soPRt_ClosePortCmd,
514  ssRltToUrs_SessDeleteReq);
515 }
516 
LE_TcpPort myPort
Definition: nts_types.hpp:397
LE_Ip4Address addr
Definition: nts_types.hpp:222
LE_Ly4Port port
Definition: nts_types.hpp:223
LE_SockAddr dst
Definition: nts_types.hpp:263
LE_SockAddr src
Definition: nts_types.hpp:262
bool allowCreation
Definition: toe.hpp:323
LE_SocketPair tuple
Definition: toe.hpp:322
Ip4Addr addr
Definition: nts_types.hpp:209
Ly4Port port
Definition: nts_types.hpp:210
SockAddr dst
Definition: nts_types.hpp:249
SockAddr src
Definition: nts_types.hpp:248
AppMeta sessionId
Definition: tb_nal.cpp:827
void session_lookup_controller(stream< SessionLookupQuery > &siRXe_SessLookupReq, stream< SessionLookupReply > &soRXe_SessLookupRep, stream< SessionId > &siSTt_SessReleaseCmd, stream< TcpPort > &soPRt_ClosePortCmd, stream< SocketPair > &siTAi_SessLookupReq, stream< SessionLookupReply > &soTAi_SessLookupRep, stream< SessionId > &siTXe_ReverseLkpReq, stream< fourTuple > &soTXe_ReverseLkpRep, stream< CamSessionLookupRequest > &soCAM_SessLookupReq, stream< CamSessionLookupReply > &siCAM_SessLookupRep, stream< CamSessionUpdateRequest > &soCAM_SessUpdateReq, stream< CamSessionUpdateReply > &siCAM_SessUpdateRep, stream< ap_uint< 16 > > &soSssRelCnt, stream< ap_uint< 16 > > &soSssRegCnt)
Session Lookup Controller (SLc)
void pReverseLookupTable(stream< SLcReverseLkp > &siLrh_ReverseLkpRsp, stream< SessionId > &siSTt_SessReleaseCmd, stream< SessionId > &siTXe_ReverseLkpReq, stream< fourTuple > &soTXe_ReverseLkpRep, stream< TcpPort > &soPRt_ClosePortCmd, stream< CamSessionUpdateRequest > &soUrs_SessDeleteReq)
Reverse Lookup Table (Rlt)
void pSessionIdManager(stream< RtlSessId > &siUrs_FreeId, stream< RtlSessId > &soLrh_FreeList)
Session Id Manager (Sim)
void pLookupReplyHandler(stream< CamSessionLookupRequest > &soCAM_SessLookupReq, stream< CamSessionLookupReply > &siCAM_SessLookupRep, stream< CamSessionUpdateReply > &siUrh_SessUpdateRsp, stream< SessionLookupQuery > &siRXe_SessLookupReq, stream< SessionLookupReply > &soRXe_SessLookupRep, stream< SocketPair > &siTAi_SessLookupReq, stream< SessionLookupReply > &soTAi_SessLookupRep, stream< RtlSessId > &siSim_FreeList, stream< CamSessionUpdateRequest > &soUrs_InsertSessReq, stream< SLcReverseLkp > &soRlt_ReverseLkpRsp)
Lookup Reply Handler (Lrh)
bool gTraceEvent
Definition: tb_nal.cpp:151
#define THIS_NAME
void pUpdateReplyHandler(stream< CamSessionUpdateReply > &siCAM_SessUpdateRep, stream< CamSessionUpdateReply > &soLrh_SessUpdateRsp)
Update Reply Handler (Urh)
void pUpdateRequestSender(stream< CamSessionUpdateRequest > &siLrh_InsertSessReq, stream< CamSessionUpdateRequest > &siRlt_SessDeleteReq, stream< CamSessionUpdateRequest > &soCAM_SessUpdateReq, stream< RtlSessId > &soSim_FreeId, stream< ap_uint< 16 > > &soSssRelCnt, stream< ap_uint< 16 > > &soSssRegCnt)
Update Request Sender (Urs)
FourTuple SLcFourTuple
ap_uint< 16 > SessionId
Definition: nts_types.hpp:136
#define FROM_TAi
Definition: nts_types.hpp:381
bool ValBool
Definition: nts_types.hpp:131
#define FROM_RXe
Definition: nts_types.hpp:380
#define concat3(firstCharConst, secondCharConst, thirdCharConst)
Definition: nts_utils.hpp:161
ap_uint< 14 > RtlSessId
Definition: nts_types.hpp:378
@ DELETE
Definition: nts_types.hpp:382
@ INSERT
Definition: nts_types.hpp:382
ap_uint< 32 > dstIp
Definition: nts_types.hpp:231
ap_uint< 32 > srcIp
Definition: nts_types.hpp:230
ap_uint< 16 > dstPort
Definition: nts_types.hpp:233
ap_uint< 16 > srcPort
Definition: nts_types.hpp:232
ap_uint< 32 > byteSwap32(ap_uint< 32 > inputVector)
Definition: udp.cpp:78
ap_uint< 16 > byteSwap16(ap_uint< 16 > inputVector)
Definition: udp.cpp:82