cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
SimNts

Support and utilities for the simulation of the Network Transport Stack (NTS). More...

Collaboration diagram for SimNts:

Files

file  SimAppData.hpp
 : A simulation class to build APP data streams.
 
file  SimArpPacket.hpp
 : A simulation class to build and handle ARP packets.
 
file  SimEthFrame.hpp
 : A simulation class to build and handle Ethernet frames.
 
file  SimIcmpPacket.hpp
 : A simulation class to build and handle ICMP packets.
 
file  SimIp4Packet.hpp
 : A simulation class to build and handle IPv4 packets.
 
file  SimNtsUtils.cpp
 : Utilities for the simulation of the Network-Transport-Stack (NTS) cores.
 
file  SimNtsUtils.hpp
 : Utilities for the simulation of the Network-Transport-Stack (NTS) components.
 
file  SimTcpSegment.hpp
 : A simulation class to build TCP segments.
 
file  SimUdpDatagram.hpp
 : A simulation class to build UDP datagrams.
 

Classes

class  SimAppData
 Class App Data. More...
 
class  SimArpPacket
 Class ARP Packet for simulation. More...
 
class  SimEthFrame
 Class ETHERNET Frame. More...
 
class  SimIcmpPacket
 Class ICMP Packet for simulation. More...
 
class  SimIp4Packet
 Class IPv4 Packet for simulation. More...
 
class  SimTcpSegment
 Class TCP Segment. More...
 
class  SimUdpDatagram
 Class UDP Datagram. More...
 

Macros

#define THIS_NAME   "SimNtsUtils"
 

Functions

bool isDatFile (string fileName)
 Checks if a file has a ".dat" extension. More...
 
bool isDottedDecimal (string ipStr)
 Checks if a string contains an IP address represented in dot-decimal notation. More...
 
bool isHexString (string str)
 Checks if a string contains a hexadecimal number. More...
 
ap_uint< 32 > myDottedDecimalIpToUint32 (string ipStr)
 Converts an IPv4 address represented with a dotted-decimal string into an UINT32. More...
 
vector< string > myTokenizer (string strBuff, char delimiter)
 Brakes a string into tokens by using the 'delimiter' character. More...
 
string myUint64ToStrHex (ap_uint< 64 > inputNumber)
 Converts an UINT64 into a string of 16 HEX characters. More...
 
string myUint8ToStrHex (ap_uint< 8 > inputNumber)
 Converts an UINT8 into a string of 2 HEX characters. More...
 
ap_uint< 64 > myStrHexToUint64 (string dataString)
 Converts a string of 16 HEX characters into an UINT64. More...
 
ap_uint< 8 > myStrHexToUint8 (string keepString)
 Converts a string of 2 HEX characters into an UINT8. More...
 
int myDiffTwoFiles (string dataFileName, string goldFileName)
 Compares 2 files line-by-line, up to length of the 2nd file. More...
 
bool readAxisRawFromLine (AxisRaw &axisRaw, string stringBuffer)
 Retrieve an AxisRaw chunk from a string. More...
 
bool writeAxisRawToFile (AxisRaw &axisRaw, ofstream &outFileStream)
 Dump an Axis raw data chunk to a file. More...
 
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 is terminated by a newline when the 'TLAST' bit of the data chunk is set. More...
 
int writeAxisAppToFile (AxisApp &axisApp, ofstream &outFile, int &wrCount)
 Dump a TCP or UDP application data chunk into a file. Data are stored as a stream of bytes with a newline being appended every time the write-counter reaches the Maximum Segment Size (.i.e, MY_MSS) or the TLAST' bit of the data chunk is set. More...
 
bool readFpgaSocketFromLine (SockAddr &fpgaSock, string stringBuffer)
 Retrieve an Fpga socket from a string. More...
 
bool readHostSocketFromLine (SockAddr &hostSock, string stringBuffer)
 Retrieve a Host socket from a string. More...
 
bool readFpgaSndPortFromLine (Ly4Port &port, string stringBuffer)
 Retrieve an FPGA send port from a string. More...
 
