39 #define THIS_NAME "TB"
41 #define TRACE_OFF 0x0000
42 #define TRACE_CGRF 1 << 1
43 #define TRACE_CGTF 1 << 2
44 #define TRACE_DUMTF 1 << 3
45 #define TRACE_ALL 0xFFFF
46 #define DEBUG_LEVEL (TRACE_OFF)
75 string datFile,
int &nrChunks,
int &nrFrames,
int &nrBytes) {
76 ofstream outFileStream;
77 char currPath[FILENAME_MAX];
83 remove(ssName.c_str());
86 if (!outFileStream.is_open()) {
95 if ( datFile.find_last_of (
'.' ) != string::npos ) {
96 string extension ( datFile.substr( datFile.find_last_of (
'.' ) + 1 ) );
97 if (extension !=
"dat") {
98 printError(
THIS_NAME,
"Cannot dump SocketPair stream to file \'%s\' because file is not of type \'DAT\'.\n", datFile.c_str());
99 outFileStream.close();
105 outFileStream << std::hex << std::noshowbase;
106 outFileStream << std::setfill(
'0');
108 while (!(ss.empty())) {
119 printInfo(myName,
"Writing new socket-pair to file:\n");
125 outFileStream.close();
143 string datFile,
int &nrChunks,
int &nrFrames,
int &nrBytes) {
144 ofstream outFileStream;
145 char currPath[FILENAME_MAX];
151 remove(ssName.c_str());
154 if (!outFileStream.is_open()) {
156 if (!outFileStream) {
163 if ( datFile.find_last_of (
'.' ) != string::npos ) {
164 string extension ( datFile.substr( datFile.find_last_of (
'.' ) + 1 ) );
165 if (extension !=
"dat") {
166 printError(
THIS_NAME,
"Cannot dump DataLength stream to file \'%s\' because file is not of type \'DAT\'.\n", datFile.c_str());
167 outFileStream.close();
173 outFileStream << std::hex << std::noshowbase;
174 outFileStream << std::setfill(
'0');
176 while (!(ss.empty())) {
183 printInfo(myName,
"Writing a new data-length to file:\n");
188 outFileStream.close();
205 ap_uint<16> currDropCount;
206 ap_uint<16> prevDropCount=0;
209 while (!(ss.empty())) {
210 ss.read(currDropCount);
211 if (currDropCount != prevDropCount) {
212 printWarn(myName,
"A datagram has been dropped (currDropCounter=%d). \n", currDropCount.to_ushort());
214 prevDropCount = currDropCount;
236 stream<AxisApp> &ssData,
const string ssDataName,
237 stream<UdpAppMeta> &ssMeta,
const string ssMetaName,
238 stream<UdpAppDLen> &ssDLen,
const string ssDLenName,
240 queue<UdpAppMeta> &metaQueue,
241 queue<UdpAppDLen> &dlenQueue,
245 int nrUAIF_UOE_MetaChunks = 0;
246 int nrUAIF_UOE_MetaGrams = 0;
247 int nrUAIF_UOE_MetaBytes = 0;
250 int nrDataChunks=0, nrDataGrams=0, nrDataBytes=0;
252 nrDataChunks, nrDataGrams, nrDataBytes)) {
254 printInfo(
THIS_NAME,
"\tGenerated %d chunks in %d datagrams, for a total of %d bytes.\n\n",
255 nrDataChunks, nrDataGrams, nrDataBytes);
256 nrFeededChunks = nrDataChunks;
264 while (!metaQueue.empty()) {
265 ssMeta.write(metaQueue.front());
272 while(!dlenQueue.empty()) {
273 ssDLen.write(dlenQueue.front());
299 queue<UdpAppMeta> &udpMetaQueue, queue<UdpAppDLen> &updDLenQueue,
300 int &inpChunks,
int &inpDgrms,
int &inpBytes,
char tbMode) {
303 vector<string> stringVector;
307 int currDgrmLenght=0;
313 getline(ifsData, stringBuffer);
322 printInfo(myName,
"Read a new HOST socket address from DAT file:\n");
330 printInfo(myName,
"Read a new FPGA send port from DAT file:\n");
341 currDgrmLenght += udpAppData.
getLen();
342 inpBytes += udpAppData.
getLen();
346 udpMetaQueue.push(udpAppMeta);
350 updDLenQueue.push(currDgrmLenght);
357 updDLenQueue.push(0);
363 }
while ((ifsData.peek() != EOF) && (!endOfDgm));
382 string inpData_FileName,
383 string outData_GoldName,
384 queue<UdpAppMeta> &udpMetaQueue,
385 queue<UdpAppDLen> &updDLenQueue,
390 const Ip4Addr fpgaDefaultIp4Address = 0x0A0CC807;
391 const UdpPort fpgaDefaultUdpLsnPort = 8803;
392 const UdpPort fpgaDefaultUdpSndPort = 32768+8803;
393 const Ip4Addr hostDefaultIp4Address = 0x0A0CC832;
394 const UdpPort hostDefaultUdpLsnPort = fpgaDefaultUdpSndPort;
395 const UdpPort hostDefaultUdpSndPort = fpgaDefaultUdpLsnPort;
398 ofstream ofsDataGold;
400 char currPath[FILENAME_MAX];
401 int inpChunks=0, outChunks=0;
402 int inpDgrms=0, outPackets=0;
403 int inpBytes=0, outBytes=0;
407 printError(myName,
"Cannot create golden file from input file \'%s\' because file is not of type \'.dat\'.\n",
408 inpData_FileName.c_str());
412 ifsData.open(inpData_FileName.c_str());
414 getcwd(currPath,
sizeof(currPath));
415 printError(myName,
"Cannot open the file: %s \n\t (FYI - The current working directory is: %s) \n",
416 inpData_FileName.c_str(), currPath);
422 remove(outData_GoldName.c_str());
423 if (!ofsDataGold.is_open()) {
427 outData_GoldName.c_str());
432 SockAddr hostLsnSock =
SockAddr(hostDefaultIp4Address, hostDefaultUdpLsnPort);
433 SockAddr fpgaSndSock =
SockAddr(fpgaDefaultIp4Address, fpgaDefaultUdpSndPort);
440 udpMetaQueue, updDLenQueue,
441 inpChunks, inpDgrms, inpBytes, tbMode);
452 while (appDatagram.
length() > 0) {
460 if (appDatagram.
length() <= UDP_MDS) {
461 splitLen = appDatagram.
length();
478 printError(myName,
"Failed to write IP packet to GOLD file.\n");
483 outChunks += ipPacket.
size();
484 outBytes += ipPacket.
length();
489 }
while(ifsData.peek() != EOF);
496 printInfo(myName,
"Done with the creation of the golden file.\n");
497 printInfo(myName,
"\tProcessed %5d chunks in %4d datagrams, for a total of %6d bytes.\n",
498 inpChunks, inpDgrms, inpBytes);
499 printInfo(myName,
"\tGenerated %5d chunks in %4d packets, for a total of %6d bytes.\n",
500 outChunks, outPackets, outBytes);
517 string inpData_FileName,
518 string outData_GoldName,
519 string outMeta_GoldName,
520 string outDLen_GoldName,
521 set<UdpPort> &udpPorts)
526 ofstream ofsDataGold;
527 ofstream ofsMetaGold;
528 ofstream ofsDLenGold;
530 char currPath[FILENAME_MAX];
532 int inpChunks=0, outChunks=0;
533 int inpPackets=0, outPackets=0;
534 int inpBytes=0, outBytes=0;
538 printError(myName,
"Cannot create golden files from input file \'%s\' because file is not of type \'.dat\'.\n",
539 inpData_FileName.c_str());
543 ifsData.open(inpData_FileName.c_str());
545 getcwd(currPath,
sizeof(currPath));
546 printError(myName,
"Cannot open the file: %s \n\t (FYI - The current working directory is: %s) \n",
547 inpData_FileName.c_str(), currPath);
553 remove(outData_GoldName.c_str());
554 remove(outMeta_GoldName.c_str());
555 remove(outDLen_GoldName.c_str());
556 if (!ofsDataGold.is_open()) {
560 outData_GoldName.c_str());
563 if (!ofsMetaGold.is_open()) {
567 outMeta_GoldName.c_str());
570 if (!ofsDLenGold.is_open()) {
574 outDLen_GoldName.c_str());
579 while ((ifsData.peek() != EOF) && (
ret !=
NTS_KO)) {
585 while ((ifsData.peek() != EOF) && (!endOfPkt)) {
603 inpBytes += ip4RxData.
getLen();
608 if (endOfPkt and
rc) {
610 printFatal(myName,
"IP packet #%d is malformed!\n", inpPackets);
617 printWarn(myName,
"IP packet #%d is dropped because it is not an UDP packet.\n", inpPackets);
618 printInfo(myName,
" Received Ip4Prot = 0x%2.2X\n", ip4Prot.to_uchar());
628 if ((udpHCsum != 0) and (udpHCsum != calcCsum)) {
629 printWarn(myName,
"IP packet #%d is dropped because the UDP checksum is invalid.\n", inpPackets);
630 printInfo(myName,
" Received Checksum = 0x%2.2X\n", udpHCsum.to_ushort());
631 printInfo(myName,
" Expected Checksum = 0x%2.2X\n", calcCsum.to_ushort());
643 printInfo(myName,
"Writing new socket-pair to file:\n");
652 printError(myName,
"Failed to write UDP payload to GOLD file.\n");
657 outChunks += udpDatagram.
size();
658 outBytes += udpDatagram.
length();
665 printInfo(myName,
"Writing a new data-length to file:\n");
677 printInfo(myName,
"Done with the creation of the golden files.\n");
678 printInfo(myName,
"\tProcessed %5d chunks in %4d packets, for a total of %6d bytes.\n",
679 inpChunks, inpPackets, inpBytes);
680 printInfo(myName,
"\tGenerated %5d chunks in %4d packets, for a total of %6d bytes.\n",
681 outChunks, outPackets, outBytes);
685 #if HLS_VERSION != 2017
713 stream<ap_uint<16> > &soMMIO_DropCnt,
714 stream<StsBool> &soMMIO_Ready,
716 stream<AxisIp4> &siIPRX_Data,
718 stream<AxisIp4> &soIPTX_Data,
720 stream<UdpAppLsnReq> &siUAIF_LsnReq,
721 stream<UdpAppLsnRep> &soUAIF_LsnRep,
722 stream<UdpAppClsReq> &siUAIF_ClsReq,
723 stream<UdpAppClsRep> &soUAIF_ClsRep,
725 stream<UdpAppData> &soUAIF_Data,
726 stream<UdpAppMeta> &soUAIF_Meta,
727 stream<UdpAppDLen> &soUAIF_DLen,
729 stream<UdpAppData> &siUAIF_Data,
730 stream<UdpAppMeta> &siUAIF_Meta,
731 stream<UdpAppDLen> &siUAIF_DLen,
733 stream<AxisIcmp> &soICMP_Data)
736 static stream<AxisRaw> ssiIPRX_Data(
"ssiIPRX_Data");
737 static stream<AxisRaw> ssoIPTX_Data(
"ssoIPTX_Data");
738 static stream<AxisRaw> ssoICMP_Data(
"ssoICMP_Data");
793 int main(
int argc,
char *argv[]) {
814 stream<StsBool> ssUOE_MMIO_Ready (
"ssUOE_MMIO_Ready");
815 stream<ap_uint<16> > ssUOE_MMIO_DropCnt (
"ssUOE_MMIO_DropCnt");
817 stream<AxisIp4> ssIPRX_UOE_Data (
"ssIPRX_UOE_Data");
818 stream<AxisIp4> ssUOE_IPTX_Data (
"ssUOE_IPTX_Data");
820 stream<UdpPort> ssUAIF_UOE_LsnReq (
"ssUAIF_UOE_LsnReq");
821 stream<StsBool> ssUOE_UAIF_LsnRep (
"ssUOE_UAIF_LsnRep");
822 stream<UdpPort> ssUAIF_UOE_ClsReq (
"ssUAIF_UOE_ClsReq");
823 stream<StsBool> ssUOE_UAIF_ClsRep (
"ssUOE_UAIF_ClsRep");
825 stream<AxisApp> ssUOE_UAIF_Data (
"ssUOE_UAIF_Data");
826 stream<UdpAppMeta> ssUOE_UAIF_Meta (
"ssUOE_UAIF_Meta");
827 stream<UdpAppDLen> ssUOE_UAIF_DLen (
"ssUOE_UAIF_DLen");
829 stream<AxisApp> ssUAIF_UOE_Data (
"ssUAIF_UOE_Data");
830 stream<UdpAppMeta> ssUAIF_UOE_Meta (
"ssUAIF_UOE_Meta");
831 stream<UdpAppDLen> ssUAIF_UOE_DLen (
"ssUAIF-UOE_DLen");
833 stream<AxisIcmp> ssUOE_ICMP_Data (
"ssUOE_ICMP_Data");
847 printFatal(
THIS_NAME,
"Expected a minimum of 2 parameters with one of the following synopsis:\n \t\t mode(0) siIPRX_<Filename>.dat\n \t\t mode(1|2) siUAIF_<Filename>.dat\n");
858 printFatal(
THIS_NAME,
"Found more than one parameter.\n \t\t Expected a single parameter to be = '3' \n");
862 printFatal(
THIS_NAME,
"Expected a minimum of 2 or 3 parameters with one of the following synopsis:\n \t\t mode(0|3) siIPRX_<Filename>.dat\n \t\t mode(1) siUAIF_<Filename>.dat\n \t\t mode(2) siIPRX_<Filename>.dat siUAIF_<Filename>.dat\n");
865 printInfo(
THIS_NAME,
"############################################################################\n");
867 printInfo(
THIS_NAME,
"############################################################################\n\n");
868 printInfo(
THIS_NAME,
"This testbench will be executed with the following parameters: \n");
870 for (
int i=2; i<argc; i++) {
877 bool isReady =
false;
879 #if HLS_VERSION == 2017
916 if (!ssUOE_MMIO_Ready.empty()) {
917 isReady = ssUOE_MMIO_Ready.read();
927 ssUAIF_UOE_ClsReq.write(0x1532);
928 for (
int i=0; i<10; ++i) {
929 #if HLS_VERSION == 2017
966 if (!ssUOE_MMIO_Ready.empty()) {
967 isReady = ssUOE_MMIO_Ready.read();
981 ssUAIF_UOE_LsnReq.write(0x80);
982 for (
int i=0; i<3; ++i) {
983 #if HLS_VERSION == 2017
1020 if (!ssUOE_MMIO_Ready.empty()) {
1021 isReady = ssUOE_MMIO_Ready.read();
1027 if (!ssUOE_UAIF_LsnRep.empty()) {
1028 openReply = ssUOE_UAIF_LsnRep.read();
1030 printInfo(
THIS_NAME,
"OK - Port #%d was successfully opened.\n", portToOpen.to_int());
1047 UdpPort portToClose = portToOpen;
1049 ssUAIF_UOE_ClsReq.write(portToClose);
1050 for (
int i=0; i<10; ++i) {
1051 #if HLS_VERSION == 2017
1088 if (!ssUOE_MMIO_Ready.empty()) {
1089 isReady = ssUOE_MMIO_Ready.read();
1103 const Ip4Addr fpgaDefaultIp4Address = 0x0A0CC807;
1104 const Ip4Addr hostDefaultIp4Address = 0x0A0CC832;
1108 AxisUdp udpChunk1(0xCAFFE000000CAFFE, 0xFF, 0);
1109 AxisUdp udpChunk2(0x000000FAB0000000, 0xFF, 1);
1121 int pktSize = ipPacket.
size();
1122 for (
int i=0; i<pktSize; i++) {
1123 ssIPRX_UOE_Data.write(ipPacket.
pullChunk());
1128 #if HLS_VERSION == 2017
1165 if (!ssUOE_MMIO_Ready.empty()) {
1166 isReady = ssUOE_MMIO_Ready.read();
1168 if (!ssUOE_UAIF_Data.empty()) {
1179 printInfo(
THIS_NAME,
"Draining the following ICMP packet from UOE:\n\t FYI, it should contain the IPv4 header and the UDP header.\n ");
1183 while (!ssUOE_ICMP_Data.empty()) {
1184 ssUOE_ICMP_Data.read(axisChunk);
1188 if (noChunks != 4) {
1189 printError(
THIS_NAME,
"Wrong number of chunks issued by UOe. \n\t Expected 4 - Received %d. \n", noChunks);
1210 string ofsUAIF_Data_FileName =
"../../../../test/simOutFiles/soUAIF_Data.dat";
1211 string ofsUAIF_Meta_FileName =
"../../../../test/simOutFiles/soUAIF_Meta.dat";
1212 string ofsUAIF_DLen_FileName =
"../../../../test/simOutFiles/soUAIF_DLen.dat";
1213 string ofsUAIF_Gold_Data_FileName =
"../../../../test/simOutFiles/soUAIF_Gold_Data.dat";
1214 string ofsUAIF_Gold_Meta_FileName =
"../../../../test/simOutFiles/soUAIF_Gold_Meta.dat";
1215 string ofsUAIF_Gold_DLen_FileName =
"../../../../test/simOutFiles/soUAIF_Gold_DLen.dat";
1216 vector<string> ofNames;
1217 ofNames.push_back(ofsUAIF_Data_FileName);
1218 ofNames.push_back(ofsUAIF_Meta_FileName);
1219 ofNames.push_back(ofsUAIF_DLen_FileName);
1220 ofstream ofStreams[ofNames.size()];
1223 string rmCmd =
"rm ../../../../test/simOutFiles/*.dat";
1224 system(rmCmd.c_str());
1225 for (
int i = 0; i < ofNames.size(); i++) {
1231 if (!ofStreams[i].is_open()) {
1233 if (!ofStreams[i]) {
1242 set<UdpPort> udpDstPorts;
1244 ofsUAIF_Gold_Meta_FileName, ofsUAIF_Gold_DLen_FileName, udpDstPorts) !=
NTS_OK) {
1250 bool isReady =
false;
1252 #if HLS_VERSION == 2017
1289 if (!ssUOE_MMIO_Ready.empty()) {
1290 isReady = ssUOE_MMIO_Ready.read();
1296 for (set<UdpPort>::iterator it=udpDstPorts.begin(); it!=udpDstPorts.end(); ++it) {
1298 ssUAIF_UOE_LsnReq.write(portToOpen);
1299 for (
int i=0; i<2; ++i) {
1300 #if HLS_VERSION == 2017
1341 for (set<UdpPort>::iterator it=udpDstPorts.begin(); it!=udpDstPorts.end(); ++it) {
1344 if (!ssUOE_UAIF_LsnRep.empty()) {
1345 openReply = ssUOE_UAIF_LsnRep.read();
1346 if (not openReply) {
1348 portToOpen.to_int(), portToOpen.to_int());
1353 portToOpen.to_int(), portToOpen.to_int());
1359 int nrIPRX_UOE_Chunks = 0;
1360 int nrIPRX_UOE_Packets = 0;
1361 int nrIPRX_UOE_Bytes = 0;
1363 nrIPRX_UOE_Chunks, nrIPRX_UOE_Packets, nrIPRX_UOE_Bytes)) {
1364 printInfo(
THIS_NAME,
"Done with the creation of the Rx input traffic as streams:\n");
1365 printInfo(
THIS_NAME,
"\tGenerated %d chunks in %d IP packets, for a total of %d bytes.\n\n",
1366 nrIPRX_UOE_Chunks, nrIPRX_UOE_Packets, nrIPRX_UOE_Bytes);
1374 int tbRun = (nrErr == 0) ? (nrIPRX_UOE_Chunks +
TB_GRACE_TIME) : 0;
1376 #if HLS_VERSION == 2017
1413 if (!ssUOE_MMIO_Ready.empty()) {
1414 isReady = ssUOE_MMIO_Ready.read();
1420 printInfo(
THIS_NAME,
"############################################################################\n");
1422 printInfo(
THIS_NAME,
"############################################################################\n");
1426 int nrUOE_UAIF_DataChunks=0, nrUOE_UAIF_DataGrams=0, nrUOE_UAIF_DataBytes=0;
1428 ofNames[0], nrUOE_UAIF_DataChunks, nrUOE_UAIF_DataGrams, nrUOE_UAIF_DataBytes)) {
1434 printInfo(
THIS_NAME,
"\tReceived %d chunks in %d datagrams, for a total of %d bytes.\n\n",
1435 nrUOE_UAIF_DataChunks, nrUOE_UAIF_DataGrams, nrUOE_UAIF_DataBytes);
1438 int nrUOE_UAIF_MetaChunks=0, nrUOE_UAIF_MetaGrams=0, nrUOE_UAIF_MetaBytes=0;
1440 ofNames[1], nrUOE_UAIF_MetaChunks, nrUOE_UAIF_MetaGrams, nrUOE_UAIF_MetaBytes)) {
1445 int nrUOE_UAIF_DLenChunks=0, nrUOE_UAIF_DLenGrams=0, nrUOE_UAIF_DLenBytes=0;
1447 ofNames[2], nrUOE_UAIF_DLenChunks, nrUOE_UAIF_DLenGrams, nrUOE_UAIF_DLenBytes)) {
1460 int res = system((
"diff --brief -w " + \
1461 std::string(ofsUAIF_Data_FileName) +
" " + \
1462 std::string(ofsUAIF_Gold_Data_FileName) +
" ").c_str());
1465 ofsUAIF_Data_FileName.c_str(), ofsUAIF_Gold_Data_FileName.c_str());
1468 res = system((
"diff --brief -w " + \
1469 std::string(ofsUAIF_Meta_FileName) +
" " + \
1470 std::string(ofsUAIF_Gold_Meta_FileName) +
" ").c_str());
1473 ofsUAIF_Meta_FileName.c_str(), ofsUAIF_Gold_Meta_FileName.c_str());
1476 res = system((
"diff --brief -w " + \
1477 std::string(ofsUAIF_DLen_FileName) +
" " + \
1478 std::string(ofsUAIF_Gold_DLen_FileName) +
" ").c_str());
1481 ofsUAIF_DLen_FileName.c_str(), ofsUAIF_Gold_DLen_FileName.c_str());
1493 ofstream ofsIPTX_Data;
1494 string ofsIPTX_Data_FileName =
"../../../../test/simOutFiles/soIPTX_Data.dat";
1495 string ofsIPTX_Gold_FileName =
"../../../../test/simOutFiles/soIPTX_Gold.dat";
1498 if (not
isDatFile(ofsIPTX_Data_FileName)) {
1499 printFatal(
THIS_NAME,
"File \'%s\' is not of type \'DAT\'.\n", ofsIPTX_Data_FileName.c_str());
1502 string rmCmd =
"rm ../../../../test/simOutFiles/*.dat";
1503 system(rmCmd.c_str());
1504 if (!ofsIPTX_Data.is_open()) {
1505 ofsIPTX_Data.open(ofsIPTX_Data_FileName.c_str(),
ofstream::out);
1506 if (!ofsIPTX_Data) {
1514 queue<UdpAppMeta> udpAppMeta;
1515 queue<UdpAppDLen> updDataLengths;
1517 udpAppMeta, updDataLengths, tbMode)) {
1522 int nrUAIF_UOE_Chunks=0;
1524 ssUAIF_UOE_Meta,
"ssUAIF_UOE_Meta",
1525 ssUAIF_UOE_DLen,
"ssUAIF_UOE_DLen",
1529 nrUAIF_UOE_Chunks)) {
1534 int tbRun = (nrErr == 0) ? (nrUAIF_UOE_Chunks +
TB_GRACE_TIME) : 0;
1536 #if HLS_VERSION == 2017
1577 printInfo(
THIS_NAME,
"############################################################################\n");
1579 printInfo(
THIS_NAME,
"############################################################################\n");
1583 int nrUOE_IPTX_Chunks=0, nrUOE_IPTX_Packets=0, nrUOE_IPTX_Bytes=0;
1585 ofsIPTX_Data_FileName, nrUOE_IPTX_Chunks, nrUOE_IPTX_Packets, nrUOE_IPTX_Bytes)) {
1591 printInfo(
THIS_NAME,
"\tReceived %d chunks in %d packets, for a total of %d bytes.\n\n",
1592 nrUOE_IPTX_Chunks, nrUOE_IPTX_Packets, nrUOE_IPTX_Bytes);
1599 std::string(ofsIPTX_Gold_FileName));
1602 ofsIPTX_Data_FileName.c_str(), ofsIPTX_Gold_FileName.c_str());
1617 printInfo(
THIS_NAME,
"== DROP-MODE : Fill up UOE with IPv4 traffic and expect packets to be dropped.\n");
1626 string ofsUAIF_Data_FileName =
"../../../../test/simOutFiles/soUAIF_Data.dat";
1627 string ofsUAIF_Meta_FileName =
"../../../../test/simOutFiles/soUAIF_Meta.dat";
1628 string ofsUAIF_DLen_FileName =
"../../../../test/simOutFiles/soUAIF_DLen.dat";
1629 string ofsUAIF_Gold_Data_FileName =
"../../../../test/simOutFiles/soUAIF_Gold_Data.dat";
1630 string ofsUAIF_Gold_Meta_FileName =
"../../../../test/simOutFiles/soUAIF_Gold_Meta.dat";
1631 string ofsUAIF_Gold_DLen_FileName =
"../../../../test/simOutFiles/soUAIF_Gold_DLen.dat";
1632 vector<string> ofNames;
1633 ofNames.push_back(ofsUAIF_Data_FileName);
1634 ofNames.push_back(ofsUAIF_Meta_FileName);
1635 ofNames.push_back(ofsUAIF_DLen_FileName);
1636 ofstream ofStreams[ofNames.size()];
1639 string rmCmd =
"rm ../../../../test/simOutFiles/*.dat";
1640 system(rmCmd.c_str());
1641 for (
int i = 0; i < ofNames.size(); i++) {
1647 if (!ofStreams[i].is_open()) {
1649 if (!ofStreams[i]) {
1659 touchCmd =
"touch " + ofsUAIF_Gold_Data_FileName;
1660 system(touchCmd.c_str());
1661 touchCmd =
"touch " + ofsUAIF_Gold_Meta_FileName;
1662 system(touchCmd.c_str());
1663 touchCmd =
"touch " + ofsUAIF_Gold_DLen_FileName;
1664 system(touchCmd.c_str());
1667 int nrIPRX_UOE_Chunks = 0;
1668 int nrIPRX_UOE_Packets = 0;
1669 int nrIPRX_UOE_Bytes = 0;
1671 nrIPRX_UOE_Chunks, nrIPRX_UOE_Packets, nrIPRX_UOE_Bytes)) {
1672 printInfo(
THIS_NAME,
"Done with the creation of the Rx input traffic as streams:\n");
1673 printInfo(
THIS_NAME,
"\tGenerated %d chunks in %d IP packets, for a total of %d bytes.\n\n",
1674 nrIPRX_UOE_Chunks, nrIPRX_UOE_Packets, nrIPRX_UOE_Bytes);
1682 int tbRun = (nrErr == 0) ? (nrIPRX_UOE_Chunks +
TB_GRACE_TIME) : 0;
1684 #if HLS_VERSION == 2017
1721 if (!ssUOE_MMIO_Ready.empty()) {
1722 ssUOE_MMIO_Ready.read();
1728 printInfo(
THIS_NAME,
"############################################################################\n");
1730 printInfo(
THIS_NAME,
"############################################################################\n");
1742 int res = system((
"diff --brief -w " + \
1743 std::string(ofsUAIF_Data_FileName) +
" " + \
1744 std::string(ofsUAIF_Gold_Data_FileName) +
" ").c_str());
1747 ofsUAIF_Data_FileName.c_str(), ofsUAIF_Gold_Data_FileName.c_str());
1750 res = system((
"diff --brief -w " + \
1751 std::string(ofsUAIF_Meta_FileName) +
" " + \
1752 std::string(ofsUAIF_Gold_Meta_FileName) +
" ").c_str());
1755 ofsUAIF_Meta_FileName.c_str(), ofsUAIF_Gold_Meta_FileName.c_str());
1758 res = system((
"diff --brief -w " + \
1759 std::string(ofsUAIF_DLen_FileName) +
" " + \
1760 std::string(ofsUAIF_Gold_DLen_FileName) +
" ").c_str());
1763 ofsUAIF_DLen_FileName.c_str(), ofsUAIF_Gold_DLen_FileName.c_str());
1777 printInfo(
THIS_NAME,
"This testbench was executed with the following parameters: \n");
1779 for (
int i=2; i<argc; i++) {
1785 printError(
THIS_NAME,
"#### TEST BENCH FAILED : TOTAL NUMBER OF ERROR(S) = %2d ####\n", nrErr);
1788 printInfo(
THIS_NAME,
"FYI - You may want to check for \'ERROR\' and/or \'WARNING\' alarms in the LOG file...\n\n");
1791 printInfo(
THIS_NAME,
"#############################################################\n");
1793 printInfo(
THIS_NAME,
"#############################################################\n");
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
Class IPv4 Packet for simulation.
void setIpTotalLength(int totLen)
UdpCsum udpRecalculateChecksum()
Recalculate checksum of an UDP datagram after it was modified.
void setIpSourceAddress(int addr)
bool isWellFormed(const char *callerName, bool checkIp4TotLen=true, bool checkIp4HdrCsum=true, bool checkUdpLen=true, bool checkLy4Csum=true)
Checks if the IP header and embedded protocol fields are properly set.
Ip4Addr getIpSourceAddress()
void pushChunk(AxisIp4 ip4Chunk)
SimUdpDatagram getUdpDatagram()
void setIpDestinationAddress(int addr)
UdpPort getUdpDestinationPort()
Ip4Addr getIpDestinationAddress()
bool addIpPayload(SimUdpDatagram &udpDgm, int len=-1)
Append some data to this packet from a UDP datagram.
bool writeToDatFile(ofstream &outFileStream)
Dump this IP packet as AxisIp4 chunks into a file.
void setUdpChecksum(UdpCsum csum)
void pushChunk(AxisUdp udpChunk)
int getUdpDestinationPort()
SimUdpDatagram pullHeader()
Pull the header of this datagram.
void setUdpLength(UdpLen len)
void cloneHeader(SimUdpDatagram &udpDgm)
Clone the header of a UDP datagram.
UdpCsum reCalculateUdpChecksum(Ip4Addr ipSa, Ip4Addr ipDa)
Recalculate the UDP checksum of a datagram.
void setUdpDestinationPort(int port)
void setUdpSourcePort(int port)
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 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 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.
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.
bool readAxisRawFromFile(AxisRaw &axisRaw, ifstream &inpFileStream)
Retrieve an Axis raw data chunk from a file.
bool readFpgaSndPortFromLine(Ly4Port &port, string stringBuffer)
Retrieve an FPGA send port from a string.
int createGoldenTxFiles(string inpData_FileName, string outData_GoldName, queue< UdpAppMeta > &udpMetaQueue, queue< UdpAppDLen > &updDLenQueue, char tbMode)
Create the golden IPTX reference file from an input UAIF test file.
void uoe_top_wrap(CmdBit piMMIO_En, stream< ap_uint< 16 > > &soMMIO_DropCnt, stream< StsBool > &soMMIO_Ready, stream< AxisIp4 > &siIPRX_Data, stream< AxisIp4 > &soIPTX_Data, stream< UdpAppLsnReq > &siUAIF_LsnReq, stream< UdpAppLsnRep > &soUAIF_LsnRep, stream< UdpAppClsReq > &siUAIF_ClsReq, stream< UdpAppClsRep > &soUAIF_ClsRep, stream< UdpAppData > &soUAIF_Data, stream< UdpAppMeta > &soUAIF_Meta, stream< UdpAppDLen > &soUAIF_DLen, stream< UdpAppData > &siUAIF_Data, stream< UdpAppMeta > &siUAIF_Meta, stream< UdpAppDLen > &siUAIF_DLen, stream< AxisIcmp > &soICMP_Data)
A wrapper for the Toplevel of the UDP Offload Engine (UOE)
int main(int argc, char *argv[])
Main function.
bool drainUdpDLenStreamToFile(stream< UdpAppDLen > &ss, string ssName, string datFile, int &nrChunks, int &nrFrames, int &nrBytes)
Empty an UdpDLen stream to a DAT file.
bool drainMmioDropCounter(stream< ap_uint< 16 > > &ss, string ssName)
Empty the DropCounter stream and throw it away.
void stepSim()
Increment the simulation counter.
bool readDatagramFromFile(const char *myName, SimUdpDatagram &appDatagram, ifstream &ifsData, UdpAppMeta &udpAppMeta, queue< UdpAppMeta > &udpMetaQueue, queue< UdpAppDLen > &updDLenQueue, int &inpChunks, int &inpDgrms, int &inpBytes, char tbMode)
Read a datagram from a DAT file.
int createGoldenRxFiles(string inpData_FileName, string outData_GoldName, string outMeta_GoldName, string outDLen_GoldName, set< UdpPort > &udpPorts)
Create the golden Rx APP reference files from an input IPRX test file.
bool drainUdpMetaStreamToFile(stream< UdpAppMeta > &ss, string ssName, string datFile, int &nrChunks, int &nrFrames, int &nrBytes)
Empty an UdpMeta stream to a DAT file.
int createUdpTxTraffic(stream< AxisApp > &ssData, const string ssDataName, stream< UdpAppMeta > &ssMeta, const string ssMetaName, stream< UdpAppDLen > &ssDLen, const string ssDLenName, string datFile, queue< UdpAppMeta > &metaQueue, queue< UdpAppDLen > &dlenQueue, int &nrFeededChunks)
Create the UDP Tx traffic as streams from an input test file.
void uoe_top(CmdBit piMMIO_En, stream< ap_uint< 16 > > &soMMIO_DropCnt, stream< StsBool > &soMMIO_Ready, stream< AxisRaw > &siIPRX_Data, stream< AxisRaw > &soIPTX_Data, stream< UdpAppLsnReq > &siUAIF_LsnReq, stream< UdpAppLsnRep > &soUAIF_LsnRep, stream< UdpAppClsReq > &siUAIF_ClsReq, stream< UdpAppClsRep > &soUAIF_ClsRep, stream< UdpAppData > &soUAIF_Data, stream< UdpAppMeta > &soUAIF_Meta, stream< UdpAppDLen > &soUAIF_DLen, stream< UdpAppData > &siUAIF_Data, stream< UdpAppMeta > &siUAIF_Meta, stream< UdpAppDLen > &siUAIF_DLen, stream< AxisRaw > &soICMP_Data)
Top of UDP Offload Engine (UOE)
#define printError(callerName, format,...)
A macro to print an error message.
void printAxisRaw(const char *callerName, AxisRaw chunk)
Prints an Axis raw data chunk (used for debugging).
void pAxisRawCast(hls::stream< TypeIn > &si, hls::stream< TypeOut > &so)
AxisRaw cast - Casts an AxisRaw stream to/from an AxisRaw derived class.
void printSockAddr(const char *callerName, SockAddr sockAddr)
Print a socket address.
#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)
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.
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.
: Testbench for the UDP Offload Engine (UOE).