cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
tss.cpp
Go to the documentation of this file.
1 
17 
30 #include "tss.hpp"
31 #include "nal.hpp"
32 
33 using namespace hls;
34 
35 
36 
53 void pTcpLsn(
54  stream<TcpAppLsnReq> &soTOE_LsnReq,
55  stream<TcpAppLsnRep> &siTOE_LsnRep,
56  stream<TcpPort> &sTcpPortsToOpen,
57  stream<bool> &sTcpPortsOpenFeedback
58  )
59 {
60  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
61 #pragma HLS INLINE off
62 #pragma HLS pipeline II=1
63 
64  char* myName = concat3(THIS_NAME, "/", "Tcp_LSn");
65 
66  //-- STATIC CONTROL VARIABLES (with RESET) --------------------------------
67  static LsnFsmStates lsnFsmState = LSN_IDLE;
68 #ifdef __SYNTHESIS_
69  static ap_uint<16> startupDelay = 0x8000;
70 #else
71  static ap_uint<16> startupDelay = 5;
72 #endif
73 
74 #pragma HLS RESET variable=lsnFsmState
75 #pragma HLS RESET variable=startupDelay
76  //-- STATIC DATAFLOW VARIABLES --------------------------------------------
77  static ap_uint<8> watchDogTimer_plisten = 0;
78  ap_uint<16> new_absolute_port = 0;
79 
80 
81  switch (lsnFsmState) {
82 
83  default:
84  case LSN_IDLE:
85  if (startupDelay > 0)
86  {
87  startupDelay--;
88  } else {
89  lsnFsmState = LSN_SEND_REQ;
90  }
91  break;
92 
93  case LSN_SEND_REQ: //we arrive here only if need_tcp_port_req == true
94  if (!soTOE_LsnReq.full() && !sTcpPortsToOpen.empty())
95  {
96  new_absolute_port = sTcpPortsToOpen.read();
97  TcpAppLsnReq tcpListenPort = new_absolute_port;
98  soTOE_LsnReq.write(tcpListenPort);
99  if (DEBUG_LEVEL & TRACE_LSN) {
100  printInfo(myName, "Server is requested to listen on port #%d (0x%4.4X).\n",
101  (int) new_absolute_port, (int) new_absolute_port);
102 #ifndef __SYNTHESIS__
103  watchDogTimer_plisten = 10;
104 #else
105  watchDogTimer_plisten = 100;
106 #endif
107  lsnFsmState = LSN_WAIT_ACK;
108  }
109  }
110  //else {
111  // printWarn(myName, "Cannot send a listen port request to [TOE] because stream is full!\n");
112  //}
113  break;
114 
115  case LSN_WAIT_ACK:
116  if (!siTOE_LsnRep.empty() && !sTcpPortsOpenFeedback.full())
117  {
118  bool listenDone;
119  siTOE_LsnRep.read(listenDone);
120  if (listenDone) {
121  printInfo(myName, "Received listen acknowledgment from [TOE].\n");
122  lsnFsmState = LSN_SEND_REQ;
123  sTcpPortsOpenFeedback.write(true);
124  }
125  else {
126  printWarn(myName, "TOE denied listening on port %d (0x%4.4X).\n",
127  (int) new_absolute_port, (int) new_absolute_port);
128  sTcpPortsOpenFeedback.write(false);
129  lsnFsmState = LSN_SEND_REQ;
130  }
131  } else if (watchDogTimer_plisten == 0 && !sTcpPortsOpenFeedback.full() )
132  {
133  ap_uint<16> new_absolute_port = 0;
134  printError(myName, "Timeout: Server failed to listen on port %d %d (0x%4.4X).\n",
135  (int) new_absolute_port, (int) new_absolute_port);
136  sTcpPortsOpenFeedback.write(false);
137  lsnFsmState = LSN_SEND_REQ;
138  } else {
139  watchDogTimer_plisten--;
140  }
141  break;
142 
143  } //switch
144 }
145 
146 
147 
148 
153  ap_uint<1> *layer_4_enabled,
154  ap_uint<1> *piNTS_ready,
155  stream<TcpAppNotif> &siTOE_Notif,
156  stream<TcpAppNotif> &sTcpNotif_buffer
157  )
158 {
159  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
160 #pragma HLS INLINE off
161 #pragma HLS pipeline II=1
162  //-- STATIC CONTROL VARIABLES (with RESET) --------------------------------
163  static RrhEnqFsmStates rrhEngFsm = RRH_ENQ_RESET;
164 #pragma HLS RESET variable=rrhEngFsm
165  //-- STATIC DATAFLOW VARIABLES --------------------------------------------
166  //-- LOCAL DATAFLOW VARIABLES ---------------------------------------------
167 
168  //This FSM is more or less senseless, but without Vivado HLS removes the 'sTcpNotif_buffer'
169 
170  switch(rrhEngFsm)
171  {
172  default:
173  case RRH_ENQ_RESET:
174  if(*layer_4_enabled == 1 && *piNTS_ready == 1)
175  {
176  rrhEngFsm = RRH_ENQ_STREAM;
177  }
178  else if(!siTOE_Notif.empty())
179  {
180  siTOE_Notif.read();
181  }
182  break;
183  case RRH_ENQ_STREAM:
184  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
185  {
186  rrhEngFsm = RRH_ENQ_RESET;
187  }
188  else if(!siTOE_Notif.empty() && !sTcpNotif_buffer.full())
189  {
190  TcpAppNotif new_notif = siTOE_Notif.read();
191  sTcpNotif_buffer.write(new_notif);
192  }
193  break;
194  }
195 
196 }
197 
198 
199 
200 
219 void pTcpRRh(
220  ap_uint<1> *layer_4_enabled,
221  ap_uint<1> *piNTS_ready,
222  ap_uint<32> *piMMIO_CfrmIp4Addr,
223  ap_uint<16> *piMMIO_FmcLsnPort,
224  stream<TcpAppNotif> &siTOE_Notif,
225  stream<TcpAppRdReq> &soTOE_DReq,
226  stream<NalNewTableEntry> &sAddNewTriple_TcpRrh,
227  stream<SessionId> &sMarkAsPriv,
228  stream<SessionId> &sDeleteEntryBySid,
229  stream<TcpAppRdReq> &sRDp_ReqNotif,
230  stream<PacketLen> &fmc_write_cnt_sig,
231  stream<PacketLen> &role_write_cnt_sig
232  )
233 {
234  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
235 #pragma HLS INLINE off
236 #pragma HLS pipeline II=1
237 
238  char* myName = concat3(THIS_NAME, "/", "Tcp_RRh");
239 
240  //-- STATIC CONTROL VARIABLES (with RESET) --------------------------------
241  static RrhFsmStates rrhFsmState = RRH_RESET;
242 
243 #pragma HLS RESET variable=rrhFsmState
244 
245  //-- STATIC DATAFLOW VARIABLES --------------------------------------------
246  static Cam8<SessionId,TcpDatLen> sessionLength = Cam8<SessionId,TcpDatLen>();
247 #ifndef __SYNTHESIS__
248  if(MAX_NAL_SESSIONS != 8)
249  {
250  printf("\n\t\tERROR: pTcpRRh is currently configured to support only 8 parallel sessions! Abort.\n(Currently, the use of \'Cam8\' must be updated accordingly by hand.)\n");
251  exit(-1);
252  }
253 #endif
254 
255  static stream<NalWaitingData> waitingSessions ("sTcpRRh_WaitingSessions");
256  static stream<NalWaitingData> session_reinsert ("sTcpRRh_sessions_to_reinsert");
257 #pragma HLS STREAM variable=waitingSessions depth=8
258 #pragma HLS STREAM variable=session_reinsert depth=8
259 
260  static TcpDatLen waiting_length = 0;
261  static TcpAppNotif notif_pRrh = TcpAppNotif();
262  static bool already_waiting = false;
263  static TcpDatLen requested_length = 0;
264  static TcpDatLen length_update_value = 0;
265  static SessionId found_ID = 0;
266  static bool found_fmc_sess = false;
267  static bool need_cam_update = false;
268  static bool go_back_to_ack_wait_role = false;
269  static bool go_back_to_ack_wait_fmc = false;
270 
271  static PacketLen role_fifo_free_cnt = NAL_MAX_FIFO_DEPTHS_BYTES;
272  static PacketLen fmc_fifo_free_cnt = NAL_MAX_FIFO_DEPTHS_BYTES;
273 
274  //-- LOCAL DATAFLOW VARIABLES ---------------------------------------------
275 
276  switch(rrhFsmState)
277  {
278  default:
279  case RRH_RESET:
280  sessionLength.reset();
281  go_back_to_ack_wait_fmc = false;
282  go_back_to_ack_wait_role = false;
283  role_fifo_free_cnt = NAL_MAX_FIFO_DEPTHS_BYTES;
284  fmc_fifo_free_cnt = NAL_MAX_FIFO_DEPTHS_BYTES;
285  rrhFsmState = RRH_WAIT_NOTIF;
286  break;
287  case RRH_WAIT_NOTIF:
288  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
289  {
290  rrhFsmState = RRH_DRAIN;
291  }
292  else if(!siTOE_Notif.empty() && !sDeleteEntryBySid.full()
293  )
294  {
295  siTOE_Notif.read(notif_pRrh);
296  if (notif_pRrh.tcpDatLen != 0)
297  {
298  //waiting_length = 0;
299  already_waiting = sessionLength.lookup(notif_pRrh.sessionID, waiting_length);
300  rrhFsmState = RRH_PROCESS_NOTIF;
301 
302  } else if(notif_pRrh.tcpState == FIN_WAIT_1 || notif_pRrh.tcpState == FIN_WAIT_2
303  || notif_pRrh.tcpState == CLOSING || notif_pRrh.tcpState == TIME_WAIT
304  || notif_pRrh.tcpState == LAST_ACK || notif_pRrh.tcpState == CLOSED)
305  {
306  // we were notified about a closing connection
307  sDeleteEntryBySid.write(notif_pRrh.sessionID);
308  if(go_back_to_ack_wait_fmc)
309  {
310  rrhFsmState = RRH_WAIT_FMC;
311  }
312  else if(go_back_to_ack_wait_role)
313  {
314  rrhFsmState = RRH_WAIT_ROLE;
315  }
316  //else, stay here...
317  }
318  }
319  else if(!session_reinsert.empty() && !waitingSessions.full()
320  && !go_back_to_ack_wait_fmc && !go_back_to_ack_wait_role
321  )
322  {
323  waitingSessions.write(session_reinsert.read());
324  rrhFsmState = RRH_START_REQUEST;
325  }
326  else if(!waitingSessions.empty()
327  && !go_back_to_ack_wait_fmc && !go_back_to_ack_wait_role
328  )
329  {
330  rrhFsmState = RRH_START_REQUEST;
331  }
332  break;
333  case RRH_PROCESS_NOTIF:
334  if(!waitingSessions.full() && !sAddNewTriple_TcpRrh.full()
335  && !sMarkAsPriv.full()
336  )
337  {
338  if(already_waiting)
339  {
340  sessionLength.update(notif_pRrh.sessionID, notif_pRrh.tcpDatLen + waiting_length);
341  printf("[TCP-RRH] adding %d to waiting sessions for session %d.\n",(int) notif_pRrh.tcpDatLen, (int) notif_pRrh.sessionID);
342 
343  } else {
344  sessionLength.insert(notif_pRrh.sessionID, notif_pRrh.tcpDatLen);
345  //bool found_slot = sessionLength.insert(notif_pRrh.sessionID, notif_pRrh.tcpDatLen);
346  //if(!found_slot)
347  //{
348  // //we have a problem...
349  // //but shouldn't happen actually since we have the same size as the table in TOE...
350  // printf("[TCP-RRH:PANIC] We don't have space left in the waiting table...\n");
351  // break;
352  //} else {
353  NalNewTableEntry ne_struct = NalNewTableEntry(newTriple(notif_pRrh.ip4SrcAddr, notif_pRrh.tcpSrcPort, notif_pRrh.tcpDstPort),
354  notif_pRrh.sessionID);
355  sAddNewTriple_TcpRrh.write(ne_struct);
356  bool is_fmc = false;
357  if(notif_pRrh.ip4SrcAddr == *piMMIO_CfrmIp4Addr && notif_pRrh.tcpDstPort == *piMMIO_FmcLsnPort)
358  {
359  is_fmc = true;
360  sMarkAsPriv.write(notif_pRrh.sessionID);
361  }
362  NalWaitingData new_sess = NalWaitingData(notif_pRrh.sessionID, is_fmc);
363  waitingSessions.write(new_sess);
364  printf("[TCP-RRH] adding %d with %d bytes as new waiting session.\n", (int) notif_pRrh.sessionID, (int) notif_pRrh.tcpDatLen);
365  //}
366  }
367  if(go_back_to_ack_wait_fmc)
368  {
369  rrhFsmState = RRH_WAIT_FMC;
370  }
371  else if(go_back_to_ack_wait_role)
372  {
373  rrhFsmState = RRH_WAIT_ROLE;
374  } else {
375  rrhFsmState = RRH_START_REQUEST;
376  }
377  }
378  break;
379  case RRH_START_REQUEST:
380  if(!waitingSessions.empty() && !session_reinsert.full()
381  //&& role_fifo_free_cnt > 0
382  //&& fmc_fifo_free_cnt > 0
383  //if we are here, we ensured there is space
384  )
385  {
386  NalWaitingData new_data = waitingSessions.read();
387  found_ID = new_data.sessId;
388  TcpDatLen found_length = 0;
389  found_fmc_sess = new_data.fmc_con;
390 
391  sessionLength.lookup(found_ID, found_length);
392  //bool found_smth = sessionLength.lookup(found_ID, found_length);
393  //if(!found_smth)
394  //{
395  // //we have a problem...
396  // //but shouldn't happen actually since the stream is filled by ourselve
397  // printf("[TCP-RRH:PANIC] We received a sessionID that is not in the CAM...\n");
398  //} else {
399  //requested_length = 0;
400  if(found_fmc_sess)
401  {
402  if(found_length >= fmc_fifo_free_cnt)
403  {
404  need_cam_update = true;
405  requested_length = fmc_fifo_free_cnt;
406  length_update_value = found_length - fmc_fifo_free_cnt;
407  } else {
408  need_cam_update = false;
409  requested_length = found_length;
410  }
411  } else {
412  if(found_length >= role_fifo_free_cnt)
413  {
414  need_cam_update = true;
415  requested_length = role_fifo_free_cnt;
416  length_update_value = found_length - role_fifo_free_cnt;
417  } else {
418  need_cam_update = false;
419  requested_length = found_length;
420  }
421  }
423  rrhFsmState = RRH_PROCESS_REQUEST;
424  //}
425  }
426  //else if(both_fifo_free_cnt == 0)
427  //{
428  // rrhFsmState = RRH_WAIT_WRITE_ACK;
429  //}
430  break;
431  case RRH_PROCESS_REQUEST:
432  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
433  {
434  rrhFsmState = RRH_DRAIN;
435  }
436  else if(!soTOE_DReq.full() && !sRDp_ReqNotif.full()
437  && !session_reinsert.full()
438  )
439  {
440  if(need_cam_update)
441  {
442  sessionLength.update(found_ID, length_update_value);
443  session_reinsert.write(NalWaitingData(found_ID, found_fmc_sess));
444  if(found_fmc_sess)
445  {
446  fmc_fifo_free_cnt = 0;
447  } else {
448  role_fifo_free_cnt = 0;
449  }
450  } else {
451  sessionLength.deleteEntry(found_ID);
452  if(found_fmc_sess)
453  {
454  fmc_fifo_free_cnt -= requested_length;
455  } else {
456  role_fifo_free_cnt -= requested_length;
457  }
458  }
459  printf("[TCP-RRH] requesting data for #%d with length %d (FMC: %d)\n", (int) found_ID, (int) requested_length, (int) found_fmc_sess);
460  TcpAppRdReq new_req = TcpAppRdReq(found_ID, requested_length);
461  soTOE_DReq.write(new_req);
462  sRDp_ReqNotif.write(new_req);
463  go_back_to_ack_wait_fmc = false;
464  go_back_to_ack_wait_role = false;
465  if(found_fmc_sess)
466  {
467  rrhFsmState = RRH_WAIT_FMC;
468  } else {
469  rrhFsmState = RRH_WAIT_ROLE;
470  }
471  }
472  break;
473  case RRH_WAIT_FMC:
474  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
475  {
476  rrhFsmState = RRH_DRAIN;
477  }
478  else if(!fmc_write_cnt_sig.empty())
479  {
480  PacketLen fmc_new_free = fmc_write_cnt_sig.read();
481  fmc_fifo_free_cnt += fmc_new_free;
482  if(fmc_fifo_free_cnt > NAL_MAX_FIFO_DEPTHS_BYTES)
483  {
484  //to be sure
485  fmc_fifo_free_cnt = NAL_MAX_FIFO_DEPTHS_BYTES;
486  }
487  printf("[TCP-RRH] FMC FIFO completed write of %d bytes; In total %d bytes are free in FMC FIFO.\n", (int) fmc_new_free, (int) fmc_fifo_free_cnt);
488  go_back_to_ack_wait_fmc = false;
489  rrhFsmState = RRH_WAIT_NOTIF;
490  }
491  else if(!siTOE_Notif.empty())
492  {
493  rrhFsmState = RRH_WAIT_NOTIF;
494  go_back_to_ack_wait_fmc = true;
495  }
496  break;
497  case RRH_WAIT_ROLE:
498  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
499  {
500  rrhFsmState = RRH_DRAIN;
501  }
502  else if(!role_write_cnt_sig.empty())
503  {
504  PacketLen role_new_free = role_write_cnt_sig.read();
505  role_fifo_free_cnt += role_new_free;
506  if(role_fifo_free_cnt > NAL_MAX_FIFO_DEPTHS_BYTES)
507  {
508  //to be sure
509  role_fifo_free_cnt = NAL_MAX_FIFO_DEPTHS_BYTES;
510  }
511  printf("[TCP-RRH] ROLE FIFO completed write of %d bytes; In total %d bytes are free in ROLE FIFO.\n", (int) role_new_free, (int) role_fifo_free_cnt);
512  go_back_to_ack_wait_role = false;
513  rrhFsmState = RRH_WAIT_NOTIF;
514  }
515  else if(!siTOE_Notif.empty())
516  {
517  rrhFsmState = RRH_WAIT_NOTIF;
518  go_back_to_ack_wait_role = true;
519  }
520  break;
521  case RRH_DRAIN:
522  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
523  {
524  if(!siTOE_Notif.empty())
525  {
526  siTOE_Notif.read();
527  }
528  if(!waitingSessions.empty())
529  {
530  waitingSessions.read();
531  }
532  if(!session_reinsert.empty())
533  {
534  session_reinsert.read();
535  }
536  if(!fmc_write_cnt_sig.empty())
537  {
538  fmc_write_cnt_sig.read();
539  }
540  if(!role_write_cnt_sig.empty())
541  {
542  role_write_cnt_sig.read();
543  }
544  } else {
545  rrhFsmState = RRH_RESET;
546  }
547  break;
548  }
549 
550 }
551 
552 
553 
554 
581 void pTcpRDp(
582  ap_uint<1> *layer_4_enabled,
583  ap_uint<1> *piNTS_ready,
584  stream<TcpAppRdReq> &sRDp_ReqNotif,
585  stream<TcpAppData> &siTOE_Data,
586  stream<TcpAppMeta> &siTOE_SessId,
587  stream<NetworkWord> &soFMC_data,
588  stream<TcpSessId> &soFMC_SessId,
589  stream<NetworkWord> &soTcp_data,
590  stream<NetworkMetaStream> &soTcp_meta,
591  stream<NalConfigUpdate> &sConfigUpdate,
592  stream<Ip4Addr> &sGetNidReq_TcpRx,
593  stream<NodeId> &sGetNidRep_TcpRx,
594  stream<SessionId> &sGetTripleFromSid_Req,
595  stream<NalTriple> &sGetTripleFromSid_Rep,
596  ap_uint<32> *piMMIO_CfrmIp4Addr,
597  ap_uint<16> *piMMIO_FmcLsnPort,
598  ap_uint<1> *layer_7_enabled,
599  ap_uint<1> *role_decoupled,
600  stream<bool> &cache_inval_sig,
601  stream<NalEventNotif> &internal_event_fifo
602  )
603 {
604  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
605 #pragma HLS INLINE off
606 #pragma HLS pipeline II=1
607 
608 
609  char* myName = concat3(THIS_NAME, "/", "Tcp_RDp");
610 
611 
612  //-- STATIC CONTROL VARIABLES (with RESET) --------------------------------
613  static RdpFsmStates rdpFsmState = RDP_RESET;
614  static ap_uint<64> cached_tcp_rx_triple = UNUSED_TABLE_ENTRY_VALUE;
615  //static bool Tcp_RX_metaWritten = false;
616  static SessionId cached_tcp_rx_session_id = UNUSED_SESSION_ENTRY_VALUE;
617  static NodeId own_rank = 0;
618  static NodeId cached_src_id = INVALID_MRT_VALUE;
619  static bool cache_init = false;
620  static uint8_t evs_loop_i = 0;
621 
622 
623 #pragma HLS RESET variable=rdpFsmState
624 #pragma HLS RESET variable=cached_tcp_rx_triple
625  //#pragma HLS RESET variable=Tcp_RX_metaWritten
626 #pragma HLS RESET variable=cached_tcp_rx_session_id
627 #pragma HLS RESET variable=cached_src_id
628 #pragma HLS RESET variable=cache_init
629 #pragma HLS RESET variable=own_rank
630 #pragma HLS RESET variable=evs_loop_i
631 
632  //-- STATIC DATAFLOW VARIABLES --------------------------------------------
633  static SessionId session_toFMC = 0;
634  static NetworkMetaStream in_meta_tcp = NetworkMetaStream();
635  static bool first_word_written = false;
636  static TcpAppData first_word = TcpAppData();
637  static NodeId src_id = INVALID_MRT_VALUE;
638  static ap_uint<64> triple_in = UNUSED_TABLE_ENTRY_VALUE;
639  static Ip4Addr remoteAddr = Ip4Addr();
640  static TcpPort dstPort = 0x0;
641  static TcpPort srcPort = 0x0;
642  static bool found_in_cache = false;
643  static AppMeta sessId = 0x0;
644  static NetworkDataLength current_length = 0;
645  static ap_uint<32> fmc_tcp_bytes_cnt = 0;
646 
647  static stream<NalEventNotif> evsStreams[7];
648 
649  //-- LOCAL DATAFLOW VARIABLES ---------------------------------------------
650  TcpAppData currWord;
651  NalEventNotif new_ev_not;
652  NetworkMeta tmp_meta;
653 
654 
655  switch (rdpFsmState)
656  {
657 
658  default:
659  case RDP_RESET:
660  if(*layer_4_enabled == 1 && *piNTS_ready == 1)
661  {
662  cache_init = false;
663  fmc_tcp_bytes_cnt = 0;
664  current_length = 0;
665  rdpFsmState = RDP_WAIT_META;
666  } else {
667  if(!sRDp_ReqNotif.empty() )
668  {
669  sRDp_ReqNotif.read();
670  }
671  if(!siTOE_SessId.empty())
672  {
673  siTOE_SessId.read();
674  }
675  if(!siTOE_Data.empty())
676  {
677  siTOE_Data.read();
678  }
679  }
680  break;
681  case RDP_WAIT_META:
682  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
683  {
684  rdpFsmState = RDP_RESET;
685  }
686  else if(!cache_inval_sig.empty())
687  {
688  if(cache_inval_sig.read())
689  {
690  cached_tcp_rx_session_id = UNUSED_SESSION_ENTRY_VALUE;
691  cached_tcp_rx_triple = UNUSED_TABLE_ENTRY_VALUE;
692  cached_src_id = INVALID_MRT_VALUE;
693  cache_init = false;
694  }
695  break;
696  } else if(!sConfigUpdate.empty())
697  {
698  NalConfigUpdate ca = sConfigUpdate.read();
700  {
701  own_rank = (NodeId) ca.update_value;
702  cache_init = false;
703  }
704  break;
705  }
706  else if (!sRDp_ReqNotif.empty()
707  && !sGetTripleFromSid_Req.full()
708  )
709  {
710  TcpAppRdReq new_req = sRDp_ReqNotif.read();
711  sessId = new_req.sessionID;
712  current_length = new_req.length;
713 
714  triple_in = UNUSED_TABLE_ENTRY_VALUE;
715  found_in_cache = false;
716  if(cache_init && sessId == cached_tcp_rx_session_id)
717  {
718  printf("used TCP RX tripple and NID cache.\n");
719  triple_in = cached_tcp_rx_triple;
720  src_id = cached_src_id;
721  found_in_cache = true;
722  rdpFsmState = RDP_FILTER_META;
723  } else {
724  sGetTripleFromSid_Req.write(sessId);
725  rdpFsmState = RDP_W8FORREQS_1;
726  cache_init = false;
727  printf("[Tcp-RDP:INFO] Need to request session and node id.\n");
728  }
729  }
730  break;
731 
732  case RDP_W8FORREQS_1:
733  if(!sGetTripleFromSid_Rep.empty() && !sGetNidReq_TcpRx.full())
734  {
735  triple_in = sGetTripleFromSid_Rep.read();
736  remoteAddr = getRemoteIpAddrFromTriple(triple_in);
737  dstPort = getLocalPortFromTriple(triple_in);
738  if(dstPort != *piMMIO_FmcLsnPort)
739  {
740  sGetNidReq_TcpRx.write(remoteAddr);
741  printf("[TCP-RX:INFO] need to ask for Node ID.\n");
742  rdpFsmState = RDP_W8FORREQS_2;
743  } else {
744  printf("[TCP-RX:INFO] found possible FMC connection, write to cache.\n");
745  cache_init = true;
746  cached_src_id = INVALID_MRT_VALUE;
747  cached_tcp_rx_session_id = sessId;
748  cached_tcp_rx_triple = triple_in;
749  rdpFsmState = RDP_FILTER_META;
750  }
751  }
752  break;
753 
754  case RDP_W8FORREQS_2:
755  if(!sGetNidRep_TcpRx.empty())
756  {
757 
758  src_id = sGetNidRep_TcpRx.read();
759  cache_init = true;
760  cached_src_id = src_id;
761  cached_tcp_rx_session_id = sessId;
762  cached_tcp_rx_triple = triple_in;
763  rdpFsmState = RDP_FILTER_META;
764  }
765  break;
766 
767  case RDP_FILTER_META:
768  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
769  {
770  rdpFsmState = RDP_RESET;
771  }
772  else if(!siTOE_SessId.empty()
773  && !soTcp_meta.full() && !soFMC_SessId.full()
774  )
775  {
776  TcpAppMeta controll_id = siTOE_SessId.read();
777  if(controll_id != sessId)
778  {//actually, should not happen
779  printf("[TCP-RDp:PANIC] We received data that we didn't expect...\n");
780  //SINK packet
781  //new_ev_not = NalEventNotif(NID_MISS_RX, 1);
782  //evsStreams[9].write_nb(new_ev_not);
783  rdpFsmState = RDP_DROP_PACKET;
784  printf("NRC drops the packet...\n");
785  cache_init = false;
786  break;
787  }
788 
789  printf("tripple_in: %llu\n",(unsigned long long) triple_in);
790  //since we requested the session, we should know it -> no error handling
791  dstPort = getLocalPortFromTriple(triple_in);
792  srcPort = getRemotePortFromTriple(triple_in);
793  remoteAddr = getRemoteIpAddrFromTriple(triple_in);
794  printf("remote Addr: %d; dstPort: %d; srcPort %d\n", (int) remoteAddr, (int) dstPort, (int) srcPort);
795 
796  if(dstPort == *piMMIO_FmcLsnPort)
797  {
798  if(remoteAddr == *piMMIO_CfrmIp4Addr)
799  {//valid connection to FMC
800  printf("found valid FMC connection.\n");
801  session_toFMC = sessId;
802  soFMC_SessId.write(session_toFMC);
803  fmc_tcp_bytes_cnt = 0;
804  rdpFsmState = RDP_STREAM_FMC;
805  new_ev_not = NalEventNotif(AUTH_ACCESS, 1);
806  evsStreams[0].write_nb(new_ev_not);
807  //done by RRh
808  //if(!found_in_cache)
809  //{
810  // //markSessionAsPrivileged(sessId);
811  // sMarkAsPriv.write(sessId);
812  //}
813  break;
814  } else {
815  new_ev_not = NalEventNotif(UNAUTH_ACCESS, 1);
816  evsStreams[1].write_nb(new_ev_not);
817  printf("unauthorized access to FMC!\n");
818  rdpFsmState = RDP_DROP_PACKET;
819  printf("NRC drops the packet...\n");
820  cache_init = false;
821  break;
822  }
823  }
824 
825  printf("TO ROLE: src_rank: %d\n", (int) src_id);
826  //Role packet
827  if(src_id == INVALID_MRT_VALUE
828  || *layer_7_enabled == 0 || *role_decoupled == 1)
829  {
830  //SINK packet
831  new_ev_not = NalEventNotif(NID_MISS_RX, 1);
832  evsStreams[2].write_nb(new_ev_not);
833  rdpFsmState = RDP_DROP_PACKET;
834  printf("NRC drops the packet...\n");
835  cache_init = false;
836  break;
837  }
838  new_ev_not = NalEventNotif(LAST_RX_NID, src_id);
839  evsStreams[3].write_nb(new_ev_not);
840  new_ev_not = NalEventNotif(LAST_RX_PORT, dstPort);
841  evsStreams[4].write_nb(new_ev_not);
842  tmp_meta = NetworkMeta(own_rank, dstPort, src_id, srcPort, current_length);
843  in_meta_tcp = NetworkMetaStream(tmp_meta);
844 
845  //write meta
846  soTcp_meta.write(in_meta_tcp);
847  new_ev_not = NalEventNotif(PACKET_RX, 1);
848  evsStreams[5].write_nb(new_ev_not);
849  rdpFsmState = RDP_STREAM_ROLE;
850  }
851  break;
852  case RDP_STREAM_ROLE:
853  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
854  {
855  rdpFsmState = RDP_RESET;
856  }
857  else if (!siTOE_Data.empty() && !soTcp_data.full())
858  {
859  siTOE_Data.read(currWord);
860  NetworkWord tcpWord = NetworkWord(currWord.getLE_TData(), currWord.getLE_TKeep(), currWord.getLE_TLast());
861  soTcp_data.write(tcpWord);
862  if (currWord.getTLast() == 1)
863  {
864  rdpFsmState = RDP_WAIT_META;
865  }
866  }
867  break;
868 
869  case RDP_STREAM_FMC:
870  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
871  {
872  rdpFsmState = RDP_RESET;
873  }
874  else if (!siTOE_Data.empty()
875  && !soFMC_data.full()
876  )
877  {
878  siTOE_Data.read(currWord);
879  NetworkWord tcpWord = NetworkWord(currWord.getLE_TData(), currWord.getLE_TKeep(), currWord.getLE_TLast());
880  soFMC_data.write(tcpWord);
881  fmc_tcp_bytes_cnt += extractByteCnt(currWord);
882  if (currWord.getTLast() == 1)
883  {
884  new_ev_not = NalEventNotif(FMC_TCP_BYTES, fmc_tcp_bytes_cnt);
885  evsStreams[6].write_nb(new_ev_not);
886  rdpFsmState = RDP_WAIT_META;
887  }
888  }
889  break;
890 
891  case RDP_DROP_PACKET:
892  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
893  {
894  rdpFsmState = RDP_RESET;
895  }
896  else if( !siTOE_Data.empty() )
897  {
898  siTOE_Data.read(currWord);
899  if (currWord.getTLast() == 1)
900  {
901  rdpFsmState = RDP_WAIT_META;
902  cache_init = false;
903  }
904  }
905  break;
906  } // switch case
907 
908  //-- ALWAYS -----------------------
909  if(!internal_event_fifo.full())
910  {
911  if(!evsStreams[evs_loop_i].empty())
912  {
913  internal_event_fifo.write(evsStreams[evs_loop_i].read());
914  }
915  evs_loop_i++;
916  if(evs_loop_i >= 7)
917  {
918  evs_loop_i = 0;
919  }
920  }
921 
922 }
923 
924 
925 
930  ap_uint<1> *layer_7_enabled,
931  ap_uint<1> *role_decoupled,
932  stream<NetworkWord> &sRoleTcpDataRx_buffer,
933  stream<NetworkMetaStream> &sRoleTcpMetaRx_buffer,
934  stream<NetworkWord> &soTcp_data,
935  stream<NetworkMetaStream> &soTcp_meta,
936  stream<PacketLen> &role_write_cnt_sig
937  )
938 {
939  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
940 #pragma HLS INLINE off
941 #pragma HLS pipeline II=1
942  //-- STATIC CONTROL VARIABLES (with RESET) --------------------------------
943  static DeqFsmStates deqFsmState = DEQ_WAIT_META;
944 #pragma HLS RESET variable=deqFsmState
945  //-- STATIC DATAFLOW VARIABLES --------------------------------------------
946  static PacketLen current_bytes_written = 0;
947  //-- LOCAL DATAFLOW VARIABLES ---------------------------------------------
948  NetworkWord cur_word = NetworkWord();
950  bool role_disabled = (*layer_7_enabled == 0 && *role_decoupled == 1);
951 
952  switch(deqFsmState)
953  {
954  default:
955  case DEQ_SEND_NOTIF:
956  if(!role_write_cnt_sig.full())
957  {
958  role_write_cnt_sig.write(current_bytes_written);
959  current_bytes_written = 0;
960  deqFsmState = DEQ_WAIT_META;
961  }
962  break;
963  case DEQ_WAIT_META:
964  if(!sRoleTcpDataRx_buffer.empty() && !sRoleTcpMetaRx_buffer.empty()
965  && ( (!soTcp_data.full() && !soTcp_meta.full()) || //user can read
966  (role_disabled) //role is disabled -> drain FIFOs
967  )
968  )
969  {
970  cur_word = sRoleTcpDataRx_buffer.read();
971  cur_meta = sRoleTcpMetaRx_buffer.read();
972  current_bytes_written = extractByteCnt(cur_word);
973  if(!role_disabled)
974  {
975  soTcp_data.write(cur_word);
976  soTcp_meta.write(cur_meta);
977  }
978  if(cur_word.tlast == 0)
979  {
980  deqFsmState = DEQ_STREAM_DATA;
981  } else {
982  deqFsmState = DEQ_SEND_NOTIF;
983  }
984  }
985  break;
986  case DEQ_STREAM_DATA:
987  if(!sRoleTcpDataRx_buffer.empty()
988  && (!soTcp_data.full() || role_disabled)
989  )
990  {
991  cur_word = sRoleTcpDataRx_buffer.read();
992  current_bytes_written += extractByteCnt(cur_word);
993  if(!role_disabled)
994  {
995  soTcp_data.write(cur_word);
996  }
997  if(cur_word.tlast == 1)
998  {
999  deqFsmState = DEQ_SEND_NOTIF;
1000  }
1001  }
1002  break;
1003  }
1004 
1005 }
1006 
1007 
1008 
1013  stream<NetworkWord> &sFmcTcpDataRx_buffer,
1014  stream<TcpSessId> &sFmcTcpMetaRx_buffer,
1015  stream<NetworkWord> &soFmc_data,
1016  stream<TcpSessId> &soFmc_meta,
1017  stream<PacketLen> &fmc_write_cnt_sig
1018  )
1019 {
1020  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
1021 #pragma HLS INLINE off
1022 #pragma HLS pipeline II=1
1023  //-- STATIC CONTROL VARIABLES (with RESET) --------------------------------
1024  static DeqFsmStates deqFsmState = DEQ_WAIT_META;
1025 #pragma HLS RESET variable=deqFsmState
1026  //-- STATIC DATAFLOW VARIABLES --------------------------------------------
1027  static PacketLen current_bytes_written = 0;
1028  //-- LOCAL DATAFLOW VARIABLES ---------------------------------------------
1029  NetworkWord cur_word = NetworkWord();
1030  TcpSessId cur_meta = TcpSessId();
1031 
1032  switch(deqFsmState)
1033  {
1034  default:
1035  case DEQ_SEND_NOTIF:
1036  if(!fmc_write_cnt_sig.full())
1037  {
1038  fmc_write_cnt_sig.write(current_bytes_written);
1039  current_bytes_written = 0;
1040  deqFsmState = DEQ_WAIT_META;
1041  }
1042  break;
1043  case DEQ_WAIT_META:
1044  if(!sFmcTcpDataRx_buffer.empty() && !sFmcTcpMetaRx_buffer.empty()
1045  && !soFmc_data.full() && !soFmc_meta.full()
1046  )
1047  {
1048  printf("[pFmcTcpRxDeq] Start processing FMC packet\n");
1049  cur_word = sFmcTcpDataRx_buffer.read();
1050  cur_meta = sFmcTcpMetaRx_buffer.read();
1051  current_bytes_written = extractByteCnt(cur_word);
1052  soFmc_data.write(cur_word);
1053  soFmc_meta.write(cur_meta);
1054  if(cur_word.tlast == 0)
1055  {
1056  deqFsmState = DEQ_STREAM_DATA;
1057  } else {
1058  deqFsmState = DEQ_SEND_NOTIF;
1059  }
1060  }
1061  break;
1062  case DEQ_STREAM_DATA:
1063  if(!sFmcTcpDataRx_buffer.empty()
1064  && !soFmc_data.full()
1065  )
1066  {
1067  cur_word = sFmcTcpDataRx_buffer.read();
1068  soFmc_data.write(cur_word);
1069  current_bytes_written += extractByteCnt(cur_word);
1070  if(cur_word.tlast == 1)
1071  {
1072  deqFsmState = DEQ_SEND_NOTIF;
1073  }
1074  }
1075  break;
1076  }
1077 }
1078 
1079 
1080 
1081 
1104 void pTcpWRp(
1105  ap_uint<1> *layer_4_enabled,
1106  ap_uint<1> *piNTS_ready,
1107  stream<NetworkWord> &siFMC_data,
1108  stream<TcpSessId> &siFMC_SessId,
1109  stream<NetworkWord> &siTcp_data,
1110  stream<NetworkMetaStream> &siTcp_meta,
1111  stream<TcpAppData> &soTOE_Data,
1112  stream<TcpAppMeta> &soTOE_SessId,
1113  stream<TcpDatLen> &soTOE_len,
1114  stream<NodeId> &sGetIpReq_TcpTx,
1115  stream<Ip4Addr> &sGetIpRep_TcpTx,
1116  stream<NalTriple> &sGetSidFromTriple_Req,
1117  stream<SessionId> &sGetSidFromTriple_Rep,
1118  stream<NalTriple> &sNewTcpCon_Req,
1119  stream<NalNewTcpConRep> &sNewTcpCon_Rep,
1120  stream<bool> &cache_inval_sig,
1121  stream<NalEventNotif> &internal_event_fifo
1122  )
1123 {
1124  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
1125 #pragma HLS INLINE off
1126 #pragma HLS pipeline II=1
1127 
1128 
1129  char* myName = concat3(THIS_NAME, "/", "Tcp_WRp");
1130 
1131  //-- STATIC CONTROL VARIABLES (with RESET) --------------------------------
1132  static WrpFsmStates wrpFsmState = WRP_RESET;
1133 
1134  static SessionId cached_tcp_tx_session_id = UNUSED_SESSION_ENTRY_VALUE;
1135  static ap_uint<64> cached_tcp_tx_triple = UNUSED_TABLE_ENTRY_VALUE;
1136  static NodeId cached_dst_rank = INVALID_MRT_VALUE;
1137  static Ip4Addr cached_dst_ip_addr = 0x0;
1138  static bool cache_init = false;
1139 
1140  static uint8_t evs_loop_i = 0;
1141 
1142 #pragma HLS RESET variable=wrpFsmState
1143 #pragma HLS RESET variable=cached_tcp_tx_session_id
1144 #pragma HLS RESET variable=cached_tcp_tx_triple
1145 #pragma HLS RESET variable=cached_dst_rank
1146 #pragma HLS RESET variable=cache_init
1147 #pragma HLS RESET variable=cached_dst_ip_addr
1148 #pragma HLS RESET variable=evs_loop_i
1149 
1150  //-- STATIC DATAFLOW VARIABLES --------------------------------------------
1151  static NetworkMetaStream out_meta_tcp = NetworkMetaStream();
1152  static NetworkDataLength tcpTX_packet_length = 0;
1153  static NetworkDataLength tcpTX_current_packet_length = 0;
1154  static TcpAppMeta tcpSessId = TcpAppMeta();
1155  static NodeId dst_rank = INVALID_MRT_VALUE;
1156  static Ip4Addr dst_ip_addr = 0x0;
1157  static NrcPort src_port = 0x0;
1158  static NrcPort dst_port = 0x0;
1159  static ap_uint<64> new_triple = UNUSED_TABLE_ENTRY_VALUE;
1160  static SessionId sessId = UNUSED_SESSION_ENTRY_VALUE;
1161  static bool streaming_mode = false;
1162 
1163  static stream<NalEventNotif> evsStreams[10];
1164 
1165 
1166  //-- LOCAL DATAFLOW VARIABLES ---------------------------------------------
1167  //NetworkWord currWordIn;
1168  //TcpAppData currWordOut;
1169  NalEventNotif new_ev_not;
1170 
1171  switch (wrpFsmState)
1172  {
1173  default:
1174  case WRP_RESET:
1175  if(*layer_4_enabled == 1 && *piNTS_ready == 1)
1176  {
1177  cache_init = false;
1178  wrpFsmState = WRP_WAIT_META;
1179  } else {
1180  if(!siFMC_data.empty())
1181  {
1182  siFMC_data.read();
1183  }
1184  if(!siFMC_SessId.empty())
1185  {
1186  siFMC_SessId.read();
1187  }
1188  if(!siTcp_data.empty())
1189  {
1190  siTcp_data.read();
1191  }
1192  if(!siTcp_meta.empty())
1193  {
1194  siTcp_meta.read();
1195  }
1196  }
1197  break;
1198  case WRP_WAIT_META:
1199  if( *layer_4_enabled == 0 || *piNTS_ready == 0)
1200  {
1201  wrpFsmState = WRP_RESET;
1202  }
1203  else if(!cache_inval_sig.empty())
1204  {
1205  if(cache_inval_sig.read())
1206  {
1207  cached_tcp_tx_session_id = UNUSED_SESSION_ENTRY_VALUE;
1208  cached_tcp_tx_triple = UNUSED_TABLE_ENTRY_VALUE;
1209  cached_dst_rank = INVALID_MRT_VALUE;
1210  cached_dst_ip_addr = 0x0;
1211  cache_init = false;
1212  }
1213  break;
1214  }
1215  else if (!siFMC_SessId.empty()
1216  && !soTOE_SessId.full()
1217  )
1218  {
1219  //FMC must come first
1220  tcpSessId = (AppMeta) siFMC_SessId.read();
1221  soTOE_SessId.write(tcpSessId);
1222  streaming_mode = true;
1223  tcpTX_current_packet_length = 0;
1224  //delete the session id, we don't need it any longer
1225  // (this expects an HTTP mode of request-response)
1226  //UPDATE: is done via the TOE_Notif if the client
1227  //closes the connection
1228 
1229  if (DEBUG_LEVEL & TRACE_WRP) {
1230  printInfo(myName, "Received new session ID #%d from [FMC].\n",
1231  tcpSessId.to_uint());
1232  }
1233  wrpFsmState = WRP_STREAM_FMC;
1234  break;
1235  }
1236  else if (!siTcp_meta.empty()
1237  && !sGetIpReq_TcpTx.full()
1238  )
1239  {
1240  //now ask the ROLE
1241  out_meta_tcp = siTcp_meta.read();
1242  tcpTX_packet_length = out_meta_tcp.tdata.len;
1243  tcpTX_current_packet_length = 0;
1244 
1245  dst_rank = out_meta_tcp.tdata.dst_rank;
1246  if(dst_rank > MAX_CF_NODE_ID)
1247  {
1248  new_ev_not = NalEventNotif(NID_MISS_TX, 1);
1249  evsStreams[0].write_nb(new_ev_not);
1250  //SINK packet
1251  wrpFsmState = WRP_DROP_PACKET;
1252  printf("NRC drops the packet...\n");
1253  break;
1254  }
1255 
1256  src_port = out_meta_tcp.tdata.src_port;
1257  if (src_port == 0)
1258  {
1259  src_port = DEFAULT_RX_PORT;
1260  }
1261  dst_port = out_meta_tcp.tdata.dst_port;
1262  if (dst_port == 0)
1263  {
1264  dst_port = DEFAULT_RX_PORT;
1265  new_ev_not = NalEventNotif(PCOR_TX, 1);
1266  evsStreams[2].write_nb(new_ev_not);
1267  }
1268 
1269  if(cache_init && dst_rank == cached_dst_rank)
1270  {
1271  dst_ip_addr = cached_dst_ip_addr;
1272  wrpFsmState = WRP_W8FORREQS_11;
1273  } else {
1274  //need request both...
1275  sGetIpReq_TcpTx.write(dst_rank);
1276  cache_init = false;
1277  wrpFsmState = WRP_W8FORREQS_1;
1278  //break;
1279  }
1280  }
1281  break;
1282 
1283  case WRP_W8FORREQS_1:
1284  if(!sGetIpRep_TcpTx.empty())
1285  {
1286  dst_ip_addr = sGetIpRep_TcpTx.read();
1287  wrpFsmState = WRP_W8FORREQS_11;
1288  }
1289  break;
1290 
1291  case WRP_W8FORREQS_11:
1292  //both cases
1293  if(//cache_init ||
1294  !sGetSidFromTriple_Req.full())
1295  {
1296  //not else, in both cases
1297  wrpFsmState = WRP_W8FORREQS_2;
1298  if(dst_ip_addr == 0)
1299  {
1300  new_ev_not = NalEventNotif(NID_MISS_TX, 1);
1301  evsStreams[1].write_nb(new_ev_not);
1302  //SINK packet
1303  wrpFsmState = WRP_DROP_PACKET;
1304  printf("NRC drops the packet...\n");
1305  break;
1306  }
1307 
1308  //check if session is present
1309  new_triple = newTriple(dst_ip_addr, dst_port, src_port);
1310  printf("From ROLE: remote Addr: %d; dstPort: %d; srcPort %d; (rank: %d)\n", (int) dst_ip_addr, (int) dst_port, (int) src_port, (int) dst_rank);
1311  sessId = UNUSED_SESSION_ENTRY_VALUE;
1312  if(cache_init && new_triple == cached_tcp_tx_triple)
1313  {
1314  printf("used TCP TX tripple chache.\n");
1315  sessId = cached_tcp_tx_session_id;
1316  wrpFsmState = WRP_W8FORREQS_22;
1317  } else {
1318  //need request
1319  sGetSidFromTriple_Req.write(new_triple);
1320  cache_init = false;
1321  wrpFsmState = WRP_W8FORREQS_2;
1322  //break;
1323  }
1324  }
1325  break;
1326 
1327  case WRP_W8FORREQS_2:
1328  if(!sGetSidFromTriple_Rep.empty())
1329  {
1330  sessId = sGetSidFromTriple_Rep.read();
1331  cached_tcp_tx_triple = new_triple;
1332  cached_tcp_tx_session_id = sessId;
1333  cached_dst_ip_addr = dst_ip_addr;
1334  cached_dst_rank = dst_rank;
1335  cache_init = true;
1336  wrpFsmState = WRP_W8FORREQS_22;
1337  }
1338  break;
1339 
1340  case WRP_W8FORREQS_22:
1341  if( *layer_4_enabled == 0 || *piNTS_ready == 0)
1342  {
1343  wrpFsmState = WRP_RESET;
1344  }
1345  else if(!soTOE_SessId.full() && !sNewTcpCon_Req.full() && !soTOE_len.full() )
1346  {
1347  //both cases
1348  //"final" preprocessing
1349  printf("session id found: %d\n", (int) sessId);
1350  if(sessId == (SessionId) UNUSED_SESSION_ENTRY_VALUE)
1351  {//we need to create one first
1352  sNewTcpCon_Req.write(new_triple);
1353  wrpFsmState = WRP_WAIT_CONNECTION;
1354  cache_init = false;
1355  printf("requesting new connection.\n");
1356  break;
1357  }
1358  new_ev_not = NalEventNotif(LAST_TX_NID, dst_rank);
1359  evsStreams[3].write_nb(new_ev_not);
1360  new_ev_not = NalEventNotif(LAST_TX_PORT, dst_port);
1361  evsStreams[4].write_nb(new_ev_not);
1362  new_ev_not = NalEventNotif(PACKET_TX, 1);
1363  evsStreams[5].write_nb(new_ev_not);
1364 
1365  soTOE_SessId.write(sessId);
1366  tcpTX_current_packet_length = 0;
1367  if(tcpTX_packet_length == 0)
1368  {
1369  streaming_mode = true;
1370  } else {
1371  streaming_mode = false;
1372  soTOE_len.write(tcpTX_packet_length);
1373  }
1374  if (DEBUG_LEVEL & TRACE_WRP) {
1375  printInfo(myName, "Received new session ID #%d from [ROLE] with length %d.\n",
1376  sessId.to_uint(), tcpTX_packet_length.to_uint());
1377  }
1378  wrpFsmState = WRP_STREAM_ROLE;
1379  }
1380  break;
1381 
1382  case WRP_WAIT_CONNECTION:
1383  if( *layer_4_enabled == 0 || *piNTS_ready == 0)
1384  {
1385  wrpFsmState = WRP_RESET;
1386  }
1387  else if( !soTOE_SessId.full() && !sNewTcpCon_Rep.empty() && !soTOE_len.full() )
1388  {
1389  NalNewTcpConRep con_rep = sNewTcpCon_Rep.read();
1390  if(con_rep.failure == true)
1391  {
1392  new_ev_not = NalEventNotif(TCP_CON_FAIL, 1);
1393  evsStreams[6].write_nb(new_ev_not);
1394  // we sink the packet, because otherwise the design will hang
1395  // and the user is notified with the flight recorder status
1396  wrpFsmState = WRP_DROP_PACKET;
1397  printf("NRC drops the packet...\n");
1398  break;
1399  }
1400  new_triple = con_rep.new_triple;
1401  sessId = con_rep.newSessionId;
1402 
1403  new_ev_not = NalEventNotif(LAST_TX_NID, dst_rank);
1404  evsStreams[7].write_nb(new_ev_not);
1405  new_ev_not = NalEventNotif(LAST_TX_PORT, dst_port);
1406  evsStreams[8].write_nb(new_ev_not);
1407  new_ev_not = NalEventNotif(PACKET_TX, 1);
1408  evsStreams[9].write_nb(new_ev_not);
1409 
1410  soTOE_SessId.write(sessId);
1411  tcpTX_current_packet_length = 0;
1412  if(tcpTX_packet_length == 0)
1413  {
1414  streaming_mode = true;
1415  } else {
1416  streaming_mode = false;
1417  soTOE_len.write(tcpTX_packet_length);
1418  }
1419  if (DEBUG_LEVEL & TRACE_WRP) {
1420  printInfo(myName, "Received new session ID #%d from [ROLE].\n",
1421  sessId.to_uint());
1422  }
1423  wrpFsmState = WRP_STREAM_ROLE;
1424  cached_tcp_tx_triple = new_triple;
1425  cached_tcp_tx_session_id = sessId;
1426  cached_dst_ip_addr = dst_ip_addr;
1427  cached_dst_rank = dst_rank;
1428  cache_init = true;
1429 
1430  }
1431  break;
1432 
1433  case WRP_STREAM_FMC:
1434  if( *layer_4_enabled == 0 || *piNTS_ready == 0)
1435  {
1436  wrpFsmState = WRP_RESET;
1437  }
1438  else if (!siFMC_data.empty() && !soTOE_Data.full() && !soTOE_len.full() )
1439  {
1440  NetworkWord tmpWord = siFMC_data.read();
1441  TcpAppData tcpWord = TcpAppData(tmpWord.tdata, tmpWord.tkeep, tmpWord.tlast); //LE stays LE
1442  tcpTX_current_packet_length += extractByteCnt(tcpWord);
1443  soTOE_Data.write(tcpWord);
1444  if(tcpWord.getTLast() == 1) {
1445  wrpFsmState = WRP_WAIT_META;
1446  soTOE_len.write(tcpTX_current_packet_length);
1447  } else {
1448  //always streaming
1449  if(tcpTX_current_packet_length >= NAL_STREAMING_SPLIT_TCP)
1450  {
1451  soTOE_len.write(tcpTX_current_packet_length);
1452  tcpTX_current_packet_length = 0;
1453  }
1454  }
1455  }
1456  break;
1457 
1458  case WRP_STREAM_ROLE:
1459  if( *layer_4_enabled == 0 || *piNTS_ready == 0)
1460  {
1461  wrpFsmState = WRP_RESET;
1462  }
1463  else if (!siTcp_data.empty() && !soTOE_Data.full() && !soTOE_len.full() )
1464  {
1465  NetworkWord currWordIn = siTcp_data.read();
1466  tcpTX_current_packet_length += extractByteCnt(currWordIn);
1467  if(!streaming_mode)
1468  {
1469  currWordIn.tlast = 0; // we ignore users tlast if the length is known
1470  }
1471  printf("streaming from ROLE to TOE: tcpTX_packet_length: %d, tcpTX_current_packet_length: %d \n", (int) tcpTX_packet_length, (int) tcpTX_current_packet_length);
1472  if(!streaming_mode && tcpTX_current_packet_length >= tcpTX_packet_length) //&& tcpTX_packet_length > 0
1473  {
1474  currWordIn.tlast = 1;
1475  }
1476  if(currWordIn.tlast == 1) //either by the user, or by us
1477  {
1478  wrpFsmState = WRP_WAIT_META;
1479  if(streaming_mode)
1480  {
1481  soTOE_len.write(tcpTX_current_packet_length);
1482  }
1483  }
1484  else if (streaming_mode)
1485  {
1486  if(tcpTX_current_packet_length >= NAL_STREAMING_SPLIT_TCP)
1487  {
1488  soTOE_len.write(tcpTX_current_packet_length);
1489  tcpTX_current_packet_length = 0;
1490  currWordIn.tlast = 1; //to be sure? (actually, unecessary)
1491  }
1492  }
1493  TcpAppData currWordOutTmp = TcpAppData(currWordIn.tdata, currWordIn.tkeep, currWordIn.tlast);
1494  soTOE_Data.write(currWordOutTmp);
1495  }
1496  break;
1497 
1498  case WRP_DROP_PACKET:
1499  if( *layer_4_enabled == 0 || *piNTS_ready == 0)
1500  {
1501  wrpFsmState = WRP_RESET;
1502  }
1503  else if( !siTcp_data.empty())
1504  {
1505  NetworkWord currWordIn = siTcp_data.read();
1506  tcpTX_current_packet_length += extractByteCnt(currWordIn);
1507  //until Tlast or length
1508  if( (tcpTX_packet_length > 0 && tcpTX_current_packet_length >= tcpTX_packet_length)
1509  || (currWordIn.tlast == 1)
1510  )
1511  {
1512  wrpFsmState = WRP_WAIT_META;
1513  }
1514  }
1515  break;
1516  } // switch case
1517 
1518  //-- ALWAYS -----------------------
1519  if(!internal_event_fifo.full()
1520  )
1521  {
1522  if(!evsStreams[evs_loop_i].empty())
1523  {
1524  internal_event_fifo.write(evsStreams[evs_loop_i].read());
1525  }
1526  evs_loop_i++;
1527  if(evs_loop_i >= 10)
1528  {
1529  evs_loop_i = 0;
1530  }
1531  }
1532 
1533 }
1534 
1535 
1536 
1552 void pTcpWBu(
1553  ap_uint<1> *layer_4_enabled,
1554  ap_uint<1> *piNTS_ready,
1555  stream<TcpAppData> &siWrp_Data,
1556  stream<TcpAppMeta> &siWrp_SessId,
1557  stream<TcpDatLen> &siWrp_len,
1558  stream<TcpAppData> &soTOE_Data,
1559  stream<TcpAppSndReq> &soTOE_SndReq,
1560  stream<TcpAppSndRep> &siTOE_SndRep
1561  )
1562 {
1563  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
1564 #pragma HLS INLINE off
1565 #pragma HLS pipeline II=1
1566  char *myName = concat3(THIS_NAME, "/", "Tcp_WBu");
1567 
1568 
1569  //-- STATIC CONTROL VARIABLES (with RESET) --------------------------------
1570  static WbuFsmStates wbuState = WBU_WAIT_META;
1571  static uint16_t dequeue_cnt = 0; //in BYTES!!
1572  //static TcpDatLen original_requested_length = 0;
1573 
1574 #pragma HLS RESET variable=wbuState
1575 #pragma HLS RESET variable=dequeue_cnt
1576  //#pragma HLS RESET variable=original_requested_length
1577 
1578  //-- STATIC DATAFLOW VARIABLES --------------------------------------------
1579  static TcpAppMeta current_sessId;
1580  static TcpDatLen current_requested_length = 0;
1581  static TcpDatLen current_approved_length = 0;
1582  static bool need_to_request_again = false;
1583 
1584 
1585  //-- LOCAL DATAFLOW VARIABLES ---------------------------------------------
1586  TcpAppSndReq toe_sendReq;
1587 
1588 
1589  switch(wbuState) {
1590  default:
1591  case WBU_WAIT_META:
1592  //wait for meta
1593  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
1594  {
1595  wbuState = WBU_DRAIN;
1596  }
1597  else if(!siWrp_SessId.empty() && !siWrp_len.empty())
1598  {
1599  TcpDatLen new_len = siWrp_len.read();
1600  current_sessId = siWrp_SessId.read();
1601  //original_requested_length = new_len;
1602 
1603  current_requested_length = new_len;
1604  dequeue_cnt = 0;
1605  wbuState = WBU_SND_REQ;
1606  }
1607  break;
1608  case WBU_SND_REQ:
1609  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
1610  {
1611  wbuState = WBU_DRAIN;
1612  }
1613  else if(!soTOE_SndReq.full())
1614  {
1615  toe_sendReq.sessId = current_sessId;
1616  toe_sendReq.length = current_requested_length;
1617  soTOE_SndReq.write(toe_sendReq);
1618  if (DEBUG_LEVEL & TRACE_WRP)
1619  {
1620  printInfo(myName, "Received a data forward request from [NAL/WRP] for sessId=%d and nrBytes=%d (repeating request %d).\n",
1621  toe_sendReq.sessId.to_uint(), toe_sendReq.length.to_uint(), (int) need_to_request_again);
1622  }
1623  wbuState = WBU_WAIT_REP;
1624  }
1625  break;
1626  case WBU_WAIT_REP:
1627  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
1628  {
1629  wbuState = WBU_DRAIN;
1630  }
1631  else if(!siTOE_SndRep.empty())
1632  {
1633  //-- Read the request-to-send reply and continue accordingly
1634  TcpAppSndRep appSndRep = siTOE_SndRep.read();
1635  switch (appSndRep.error) {
1636  case NO_ERROR:
1637  wbuState = WBU_STREAM;
1638  current_approved_length = current_requested_length; //not spaceLeft(!), because this could be bigger!
1639  need_to_request_again = false;
1640  dequeue_cnt = 0;
1641  break;
1642  case NO_SPACE:
1643  printWarn(myName, "Not enough space for writing %d bytes in the Tx buffer of session #%d. Available space is %d bytes.\n",
1644  appSndRep.length.to_uint(), appSndRep.sessId.to_uint(), appSndRep.spaceLeft.to_uint());
1645 
1646  dequeue_cnt = 0;
1647  current_approved_length = appSndRep.spaceLeft - 7; //with "security margin" (so that the length is correct if tkeep is not 0xff for the last word)
1648  need_to_request_again = true;
1649 
1650  wbuState = WBU_STREAM;
1651  break;
1652  case NO_CONNECTION:
1653  printWarn(myName, "Attempt to write data for a session that is not established.\n");
1654  //since this is after the WRP, this should never happen
1655  wbuState = WBU_DROP;
1656  dequeue_cnt = current_requested_length;
1657  //TODO: write internal event?
1658  //TODO: or ignore it, because WRP ensures this should not happen?
1659  break;
1660  default:
1661  printWarn(myName, "Received unknown TCP request to send reply from [TOE].\n");
1662  wbuState = WBU_DROP;
1663  dequeue_cnt = current_requested_length;
1664  //TODO: write internal event?
1665  //TODO: or ignore it, because WRP ensures this should not happen?
1666  break;
1667  }
1668  }
1669  break;
1670  case WBU_STREAM:
1671  //dequeue data
1672  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
1673  {
1674  wbuState = WBU_DRAIN;
1675  }
1676  else if(!soTOE_Data.full() && !siWrp_Data.empty() )
1677  {
1678  TcpAppData tmp = siWrp_Data.read();
1679  dequeue_cnt += extractByteCnt(tmp);
1680  if(dequeue_cnt >= current_approved_length)
1681  {
1682  tmp.setTLast(1); //to be sure
1683  if(need_to_request_again)
1684  {
1685  current_requested_length -= dequeue_cnt;
1686  wbuState = WBU_SND_REQ;
1687  } else {
1688  //done
1689  wbuState = WBU_WAIT_META;
1690  printInfo(myName, "Done with packet (#%d, %d)\n",
1691  current_sessId.to_uint(), current_requested_length.to_uint());
1692  }
1693  } else {
1694  tmp.setTLast(0); //to be sure
1695  }
1696  soTOE_Data.write(tmp);
1697  }
1698  break;
1699  case WBU_DROP:
1700  //TODO: delete, because WRP ensures this should not happen?
1701  if(!siWrp_Data.empty())
1702  {
1703  TcpAppData tmp = siWrp_Data.read();
1704  if(tmp.getTLast() == 1)
1705  {
1706  //dequeue_cnt = 0;
1707  wbuState = WBU_WAIT_META;
1708  } else {
1709  dequeue_cnt -= extractByteCnt(tmp);
1710  if(dequeue_cnt == 0)
1711  {
1712  wbuState = WBU_WAIT_META;
1713  }
1714  }
1715  }
1716  break;
1717  case WBU_DRAIN:
1718  //drain all streams as long as NTS disabled
1719  if(*layer_4_enabled == 0 || *piNTS_ready == 0)
1720  {
1721  if(!siWrp_Data.empty())
1722  {
1723  siWrp_Data.read();
1724  }
1725  if(!siWrp_SessId.empty())
1726  {
1727  siWrp_SessId.read();
1728  }
1729  if(!siWrp_len.empty())
1730  {
1731  siWrp_len.read();
1732  }
1733  } else {
1734  wbuState = WBU_WAIT_META;
1735  }
1736  break;
1737  } //switch
1738 }
1739 
1740 
1741 
1751 void pTcpCOn(
1752  stream<TcpAppOpnReq> &soTOE_OpnReq,
1753  stream<TcpAppOpnRep> &siTOE_OpnRep,
1754  stream<NalNewTableEntry> &sAddNewTriple_TcpCon,
1755  stream<NalTriple> &sNewTcpCon_Req,
1756  stream<NalNewTcpConRep> &sNewTcpCon_Rep
1757  )
1758 {
1759  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
1760 #pragma HLS INLINE off
1761 #pragma HLS pipeline II=1
1762 
1763 
1764  char *myName = concat3(THIS_NAME, "/", "Tcp_COn");
1765 
1766 
1767  //-- STATIC CONTROL VARIABLES (with RESET) --------------------------------
1768  static OpnFsmStates opnFsmState = OPN_IDLE;
1769  // Set a startup delay long enough to account for the initialization
1770  // of TOE's listen port table which takes 32,768 cycles after reset.
1771  // [FIXME - StartupDelay must be replaced by a piSHELL_Reday signal]
1772 #ifdef __SYNTHESIS_
1773  static ap_uint<16> startupDelay = 0x8000;
1774 #else
1775  static ap_uint<16> startupDelay = 30;
1776 #endif
1777 
1778 #pragma HLS RESET variable=opnFsmState
1779 #pragma HLS RESET variable=startupDelay
1780  //-- STATIC DATAFLOW VARIABLES --------------------------------------------
1781  static ap_uint<32> watchDogTimer_pcon = 0;
1782  static TcpAppOpnReq HostSockAddr; // Socket Address stored in LITTLE-ENDIAN ORDER
1783  static NalTriple triple_for_new_connection = 0x0;
1784 
1785  //-- LOCAL DATAFLOW VARIABLES ---------------------------------------------
1786  TcpAppOpnRep newConn;
1787 
1788 
1789  switch (opnFsmState)
1790  {
1791 
1792  case OPN_IDLE:
1793  if (startupDelay > 0)
1794  {
1795  startupDelay--;
1796  //Drain any potential status data
1797  //TODO?
1798  //if (!siTOE_OpnRep.empty())
1799  //{
1800  // siTOE_OpnRep.read(newConn);
1801  // //printInfo(myName, "Requesting to close sessionId=%d.\n", newConn.sessId.to_uint());
1802  // //soTOE_ClsReq.write(newConn.sessId);
1803  //}
1804  } else {
1805  opnFsmState = OPN_REQ;
1806  }
1807  break;
1808 
1809  case OPN_REQ:
1810  if (!sNewTcpCon_Req.empty() && !soTOE_OpnReq.full())
1811  {
1812  triple_for_new_connection = sNewTcpCon_Req.read();
1813  Ip4Addr remoteIp = getRemoteIpAddrFromTriple(triple_for_new_connection);
1814  TcpPort remotePort = getRemotePortFromTriple(triple_for_new_connection);
1815 
1816  SockAddr hostSockAddr(remoteIp, remotePort);
1817  HostSockAddr.addr = hostSockAddr.addr;
1818  HostSockAddr.port = hostSockAddr.port;
1819  soTOE_OpnReq.write(HostSockAddr);
1820  if (DEBUG_LEVEL & TRACE_CON) {
1821  printInfo(myName, "Client is requesting to connect to remote socket:\n");
1822  printSockAddr(myName, HostSockAddr);
1823  }
1824 #ifndef __SYNTHESIS__
1825  watchDogTimer_pcon = 10;
1826 #else
1827  watchDogTimer_pcon = NAL_CONNECTION_TIMEOUT;
1828 #endif
1829  opnFsmState = OPN_REP;
1830  }
1831  break;
1832 
1833  case OPN_REP:
1834  if(!sAddNewTriple_TcpCon.full() && !sNewTcpCon_Rep.full())
1835  {
1836  watchDogTimer_pcon--;
1837  if (!siTOE_OpnRep.empty())
1838  {
1839  // Read the reply stream
1840  siTOE_OpnRep.read(newConn);
1841  if (newConn.tcpState == ESTABLISHED) {
1842  if (DEBUG_LEVEL & TRACE_CON) {
1843  printInfo(myName, "Client successfully connected to remote socket:\n");
1844  printSockAddr(myName, HostSockAddr);
1845  }
1846  NalNewTableEntry ne_struct = NalNewTableEntry(triple_for_new_connection, newConn.sessId);
1847  sAddNewTriple_TcpCon.write(ne_struct);
1848  opnFsmState = OPN_DONE;
1849  NalNewTcpConRep con_rep = NalNewTcpConRep(triple_for_new_connection, newConn.sessId, false);
1850  sNewTcpCon_Rep.write(con_rep);
1851  }
1852  else {
1853  printError(myName, "Client failed to connect to remote socket:\n");
1854  printSockAddr(myName, HostSockAddr);
1855  opnFsmState = OPN_DONE;
1856  NalNewTcpConRep con_rep = NalNewTcpConRep(triple_for_new_connection, UNUSED_SESSION_ENTRY_VALUE, true);
1857  sNewTcpCon_Rep.write(con_rep);
1858  }
1859  }
1860  else {
1861  if (watchDogTimer_pcon == 0) {
1862  if (DEBUG_LEVEL & TRACE_CON) {
1863  printError(myName, "Timeout: Failed to connect to the following remote socket:\n");
1864  printSockAddr(myName, HostSockAddr);
1865  }
1866  //the packet will be dropped, so we are done
1867  opnFsmState = OPN_DONE;
1868  NalNewTcpConRep con_rep = NalNewTcpConRep(triple_for_new_connection, UNUSED_SESSION_ENTRY_VALUE, true);
1869  sNewTcpCon_Rep.write(con_rep);
1870  }
1871 
1872  }
1873  }
1874  break;
1875  case OPN_DONE:
1876  //No need to wait...
1877  opnFsmState = OPN_REQ;
1878  break;
1879  } //switch
1880 }
1881 
1882 
1892 void pTcpCls(
1893  stream<TcpAppClsReq> &soTOE_ClsReq,
1894  stream<bool> &sGetNextDelRow_Req,
1895  stream<SessionId> &sGetNextDelRow_Rep,
1896  stream<bool> &sStartTclCls
1897  )
1898 {
1899  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
1900 #pragma HLS INLINE off
1901 #pragma HLS pipeline II=1
1902 
1903 
1904  char *myName = concat3(THIS_NAME, "/", "Tcp_Cls");
1905 
1906 
1907  //-- STATIC CONTROL VARIABLES (with RESET) --------------------------------
1908  static ClsFsmStates clsFsmState_Tcp = CLS_IDLE;
1909 
1910 #pragma HLS RESET variable=clsFsmState_Tcp
1911  //-- STATIC DATAFLOW VARIABLES --------------------------------------------
1912 
1913 
1914  switch (clsFsmState_Tcp) {
1915  default:
1916  case CLS_IDLE:
1917  //we wait until we are activated;
1918  if(!sStartTclCls.empty())
1919  {
1920  if(sStartTclCls.read())
1921  {
1922  clsFsmState_Tcp = CLS_NEXT;
1923  }
1924  }
1925  break;
1926  case CLS_NEXT:
1927  if(!sGetNextDelRow_Req.full())
1928  {
1929  sGetNextDelRow_Req.write(true);
1930  clsFsmState_Tcp = CLS_WAIT4RESP;
1931  }
1932  break;
1933  case CLS_WAIT4RESP:
1934  if(!soTOE_ClsReq.full() && !sGetNextDelRow_Rep.empty())
1935  {
1936  SessionId nextToDelete = sGetNextDelRow_Rep.read();
1937  if(nextToDelete != (SessionId) UNUSED_SESSION_ENTRY_VALUE)
1938  {
1939  soTOE_ClsReq.write(nextToDelete);
1940  clsFsmState_Tcp = CLS_NEXT;
1941  } else {
1942  clsFsmState_Tcp = CLS_IDLE;
1943  }
1944  }
1945  break;
1946  }
1947 }
1948 
1949 
1950 
tLast getTLast() const
Definition: AxisRaw.hpp:219
LE_tKeep getLE_TKeep(int leHi=64/8-1, int leLo=0) const
Definition: AxisRaw.hpp:264
LE_tData getLE_TData(int leHi=64 -1, int leLo=0) const
Definition: AxisRaw.hpp:260
LE_tLast getLE_TLast() const
Definition: AxisRaw.hpp:268
Ip4Addr addr
Definition: nts_types.hpp:209
Ly4Port port
Definition: nts_types.hpp:210
SessionId sessionID
Definition: nts.hpp:89
Ip4Addr ip4SrcAddr
Definition: nts.hpp:91
TcpPort tcpDstPort
Definition: nts.hpp:93
TcpDatLen tcpDatLen
Definition: nts.hpp:90
TcpPort tcpSrcPort
Definition: nts.hpp:92
TcpState tcpState
Definition: nts.hpp:94
SessionId sessId
Definition: nts.hpp:167
TcpState tcpState
Definition: nts.hpp:168
TcpDatLen length
Definition: nts.hpp:117
SessionId sessionID
Definition: nts.hpp:116
TcpDatLen spaceLeft
Definition: nts.hpp:144
SessionId sessId
Definition: nts.hpp:142
TcpAppSndErr error
Definition: nts.hpp:145
TcpDatLen length
Definition: nts.hpp:143
TcpDatLen length
Definition: nts.hpp:130
SessionId sessId
Definition: nts.hpp:129
ap_uint< 1 > layer_7_enabled
Definition: tb_fmc.cpp:68
ap_uint< 1 > layer_4_enabled
Definition: tb_fmc.cpp:66
#define TRACE_CON
Definition: nal.hpp:120
#define UNUSED_SESSION_ENTRY_VALUE
Definition: nal.hpp:202
NalTriple newTriple(Ip4Addr ipRemoteAddres, TcpPort tcpRemotePort, TcpPort tcpLocalPort)
Definition: nal.cpp:62
RrhEnqFsmStates
Definition: nal.hpp:150
OpnFsmStates
Definition: nal.hpp:144
LsnFsmStates
Definition: nal.hpp:146
void pFmcTcpRxDeq(stream< NetworkWord > &sFmcTcpDataRx_buffer, stream< TcpSessId > &sFmcTcpMetaRx_buffer, stream< NetworkWord > &soFmc_data, stream< TcpSessId > &soFmc_meta, stream< PacketLen > &fmc_write_cnt_sig)
Terminates the internal TCP RX FIFOs and forwards packets to the FMC.
Definition: tss.cpp:1012
DeqFsmStates
Definition: nal.hpp:164
void pTcpLsn(stream< TcpAppLsnReq > &soTOE_LsnReq, stream< TcpAppLsnRep > &siTOE_LsnRep, stream< TcpPort > &sTcpPortsToOpen, stream< bool > &sTcpPortsOpenFeedback)
Request the TOE to start listening (LSn) for incoming connections on a specific port (....
Definition: tss.cpp:53
void pTcpWRp(ap_uint< 1 > *layer_4_enabled, ap_uint< 1 > *piNTS_ready, stream< NetworkWord > &siFMC_data, stream< TcpSessId > &siFMC_SessId, stream< NetworkWord > &siTcp_data, stream< NetworkMetaStream > &siTcp_meta, stream< TcpAppData > &soTOE_Data, stream< TcpAppMeta > &soTOE_SessId, stream< TcpDatLen > &soTOE_len, stream< NodeId > &sGetIpReq_TcpTx, stream< Ip4Addr > &sGetIpRep_TcpTx, stream< NalTriple > &sGetSidFromTriple_Req, stream< SessionId > &sGetSidFromTriple_Rep, stream< NalTriple > &sNewTcpCon_Req, stream< NalNewTcpConRep > &sNewTcpCon_Rep, stream< bool > &cache_inval_sig, stream< NalEventNotif > &internal_event_fifo)
Write Path (WRp) - From ROLE or FMC to TOE. Process waits for a new data segment to write and forward...
Definition: tss.cpp:1104
RrhFsmStates
Definition: nal.hpp:148
RdpFsmStates
Definition: nal.hpp:152
WbuFsmStates
Definition: nal.hpp:158
void pTcpCOn(stream< TcpAppOpnReq > &soTOE_OpnReq, stream< TcpAppOpnRep > &siTOE_OpnRep, stream< NalNewTableEntry > &sAddNewTriple_TcpCon, stream< NalTriple > &sNewTcpCon_Req, stream< NalNewTcpConRep > &sNewTcpCon_Rep)
Client connection to remote HOST or FPGA socket (COn).
Definition: tss.cpp:1751
#define UNUSED_TABLE_ENTRY_VALUE
Definition: nal.hpp:201
void pTcpRxNotifEnq(ap_uint< 1 > *layer_4_enabled, ap_uint< 1 > *piNTS_ready, stream< TcpAppNotif > &siTOE_Notif, stream< TcpAppNotif > &sTcpNotif_buffer)
Enqueus the incoming notificiations from TOE into the internal buffer.
Definition: tss.cpp:152
#define DEFAULT_RX_PORT
Definition: nal.hpp:139
ap_uint< 16 > PacketLen
Definition: nal.hpp:260
ClsFsmStates
Definition: nal.hpp:162
uint8_t extractByteCnt(AxisRaw currWord)
Definition: nal.cpp:94
ap_uint< 64 > NalTriple
Definition: nal.hpp:273
TcpPort getLocalPortFromTriple(NalTriple triple)
Definition: nal.cpp:86
#define THIS_NAME
Definition: nal.hpp:113
void pTcpWBu(ap_uint< 1 > *layer_4_enabled, ap_uint< 1 > *piNTS_ready, stream< TcpAppData > &siWrp_Data, stream< TcpAppMeta > &siWrp_SessId, stream< TcpDatLen > &siWrp_len, stream< TcpAppData > &soTOE_Data, stream< TcpAppSndReq > &soTOE_SndReq, stream< TcpAppSndRep > &siTOE_SndRep)
Write Buffer (WBu) - From WRp to TOE. Process to synchronize with TOE's TX buffer (and it's available...
Definition: tss.cpp:1552
void pRoleTcpRxDeq(ap_uint< 1 > *layer_7_enabled, ap_uint< 1 > *role_decoupled, stream< NetworkWord > &sRoleTcpDataRx_buffer, stream< NetworkMetaStream > &sRoleTcpMetaRx_buffer, stream< NetworkWord > &soTcp_data, stream< NetworkMetaStream > &soTcp_meta, stream< PacketLen > &role_write_cnt_sig)
Terminates the internal TCP RX FIFOs and forwards packets to the Role.
Definition: tss.cpp:929
Ip4Addr getRemoteIpAddrFromTriple(NalTriple triple)
Definition: nal.cpp:70
void pTcpRRh(ap_uint< 1 > *layer_4_enabled, ap_uint< 1 > *piNTS_ready, ap_uint< 32 > *piMMIO_CfrmIp4Addr, ap_uint< 16 > *piMMIO_FmcLsnPort, stream< TcpAppNotif > &siTOE_Notif, stream< TcpAppRdReq > &soTOE_DReq, stream< NalNewTableEntry > &sAddNewTriple_TcpRrh, stream< SessionId > &sMarkAsPriv, stream< SessionId > &sDeleteEntryBySid, stream< TcpAppRdReq > &sRDp_ReqNotif, stream< PacketLen > &fmc_write_cnt_sig, stream< PacketLen > &role_write_cnt_sig)
ReadRequestHandler (RRh). Waits for a notification indicating the availability of new data for the RO...
Definition: tss.cpp:219
void pTcpCls(stream< TcpAppClsReq > &soTOE_ClsReq, stream< bool > &sGetNextDelRow_Req, stream< SessionId > &sGetNextDelRow_Rep, stream< bool > &sStartTclCls)
Asks the TOE to close Tcp connections, based on the request from pPortLogic.
Definition: tss.cpp:1892
TcpPort getRemotePortFromTriple(NalTriple triple)
Definition: nal.cpp:78
#define NAL_CONNECTION_TIMEOUT
Definition: nal.hpp:196
ap_uint< 1 > role_decoupled
Definition: tb_nal.cpp:134
#define DEBUG_LEVEL
Definition: nal.hpp:123
#define NAL_CONFIG_OWN_RANK
Definition: nal.hpp:215
#define TRACE_LSN
Definition: nal.hpp:119
#define MAX_NAL_SESSIONS
Definition: nal.hpp:186
void pTcpRDp(ap_uint< 1 > *layer_4_enabled, ap_uint< 1 > *piNTS_ready, stream< TcpAppRdReq > &sRDp_ReqNotif, stream< TcpAppData > &siTOE_Data, stream< TcpAppMeta > &siTOE_SessId, stream< NetworkWord > &soFMC_data, stream< TcpSessId > &soFMC_SessId, stream< NetworkWord > &soTcp_data, stream< NetworkMetaStream > &soTcp_meta, stream< NalConfigUpdate > &sConfigUpdate, stream< Ip4Addr > &sGetNidReq_TcpRx, stream< NodeId > &sGetNidRep_TcpRx, stream< SessionId > &sGetTripleFromSid_Req, stream< NalTriple > &sGetTripleFromSid_Rep, ap_uint< 32 > *piMMIO_CfrmIp4Addr, ap_uint< 16 > *piMMIO_FmcLsnPort, ap_uint< 1 > *layer_7_enabled, ap_uint< 1 > *role_decoupled, stream< bool > &cache_inval_sig, stream< NalEventNotif > &internal_event_fifo)
Read Path (RDp) - From TOE to ROLE or FMC. Process waits for a new data segment to read and forwards ...
Definition: tss.cpp:581
#define NAL_MAX_FIFO_DEPTHS_BYTES
Definition: nal.hpp:190
#define NAL_STREAMING_SPLIT_TCP
Definition: nal.hpp:187
#define TRACE_WRP
Definition: nal.hpp:117
WrpFsmStates
Definition: nal.hpp:155
#define INVALID_MRT_VALUE
Definition: nal.hpp:203
@ RRH_ENQ_STREAM
Definition: nal.hpp:150
@ RRH_ENQ_RESET
Definition: nal.hpp:150
@ OPN_DONE
Definition: nal.hpp:144
@ OPN_REP
Definition: nal.hpp:144
@ OPN_REQ
Definition: nal.hpp:144
@ OPN_IDLE
Definition: nal.hpp:144
@ LSN_IDLE
Definition: nal.hpp:146
@ LSN_SEND_REQ
Definition: nal.hpp:146
@ LSN_WAIT_ACK
Definition: nal.hpp:146
@ DEQ_WAIT_META
Definition: nal.hpp:164
@ DEQ_STREAM_DATA
Definition: nal.hpp:164
@ DEQ_SEND_NOTIF
Definition: nal.hpp:164
@ RRH_DRAIN
Definition: nal.hpp:148
@ RRH_WAIT_FMC
Definition: nal.hpp:148
@ RRH_WAIT_NOTIF
Definition: nal.hpp:148
@ RRH_START_REQUEST
Definition: nal.hpp:148
@ RRH_PROCESS_NOTIF
Definition: nal.hpp:148
@ RRH_WAIT_ROLE
Definition: nal.hpp:148
@ RRH_RESET
Definition: nal.hpp:148
@ RRH_PROCESS_REQUEST
Definition: nal.hpp:148
@ RDP_STREAM_FMC
Definition: nal.hpp:152
@ RDP_RESET
Definition: nal.hpp:152
@ RDP_STREAM_ROLE
Definition: nal.hpp:152
@ RDP_W8FORREQS_1
Definition: nal.hpp:152
@ RDP_DROP_PACKET
Definition: nal.hpp:153
@ RDP_WAIT_META
Definition: nal.hpp:152
@ RDP_W8FORREQS_2
Definition: nal.hpp:152
@ RDP_FILTER_META
Definition: nal.hpp:152
@ WBU_SND_REQ
Definition: nal.hpp:158
@ WBU_DRAIN
Definition: nal.hpp:158
@ WBU_DROP
Definition: nal.hpp:158
@ WBU_WAIT_META
Definition: nal.hpp:158
@ WBU_STREAM
Definition: nal.hpp:158
@ WBU_WAIT_REP
Definition: nal.hpp:158
@ CLS_WAIT4RESP
Definition: nal.hpp:162
@ CLS_IDLE
Definition: nal.hpp:162
@ CLS_NEXT
Definition: nal.hpp:162
@ LAST_TX_PORT
Definition: nal.hpp:182
@ NID_MISS_RX
Definition: nal.hpp:181
@ PCOR_TX
Definition: nal.hpp:181
@ PACKET_TX
Definition: nal.hpp:182
@ AUTH_ACCESS
Definition: nal.hpp:183
@ FMC_TCP_BYTES
Definition: nal.hpp:183
@ LAST_TX_NID
Definition: nal.hpp:182
@ PACKET_RX
Definition: nal.hpp:182
@ TCP_CON_FAIL
Definition: nal.hpp:181
@ NID_MISS_TX
Definition: nal.hpp:181
@ UNAUTH_ACCESS
Definition: nal.hpp:182
@ LAST_RX_PORT
Definition: nal.hpp:181
@ LAST_RX_NID
Definition: nal.hpp:182
@ WRP_WAIT_CONNECTION
Definition: nal.hpp:155
@ WRP_WAIT_META
Definition: nal.hpp:155
@ WRP_W8FORREQS_2
Definition: nal.hpp:155
@ WRP_RESET
Definition: nal.hpp:155
@ WRP_W8FORREQS_11
Definition: nal.hpp:155
@ WRP_STREAM_FMC
Definition: nal.hpp:155
@ WRP_DROP_PACKET
Definition: nal.hpp:156
@ WRP_W8FORREQS_1
Definition: nal.hpp:155
@ WRP_W8FORREQS_22
Definition: nal.hpp:155
@ WRP_STREAM_ROLE
Definition: nal.hpp:156
ap_uint< 16 > SessionId
Definition: nts_types.hpp:136
#define printError(callerName, format,...)
A macro to print an error message.
Definition: nts_utils.hpp:195
AxisRaw TcpAppData
Definition: nts.hpp:68
ap_uint< 32 > Ip4Addr
Definition: AxisIp4.hpp:169
void printSockAddr(const char *callerName, SockAddr sockAddr)
Print a socket address.
Definition: nts_utils.cpp:174
TcpPort TcpAppLsnReq
Definition: nts.hpp:190
ap_uint< 16 > TcpPort
Definition: AxisTcp.hpp:105
ap_uint< 16 > TcpDatLen
Definition: AxisTcp.hpp:123
#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
#define concat3(firstCharConst, secondCharConst, thirdCharConst)
Definition: nts_utils.hpp:161
TcpSessId TcpAppMeta
Definition: nts.hpp:74
ap_uint< 16 > TcpSessId
Definition: nts_types.hpp:137
@ LAST_ACK
Definition: nts_types.hpp:298
@ FIN_WAIT_2
Definition: nts_types.hpp:297
@ FIN_WAIT_1
Definition: nts_types.hpp:297
@ TIME_WAIT
Definition: nts_types.hpp:297
@ ESTABLISHED
Definition: nts_types.hpp:296
@ CLOSING
Definition: nts_types.hpp:297
@ CLOSED
Definition: nts_types.hpp:296
@ NO_ERROR
Definition: nts_types.hpp:304
@ NO_CONNECTION
Definition: nts_types.hpp:304
@ NO_SPACE
Definition: nts_types.hpp:304
: The cloudFPGA Network Abstraction Layer (NAL) between NTS and ROlE. The NAL core manages the NTS St...
ap_uint< 8 > NodeId
Definition: network.hpp:82
ap_uint< 16 > NrcPort
Definition: network.hpp:81
ap_uint< 16 > NetworkDataLength
Definition: network.hpp:92
#define MAX_CF_NODE_ID
Definition: network.hpp:85
TcpSessId AppMeta
Definition: cam8.hpp:59
bool update(K key, V value)
Search the CAM array for a key and updates the corresponding value.
Definition: cam8.hpp:243
bool lookup(K key, V &value)
Search the CAM array for a key.
Definition: cam8.hpp:89
bool deleteEntry(K key)
Remove a key-value pair from the CAM array.
Definition: cam8.hpp:297
bool insert(KeyValuePair< K, V > kVP)
Insert a new key-value pair in the CAM array.
Definition: cam8.hpp:187
void reset()
Invalidate all entries of the CAM array.
Definition: cam8.hpp:343
ap_uint< 16 > config_addr
Definition: nal.hpp:291
ap_uint< 32 > update_value
Definition: nal.hpp:292
NalTriple new_triple
Definition: nal.hpp:283
SessionId newSessionId
Definition: nal.hpp:284
bool failure
Definition: nal.hpp:285
bool fmc_con
Definition: nal.hpp:320
SessionId sessId
Definition: nal.hpp:319
NetworkMeta tdata
Definition: network.hpp:109
NetworkDataLength len
Definition: network.hpp:99
NodeId dst_rank
Definition: network.hpp:95
NrcPort src_port
Definition: network.hpp:98
NrcPort dst_port
Definition: network.hpp:96
ap_uint< 64 > tdata
Definition: network.hpp:49
ap_uint< 8 > tkeep
Definition: network.hpp:50
ap_uint< 1 > tlast
Definition: network.hpp:51
: The TCP Sub System (TSS) of the NAL core.