bool readAxisRawFromFile (AxisRaw &axisRaw, ifstream &inpFileStream)
 Retrieve an Axis raw data chunk from a file. More...
 
bool readTbParamFromFile (const string paramName, const string datFile, unsigned int &paramVal)
 Retrieve a testbench parameter from a DAT file. More...
 
template<int D>
bool writeApUintToFile (ap_uint< D > &data, ofstream &outFileStream)
 Dump an AP_UINT to a file. More...
 
bool writeSocketPairToFile (SocketPair &socketPair, ofstream &outFileStream)
 Dump a SocketPair to a file. More...
 
template<class AXIS_T >
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. More...
 
template<class AXIS_T >
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. More...
 
void _fakeCallTo_feedAxisAppFromFile ()
 Create a bunch of fake local calls to functions as workaround to link errors related to template classes. More...
 
void _fakeCallTo_feedAxisArpFromFile ()
 
void _fakeCallTo_feedAxisIp4FromFile ()
 
void _fakeCallTo_feedAxisEthFromFile ()
 
void _fakeCallTo_drainAxisAppToFile ()
 
void _fakeCallTo_drainAxisArpToFile ()
 
void _fakeCallTo_drainAxisEthToFile ()
 
void _fakeCallTo_drainAxisIp4ToFile ()
 
void _fakeCallTo_writeApUintToFile ()
 
bool feedAxisRawStreamFromFile (stream< AxisRaw > &ss, const string ssName, string datFile, int &nrChunks, int &nrFrames, int &nrBytes)
 
bool drainAxisRawStreamToFile (stream< AxisRaw > &ss, const string ssName, string datFile, int &nrChunks, int &nrFrames, int &nrBytes)
 

Detailed Description

Support and utilities for the simulation of the Network Transport Stack (NTS).

Macro Definition Documentation

◆ THIS_NAME

#define THIS_NAME   "SimNtsUtils"

DEBUG PRINT HELPERS

Definition at line 39 of file SimNtsUtils.cpp.

Function Documentation

◆ _fakeCallTo_drainAxisAppToFile()

void _fakeCallTo_drainAxisAppToFile ( )

Definition at line 937 of file SimNtsUtils.cpp.

937  {
938  stream<AxisApp> ss;
939  int nr1, nr2, nr3;
940  drainAxisToFile<AxisApp>(ss, "ssName", "aFileName", nr1, nr2, nr3);
941 }

◆ _fakeCallTo_drainAxisArpToFile()

void _fakeCallTo_drainAxisArpToFile ( )

Definition at line 942 of file SimNtsUtils.cpp.

942  {
943  stream<AxisArp> ss;
944  int nr1, nr2, nr3;
945  drainAxisToFile<AxisArp>(ss, "ssName", "aFileName", nr1, nr2, nr3);
946 }

◆ _fakeCallTo_drainAxisEthToFile()

void _fakeCallTo_drainAxisEthToFile ( )

Definition at line 947 of file SimNtsUtils.cpp.

947  {
948  stream<AxisEth> ss;
949  int nr1, nr2, nr3;
950  drainAxisToFile<AxisEth>(ss, "ssName", "aFileName", nr1, nr2, nr3);
951 }

◆ _fakeCallTo_drainAxisIp4ToFile()

void _fakeCallTo_drainAxisIp4ToFile ( )

Definition at line 952 of file SimNtsUtils.cpp.

952  {
953  stream<AxisIp4> ss;
954  int nr1, nr2, nr3;
955  drainAxisToFile<AxisIp4>(ss, "ssName", "aFileName", nr1, nr2, nr3);
956 }

◆ _fakeCallTo_feedAxisAppFromFile()

void _fakeCallTo_feedAxisAppFromFile ( )

Create a bunch of fake local calls to functions as workaround to link errors related to template classes.

  • The common procedure in C++ is to put the class definition in a C++ header file and the implementation in a C++ source file. However, this approach creates linking problems when template functions are used because template functions are expected to be declared and defined in the same file.
  • Here we implement method #1 proposed by Febil Chacko Thanikal in [1]. The idea is to create a fake call to the template function in the current file, in order for the compiler to compile the function with the appropriate class. This function will then become available at link time.
  • There is no need to call these functions. They are just here to solve and avoid link errors.
