39 #define THIS_NAME "SimNtsUtils" 
   53     if (
fileName.find_last_of ( 
'.' ) != string::npos) {
 
   55         if (extension != 
"dat")
 
   73     vector<string>  stringVector;
 
   76     if (stringVector.size() == 4)
 
   96     res = strtol(
str.c_str(), &pEnd, 16);
 
   99         if ((
str.find(
"0x") != string::npos) || (
str.find(
"0X") != string::npos))
 
  109 #ifndef __SYNTHESIS__ 
  118     vector<string>  stringVector;
 
  119     ap_uint<32>     ip4Uint = 0x00000000;
 
  124     for (
int i=0; i<stringVector.size(); i++) {
 
  125         octet = strtoul(stringVector[i].c_str(), &ptr, 10);
 
  126         ip4Uint |= (octet << 8*(3-i));
 
  132 #ifndef __SYNTHESIS__ 
  142     vector<string>   tmpBuff;
 
  143     int              tokenCounter = 0;
 
  146     if (strBuff.empty()) {
 
  147         tmpBuff.push_back(strBuff);
 
  152         if (strBuff[strBuff.size() - 1] == 
'\r')
 
  153             strBuff.erase(strBuff.size() - 1);
 
  156     while (strBuff.find(delimiter) != string::npos) {
 
  158         string temp = strBuff.substr(0, strBuff.find(delimiter));
 
  160         strBuff = strBuff.substr(strBuff.find(delimiter)+1, strBuff.length());
 
  163             tmpBuff.push_back(temp);
 
  165         if ((tokenCounter == 0) && (temp ==
"#"))
 
  170     tmpBuff.push_back(strBuff);
 
  175 #ifndef __SYNTHESIS__ 
  183     string                    outputString    = 
"0000000000000000";
 
  184     unsigned short int        tempValue       = 16;
 
  185     static const char* 
const  lut             = 
"0123456789ABCDEF";
 
  187     for (
int i = 15;i>=0;--i) {
 
  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));
 
  193         outputString[15-i] = lut[tempValue];
 
  199 #ifndef __SYNTHESIS__ 
  207     string                      outputString    = 
"00";
 
  208     unsigned short int          tempValue       = 16;
 
  209     static const char* 
const    lut             = 
"0123456789ABCDEF";
 
  211     for (
int i = 1;i>=0;--i) {
 
  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));
 
  217         outputString[1-i] = lut[tempValue];
 
  223 #ifndef __SYNTHESIS__ 
  231     ap_uint<64> tempOutput          = 0;
 
  232     unsigned short int  tempValue   = 16;
 
  233     static const char* 
const    lut = 
"0123456789ABCDEF";
 
  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])) {
 
  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));
 
  255 #ifndef __SYNTHESIS__ 
  263     ap_uint<8>               tempOutput = 0;
 
  264     unsigned short int       tempValue  = 16;
 
  265     static const char* 
const lut        = 
"0123456789ABCDEF";
 
  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])) {
 
  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));
 
  287 #ifndef __SYNTHESIS__ 
  306     ifstream    dataFileStream;
 
  307     ifstream    goldFileStream;
 
  311     dataFileStream.open(dataFileName.c_str());
 
  312     if (!dataFileStream) {
 
  316     goldFileStream.open(goldFileName.c_str());
 
  317     if (!goldFileStream) {
 
  319         dataFileStream.close();
 
  323     if ((dataFileStream.peek() != std::ifstream::traits_type::eof()) and
 
  324         (goldFileStream.peek() != std::ifstream::traits_type::eof())) {
 
  327         while (getline(goldFileStream, goldStrLine)) {
 
  328             if (getline(dataFileStream, dataStrLine)) {
 
  329                 if (goldStrLine != dataStrLine) {
 
  335                 printWarn(
THIS_NAME, 
"Diff: %s - %s\n", goldStrLine.c_str(), 
"No entry found in data file!");
 
  340     else if (dataFileStream.peek() == std::ifstream::traits_type::eof()) {
 
  342         while (getline(goldFileStream, goldStrLine)) {
 
  347     else if (goldFileStream.peek() == std::ifstream::traits_type::eof()) {
 
  349         while (getline(goldFileStream, dataStrLine)) {
 
  358     dataFileStream.close();
 
  359     goldFileStream.close();
 
  369 #ifndef __SYNTHESIS__ 
  379     vector<string> stringVector;
 
  381     if (stringVector[0] == 
"") {
 
  384     else if (stringVector[0].length() == 1) {
 
  388     else if ( (stringVector.size() == 3) or
 
  389              ((stringVector.size() == 4) and (stringVector[3] == 
"(FORCED_INVALID_TKEEP)")) ) {
 
  391         axisRaw.
setLE_TLast(atoi(            stringVector[1].c_str()));
 
  393         if ((stringVector.size() == 3) and (not axisRaw.
isValid())) {
 
  407 #ifndef __SYNTHESIS__ 
  417     if (not outFileStream) {
 
  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";
 
  428         outFileStream << 
"\n";
 
  434 #ifndef __SYNTHESIS__ 
  445     int writtenBytes = 0;
 
  446     for (
int bytNum=0; bytNum<8; bytNum++) {
 
  448             int hi = ((bytNum*8) + 7);
 
  449             int lo = ((bytNum*8) + 0);
 
  463 #ifndef __SYNTHESIS__ 
  476     int writtenBytes = 0;
 
  477     for (
int bytNum=0; bytNum<8; bytNum++) {
 
  479             int hi = ((bytNum*8) + 7);
 
  480             int lo = ((bytNum*8) + 0);
 
  486             if (wrCount == ZYC2_MSS) {
 
  494     if ((axisApp.
getTLast()) && (wrCount != 0)) {
 
  502 #ifndef __SYNTHESIS__ 
  512     vector<string> stringVector;
 
  514     if ((stringVector[0] == 
">") and (stringVector[1] == 
"SET")) {
 
  515         if ((stringVector[2] == 
"FpgaServerSocket") or
 
  516             (stringVector[2] == 
"FpgaSocket")) {
 
  523                 fpgaSock.
addr = strtoul(stringVector[3].c_str(), &pEnd, 16);
 
  526                 fpgaSock.
addr = strtoul(stringVector[3].c_str(), &pEnd, 10);
 
  530                 fpgaSock.
port = strtoul(stringVector[4].c_str(), &pEnd, 16);
 
  533                 fpgaSock.
port = strtoul(stringVector[4].c_str(), &pEnd, 10);
 
  542 #ifndef __SYNTHESIS__ 
  552     vector<string> stringVector;
 
  554     if ((stringVector[0] == 
">") and (stringVector[1] == 
"SET")) {
 
  555         if ((stringVector[2] == 
"HostServerSocket") or
 
  556             (stringVector[2] == 
"HostSocket")) {
 
  563                 hostSock.
addr = strtoul(stringVector[3].c_str(), &pEnd, 16);
 
  566                 hostSock.
addr = strtoul(stringVector[3].c_str(), &pEnd, 10);
 
  570                 hostSock.
port = strtoul(stringVector[4].c_str(), &pEnd, 16);
 
  573                 hostSock.
port = strtoul(stringVector[4].c_str(), &pEnd, 10);
 
  582 #ifndef __SYNTHESIS__ 
  592     vector<string> stringVector;
 
  594     if ((stringVector[0] == 
">") and (stringVector[1] == 
"SET")) {
 
  595         if (stringVector[2] == 
"FpgaSndPort") {
 
  599                 port = strtoul(stringVector[4].c_str(), &pEnd, 16);
 
  602                 port = strtoul(stringVector[4].c_str(), &pEnd, 10);
 
  615 #ifndef __SYNTHESIS__ 
  626     vector<string>  stringVector;
 
  629     if (!inpFileStream.is_open()) {
 
  633     while (inpFileStream.peek() != EOF) {
 
  634         getline(inpFileStream, stringBuffer);
 
  644 #ifndef __SYNTHESIS__ 
  655                          unsigned int ¶mVal) {
 
  656     ifstream        inpFileStream;
 
  657     char            currPath[FILENAME_MAX];
 
  658     string          rxStringBuffer;
 
  659     vector<string>  stringVector;
 
  662         printError(
THIS_NAME, 
"Input test vector file \'%s\' is not of type \'DAT\'.\n", datFile.c_str());
 
  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);
 
  674         getline(inpFileStream, rxStringBuffer);
 
  676         if (stringVector[0] == 
"") {
 
  679         else if (stringVector[0].length() == 1) {
 
  681             if ((stringVector[0] == 
"G") && (stringVector[1] == 
"PARAM")) {
 
  682                 if (stringVector[2] == paramName) {
 
  688                         paramVal = strtoul(stringVector[3].c_str(), &ptr, 16);
 
  691                         paramVal = strtoul(stringVector[3].c_str(), &ptr, 10);
 
  693                     inpFileStream.close();
 
  698     } 
while(!inpFileStream.eof());
 
  699     inpFileStream.close();
 
  704 #ifndef __SYNTHESIS__ 
  715     if (not outFileStream.is_open()) {
 
  720     outFileStream << 
"0x" << hex << noshowbase << setfill(
'0');
 
  726         outFileStream << setw(D/4) << 
data.to_int() << 
"\n";
 
  736 #ifndef __SYNTHESIS__ 
  746     if (!outFileStream.is_open()) {
 
  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";
 
  763 #ifndef __SYNTHESIS__ 
  777                 string datFile, 
int &nrChunks, 
int &nrFrames, 
int &nrBytes) {
 
  778     ifstream    inpFileStream;
 
  779     char        currPath[FILENAME_MAX];
 
  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);
 
  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();
 
  799     while (!inpFileStream.eof()) {
 
  811             ss.write(AXIS_T(axisRaw));
 
  814             nrBytes  += axisRaw.
getLen();
 
  820     inpFileStream.close();
 
  825 #ifndef __SYNTHESIS__ 
  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];
 
  847     remove(ssName.c_str());
 
  850     if (!outFileStream.is_open()) {
 
  852         if (!outFileStream) {
 
  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();
 
  869     outFileStream << std::hex << std::noshowbase;
 
  870     outFileStream << std::setfill(
'0');
 
  872     while (!(ss.empty())) {
 
  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;
 
  881         nrBytes  += axisChunk.getLen();
 
  882         if (axisChunk.getLE_TLast()) {
 
  884             outFileStream << std::endl;
 
  889     outFileStream.close();
 
  895 #ifndef __SYNTHESIS__ 
  919     feedAxisFromFile<AxisApp>(ss, 
"ssName", 
"aFileName", nr1, nr2, nr3);
 
  924     feedAxisFromFile<AxisArp>(ss, 
"ssName", 
"aFileName", nr1, nr2, nr3);
 
  929     feedAxisFromFile<AxisIp4>(ss, 
"ssName", 
"aFileName", nr1, nr2, nr3);
 
  934     feedAxisFromFile<AxisEth>(ss, 
"ssName", 
"aFileName", nr1, nr2, nr3);
 
  940     drainAxisToFile<AxisApp>(ss, 
"ssName", 
"aFileName", nr1, nr2, nr3);
 
  945     drainAxisToFile<AxisArp>(ss, 
"ssName", 
"aFileName", nr1, nr2, nr3);
 
  950     drainAxisToFile<AxisEth>(ss, 
"ssName", 
"aFileName", nr1, nr2, nr3);
 
  955     drainAxisToFile<AxisIp4>(ss, 
"ssName", 
"aFileName", nr1, nr2, nr3);
 
: Utilities for the simulation of the Network-Transport-Stack (NTS) components.
 
LE_tKeep getLE_TKeep(int leHi=64/8-1, int leLo=0) const
 
LE_tData getLE_TData(int leHi=64 -1, int leLo=0) const
 
void setLE_TLast(LE_tLast last)
 
void setLE_TData(LE_tData data, int leHi=64 -1, int leLo=0)
 
void setLE_TKeep(LE_tKeep keep, int leHi=64/8-1, int leLo=0)
 
LE_tLast getLE_TLast() const
 
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.
 
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.
 
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 ¶mVal)
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.
 
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.
 
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 printError(callerName, format,...)
A macro to print an error message.
 
#define printWarn(callerName, format,...)
A macro to print a warning message.
 
#define printFatal(callerName, format,...)
A macro to print a fatal error message and exit.
 
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.