cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
SimNtsUtils.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016 -- 2021 IBM Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
31 #include "SimNtsUtils.hpp"
32 
33 using namespace std;
34 using namespace hls;
35 
36 
39 #define THIS_NAME "SimNtsUtils"
40 
41 
45 #ifndef __SYNTHESIS__
46 
52 bool isDatFile(string fileName) {
53  if (fileName.find_last_of ( '.' ) != string::npos) {
54  string extension (fileName.substr(fileName.find_last_of ( '.' ) + 1 ) );
55  if (extension != "dat")
56  return false;
57  else
58  return true;
59  }
60  return false;
61 }
62 #endif
63 
64 #ifndef __SYNTHESIS__
65 
72 bool isDottedDecimal(string ipStr) {
73  vector<string> stringVector;
74 
75  stringVector = myTokenizer(ipStr, '.');
76  if (stringVector.size() == 4)
77  return true;
78  else
79  return false;
80 }
81 #endif
82 
83 #ifndef __SYNTHESIS__
84 
90 bool isHexString(string str) {
91  char *pEnd;
92  long int res;
93 
94  if (str == "")
95  return false;
96  res = strtol(str.c_str(), &pEnd, 16);
97  // If string is not '\0' and *pEnd is '\0' on return, the entire string is valid.
98  if (*pEnd == '\0') {
99  if ((str.find("0x") != string::npos) || (str.find("0X") != string::npos))
100  return true;
101  else
102  return false;
103  }
104  else
105  return false;
106 }
107 #endif
108 
109 #ifndef __SYNTHESIS__
110 
117 ap_uint<32> myDottedDecimalIpToUint32(string ipStr) {
118  vector<string> stringVector;
119  ap_uint<32> ip4Uint = 0x00000000;
120  ap_uint<32> octet;
121 
122  stringVector = myTokenizer(ipStr, '.');
123  char * ptr;
124  for (int i=0; i<stringVector.size(); i++) {
125  octet = strtoul(stringVector[i].c_str(), &ptr, 10);
126  ip4Uint |= (octet << 8*(3-i));
127  }
128  return ip4Uint;
129 }
130 #endif
131 
132 #ifndef __SYNTHESIS__
133 
141 vector<string> myTokenizer(string strBuff, char delimiter) {
142  vector<string> tmpBuff;
143  int tokenCounter = 0;
144  bool found = false;
145 
146  if (strBuff.empty()) {
147  tmpBuff.push_back(strBuff);
148  return tmpBuff;
149  }
150  else {
151  // Substitute the "\r" with nothing
152  if (strBuff[strBuff.size() - 1] == '\r')
153  strBuff.erase(strBuff.size() - 1);
154  }
155  // Search for 'delimiter' characters between the different strings
156  while (strBuff.find(delimiter) != string::npos) {
157  // Split the string in two parts
158  string temp = strBuff.substr(0, strBuff.find(delimiter));
159  // Remove first element from 'strBuff'
160  strBuff = strBuff.substr(strBuff.find(delimiter)+1, strBuff.length());
161  // Store the new part into the vector.
162  if (temp != "")
163  tmpBuff.push_back(temp);
164  // Quit if the current line is a comment
165  if ((tokenCounter == 0) && (temp =="#"))
166  break;
167  }
168 
169  // Push the final part of the string into the vector when no more spaces are present.
170  tmpBuff.push_back(strBuff);
171  return tmpBuff;
172 }
173 #endif
174 
175 #ifndef __SYNTHESIS__
176 
182 string myUint64ToStrHex(ap_uint<64> inputNumber) {
183  string outputString = "0000000000000000";
184  unsigned short int tempValue = 16;
185  static const char* const lut = "0123456789ABCDEF";
186 
187  for (int i = 15;i>=0;--i) {
188  tempValue = 0;
189  for (unsigned short int k = 0;k<4;++k) {
190  if (inputNumber.bit((i+1)*4-k-1) == 1)
191  tempValue += static_cast <unsigned short int>(pow(2.0, 3-k));
192  }
193  outputString[15-i] = lut[tempValue];
194  }
195  return outputString;
196 }
197 #endif
198 
199 #ifndef __SYNTHESIS__
200 
206 string myUint8ToStrHex(ap_uint<8> inputNumber) {
207  string outputString = "00";
208  unsigned short int tempValue = 16;
209  static const char* const lut = "0123456789ABCDEF";
210 
211  for (int i = 1;i>=0;--i) {
212  tempValue = 0;
213  for (unsigned short int k = 0; k<4; ++k) {
214  if (inputNumber.bit((i+1)*4-k-1) == 1)
215  tempValue += static_cast <unsigned short int>(pow(2.0, 3-k));
216  }
217  outputString[1-i] = lut[tempValue];
218  }
219  return outputString;
220 }
221 #endif
222 
223 #ifndef __SYNTHESIS__
224 
230 ap_uint<64> myStrHexToUint64(string dataString) {
231  ap_uint<64> tempOutput = 0;
232  unsigned short int tempValue = 16;
233  static const char* const lut = "0123456789ABCDEF";
234 
235  for (unsigned short int i = 0; i<dataString.size(); ++i) {
236  for (unsigned short int j = 0;j<16;++j) {
237  if (lut[j] == toupper(dataString[i])) {
238  tempValue = j;
239  break;
240  }
241  }
242  if (tempValue != 16) {
243  for (short int k = 3; k>=0; --k) {
244  if (tempValue >= pow(2.0, k)) {
245  tempOutput.bit(63-(4*i+(3-k))) = 1;
246  tempValue -= static_cast <unsigned short int>(pow(2.0, k));
247  }
248  }
249  }
250  }
251  return tempOutput;
252 }
253 #endif
254 
255 #ifndef __SYNTHESIS__
256 
262 ap_uint<8> myStrHexToUint8(string keepString) {
263  ap_uint<8> tempOutput = 0;
264  unsigned short int tempValue = 16;
265  static const char* const lut = "0123456789ABCDEF";
266 
267  for (unsigned short int i = 0; i<2;++i) {
268  for (unsigned short int j = 0;j<16;++j) {
269  if (lut[j] == toupper(keepString[i])) {
270  tempValue = j;
271  break;
272  }
273  }
274  if (tempValue != 16) {
275  for (short int k = 3;k>=0;--k) {
276  if (tempValue >= pow(2.0, k)) {
277  tempOutput.bit(7-(4*i+(3-k))) = 1;
278  tempValue -= static_cast <unsigned short int>(pow(2.0, k));
279  }
280  }
281  }
282  }
283  return tempOutput;
284 }
285 #endif
286 
287 #ifndef __SYNTHESIS__
288 
305 int myDiffTwoFiles(string dataFileName, string goldFileName) {
306  ifstream dataFileStream;
307  ifstream goldFileStream;
308  int noLineDiff = 0;
309 
310  //-- OPEN FILES
311  dataFileStream.open(dataFileName.c_str());
312  if (!dataFileStream) {
313  printError(THIS_NAME, "Cannot open the file: \'%s\'.\n", dataFileName.c_str());
314  return(NTS_KO);
315  }
316  goldFileStream.open(goldFileName.c_str());
317  if (!goldFileStream) {
318  printError(THIS_NAME, "Cannot open the file: \'%s\'.\n", goldFileName.c_str());
319  dataFileStream.close();
320  return(NTS_KO);
321  }
322 
323  if ((dataFileStream.peek() != std::ifstream::traits_type::eof()) and
324  (goldFileStream.peek() != std::ifstream::traits_type::eof())) {
325  string goldStrLine;
326  string dataStrLine;
327  while (getline(goldFileStream, goldStrLine)) {
328  if (getline(dataFileStream, dataStrLine)) {
329  if (goldStrLine != dataStrLine) {
330  printWarn(THIS_NAME, "Diff: %s - %s\n", goldStrLine.c_str(), dataStrLine.c_str());
331  noLineDiff++;
332  }
333  }
334  else {
335  printWarn(THIS_NAME, "Diff: %s - %s\n", goldStrLine.c_str(), "No entry found in data file!");
336  noLineDiff++;
337  }
338  }
339  }
340  else if (dataFileStream.peek() == std::ifstream::traits_type::eof()) {
341  string goldStrLine;
342  while (getline(goldFileStream, goldStrLine)) {
343  printWarn(THIS_NAME, "Diff: %s - %s\n", goldStrLine.c_str(), " ");
344  noLineDiff++;
345  }
346  }
347  else if (goldFileStream.peek() == std::ifstream::traits_type::eof()) {
348  string dataStrLine;
349  while (getline(goldFileStream, dataStrLine)) {
350  printWarn(THIS_NAME, "Diff: %s - %s\n", dataStrLine.c_str(), " ");
351  noLineDiff++;
352  }
353  }
354  else {
355  noLineDiff++;
356  }
357  //-- CLOSE FILES
358  dataFileStream.close();
359  goldFileStream.close();
360 
361  return noLineDiff;
362 }
363 #endif
364 
365 
369 #ifndef __SYNTHESIS__
370 
378 bool readAxisRawFromLine(AxisRaw &axisRaw, string stringBuffer) {
379  vector<string> stringVector;
380  stringVector = myTokenizer(stringBuffer, ' ');
381  if (stringVector[0] == "") {
382  return false;
383  }
384  else if (stringVector[0].length() == 1) {
385  // Skip this line as it is either a comment of a command
386  return false;
387  }
388  else if ( (stringVector.size() == 3) or
389  ((stringVector.size() == 4) and (stringVector[3] == "(FORCED_INVALID_TKEEP)")) ) {
390  axisRaw.setLE_TData(myStrHexToUint64(stringVector[0]));
391  axisRaw.setLE_TLast(atoi( stringVector[1].c_str()));
392  axisRaw.setLE_TKeep(myStrHexToUint8( stringVector[2]));
393  if ((stringVector.size() == 3) and (not axisRaw.isValid())) {
394  printError(THIS_NAME, "Failed to read AxisRaw from line \"%s\".\n", stringBuffer.c_str());
395  printFatal(THIS_NAME, "\tFYI - 'tkeep' and 'tlast' are inconsistent...\n");
396  }
397  return true;
398  }
399  else {
400  printError(THIS_NAME, "Failed to read AxisRaw from line \"%s\".\n", stringBuffer.c_str());
401  printFatal(THIS_NAME, "\tFYI - The file might be corrupted...\n");
402  }
403  return false;
404 }
405 #endif
406 
407 #ifndef __SYNTHESIS__
408 
416 bool writeAxisRawToFile(AxisRaw &axisRaw, ofstream &outFileStream) {
417  if (not outFileStream) {
418  printError(THIS_NAME, "File is not opened.\n");
419  return false;
420  }
421  outFileStream << std::uppercase;
422  outFileStream << hex << noshowbase << setfill('0') << setw(16) << axisRaw.getLE_TData().to_uint64();
423  outFileStream << " ";
424  outFileStream << setw(1) << axisRaw.getLE_TLast().to_int();
425  outFileStream << " ";
426  outFileStream << hex << noshowbase << setfill('0') << setw(2) << axisRaw.getLE_TKeep().to_int() << "\n";
427  if (axisRaw.getLE_TLast()) {
428  outFileStream << "\n";
429  }
430  return(true);
431 }
432 #endif
433 
434 #ifndef __SYNTHESIS__
435 
444 int writeAxisAppToFile(AxisApp &axisApp, ofstream &outFile) {
445  int writtenBytes = 0;
446  for (int bytNum=0; bytNum<8; bytNum++) {
447  if (axisApp.getLE_TKeep()[bytNum]) {
448  int hi = ((bytNum*8) + 7);
449  int lo = ((bytNum*8) + 0);
450  ap_uint<8> octet = axisApp.getLE_TData(hi, lo);
451  // Write byte to file
452  outFile << myUint8ToStrHex(octet);
453  writtenBytes++;
454  }
455  }
456  if (axisApp.getTLast()) {
457  outFile << endl;
458  }
459  return writtenBytes;
460 }
461 #endif
462 
463 #ifndef __SYNTHESIS__
464 
475 int writeAxisAppToFile(AxisApp &axisApp, ofstream &outFile, int &wrCount) {
476  int writtenBytes = 0;
477  for (int bytNum=0; bytNum<8; bytNum++) {
478  if (axisApp.getLE_TKeep()[bytNum]) {
479  int hi = ((bytNum*8) + 7);
480  int lo = ((bytNum*8) + 0);
481  ap_uint<8> octet = axisApp.getLE_TData(hi, lo);
482  // Write byte to file
483  outFile << myUint8ToStrHex(octet);
484  writtenBytes++;
485  wrCount++;
486  if (wrCount == ZYC2_MSS) {
487  // Emulate the IP segmentation behavior when writing this
488  // file by appending a newline when mssCounter == MMS
489  outFile << endl;
490  wrCount = 0;
491  }
492  }
493  }
494  if ((axisApp.getTLast()) && (wrCount != 0)) {
495  outFile << endl;
496  wrCount = 0;
497  }
498  return writtenBytes;
499 }
500 #endif
501 
502 #ifndef __SYNTHESIS__
503 
511 bool readFpgaSocketFromLine(SockAddr &fpgaSock, string stringBuffer) {
512  vector<string> stringVector;
513  stringVector = myTokenizer(stringBuffer, ' ');
514  if ((stringVector[0] == ">") and (stringVector[1] == "SET")) {
515  if ((stringVector[2] == "FpgaServerSocket") or
516  (stringVector[2] == "FpgaSocket")) {
517  char *pEnd;
518  // Retrieve the fpga IPv4 address
519  if (isDottedDecimal(stringVector[3])) {
520  fpgaSock.addr = myDottedDecimalIpToUint32(stringVector[3]);
521  }
522  else if (isHexString(stringVector[3])) {
523  fpgaSock.addr = strtoul(stringVector[3].c_str(), &pEnd, 16);
524  }
525  else {
526  fpgaSock.addr = strtoul(stringVector[3].c_str(), &pEnd, 10);
527  }
528  // Retrieve the fpga LY4 port
529  if (isHexString(stringVector[4])) {
530  fpgaSock.port = strtoul(stringVector[4].c_str(), &pEnd, 16);
531  }
532  else {
533  fpgaSock.port = strtoul(stringVector[4].c_str(), &pEnd, 10);
534  }
535  return true;
536  }
537  }
538  return false;
539 }
540 #endif
541 
542 #ifndef __SYNTHESIS__
543 
551 bool readHostSocketFromLine(SockAddr &hostSock, string stringBuffer) {
552  vector<string> stringVector;
553  stringVector = myTokenizer(stringBuffer, ' ');
554  if ((stringVector[0] == ">") and (stringVector[1] == "SET")) {
555  if ((stringVector[2] == "HostServerSocket") or
556  (stringVector[2] == "HostSocket")) {
557  char *pEnd;
558  // Retrieve the host IPv4 address
559  if (isDottedDecimal(stringVector[3])) {
560  hostSock.addr = myDottedDecimalIpToUint32(stringVector[3]);
561  }
562  else if (isHexString(stringVector[3])) {
563  hostSock.addr = strtoul(stringVector[3].c_str(), &pEnd, 16);
564  }
565  else {
566  hostSock.addr = strtoul(stringVector[3].c_str(), &pEnd, 10);
567  }
568  // Retrieve the host LY4 port
569  if (isHexString(stringVector[4])) {
570  hostSock.port = strtoul(stringVector[4].c_str(), &pEnd, 16);
571  }
572  else {
573  hostSock.port = strtoul(stringVector[4].c_str(), &pEnd, 10);
574  }
575  return true;
576  }
577  }
578  return false;
579 }
580 #endif
581 
582 #ifndef __SYNTHESIS__
583 
591 bool readFpgaSndPortFromLine(Ly4Port &port, string stringBuffer) {
592  vector<string> stringVector;
593  stringVector = myTokenizer(stringBuffer, ' ');
594  if ((stringVector[0] == ">") and (stringVector[1] == "SET")) {
595  if (stringVector[2] == "FpgaSndPort") {
596  char *pEnd;
597  // Retrieve the host LY4 port
598  if (isHexString(stringVector[4])) {
599  port = strtoul(stringVector[4].c_str(), &pEnd, 16);
600  }
601  else {
602  port = strtoul(stringVector[4].c_str(), &pEnd, 10);
603  }
604  return true;
605  }
606  }
607  return false;
608 }
609 #endif
610 
611 
615 #ifndef __SYNTHESIS__
616 
624 bool readAxisRawFromFile(AxisRaw &axisRaw, ifstream &inpFileStream) {
625  string stringBuffer;
626  vector<string> stringVector;
627  bool rc = false;
628 
629  if (!inpFileStream.is_open()) {
630  printError(THIS_NAME, "File is not opened.\n");
631  return false;
632  }
633  while (inpFileStream.peek() != EOF) {
634  getline(inpFileStream, stringBuffer);
635  rc = readAxisRawFromLine(axisRaw, stringBuffer);
636  if (rc) {
637  break;
638  }
639  }
640  return rc;
641 }
642 #endif
643 
644 #ifndef __SYNTHESIS__
645 
654 bool readTbParamFromFile(const string paramName, const string datFile,
655  unsigned int &paramVal) {
656  ifstream inpFileStream;
657  char currPath[FILENAME_MAX];
658  string rxStringBuffer;
659  vector<string> stringVector;
660 
661  if (not isDatFile(datFile)) {
662  printError(THIS_NAME, "Input test vector file \'%s\' is not of type \'DAT\'.\n", datFile.c_str());
663  return(NTS_KO);
664  }
665  inpFileStream.open(datFile.c_str());
666  if (!inpFileStream) {
667  getcwd(currPath, sizeof(currPath));
668  printError(THIS_NAME, "Cannot open the file: %s \n\t (FYI - The current working directory is: %s) \n", datFile.c_str(), currPath);
669  return(NTS_KO);
670  }
671 
672  do {
673  //-- READ ONE LINE AT A TIME FROM INPUT FILE ---------------
674  getline(inpFileStream, rxStringBuffer);
675  stringVector = myTokenizer(rxStringBuffer, ' ');
676  if (stringVector[0] == "") {
677  continue;
678  }
679  else if (stringVector[0].length() == 1) {
680  // By convention, a global parameter must start with a single 'G' character.
681  if ((stringVector[0] == "G") && (stringVector[1] == "PARAM")) {
682  if (stringVector[2] == paramName) {
683  char * ptr;
684  if (isDottedDecimal(stringVector[3])) {
685  paramVal = myDottedDecimalIpToUint32(stringVector[3]);
686  }
687  else if (isHexString(stringVector[3])) {
688  paramVal = strtoul(stringVector[3].c_str(), &ptr, 16);
689  }
690  else {
691  paramVal = strtoul(stringVector[3].c_str(), &ptr, 10);
692  }
693  inpFileStream.close();
694  return NTS_OK;
695  }
696  }
697  }
698  } while(!inpFileStream.eof());
699  inpFileStream.close();
700  return NTS_KO;
701 }
702 #endif
703 
704 #ifndef __SYNTHESIS__
705 
714 template <int D> bool writeApUintToFile(ap_uint<D> &data, ofstream &outFileStream) {
715  if (not outFileStream.is_open()) {
716  printError(THIS_NAME, "File is not opened.\n");
717  return false;
718  }
719  outFileStream << std::uppercase;
720  outFileStream << "0x" << hex << noshowbase << setfill('0');
721  switch (D) {
722  case 8:
723  case 16:
724  case 32:
725  case 64:
726  outFileStream << setw(D/4) << data.to_int() << "\n";
727  break;
728  default:
729  printError(THIS_NAME, "Format ap_uint<%d> is not supported.\n", D);
730  return false;
731  }
732  return true;
733 }
734 #endif
735 
736 #ifndef __SYNTHESIS__
737 
745 bool writeSocketPairToFile(SocketPair &socketPair, ofstream &outFileStream) {
746  if (!outFileStream.is_open()) {
747  printError(THIS_NAME, "File is not opened.\n");
748  return false;
749  }
750  outFileStream << std::uppercase;
751  outFileStream << "0x" << hex << noshowbase << setfill('0') << setw(8) << socketPair.src.addr.to_uint();
752  outFileStream << " ";
753  outFileStream << "0x" << hex << noshowbase << setfill('0') << setw(4) << socketPair.src.port.to_ushort();
754  outFileStream << " ";
755  outFileStream << "0x" << hex << noshowbase << setfill('0') << setw(8) << socketPair.dst.addr.to_uint();
756  outFileStream << " ";
757  outFileStream << "0x" << hex << noshowbase << setfill('0') << setw(4) << socketPair.dst.port.to_ushort();
758  outFileStream << "\n";
759  return true;
760 }
761 #endif
762 
763 #ifndef __SYNTHESIS__
764 
776 template <class AXIS_T> bool feedAxisFromFile(stream<AXIS_T> &ss, const string ssName,
777  string datFile, int &nrChunks, int &nrFrames, int &nrBytes) {
778  ifstream inpFileStream;
779  char currPath[FILENAME_MAX];
780  string strLine;
781  int lineCnt=0;
782  AxisRaw axisRaw;
783  bool rc=false;
784 
785  //-- STEP-1 : OPEN FILE
786  inpFileStream.open(datFile.c_str());
787  if (!inpFileStream) {
788  getcwd(currPath, sizeof(currPath));
789  printError(THIS_NAME, "Cannot open the file: %s \n\t (FYI - The current working directory is: %s) \n", datFile.c_str(), currPath);
790  return(NTS_KO);
791  }
792  // Assess that file has ".dat" extension
793  if (not isDatFile(datFile)) {
794  printError(THIS_NAME, "Cannot set AxisRaw stream from file \'%s\' because file is not of type \'DAT\'.\n", datFile.c_str());
795  inpFileStream.close();
796  return(NTS_KO);
797  }
798  //-- STEP-2 : READ FROM FILE AND WRITE TO STREAM
799  while (!inpFileStream.eof()) {
800  if (not readAxisRawFromFile(axisRaw, inpFileStream)) {
801  break;
802  }
803  // Write to stream
804  if (ss.full()) {
805  printError(THIS_NAME, "Cannot write stream \'%s\'. Stream is full.\n",
806  ssName.c_str());
807  rc = false;
808  break;
809  }
810  else {
811  ss.write(AXIS_T(axisRaw));
812  nrChunks++;
813  nrFrames += axisRaw.getLE_TLast().to_int();
814  nrBytes += axisRaw.getLen();
815  lineCnt++;
816  rc = true;
817  }
818  }
819  //-- STEP-3: CLOSE FILE
820  inpFileStream.close();
821  return(rc);
822 }
823 #endif
824 
825 #ifndef __SYNTHESIS__
826 
838 template <class AXIS_T> bool drainAxisToFile(stream<AXIS_T> &ss, const string ssName, \
839  string datFile, int &nrChunks, int &nrFrames, int &nrBytes) {
840  ofstream outFileStream;
841  char currPath[FILENAME_MAX];
842  string strLine;
843  int lineCnt=0;
844  AXIS_T axisChunk;
845 
846  //-- REMOVE PREVIOUS FILE
847  remove(ssName.c_str());
848 
849  //-- OPEN FILE
850  if (!outFileStream.is_open()) {
851  outFileStream.open(datFile.c_str(), ofstream::out);
852  if (!outFileStream) {
853  printError(THIS_NAME, "Cannot open the file: \'%s\'.\n", datFile.c_str());
854  return(NTS_KO);
855  }
856  }
857 
858  // Assess that file has ".dat" extension
859  if ( datFile.find_last_of ( '.' ) != string::npos ) {
860  string extension ( datFile.substr( datFile.find_last_of ( '.' ) + 1 ) );
861  if (extension != "dat") {
862  printError(THIS_NAME, "Cannot dump AxisChunk stream to file \'%s\' because file is not of type \'DAT\'.\n", datFile.c_str());
863  outFileStream.close();
864  return(NTS_KO);
865  }
866  }
867 
868  //-- READ FROM STREAM AND WRITE TO FILE
869  outFileStream << std::hex << std::noshowbase;
870  outFileStream << std::setfill('0');
871  outFileStream << std::uppercase;
872  while (!(ss.empty())) {
873  ss.read(axisChunk);
874  outFileStream << std::setw(16) << ((uint64_t) axisChunk.getLE_TData());
875  outFileStream << " ";
876  outFileStream << std::setw(1) << ( (uint32_t) axisChunk.getLE_TLast());
877  outFileStream << " ";
878  outFileStream << std::setw(2) << ( (uint32_t) axisChunk.getLE_TKeep());
879  outFileStream << std::endl;
880  nrChunks++;
881  nrBytes += axisChunk.getLen();
882  if (axisChunk.getLE_TLast()) {
883  nrFrames ++;
884  outFileStream << std::endl;
885  }
886  }
887 
888  //-- CLOSE FILE
889  outFileStream.close();
890 
891  return(NTS_OK);
892 }
893 #endif
894 
895 #ifndef __SYNTHESIS__
896 
917  stream<AxisApp> ss;
918  int nr1, nr2, nr3;
919  feedAxisFromFile<AxisApp>(ss, "ssName", "aFileName", nr1, nr2, nr3);
920 }
922  stream<AxisArp> ss;
923  int nr1, nr2, nr3;
924  feedAxisFromFile<AxisArp>(ss, "ssName", "aFileName", nr1, nr2, nr3);
925 }
927  stream<AxisIp4> ss;
928  int nr1, nr2, nr3;
929  feedAxisFromFile<AxisIp4>(ss, "ssName", "aFileName", nr1, nr2, nr3);
930 }
932  stream<AxisEth> ss;
933  int nr1, nr2, nr3;
934  feedAxisFromFile<AxisEth>(ss, "ssName", "aFileName", nr1, nr2, nr3);
935 }
936 
938  stream<AxisApp> ss;
939  int nr1, nr2, nr3;
940  drainAxisToFile<AxisApp>(ss, "ssName", "aFileName", nr1, nr2, nr3);
941 }
943  stream<AxisArp> ss;
944  int nr1, nr2, nr3;
945  drainAxisToFile<AxisArp>(ss, "ssName", "aFileName", nr1, nr2, nr3);
946 }
948  stream<AxisEth> ss;
949  int nr1, nr2, nr3;
950  drainAxisToFile<AxisEth>(ss, "ssName", "aFileName", nr1, nr2, nr3);
951 }
953  stream<AxisIp4> ss;
954  int nr1, nr2, nr3;
955  drainAxisToFile<AxisIp4>(ss, "ssName", "aFileName", nr1, nr2, nr3);
956 }
957 
959  ap_uint<16> data;
960  ofstream ofs;
961  writeApUintToFile(data, ofs);
962 }
963 #endif
964 
: Utilities for the simulation of the Network-Transport-Stack (NTS) components.
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
void setLE_TLast(LE_tLast last)
Definition: AxisRaw.hpp:280
void setLE_TData(LE_tData data, int leHi=64 -1, int leLo=0)
Definition: AxisRaw.hpp:272
int getLen() const
Definition: AxisRaw.hpp:411
void setLE_TKeep(LE_tKeep keep, int leHi=64/8-1, int leLo=0)
Definition: AxisRaw.hpp:276
bool isValid() const
Definition: AxisRaw.hpp:434
LE_tLast getLE_TLast() const
Definition: AxisRaw.hpp:268
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
ap_uint< 64 > data
Definition: tb_nal.cpp:832
void _fakeCallTo_feedAxisAppFromFile()
Create a bunch of fake local calls to functions as workaround to link errors related to template clas...
bool readHostSocketFromLine(SockAddr &hostSock, string stringBuffer)
Retrieve a Host socket from a string.
void _fakeCallTo_feedAxisArpFromFile()
bool readFpgaSocketFromLine(SockAddr &fpgaSock, string stringBuffer)
Retrieve an Fpga socket from a string.
bool readAxisRawFromLine(AxisRaw &axisRaw, string stringBuffer)
Retrieve an AxisRaw chunk from a string.
bool writeApUintToFile(ap_uint< D > &data, ofstream &outFileStream)
Dump an AP_UINT to a file.
string myUint8ToStrHex(ap_uint< 8 > inputNumber)
Converts an UINT8 into a string of 2 HEX characters.
vector< string > myTokenizer(string strBuff, char delimiter)
Brakes a string into tokens by using the 'delimiter' character.
void _fakeCallTo_writeApUintToFile()
bool isDatFile(string fileName)
Checks if a file has a ".dat" extension.
Definition: SimNtsUtils.cpp:52
bool writeAxisRawToFile(AxisRaw &axisRaw, ofstream &outFileStream)
Dump an Axis raw data chunk to a file.
void _fakeCallTo_drainAxisAppToFile()
bool isDottedDecimal(string ipStr)
Checks if a string contains an IP address represented in dot-decimal notation.
Definition: SimNtsUtils.cpp:72
void _fakeCallTo_drainAxisIp4ToFile()
ap_uint< 64 > myStrHexToUint64(string dataString)
Converts a string of 16 HEX characters into an UINT64.
bool readTbParamFromFile(const string paramName, const string datFile, unsigned int &paramVal)
Retrieve a testbench parameter from a DAT file.
bool feedAxisFromFile(stream< AXIS_T > &ss, const string ssName, string datFile, int &nrChunks, int &nrFrames, int &nrBytes)
Initialize an Axi4-Stream (Axis) from a DAT file.
bool drainAxisToFile(stream< AXIS_T > &ss, const string ssName, string datFile, int &nrChunks, int &nrFrames, int &nrBytes)
Empty an Axi4-Stream (Axis) to a DAT file.
string myUint64ToStrHex(ap_uint< 64 > inputNumber)
Converts an UINT64 into a string of 16 HEX characters.
#define THIS_NAME
Definition: SimNtsUtils.cpp:39
bool writeSocketPairToFile(SocketPair &socketPair, ofstream &outFileStream)
Dump a SocketPair to a file.
int myDiffTwoFiles(string dataFileName, string goldFileName)
Compares 2 files line-by-line, up to length of the 2nd file.
int writeAxisAppToFile(AxisApp &axisApp, ofstream &outFile)
Dump a TCP or UDP application data chunk into a file. The data are stored as a stream of bytes which ...
ap_uint< 8 > myStrHexToUint8(string keepString)
Converts a string of 2 HEX characters into an UINT8.
void _fakeCallTo_feedAxisIp4FromFile()
void _fakeCallTo_drainAxisArpToFile()
void _fakeCallTo_feedAxisEthFromFile()
bool readAxisRawFromFile(AxisRaw &axisRaw, ifstream &inpFileStream)
Retrieve an Axis raw data chunk from a file.
void _fakeCallTo_drainAxisEthToFile()
bool isHexString(string str)
Checks if a string contains a hexadecimal number.
Definition: SimNtsUtils.cpp:90
ap_uint< 32 > myDottedDecimalIpToUint32(string ipStr)
Converts an IPv4 address represented with a dotted-decimal string into an UINT32.
bool readFpgaSndPortFromLine(Ly4Port &port, string stringBuffer)
Retrieve an FPGA send port from a string.
#define NTS_KO
Definition: nts_types.hpp:56
#define printError(callerName, format,...)
A macro to print an error message.
Definition: nts_utils.hpp:195
ap_uint< 16 > Ly4Port
Definition: nts_types.hpp:201
#define NTS_OK
Definition: nts_types.hpp:55
#define printWarn(callerName, format,...)
A macro to print a warning message.
Definition: nts_utils.hpp:182
#define printFatal(callerName, format,...)
A macro to print a fatal error message and exit.
Definition: nts_utils.hpp:208
void uppercase(ap_uint< 32 > *pi_rank, ap_uint< 32 > *pi_size, stream< NetworkWord > &siSHL_This_Data, stream< NetworkWord > &soTHIS_Shl_Data, stream< NetworkMetaStream > &siNrc_meta, stream< NetworkMetaStream > &soNrc_meta, ap_uint< 32 > *po_rx_ports)
Main process of the Uppercase Application directives.
Definition: uppercase.cpp:335
string fileName
Definition: genTestFile.py:100
out
Definition: test.py:12