See also
[1] https://www.codeproject.com/Articles/48575/How-to-define-a-template-class-in-a-h-file-and-imp

Definition at line 916 of file SimNtsUtils.cpp.

916  {
917  stream<AxisApp> ss;
918  int nr1, nr2, nr3;
919  feedAxisFromFile<AxisApp>(ss, "ssName", "aFileName", nr1, nr2, nr3);
920 }

◆ _fakeCallTo_feedAxisArpFromFile()

void _fakeCallTo_feedAxisArpFromFile ( )

Definition at line 921 of file SimNtsUtils.cpp.

921  {
922  stream<AxisArp> ss;
923  int nr1, nr2, nr3;
924  feedAxisFromFile<AxisArp>(ss, "ssName", "aFileName", nr1, nr2, nr3);
925 }

◆ _fakeCallTo_feedAxisEthFromFile()

void _fakeCallTo_feedAxisEthFromFile ( )

Definition at line 931 of file SimNtsUtils.cpp.

931  {
932  stream<AxisEth> ss;
933  int nr1, nr2, nr3;
934  feedAxisFromFile<AxisEth>(ss, "ssName", "aFileName", nr1, nr2, nr3);
935 }

◆ _fakeCallTo_feedAxisIp4FromFile()

void _fakeCallTo_feedAxisIp4FromFile ( )

Definition at line 926 of file SimNtsUtils.cpp.

926  {
927  stream<AxisIp4> ss;
928  int nr1, nr2, nr3;
929  feedAxisFromFile<AxisIp4>(ss, "ssName", "aFileName", nr1, nr2, nr3);
930 }

◆ _fakeCallTo_writeApUintToFile()

void _fakeCallTo_writeApUintToFile ( )

Definition at line 958 of file SimNtsUtils.cpp.

958  {
959  ap_uint<16> data;
960  ofstream ofs;
961  writeApUintToFile(data, ofs);
962 }
ap_uint< 64 > data
Definition: tb_nal.cpp:832
bool writeApUintToFile(ap_uint< D > &data, ofstream &outFileStream)
Dump an AP_UINT to a file.
Here is the call graph for this function:

◆ drainAxisRawStreamToFile()

bool drainAxisRawStreamToFile ( stream< AxisRaw > &  ss,
const string  ssName,
string  datFile,
int &  nrChunks,
int &  nrFrames,
int &  nrBytes 
)

◆ drainAxisToFile()

template<class AXIS_T >
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.

