cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
test_upper_lower_app.cpp
Go to the documentation of this file.
1 
17 
27 #include <stdio.h>
28 #include <hls_stream.h>
29 
30 #include "../src/upper_lower_app.hpp"
31 
32 using namespace std;
33 
34 
35 #define OK true
36 #define KO false
37 #define VALID true
38 #define UNVALID false
39 #define DEBUG_TRACE true
40 
41 #define ENABLED (ap_uint<1>)1
42 #define DISABLED (ap_uint<1>)0
43 
44 //------------------------------------------------------
45 //-- DUT INTERFACES AS GLOBAL VARIABLES
46 //------------------------------------------------------
47 
48 //-- SHELL / Uaf / Mmio / Config Interfaces
49 //ap_uint<2> piSHL_This_MmioEchoCtrl;
52 
53 //-- SHELL / Uaf / Udp Interfaces
54 stream<UdpWord> sSHL_Uaf_Data ("sSHL_Uaf_Data");
55 stream<UdpWord> sUAF_Shl_Data ("sUAF_Shl_Data");
56 ap_uint<32> s_udp_rx_ports = 0x0;
57 stream<NetworkMetaStream> siUdp_meta ("siUdp_meta");
58 stream<NetworkMetaStream> soUdp_meta ("soUdp_meta");
59 ap_uint<32> node_rank;
60 ap_uint<32> cluster_size;
61 
62 //------------------------------------------------------
63 //-- TESTBENCH GLOBAL VARIABLES
64 //------------------------------------------------------
65 int simCnt;
66 
67 
68 
73 void stepDut() {
79  simCnt++;
80  printf("[%4.4d] STEP DUT \n", simCnt);
81 }
82 
83 
92 bool setInputDataStream(stream<UdpWord> &sDataStream, const string dataStreamName, const string inpFileName) {
93  string strLine;
94  ifstream inpFileStream;
95  string datFile = "../../../../test/" + inpFileName;
96  UdpWord udpWord;
97 
98  //-- STEP-1 : OPEN FILE
99  inpFileStream.open(datFile.c_str());
100  if ( !inpFileStream ) {
101  cout << "### ERROR : Could not open the input data file " << datFile << endl;
102  return(KO);
103  }
104 
105  //-- STEP-2 : SET DATA STREAM
106  while (inpFileStream) {
107 
108  if (!inpFileStream.eof()) {
109 
110  getline(inpFileStream, strLine);
111  if (strLine.empty()) continue;
112  sscanf(strLine.c_str(), "%llx %x %d", &udpWord.tdata, &udpWord.tkeep, &udpWord.tlast);
113 
114  // Write to sDataStream
115  if (sDataStream.full()) {
116  printf("### ERROR : Stream is full. Cannot write stream with data from file \"%s\".\n", inpFileName.c_str());
117  return(KO);
118  } else {
119  sDataStream.write(udpWord);
120  // Print Data to console
121  printf("[%4.4d] TB is filling input stream [%s] - Data write = {D=0x%16.16llX, K=0x%2.2X, L=%d} \n",
122  simCnt, dataStreamName.c_str(),
123  udpWord.tdata.to_long(), udpWord.tkeep.to_int(), udpWord.tlast.to_int());
124  }
125  }
126  }
127 
128  //-- STEP-3: CLOSE FILE
129  inpFileStream.close();
130 
131  return(OK);
132 }
133 
134 
135 
136 
146 bool readDataStream(stream <UdpWord> &sDataStream, UdpWord *udpWord) {
147  // Get the DUT/Data results
148  sDataStream.read(*udpWord);
149  return(VALID);
150 }
151 
152 
153 
161 bool dumpDataToFile(UdpWord *udpWord, ofstream &outFileStream) {
162  if (!outFileStream.is_open()) {
163  printf("### ERROR : Output file stream is not open. \n");
164  return(KO);
165  }
166  outFileStream << hex << noshowbase << setfill('0') << setw(16) << udpWord->tdata.to_uint64();
167  outFileStream << " ";
168  outFileStream << hex << noshowbase << setfill('0') << setw(2) << udpWord->tkeep.to_int();
169  outFileStream << " ";
170  outFileStream << setw(1) << udpWord->tlast.to_int() << "\n";
171  return(OK);
172 }
173 
174 
175 
184 bool getOutputDataStream(stream<UdpWord> &sDataStream,
185  const string dataStreamName, const string outFileName)
186 {
187  string strLine;
188  ofstream outFileStream;
189  string datFile = "../../../../test/" + outFileName;
190  UdpWord udpWord;
191  bool rc = OK;
192 
193  //-- STEP-1 : OPEN FILE
194  outFileStream.open(datFile.c_str());
195  if ( !outFileStream ) {
196  cout << "### ERROR : Could not open the output data file " << datFile << endl;
197  return(KO);
198  }
199 
200  //-- STEP-2 : EMPTY STREAM AND DUMP DATA TO FILE
201  while (!sDataStream.empty()) {
202  if (readDataStream(sDataStream, &udpWord) == VALID) {
203  // Print DUT/Data to console
204  printf("[%4.4d] TB is draining output stream [%s] - Data read = {D=0x%16.16llX, K=0x%2.2X, L=%d} \n",
205  simCnt, dataStreamName.c_str(),
206  udpWord.tdata.to_long(), udpWord.tkeep.to_int(), udpWord.tlast.to_int());
207  if (!dumpDataToFile(&udpWord, outFileStream)) {
208  rc = KO;
209  break;
210  }
211  }
212  }
213 
214  //-- STEP-3: CLOSE FILE
215  outFileStream.close();
216 
217  return(rc);
218 }
219 
220 
221 int main() {
222 
223  //------------------------------------------------------
224  //-- TESTBENCH LOCAL VARIABLES
225  //------------------------------------------------------
226  int nrErr = 0;
227 
228  printf("#####################################################\n");
229  printf("## TESTBENCH STARTS HERE ##\n");
230  printf("#####################################################\n");
231 
232  simCnt = 0;
233  nrErr = 0;
234 
235  //------------------------------------------------------
236  //-- STEP-1.1 : CREATE TRAFFIC AS INPUT STREAMS
237  //------------------------------------------------------
238  if (nrErr == 0) {
239  if (!setInputDataStream(sSHL_Uaf_Data, "sSHL_Uaf_Data", "ifsSHL_Uaf_Data.dat")) {
240  printf("### ERROR : Failed to set input data stream \"sSHL_Uaf_Data\". \n");
241  nrErr++;
242  }
243 
244  //there are 2 streams from the the App to the Role
246  siUdp_meta.write(NetworkMetaStream(tmp_meta));
247  siUdp_meta.write(NetworkMetaStream(tmp_meta));
248  //set correct node_rank and cluster_size
249  node_rank = 1;
250  cluster_size = 3;
251  }
252 
253  //------------------------------------------------------
254  //-- STEP-1.2 : SET THE PASS-THROUGH MODE
255  //------------------------------------------------------
256  //piSHL_This_MmioEchoCtrl.write(ECHO_PATH_THRU);
257  //[TODO] piSHL_This_MmioPostPktEn.write(DISABLED);
258  //[TODO] piSHL_This_MmioCaptPktEn.write(DISABLED);
259 
260  //------------------------------------------------------
261  //-- STEP-2 : MAIN TRAFFIC LOOP
262  //------------------------------------------------------
263  while (!nrErr) {
264 
265  if (simCnt < 25)
266  {
267  stepDut();
268 
269  if(simCnt > 2)
270  {
271  assert(s_udp_rx_ports == 0x1);
272  }
273 
274  //if( !soUdp_meta.empty())
275  //{
276  // NetworkMetaStream tmp_meta = soUdp_meta.read();
277  // printf("NRC received NRCmeta stream from node_rank %d.\n", (int) tmp_meta.tdata.src_rank);
278  //}
279 
280 
281  } else {
282  printf("## End of simulation at cycle=%3d. \n", simCnt);
283  break;
284  }
285 
286  } // End: while()
287 
288  //-------------------------------------------------------
289  //-- STEP-3 : DRAIN AND WRITE OUTPUT FILE STREAMS
290  //-------------------------------------------------------
291  //---- UAF-->SHELL Data ----
292  if (!getOutputDataStream(sUAF_Shl_Data, "sUAF_Shl_Data", "ofsUAF_Shl_Data.dat"))
293  {
294  nrErr++;
295  }
296  //---- UAF-->SHELL META ----
297  if( !soUdp_meta.empty())
298  {
299  int i = 0;
300  while( !soUdp_meta.empty())
301  {
302  i++;
303  NetworkMetaStream tmp_meta = soUdp_meta.read();
304  printf("NRC received NRCmeta stream to rank %d.\n", (int) tmp_meta.tdata.dst_rank);
305  //assert(tmp_meta.tdata.src_rank == node_rank); //is not relevant
306  //ensure forwarding behavior
307  assert(tmp_meta.tdata.dst_rank == ((node_rank + 1) % cluster_size));
308  }
309  assert(i == 2);
310  } else {
311  printf("Error No metadata received...\n");
312  nrErr++;
313  }
314 
315  //------------------------------------------------------
316  //-- STEP-4 : COMPARE VERIFICATION AND OUTPUT FILE STREAMS
317  //------------------------------------------------------
318  int rc1 = system("diff --brief -w -i -y ../../../../test/ofsUAF_Shl_Data.dat \
319  ../../../../test/verify_UAF_Shl_Data.dat");
320  if (rc1)
321  {
322  printf("## Error : File \'ofsUAF_Shl_Data.dat\' does not match \'verify_UAF_Shl_Data.dat\'.\n");
323  } else {
324  printf("Output data in file \'ofsUAF_Shl_Data.dat\' verified.\n");
325  }
326 
327  nrErr += rc1;
328 
329  printf("#####################################################\n");
330  if (nrErr)
331  printf("## ERROR - TESTBENCH FAILED (RC=%d) !!! ##\n", nrErr);
332  else
333  printf("## SUCCESSFULL END OF TESTBENCH (RC=0) ##\n");
334 
335  printf("#####################################################\n");
336 
337  return(nrErr);
338 }
void stepDut()
Run a single iteration of the DUT model.
Definition: tb_fmc.cpp:115
bool setInputDataStream(stream< UdpAppData > &sDataStream, const string dataStreamName, const string inpFileName)
Initialize an input data stream from a file.
Definition: tb_nal.cpp:214
bool readDataStream(stream< UdpAppData > &sDataStream, UdpAppData *udpWord)
Read data from a stream.
Definition: tb_nal.cpp:395
#define DEFAULT_RX_PORT
Definition: nal.hpp:139
bool dumpDataToFile(UdpAppData *udpWord, ofstream &outFileStream)
Dump a data word to a file.
Definition: tb_nal.cpp:449
bool getOutputDataStream(stream< UdpAppData > &sDataStream, const string dataStreamName, const string outFileName)
Fill an output file with data from an output stream.
Definition: tb_nal.cpp:526
NetworkMeta tdata
Definition: network.hpp:109
NodeId dst_rank
Definition: network.hpp:95
ap_uint< 64 > tdata
ap_uint< 1 > tlast
ap_uint< 8 > tkeep
stream< NetworkMetaStream > siUdp_meta("siUdp_meta")
stream< NetworkMetaStream > soUdp_meta("soUdp_meta")
int simCnt
ap_uint< 1 > piSHL_This_MmioCaptPktEn
ap_uint< 1 > piSHL_This_MmioPostPktEn
stream< UdpWord > sUAF_Shl_Data("sUAF_Shl_Data")
#define OK
#define KO
#define VALID
stream< UdpWord > sSHL_Uaf_Data("sSHL_Uaf_Data")
int main()
ap_uint< 32 > cluster_size
ap_uint< 32 > s_udp_rx_ports
ap_uint< 32 > node_rank
void upper_lower_app(ap_uint< 32 > *pi_rank, ap_uint< 32 > *pi_size, stream< NetworkWord > &siNrc_data, stream< NetworkWord > &soNrc_data, stream< NetworkMetaStream > &siNrc_meta, stream< NetworkMetaStream > &soNrc_meta, ap_uint< 32 > *po_rx_ports)
Main process of the UDP/TCP Triangle Application. This HLS IP receives a packet, invert the case of A...