39 #define THIS_NAME "TB"
41 #define TRACE_OFF 0x0000
42 #define TRACE_CGF 1 << 1
43 #define TRACE_ARP 1 << 2
44 #define TRACE_ALL 0xFFFF
46 #define DEBUG_LEVEL (TRACE_OFF)
73 stream<Ip4Addr> &siIPTX_LookupReq,
74 stream<ArpLkpReply> &soIPTX_LookupRep,
82 static bool macAddrOfGatewayIsResolved =
false;
85 if (!siIPTX_LookupReq.empty()) {
86 siIPTX_LookupReq.read(ip4ToMacLkpReq);
88 printIp4Addr(myName,
"Received a lookup request from [IPTX] with key = ",
91 if (ip4ToMacLkpReq == piGatewayAddr) {
93 if (macAddrOfGatewayIsResolved) {
94 EthAddr aComposedMacAddr = 0xFECA00000000 | piGatewayAddr;
95 soIPTX_LookupRep.write(
ArpLkpReply(aComposedMacAddr,
true));
97 printInfo(myName,
"MAC lookup = HIT - Replying with MAC = 0x%12.12lX\n",
98 aComposedMacAddr.to_ulong());
105 EthAddr aComposedMacAddr = 0xADDE00000000 | piGatewayAddr;
106 soIPTX_LookupRep.write(
ArpLkpReply(aComposedMacAddr,
false));
107 printWarn(myName,
"Result of MAC lookup = NO-HIT \n");
108 macAddrOfGatewayIsResolved =
true;
111 else if ((ip4ToMacLkpReq & piSubNetMask) == (piGatewayAddr & piSubNetMask)) {
113 EthAddr aComposedMacAddr = 0xFECA00000000 | ip4ToMacLkpReq;
114 soIPTX_LookupRep.write(
ArpLkpReply(aComposedMacAddr,
true));
116 printInfo(myName,
"MAC lookup = HIT - Replying with MAC = 0x%12.12lX\n",
117 aComposedMacAddr.to_ulong());
121 printWarn(myName,
"Result of MAC lookup = NO-HIT \n");
139 string inpDAT_FileName,
140 string outDAT_GoldName,
151 char currPath[FILENAME_MAX];
153 int inpChunks=0, outChunks=0;
154 int inpPackets=0, outFrames=0;
155 int inpBytes=0, outBytes=0;
156 bool macAddrOfGatewayIsResolved =
false;
159 ifsDAT.open(inpDAT_FileName.c_str());
161 getcwd(currPath,
sizeof(currPath));
162 printError(
"TB",
"Cannot open the file: %s \n\t (FYI - The current working directory is: %s) \n",
163 inpDAT_FileName.c_str(), currPath);
167 printError(
"TB",
"Cannot create golden files from input file \'%s\' because file is not of type \'.dat\'.\n",
168 inpDAT_FileName.c_str());
174 remove(outDAT_GoldName.c_str());
175 if (!ofsDAT.is_open()) {
179 outDAT_GoldName.c_str());
184 while ((ifsDAT.peek() != EOF) && (
ret !=
NTS_KO)) {
187 bool endOfPacket=
false;
190 while ((ifsDAT.peek() != EOF) && (!endOfPacket)) {
208 inpBytes += axisIp4.
getLen();
213 if(ipSA != myIp4Address) {
220 printError(myName,
"IP packet #%d is dropped because it is malformed.\n", inpPackets);
230 if ((ipDA & mySubNetMask) == (myGatewayAddr & mySubNetMask)) {
232 EthAddr macDaAddr = 0xFECA00000000 | ipDA;
238 if (macAddrOfGatewayIsResolved) {
239 EthAddr aComposedMacAddr = 0xFECA00000000 | myGatewayAddr;
241 printInfo(myName,
"Packet with remote IPv4 address to fall out of our sub-network.\n");
242 printInfo(myName,
"\tThe IP address of this packet is binded with the MAC address of the default gateway.\n");
246 printWarn(myName,
"First packet with remote IPv4 address to fall out of our sub-network.\n");
247 printIp4Addr(myName,
"\tThis packet will be dropped. Remote", ipDA);
251 macAddrOfGatewayIsResolved =
true;
259 printWarn(
THIS_NAME,
"Frame #%d is dropped because IP version is not \'4\'.\n", inpPackets);
271 printWarn(
THIS_NAME,
"Failed to verify the TCP checksum of Frame #%d.\n", inpPackets);
276 printWarn(
THIS_NAME,
"Failed to verify the UDP checksum of Frame #%d.\n", inpPackets);
290 outChunks += ethGoldFrame.
size();
291 outBytes += ethGoldFrame.
length();
303 printInfo(
THIS_NAME,
"\tProcessed %5d chunks in %4d packets, for a total of %6d bytes.\n",
304 inpChunks, inpPackets, inpBytes);
305 printInfo(
THIS_NAME,
"\tGenerated %5d chunks in %4d frames, for a total of %6d bytes.\n\n",
306 outChunks, outFrames, outBytes);
310 #if HLS_VERSION != 2017
334 stream<AxisIp4> &siL3MUX_Data,
336 stream<AxisEth> &soL2MUX_Data,
338 stream<Ip4Addr> &soARP_LookupReq,
339 stream<ArpLkpReply> &siARP_LookupRep)
342 stream<AxisRaw> ssiL3MUX_Data (
"ssiL3MUX_Data");
343 stream<AxisRaw> ssoL2MUX_Data (
"ssoL2MUX_Data");
368 int main(
int argc,
char* argv[]) {
383 EthAddr myMacAddress = 0x60504030201;
384 Ip4Addr mySubNetMask = 0xFFFF0000;
385 Ip4Addr myIp4Address = 0x0A0CC807;
386 Ip4Addr myGatewayAddr = 0x0A0C0001;
388 string ofsL2MUX_Data_FileName =
"../../../../test/simOutFiles/soL2MUX_Data.dat";
389 string ofsL2MUX_Gold_FileName =
"../../../../test/simOutFiles/soL2MUX_Gold.dat";
395 stream<AxisIp4> ssL3MUX_IPTX_Data (
"ssL3MUX_IPTX_Data");
396 int nrL3MUX_IPTX_Chunks = 0;
397 int nrL3MUX_IPTX_Frames = 0;
398 int nrL3MUX_IPTX_Bytes = 0;
400 stream<AxisEth> ssIPTX_L2MUX_Data (
"ssIPTX_L2MUX_Data");
401 int nrIPTX_L2MUX_Chunks = 0;
402 int nrIPTX_L2MUX_Frames = 0;
403 int nrIPTX_L2MUX_Bytes = 0;
405 stream<Ip4Addr> ssIPTX_ARP_LookupReq (
"ssIPTX_ARP_LookupReq");
406 stream<ArpLkpReply> ssARP_IPTX_LookupRep (
"ssARP_IPTX_LookupRep");
412 printFatal(
THIS_NAME,
"Missing testbench parameter:\n\t Expecting an input test vector file.\n");
416 myIp4Address = param;
417 printIp4Addr(
THIS_NAME,
"The input test vector is setting the IP address of the FPGA to", myIp4Address);
423 if (feedAxisFromFile<AxisIp4>(ssL3MUX_IPTX_Data,
"ssL3MUX_IPTX_Data",
string(argv[1]),
424 nrL3MUX_IPTX_Chunks, nrL3MUX_IPTX_Frames, nrL3MUX_IPTX_Bytes)) {
426 printInfo(
THIS_NAME,
"\tGenerated %d chunks in %d frames, for a total of %d bytes.\n\n",
427 nrL3MUX_IPTX_Chunks, nrL3MUX_IPTX_Frames, nrL3MUX_IPTX_Bytes);
437 ofstream outFileStream;
439 remove(ofsL2MUX_Data_FileName.c_str());
441 if (not
isDatFile(ofsL2MUX_Data_FileName)) {
442 printError(
THIS_NAME,
"File \'%s\' is not of type \'DAT\'.\n", ofsL2MUX_Data_FileName.c_str());
443 outFileStream.close();
447 if (!outFileStream.is_open()) {
448 outFileStream.open(ofsL2MUX_Data_FileName.c_str(),
ofstream::out);
449 if (!outFileStream) {
455 outFileStream << std::hex << std::noshowbase;
456 outFileStream << std::setfill(
'0');
463 myMacAddress, myIp4Address, mySubNetMask, myGatewayAddr)) {
468 printInfo(
THIS_NAME,
"############################################################################\n");
470 printInfo(
THIS_NAME,
"############################################################################\n");
471 printInfo(
THIS_NAME,
"This testbench will be executed with the following parameters: \n");
472 for (
int i=1; i<argc; i++) {
477 tbRun = (nrErr == 0) ? (nrL3MUX_IPTX_Chunks +
TB_GRACE_TIME) : 0;
481 #if HLS_VERSION == 2017
488 ssIPTX_ARP_LookupReq,
498 ssIPTX_ARP_LookupReq,
505 ssIPTX_ARP_LookupReq,
506 ssARP_IPTX_LookupRep,
514 if (!(ssIPTX_L2MUX_Data.empty())) {
515 ssIPTX_L2MUX_Data.read(axisEth);
520 nrIPTX_L2MUX_Chunks++;
521 nrIPTX_L2MUX_Bytes += axisEth.
getLen();
523 nrIPTX_L2MUX_Frames++;
535 outFileStream.close();
537 printInfo(
THIS_NAME,
"############################################################################\n");
539 printInfo(
THIS_NAME,
"############################################################################\n");
546 std::string(ofsL2MUX_Gold_FileName));
549 ofsL2MUX_Data_FileName.c_str(), ofsL2MUX_Gold_FileName.c_str(), res);
562 printError(
THIS_NAME,
"#### TEST BENCH FAILED : TOTAL NUMBER OF ERROR(S) = %2d ####\n", nrErr);
565 printInfo(
THIS_NAME,
"FYI - You may want to check for \'ERROR\' and/or \'WARNING\' alarms in the LOG file...\n\n");
568 printInfo(
THIS_NAME,
"#############################################################\n");
570 printInfo(
THIS_NAME,
"#############################################################\n");
LE_tData getLE_TData(int leHi=64 -1, int leLo=0) const
LE_tLast getLE_TLast() const
bool writeToDatFile(ofstream &outFileStream)
Dump this Ethernet frame as raw AxisEth chunks into a file.
void setMacDestinAddress(EthAddr addr)
bool addPayload(SimArpPacket arpPkt)
Add data payload to this frame from an ARP packet.
void setTypeLength(EthTypeLen typLen)
void setMacSourceAddress(EthAddr addr)
Class IPv4 Packet for simulation.
bool tcpVerifyChecksum()
Recalculate the TCP checksum and compare it with the one embedded into the segment.
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)
Ip4HdrCsum getIpHeaderChecksum()
bool udpVerifyChecksum()
Recalculate the UDP checksum and compare it with the one embedded into the datagram.
Ip4HdrCsum reCalculateIpHeaderChecksum()
Recalculate the IPv4 header checksum of a packet.
Ip4Addr getIpDestinationAddress()
#define TB_MAX_SIM_CYCLES
unsigned int gMaxSimCycles
int main(int argc, char *argv[])
Main function.
void pEmulateArp(stream< Ip4Addr > &siIPTX_LookupReq, stream< ArpLkpReply > &soIPTX_LookupRep, EthAddr piMacAddress, Ip4Addr piIp4Address, Ip4Addr piSubNetMask, Ip4Addr piGatewayAddr)
Emulate the behavior of the Address Resolution Process (ARP).
void stepSim()
Increment the simulation counter.
void iptx_top_wrap(EthAddr piMMIO_MacAddress, Ip4Addr piMMIO_SubNetMask, Ip4Addr piMMIO_GatewayAddr, stream< AxisIp4 > &siL3MUX_Data, stream< AxisEth > &soL2MUX_Data, stream< Ip4Addr > &soARP_LookupReq, stream< ArpLkpReply > &siARP_LookupRep)
A wrapper for the Toplevel of IP the IP Transmitter Handler (IPTX).
int createGoldenFile(string inpDAT_FileName, string outDAT_GoldName, EthAddr myMacAddress, Ip4Addr myIp4Address, Ip4Addr mySubNetMask, Ip4Addr myGatewayAddr)
Create the golden reference file from an input test file.
void iptx_top(EthAddr piMMIO_MacAddress, Ip4Addr piMMIO_SubNetMask, Ip4Addr piMMIO_GatewayAddr, stream< AxisRaw > &siL3MUX_Data, stream< AxisRaw > &soL2MUX_Data, stream< Ip4Addr > &soARP_LookupReq, stream< ArpLkpReply > &siARP_LookupRep)
Top of IP Transmitter Handler (IPTX)
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.
bool readTbParamFromFile(const string paramName, const string datFile, unsigned int ¶mVal)
Retrieve a testbench parameter from a DAT 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.
#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 printInfo(callerName, format,...)
A macro to print an information message.
void printIp4Addr(const char *callerName, const char *message, Ip4Addr ip4Addr)
Print an IPv4 address prepended with a message (used for debugging).
#define printWarn(callerName, format,...)
A macro to print a warning message.
#define concat3(firstCharConst, secondCharConst, thirdCharConst)
#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 IP Transmitter packet handler (IPTX).