Parameters
[in/out]ss, a ref to the Axis to drain.
[in]ssName,thename of the Axis to drain.
[in]fileName,theDAT file to write to.
[outnrChunks, a ref to the number of written chuncks.
[out]nrFrames,aref to the number of written frames.
[out]nrBytes,aref to the number of written bytes.
Returns
NTS_OK if successful, otherwise NTS_KO.

Definition at line 838 of file SimNtsUtils.cpp.

839  {
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 }
#define THIS_NAME
Definition: SimNtsUtils.cpp:39
#define NTS_KO
Definition: nts_types.hpp:56
#define printError(callerName, format,...)
A macro to print an error message.
Definition: nts_utils.hpp:195
#define NTS_OK
Definition: nts_types.hpp:55
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
out
Definition: test.py:12
Here is the call graph for this function:
Here is the caller graph for this function:

◆ feedAxisFromFile()

template<class AXIS_T >
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.

Parameters
[in/out]ss A ref to the Axis to set.
[in]ssNameThe name of the Axis to set.
[in]fileNameThe DAT file to read from.
[outnrChunks A ref to the number of written chunks.
[out]nrFramesA ref to the number of written frames.
[out]nrBytesA ref to the number of written bytes.
Returns
true successful, otherwise false.

Definition at line 776 of file SimNtsUtils.cpp.

777  {
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 }
int getLen() const
Definition: AxisRaw.hpp:411
LE_tLast getLE_TLast() const
Definition: AxisRaw.hpp:268
bool isDatFile(string fileName)
Checks if a file has a ".dat" extension.
Definition: SimNtsUtils.cpp:52
bool readAxisRawFromFile(AxisRaw &axisRaw, ifstream &inpFileStream)
Retrieve an Axis raw data chunk from a file.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ feedAxisRawStreamFromFile()

bool feedAxisRawStreamFromFile ( stream< AxisRaw > &  ss,
const string  ssName,
string  datFile,
int &  nrChunks,
int &  nrFrames,
int &  nrBytes 
)

SIMULATION STREAM WRITER HELPERS - PROTOTYPE DEFINITIONS

◆ isDatFile()

bool isDatFile ( string  fileName)

Checks if a file has a ".dat" extension.

SIMULATION UTILITY HELPERS

Parameters
[in]fileName,thename of the file to assess.
Returns
True/False.

FORWARD DECLARATIONS HELPERS FOR THE DEBUGGING TRACES FYI: The global variable 'gTraceEvent' is set whenever a trace call is done. SIMULATION UTILITY HELPERS - PROTOTYPE DEFINITIONS

Definition at line 52 of file SimNtsUtils.cpp.

52  {
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 }
string fileName
Definition: genTestFile.py:100
Here is the caller graph for this function:

◆ isDottedDecimal()

bool isDottedDecimal ( string  ipStr)

Checks if a string contains an IP address represented in dot-decimal notation.

Parameters
[in]ipAddStrThe string to assess.
Returns
True/False.

Definition at line 72 of file SimNtsUtils.cpp.

72  {
73  vector<string> stringVector;
74 
75  stringVector = myTokenizer(ipStr, '.');
76  if (stringVector.size() == 4)
77  return true;
78  else
79  return false;
80 }
vector< string > myTokenizer(string strBuff, char delimiter)
Brakes a string into tokens by using the 'delimiter' character.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isHexString()

bool isHexString ( string  str)

Checks if a string contains a hexadecimal number.

Parameters
[in]strThe string to assess.
Returns
True/False.

Definition at line 90 of file SimNtsUtils.cpp.

90  {
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 }
Here is the caller graph for this function:

◆ myDiffTwoFiles()

int myDiffTwoFiles ( string  dataFileName,
string  goldFileName 
)

Compares 2 files line-by-line, up to length of the 2nd file.

Parameters
[in]dataFileNameThe name of the 1st file.
[in]goldFileNameThe name of the 2nd file.
Returns
NTS_OK upon success, otherwise the number of line that differ.

@info: This comparison is equivalent to the Linux command 'diff –brief -w', except that it offers the possibility to stop the comparison after a certain number of lines. This can be useful when comparing a golden file with the output data file generated by a Vivado HLS C/RTL Co-simulation. In facts, when using the pragma 'HLS INTERFACE ap_ctrl_none', we observe that the simulator is generating unexpected stimuli after the testbench is over (at least with Vivado 2017.4), which can create a discrepancy with the golden file. Therefore, this function can be used to compare two files based on the length of the 2nd file.

Definition at line 305 of file SimNtsUtils.cpp.

305  {
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 }
#define printWarn(callerName, format,...)
A macro to print a warning message.
Definition: nts_utils.hpp:182
Here is the caller graph for this function:

◆ myDottedDecimalIpToUint32()

ap_uint< 32 > myDottedDecimalIpToUint32 ( string  ipStr)

Converts an IPv4 address represented with a dotted-decimal string into an UINT32.

Parameters
[in]inputNumberThe string to convert.
Returns
ap_uint<32>.

Definition at line 117 of file SimNtsUtils.cpp.

117  {
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 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ myStrHexToUint64()

ap_uint< 64 > myStrHexToUint64 ( string  dataString)

Converts a string of 16 HEX characters into an UINT64.

Parameters
[in]inputNumberThe string to convert.
Returns
ap_uint<64>.

Definition at line 230 of file SimNtsUtils.cpp.

230  {
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 }
Here is the caller graph for this function:

◆ myStrHexToUint8()

ap_uint< 8 > myStrHexToUint8 ( string  keepString)

Converts a string of 2 HEX characters into an UINT8.

Parameters
[in]inputNumberThe string to convert.
Returns
ap_uint<8>.

Definition at line 262 of file SimNtsUtils.cpp.

262  {
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 }
Here is the caller graph for this function:

◆ myTokenizer()

vector< string > myTokenizer ( string  strBuff,
char  delimiter 
)

Brakes a string into tokens by using the 'delimiter' character.

Parameters
[in]stringBufferThe string to tokenize.
[in]delimiterThe delimiter character to use.
Returns
a vector of strings.

Definition at line 141 of file SimNtsUtils.cpp.

141  {
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 }
Here is the caller graph for this function:

◆ myUint64ToStrHex()

string myUint64ToStrHex ( ap_uint< 64 >  inputNumber)

Converts an UINT64 into a string of 16 HEX characters.

Parameters
[in]inputNumberThe UINT64 to convert.
Returns
a string of 16 HEX characters.

Definition at line 182 of file SimNtsUtils.cpp.

182  {
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 }

◆ myUint8ToStrHex()

string myUint8ToStrHex ( ap_uint< 8 >  inputNumber)

Converts an UINT8 into a string of 2 HEX characters.

Parameters
[in]inputNumberThe UINT8 to convert.
Returns
a string of 2 HEX characters.

Definition at line 206 of file SimNtsUtils.cpp.

206  {
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 }
Here is the caller graph for this function:

◆ readAxisRawFromFile()

bool readAxisRawFromFile ( AxisRaw axisRaw,
ifstream &  inpFileStream 
)

Retrieve an Axis raw data chunk from a file.

FILE READ & WRITER HELPERS

Parameters
[in]axisRawA reference to the raw data chunk to retrieve.
[in]inpFileStreamThe input file stream to read from.
Returns
true if successful, otherwise false.

SIMULATION FILE READ & WRITE HELPERS - PROTOTYPE DEFINITIONS

Definition at line 624 of file SimNtsUtils.cpp.

624  {
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 }
bool readAxisRawFromLine(AxisRaw &axisRaw, string stringBuffer)
Retrieve an AxisRaw chunk from a string.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readAxisRawFromLine()

bool readAxisRawFromLine ( AxisRaw axisRaw,
string  stringBuffer 
)

Retrieve an AxisRaw chunk from a string.

LINE READ & WRITE HELPERS

Parameters
[in]axisRawA ref to the AxisRaw to retrieve.
[in]stringBufferThe string buffer to read from.
Returns
true if successful, otherwise false.

SIMULATION LINE READ & WRITE HELPERS - PROTOTYPE DEFINITIONS

Definition at line 378 of file SimNtsUtils.cpp.

378  {
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 }
ap_uint< 64 > myStrHexToUint64(string dataString)
Converts a string of 16 HEX characters into an UINT64.
ap_uint< 8 > myStrHexToUint8(string keepString)
Converts a string of 2 HEX characters into an UINT8.
#define printFatal(callerName, format,...)
A macro to print a fatal error message and exit.
Definition: nts_utils.hpp:208
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readFpgaSndPortFromLine()

bool readFpgaSndPortFromLine ( Ly4Port port,
string  stringBuffer 
)

Retrieve an FPGA send port from a string.

Parameters
[in]portA ref to the socket port to retrieve.
[in]stringBufferThe string buffer to read from.
Returns
true if successful, otherwise false.

Definition at line 591 of file SimNtsUtils.cpp.

591  {
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 }
bool isHexString(string str)
Checks if a string contains a hexadecimal number.
Definition: SimNtsUtils.cpp:90
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readFpgaSocketFromLine()

bool readFpgaSocketFromLine ( SockAddr fpgaSock,
string  stringBuffer 
)

Retrieve an Fpga socket from a string.

Parameters
[in]fpgaSockA ref to the socket address to retrieve.
[in]stringBufferThe string buffer to read from.
Returns
true if successful, otherwise false.

Definition at line 511 of file SimNtsUtils.cpp.

511  {
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 }
Ip4Addr addr
Definition: nts_types.hpp:209
Ly4Port port
Definition: nts_types.hpp:210
bool isDottedDecimal(string ipStr)
Checks if a string contains an IP address represented in dot-decimal notation.
Definition: SimNtsUtils.cpp:72
ap_uint< 32 > myDottedDecimalIpToUint32(string ipStr)
Converts an IPv4 address represented with a dotted-decimal string into an UINT32.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readHostSocketFromLine()

bool readHostSocketFromLine ( SockAddr hostSock,
string  stringBuffer 
)

Retrieve a Host socket from a string.

Parameters
[in]hostSockA ref to the socket address to retrieve.
[in]stringBufferThe string buffer to read from.
Returns
true if successful, otherwise false.

Definition at line 551 of file SimNtsUtils.cpp.

551  {
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 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readTbParamFromFile()

bool readTbParamFromFile ( const string  paramName,
const string  datFile,
unsigned int &  paramVal 
)

Retrieve a testbench parameter from a DAT file.

Parameters
[in]paramNameThe name of the parameter to read.
[in]datFileThe input file to read from.
[out]paramValA ref. to the parameter value.
Returns
true if successful, otherwise false.

Definition at line 654 of file SimNtsUtils.cpp.

655  {
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 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeApUintToFile()

template<int D>
bool writeApUintToFile ( ap_uint< D > &  data,
ofstream &  outFileStream 
)

Dump an AP_UINT to a file.

Parameters
[in]dataA reference to the data to dump.
[in]outFileStreamA reference to the file stream to write.
Returns
true upon successful, otherwise false.

Definition at line 714 of file SimNtsUtils.cpp.

714  {
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 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeAxisAppToFile() [1/2]

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 is terminated by a newline when the 'TLAST' bit of the data chunk is set.

Parameters
[in]appDataA reference to AxisApp chunk to write.
[in]outFileA reference to the file stream to write.
Returns
the number of bytes written into the file.

Definition at line 444 of file SimNtsUtils.cpp.

444  {
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 }
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
string myUint8ToStrHex(ap_uint< 8 > inputNumber)
Converts an UINT8 into a string of 2 HEX characters.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeAxisAppToFile() [2/2]

int writeAxisAppToFile ( AxisApp axisApp,
ofstream &  outFile,
int &  wrCount 
)

Dump a TCP or UDP application data chunk into a file. Data are stored as a stream of bytes with a newline being appended every time the write-counter reaches the Maximum Segment Size (.i.e, MY_MSS) or the TLAST' bit of the data chunk is set.

Parameters
[in]appDataA reference to the AxisApp chunk to write.
[in]outFileA reference to the file stream to write.
[in]wrCountA ref to a segment write counter.
Returns
the number of bytes written into the file.

Definition at line 475 of file SimNtsUtils.cpp.

475  {
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 }
Here is the call graph for this function:

◆ writeAxisRawToFile()

bool writeAxisRawToFile ( AxisRaw axisRaw,
ofstream &  outFileStream 
)

Dump an Axis raw data chunk to a file.

Parameters
[in]axisRawA reference to the raw data chunk to write.
[in]outFileStreamA reference to the file stream to write.
Returns
true upon successful, otherwise false.

Definition at line 416 of file SimNtsUtils.cpp.

416  {
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 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeSocketPairToFile()

bool writeSocketPairToFile ( SocketPair socketPair,
ofstream &  outFileStream 
)

Dump a SocketPair to a file.

Parameters
[in]socketPairA reference to the SocketPair to dump.
[in]outFileStreamThe output file stream to write to.
Returns
true if successful, otherwise false.

Definition at line 745 of file SimNtsUtils.cpp.

745  {
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 }
SockAddr dst
Definition: nts_types.hpp:249
SockAddr src
Definition: nts_types.hpp:248
Here is the call graph for this function:
Here is the caller graph for this function: