60 #define THIS_NAME "SIM"
62 #define TRACE_OFF 0x0000
63 #define TRACE_USIF 1 << 1
64 #define TRACE_UAF 1 << 2
65 #define TRACE_CGTF 1 << 3
66 #define TRACE_DUMTF 1 << 4
67 #define TRACE_ALL 0xFFFF
68 #define DEBUG_LEVEL (TRACE_OFF)
109 queue<UdpAppMeta> &udpMetaQueue,
110 queue<UdpAppDLen> &udpDLenQueue,
int &inpChunks,
111 int &inpDgrms,
int &inpBytes) {
114 vector<string> stringVector;
122 getline(ifsData, stringBuffer);
128 printInfo(myName,
"Read a new HOST socket address from DAT file:\n");
136 printInfo(myName,
"Read a new FPGA socket address from DAT file:\n");
147 inpBytes += udpAppData.
getLen();
148 udpAppDLen += udpAppData.
getLen();
153 udpDLenQueue.push(udpAppDLen);
157 }
while ((ifsData.peek() != EOF) && (!endOfDgm));
179 string inpData_FileName,
180 queue<UdpAppMeta> &udpMetaQueue,
181 queue<UdpAppDLen> &udpDLenQueue,
182 string outData_GoldName,
183 string outMeta_GoldName,
184 string outDLen_GoldName)
188 const Ip4Addr hostDefaultIp4Address = 0x0A0CC832;
189 const Ip4Addr fpgaDefaultIp4Address = 0x0A0CC807;
191 const UdpPort hostDefaultUdpLsnPort = fpgaDefaultUdpLsnPort;
193 const UdpPort fpgaDefaultUdpSndPort = hostDefaultUdpSndPort;
196 ofstream ofsDataGold;
197 ofstream ofsMetaGold;
198 ofstream ofsDLenGold;
200 char currPath[FILENAME_MAX];
202 int inpChunks=0, outChunks=0;
203 int inpDgrms=0, outDgrms=0;
204 int inpBytes=0, outBytes=0;
208 printError(myName,
"Cannot create golden files from input file \'%s\' because file is not of type \'.dat\'.\n",
209 inpData_FileName.c_str());
213 ifsData.open(inpData_FileName.c_str());
215 getcwd(currPath,
sizeof(currPath));
216 printError(myName,
"Cannot open the file: %s \n\t (FYI - The current working directory is: %s) \n",
217 inpData_FileName.c_str(), currPath);
223 remove(outData_GoldName.c_str());
224 remove(outMeta_GoldName.c_str());
225 remove(outDLen_GoldName.c_str());
226 if (!ofsDataGold.is_open()) {
230 outData_GoldName.c_str());
233 if (!ofsMetaGold.is_open()) {
237 outMeta_GoldName.c_str());
240 if (!ofsDLenGold.is_open()) {
244 outDLen_GoldName.c_str());
259 currSockPair, udpMetaQueue, udpDLenQueue,
260 inpChunks, inpDgrms, inpBytes);
269 printInfo(myName,
"Writing new socket-pair to gold file:\n");
301 printInfo(myName,
"Writing new datagram len (%d) to gold file:\n", appDLen.to_int());
308 printError(myName,
"Failed to write UDP payload to GOLD file.\n");
313 outChunks += appDatagram.
size();
314 outBytes += appDatagram.
length();
320 }
while(ifsData.peek() != EOF);
329 printInfo(myName,
"Done with the creation of the golden file.\n");
330 printInfo(myName,
"\tProcessed %5d chunks in %4d datagrams, for a total of %6d bytes.\n",
331 inpChunks, inpDgrms, inpBytes);
332 printInfo(myName,
"\tGenerated %5d chunks in %4d datagrams, for a total of %6d bytes.\n",
333 outChunks, outDgrms, outBytes);
354 stream<AxisApp> &ssData,
const string ssDataName,
355 stream<UdpAppMeta> &ssMeta,
const string ssMetaName,
356 stream<UdpAppDLen> &ssDLen,
const string ssMDLenName,
358 queue<UdpAppMeta> &metaQueue,
359 queue<UdpAppDLen> &dlenQueue,
363 int nrUSIF_UAF_MetaChunks = 0;
364 int nrUSIF_UAF_MetaGrams = 0;
365 int nrUSIF_UAF_MetaBytes = 0;
368 int nrDataChunks=0, nrDataGrams=0, nrDataBytes=0;
370 nrDataChunks, nrDataGrams, nrDataBytes)) {
372 printInfo(
THIS_NAME,
"\tGenerated %d chunks in %d datagrams, for a total of %d bytes.\n\n",
373 nrDataChunks, nrDataGrams, nrDataBytes);
374 nrFeededChunks = nrDataChunks;
382 while (!metaQueue.empty()) {
383 ssMeta.write(metaQueue.front());
388 while (!dlenQueue.empty()) {
389 ssDLen.write(dlenQueue.front());
410 string datFile,
int &nrChunks,
int &nrFrames,
int &nrBytes) {
411 ofstream outFileStream;
412 char currPath[FILENAME_MAX];
418 remove(ssName.c_str());
421 if (!outFileStream.is_open()) {
423 if (!outFileStream) {
430 if ( datFile.find_last_of (
'.' ) != string::npos ) {
431 string extension ( datFile.substr( datFile.find_last_of (
'.' ) + 1 ) );
432 if (extension !=
"dat") {
433 printError(
THIS_NAME,
"Cannot dump SocketPair stream to file \'%s\' because file is not of type \'DAT\'.\n", datFile.c_str());
434 outFileStream.close();
440 while (!(ss.empty())) {
449 printInfo(myName,
"Writing new socket-pair to file:\n");
455 outFileStream.close();
473 string datFile,
int &nrChunks,
int &nrFrames,
int &nrBytes) {
474 ofstream outFileStream;
475 char currPath[FILENAME_MAX];
481 remove(ssName.c_str());
484 if (!outFileStream.is_open()) {
486 if (!outFileStream) {
493 if ( datFile.find_last_of (
'.' ) != string::npos ) {
494 string extension ( datFile.substr( datFile.find_last_of (
'.' ) + 1 ) );
495 if (extension !=
"dat") {
496 printError(
THIS_NAME,
"Cannot dump SocketPair stream to file \'%s\' because file is not of type \'DAT\'.\n", datFile.c_str());
497 outFileStream.close();
503 while (!(ss.empty())) {
510 printInfo(myName,
"Writing new datagram length file. Len=%d.\n", udpDLen.to_int());
515 outFileStream.close();
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
LE_tLast getLE_TLast() const
void pushChunk(AxisUdp udpChunk)
bool writePayloadToDatFile(ofstream &outFileStream)
Dump the payload of this datagram as AxisUdp chunks into a file.
bool readHostSocketFromLine(SockAddr &hostSock, string stringBuffer)
Retrieve a Host socket from a string.
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.
vector< string > myTokenizer(string strBuff, char delimiter)
Brakes a string into tokens by using the 'delimiter' character.
bool isDatFile(string fileName)
Checks if a file has a ".dat" extension.
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 writeSocketPairToFile(SocketPair &socketPair, ofstream &outFileStream)
Dump a SocketPair to a file.
#define printError(callerName, format,...)
A macro to print an error message.
void printSockAddr(const char *callerName, SockAddr sockAddr)
Print a socket address.
#define printInfo(callerName, format,...)
A macro to print an information message.
#define concat3(firstCharConst, secondCharConst, thirdCharConst)
void printSockPair(const char *callerName, SocketPair sockPair)
Print a socket pair association.
#define printFatal(callerName, format,...)
A macro to print a fatal error message and exit.
#define ECHO_PATH_THRU_PORT
bool drainUdpDLenStreamToFile(stream< UdpAppDLen > &ss, string ssName, string datFile, int &nrChunks, int &nrFrames, int &nrBytes)
Empty a UdpDLen stream to a DAT file.
void stepSim()
Increment the simulation counter.
bool readDatagramFromFile(const char *myName, SimUdpDatagram &appDatagram, ifstream &ifsData, SocketPair &sockPair, queue< UdpAppMeta > &udpMetaQueue, queue< UdpAppDLen > &udpDLenQueue, int &inpChunks, int &inpDgrms, int &inpBytes)
Read a datagram from a DAT file.
unsigned int gMaxSimCycles
int createUdpRxTraffic(stream< AxisApp > &ssData, const string ssDataName, stream< UdpAppMeta > &ssMeta, const string ssMetaName, stream< UdpAppDLen > &ssDLen, const string ssMDLenName, string datFile, queue< UdpAppMeta > &metaQueue, queue< UdpAppDLen > &dlenQueue, int &nrFeededChunks)
Create the UDP Rx traffic as streams from an input test file.
void increaseSimTime(unsigned int cycles)
Increase the simulation time of the testbench.
bool drainUdpMetaStreamToFile(stream< UdpAppMeta > &ss, string ssName, string datFile, int &nrChunks, int &nrFrames, int &nrBytes)
Empty an UdpMeta stream to a DAT file.
int createGoldenTxFiles(EchoCtrl tbCtrlMode, string inpData_FileName, queue< UdpAppMeta > &udpMetaQueue, queue< UdpAppDLen > &udpDLenQueue, string outData_GoldName, string outMeta_GoldName, string outDLen_GoldName)
Create the golden UDP Tx files from an input test file.