39 #define THIS_NAME "TB"
41 #define TRACE_OFF 0x0000
42 #define TRACE_CGF 1 << 1
43 #define TRACE_ALL 0xFFFF
44 #define DEBUG_LEVEL (TRACE_OFF)
73 string inpDAT_FileName,
74 string outARP_GoldName,
string outICMP_GoldName,
75 string outTOE_GoldName,
string outUOE_GoldName)
80 string ofNameArray[4] = { outARP_GoldName, outICMP_GoldName, \
81 outTOE_GoldName, outUOE_GoldName };
85 char currPath[FILENAME_MAX];
86 deque<SimEthFrame> ethRxFramer;
88 int inpChunks=0, arpChunks=0, icmpChunks=0, tcpChunks=0, udpChunks=0, outChunks=0;
89 int inpFrames=0, arpFrames=0, icmpFrames=0, tcpFrames=0, udpFrames=0, outFrames=0;
90 int inpBytes=0, arpBytes=0, icmpBytes=0, tcpBytes=0, udpBytes=0, outBytes=0;
91 bool assessTkeepTlast =
true;
94 ifsDAT.open(inpDAT_FileName.c_str());
96 getcwd(currPath,
sizeof(currPath));
97 printError(myName,
"Cannot open the file: %s \n\t (FYI - The current working directory is: %s) \n", inpDAT_FileName.c_str(), currPath);
101 printError(myName,
"Cannot create golden files from input file \'%s\' because file is not of type \'.dat\'.\n", inpDAT_FileName.c_str());
107 for (
int i=0; i<4; i++) {
108 remove(ofNameArray[i].c_str());
109 if (!ofsArray[i].is_open()) {
112 printFatal(
THIS_NAME,
"Could not open the output gold file \'%s\'. \n", ofNameArray[i].c_str());
118 while ((ifsDAT.peek() != EOF) && (
ret !=
NTS_KO)) {
121 vector<string> stringVector;
123 bool endOfFrame=
false;
126 while ((ifsDAT.peek() != EOF) && (!endOfFrame)) {
128 getline(ifsDAT, stringBuffer);
148 inpBytes += axisEth.
getLen();
154 if((macDA != myMacAddress) and (macDA != 0xFFFFFFFFFFFF)) {
155 printWarn(
THIS_NAME,
"Frame #%d is dropped because MAC_DA does not match.\n", inpFrames);
162 if (etherType.to_uint() >= 0x0600) {
163 switch (etherType.to_uint()) {
167 printInfo(myName,
"Frame #%d is an ARP frame.\n", inpFrames);
171 printError(myName,
"Failed to write ARP frame to DAT file.\n");
175 arpChunks += arpPacket.
size();
176 arpBytes += arpPacket.
length();
179 printError(myName,
"This Ethernet frame has zero payload bytes!?\n");
186 printWarn(myName,
"Frame #%d is dropped because IP version is not \'4\'.\n", inpFrames);
190 printInfo(myName,
"Frame #%d is an IPv4 frame (EtherType=0x%4.4X).\n",
191 inpFrames, etherType.to_uint());
203 icmpChunks += ipPacket.
size();
204 icmpBytes += ipPacket.
length();
208 tcpChunks += ipPacket.
size();
209 tcpBytes += ipPacket.
length();
213 udpChunks += ipPacket.
size();
214 udpBytes += ipPacket.
length();
217 printError(myName,
"Unknown IP protocol #%d.\n",
223 printWarn(myName,
"Frame #%d is dropped because IPv4 header checksum does not match.\n", inpFrames);
227 printError(myName,
"Unsupported protocol 0x%4.4X.\n", etherType.to_ushort());
238 for (
int i=0; i<4; i++) {
243 outFrames = arpFrames + icmpFrames + tcpFrames + udpFrames;
244 outChunks = arpChunks + icmpChunks + tcpChunks + udpChunks;
245 outBytes = arpBytes + icmpBytes + tcpBytes + udpBytes;
246 printInfo(myName,
"Done with the creation of the golden files.\n");
247 printInfo(myName,
"\tProcessed %5d chunks in %4d frames, for a total of %6d bytes.\n",
248 inpChunks, inpFrames, inpBytes);
249 printInfo(myName,
"\tGenerated %5d chunks in %4d frames, for a total of %6d bytes.\n\n",
250 outChunks, outFrames, outBytes);
251 printInfo(myName,
"\tARP : %5d chunks in %4d frames, for a total of %6d bytes.\n",
252 arpChunks, arpFrames, arpBytes);
253 printInfo(myName,
"\tICMP : %5d chunks in %4d frames, for a total of %6d bytes.\n",
254 icmpChunks, icmpFrames, icmpBytes);
255 printInfo(myName,
"\tTCP : %5d chunks in %4d frames, for a total of %6d bytes.\n",
256 tcpChunks, tcpFrames, tcpBytes);
257 printInfo(myName,
"\tUDP : %5d chunks in %4d frames, for a total of %6d bytes.\n\n",
258 udpChunks, udpFrames, udpBytes);
263 #if HLS_VERSION != 2017
286 stream<AxisEth> &siETH_Data,
288 stream<AxisArp> &soARP_Data,
290 stream<AxisIp4> &soICMP_Data,
291 stream<AxisIp4> &soICMP_Derr,
293 stream<AxisIp4> &soUOE_Data,
295 stream<AxisIp4> &soTOE_Data)
298 static stream<AxisRaw> ssiETH_Data (
"ssiETH_Data");
299 static stream<AxisRaw> ssoARP_Data (
"ssoARP_Data");
300 static stream<AxisRaw> ssoICMP_Data(
"ssoICMP_Data");
301 static stream<AxisRaw> ssoICMP_Derr(
"ssoICMP_Derr");
302 static stream<AxisRaw> ssoUOE_Data (
"ssoUOE_Data");
303 static stream<AxisRaw> ssoTOE_Data (
"ssoTOE_Data");
333 int main(
int argc,
char* argv[]) {
348 string ofsARP_Data_FileName =
"../../../../test/simOutFiles/soARP_Data.dat";
349 string ofsTOE_Data_FileName =
"../../../../test/simOutFiles/soTOE_Data.dat";
350 string ofsUOE_Data_FileName =
"../../../../test/simOutFiles/soUOE_Data.dat";
351 string ofsICMP_Data_FileName=
"../../../../test/simOutFiles/soICMP_Data.dat";
352 string dataFileArray[4] = { ofsARP_Data_FileName, ofsTOE_Data_FileName, \
353 ofsUOE_Data_FileName, ofsICMP_Data_FileName };
355 string ofsARP_Gold_FileName =
"../../../../test/simOutFiles/soARP_Gold.dat";
356 string ofsTOE_Gold_FileName =
"../../../../test/simOutFiles/soTOE_Gold.dat";
357 string ofsUOE_Gold_FileName =
"../../../../test/simOutFiles/soUOE_Gold.dat";
358 string ofsICMP_Gold_FileName=
"../../../../test/simOutFiles/soICMP_Gold.dat";
359 string goldFileArray[4] = { ofsARP_Gold_FileName, ofsTOE_Gold_FileName, \
360 ofsUOE_Gold_FileName, ofsICMP_Gold_FileName };
362 Ip4Addr myIp4Address = 0x01010101;
363 EthAddr myMacAddress = 0x010203040506;
370 stream<AxisEth> ssETH_IPRX_Data (
"ssETH_IPRX_Data");
371 int nrETH_IPRX_Chunks = 0;
372 int nrETH_IPRX_Frames = 0;
373 int nrETH_IPRX_Bytes = 0;
375 stream<AxisArp> ssIPRX_ARP_Data (
"ssIPRX_ARP_Data");
376 int nrIPRX_ARP_Chunks = 0;
377 int nrIPRX_ARP_Frames = 0;
378 int nrIPRX_ARP_Bytes = 0;
379 stream<AxisIp4> ssIPRX_TOE_Data (
"ssIPRX_TOE_Data");
380 int nrIPRX_TOE_Chunks = 0;
381 int nrIPRX_TOE_Frames = 0;
382 int nrIPRX_TOE_Bytes = 0;
383 stream<AxisIp4> ssIPRX_UOE_Data (
"ssIPRX_UOE_Data");
384 int nrIPRX_UOE_Chunks = 0;
385 int nrIPRX_UOE_Frames = 0;
386 int nrIPRX_UOE_Bytes = 0;
387 stream<AxisIp4> ssIPRX_ICMP_Data (
"ssIPRX_ICMP_Data");
388 int nrIPRX_ICMP_Chunks = 0;
389 int nrIPRX_ICMP_Frames = 0;
390 int nrIPRX_ICMP_Bytes = 0;
391 stream<AxisIp4> ssIPRX_ICMP_DErr (
"ssIPRX_ICMP_DErr");
397 printFatal(
THIS_NAME,
"Missing testbench parameter:\n\t Expecting an input test vector file.\n");
403 if (feedAxisFromFile<AxisEth>(ssETH_IPRX_Data,
"ssETH_IPRX_Data",
string(argv[1]),
404 nrETH_IPRX_Chunks, nrETH_IPRX_Frames, nrETH_IPRX_Bytes)) {
406 printInfo(
THIS_NAME,
"\tGenerated %d chunks in %d frames, for a total of %d bytes.\n\n",
407 nrETH_IPRX_Chunks, nrETH_IPRX_Frames, nrETH_IPRX_Bytes);
418 ofsARP_Gold_FileName, ofsICMP_Gold_FileName,
419 ofsTOE_Gold_FileName, ofsUOE_Gold_FileName)) {
424 printInfo(
THIS_NAME,
"############################################################################\n");
426 printInfo(
THIS_NAME,
"############################################################################\n");
427 printInfo(
THIS_NAME,
"This testbench will be executed with the following parameters: \n");
428 for (
int i=1; i<argc; i++) {
437 #if HLS_VERSION == 2017
465 if (not drainAxisToFile<AxisIp4>(ssIPRX_TOE_Data,
"ssIPRX_TOE_Data", ofsTOE_Data_FileName,
466 nrIPRX_TOE_Chunks, nrIPRX_TOE_Frames, nrIPRX_TOE_Bytes)) {
470 if (not drainAxisToFile<AxisIp4>(ssIPRX_UOE_Data,
"ssIPRX_UOE_Data", ofsUOE_Data_FileName,
471 nrIPRX_UOE_Chunks, nrIPRX_UOE_Frames, nrIPRX_UOE_Bytes)) {
475 if (not drainAxisToFile<AxisArp>(ssIPRX_ARP_Data,
"ssIPRX_ARP_Data", ofsARP_Data_FileName,
476 nrIPRX_ARP_Chunks, nrIPRX_ARP_Frames, nrIPRX_ARP_Bytes)) {
480 if (not drainAxisToFile<AxisIp4>(ssIPRX_ICMP_Data,
"ssIPRX_ICMP_Data", ofsICMP_Data_FileName,
481 nrIPRX_ICMP_Chunks, nrIPRX_ICMP_Frames, nrIPRX_ICMP_Bytes)) {
486 printInfo(
THIS_NAME,
"############################################################################\n");
488 printInfo(
THIS_NAME,
"############################################################################\n");
494 int res[4] = { 0, 0, 0, 0 };
495 for (
int i=0; i<4; i++ ) {
496 res[i] = system((
"diff --brief -w " + std::string(dataFileArray[i]) +
" " + std::string(goldFileArray[i]) +
" ").c_str());
498 printError(
THIS_NAME,
"File \'%s\' does not match \'%s\'.\n", dataFileArray[i].c_str(), goldFileArray[i].c_str());
507 printInfo(
THIS_NAME,
"This testbench was executed with the following ETH test-file: \n");
508 for (
int i=1; i<argc; i++) {
514 printError(
THIS_NAME,
"#### TEST BENCH FAILED : TOTAL NUMBER OF ERROR(S) = %2d ####\n", nrErr);
517 printInfo(
THIS_NAME,
"FYI - You may want to check for \'ERROR\' and/or \'WARNING\' alarms in the LOG file...\n\n");
520 printInfo(
THIS_NAME,
"#############################################################\n");
522 printInfo(
THIS_NAME,
"#############################################################\n");
LE_tData getLE_TData(int leHi=64 -1, int leLo=0) const
LE_tLast getLE_TLast() const
Class ARP Packet for simulation.
void pushChunk(AxisEth ethChunk)
SimIp4Packet getIpPacket()
bool writeToDatFile(ofstream &outFileStream)
Dump this Ethernet frame as raw AxisEth chunks into a file.
EthAddr getMacDestinAddress()
SimArpPacket getArpPacket()
EthTypeLen getTypeLength()
Class IPv4 Packet for simulation.
bool verifyIpHeaderChecksum()
Recalculate the IPv4 header checksum and compare it with the one embedded into the packet.
bool writeToDatFile(ofstream &outFileStream)
Dump this IP packet as AxisIp4 chunks into a file.
#define TB_MAX_SIM_CYCLES
unsigned int gMaxSimCycles
void iprx_top_wrap(EthAddr piMMIO_MacAddress, Ip4Addr piMMIO_Ip4Address, stream< AxisEth > &siETH_Data, stream< AxisArp > &soARP_Data, stream< AxisIp4 > &soICMP_Data, stream< AxisIp4 > &soICMP_Derr, stream< AxisIp4 > &soUOE_Data, stream< AxisIp4 > &soTOE_Data)
A wrapper for the Toplevel of the IP Receive handler (IPRX).
int createGoldenFiles(EthAddr myMacAddress, string inpDAT_FileName, string outARP_GoldName, string outICMP_GoldName, string outTOE_GoldName, string outUOE_GoldName)
Create the golden reference files from an input test file.
int main(int argc, char *argv[])
Main function.
void stepSim()
Increment the simulation counter.
void iprx_top(EthAddr piMMIO_MacAddress, Ip4Addr piMMIO_Ip4Address, stream< AxisRaw > &siETH_Data, stream< AxisRaw > &soARP_Data, stream< AxisRaw > &soICMP_Data, stream< AxisRaw > &soICMP_Derr, stream< AxisRaw > &soUOE_Data, stream< AxisRaw > &soTOE_Data)
Top of IP Receive handler (IPRX)
bool readAxisRawFromLine(AxisRaw &axisRaw, string stringBuffer)
Retrieve an AxisRaw chunk from a string.
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.
#define printError(callerName, format,...)
A macro to print an error message.
void pAxisRawCast(hls::stream< TypeIn > &si, hls::stream< TypeOut > &so)
AxisRaw cast - Casts an AxisRaw stream to/from an AxisRaw derived class.
#define ETH_ETHERTYPE_ARP
#define printInfo(callerName, format,...)
A macro to print an information message.
#define printWarn(callerName, format,...)
A macro to print a warning message.
#define concat3(firstCharConst, secondCharConst, thirdCharConst)
#define ETH_ETHERTYPE_IP4
#define printFatal(callerName, format,...)
A macro to print a fatal error message and exit.
: Testbench for the IP Receiver packet handler (IPRX).