42 #include "../src/udp.hpp"
46 #define maxOverflowValue 2000
51 ap_uint<64> tempOutput = 0;
52 unsigned short int tempValue = 16;
53 static const char*
const lut =
"0123456789ABCDEF";
55 for (
unsigned short int i = 0; i<stringToConvert.size();++i) {
57 for (
unsigned short int j = 0;j<16;++j) {
58 if (lut[j] == stringToConvert[i]) {
63 if (tempValue != 16) {
64 for (
short int k = 3;k>=0;--k) {
65 if (tempValue >= pow(2.0, k)) {
66 tempOutput.bit(63-(4*i+(3-k))) = 1;
67 tempValue -=
static_cast <unsigned short int>(pow(2.0, k));
76 std::vector<std::string>
parseLine(std::string stringBuffer)
78 std::vector<std::string> tempBuffer;
81 while (stringBuffer.find(
" ") != std::string::npos)
83 std::string temp = stringBuffer.substr(0, stringBuffer.find(
" "));
84 stringBuffer = stringBuffer.substr(stringBuffer.find(
" ")+1, stringBuffer.length());
85 tempBuffer.push_back(temp);
87 tempBuffer.push_back(stringBuffer);
92 std::string outputString =
"0000000000000000";
93 unsigned short int tempValue = 16;
94 static const char*
const lut =
"0123456789ABCDEF";
95 for (
int i = 15;i>=0;--i) {
97 for (
unsigned short int k = 0;k<4;++k) {
98 if (inputNumber.bit((i+1)*4-k-1) == 1)
99 tempValue +=
static_cast <unsigned short int>(pow(2.0, 3-k));
101 outputString[15-i] = lut[tempValue];
107 std::string outputString =
"00000000";
108 unsigned short int tempValue = 16;
109 static const char*
const lut =
"0123456789ABCDEF";
110 for (
int i = 7;i>=0;--i) {
112 for (
unsigned short int k = 0;k<4;++k) {
113 if (inputNumber.bit((i+1)*4-k-1) == 1)
114 tempValue +=
static_cast <unsigned short int>(pow(2.0, 3-k));
116 outputString[7-i] = lut[tempValue];
122 std::string outputString =
"0000";
123 unsigned short int tempValue = 16;
124 static const char*
const lut =
"0123456789ABCDEF";
125 for (
int i = 3;i>=0;--i) {
127 for (
unsigned short int k = 0;k<4;++k) {
128 if (inputNumber.bit((i+1)*4-k-1) == 1)
129 tempValue +=
static_cast <unsigned short int>(pow(2.0, 3-k));
131 outputString[4-i] = lut[tempValue];
137 string outputString =
"00";
138 unsigned short int tempValue = 16;
139 static const char*
const lut =
"0123456789ABCDEF";
140 for (
int i = 1;i>=0;--i) {
142 for (
unsigned short int k = 0;k<4;++k) {
143 if (inputNumber.bit((i+1)*4-k-1) == 1)
144 tempValue +=
static_cast <unsigned short int>(pow(2.0, 3-k));
146 outputString[1-i] = lut[tempValue];
152 ap_uint<64> tempOutput = 0;
153 unsigned short int tempValue = 16;
154 static const char*
const lut =
"0123456789ABCDEF";
156 for (
unsigned short int i = 0; i<dataString.size();++i) {
157 for (
unsigned short int j = 0;j<16;++j) {
158 if (lut[j] == dataString[i]) {
163 if (tempValue != 16) {
164 for (
short int k = 3;k>=0;--k) {
165 if (tempValue >= pow(2.0, k)) {
166 tempOutput.bit(63-(4*i+(3-k))) = 1;
167 tempValue -=
static_cast <unsigned short int>(pow(2.0, k));
176 ap_uint<32> tempOutput = 0;
177 unsigned short int tempValue = 16;
178 static const char*
const lut =
"0123456789ABCDEF";
180 for (
unsigned short int i = 0; i<8;++i) {
181 for (
unsigned short int j = 0;j<16;++j) {
182 if (lut[j] == parseString[i]) {
187 if (tempValue != 16) {
188 for (
short int k = 3;k>=0;--k) {
189 if (tempValue >= pow(2.0, k)) {
190 tempOutput.bit(31-(4*i+(3-k))) = 1;
191 tempValue -=
static_cast <unsigned short int>(pow(2.0, k));
200 ap_uint<8> tempOutput = 0;
201 unsigned short int tempValue = 16;
202 static const char*
const lut =
"0123456789ABCDEF";
204 for (
unsigned short int i = 0; i<2;++i) {
205 for (
unsigned short int j = 0;j<16;++j) {
206 if (lut[j] == keepString[i]) {
211 if (tempValue != 16) {
212 for (
short int k = 3;k>=0;--k) {
213 if (tempValue >= pow(2.0, k)) {
214 tempOutput.bit(7-(4*i+(3-k))) = 1;
215 tempValue -=
static_cast <unsigned short int>(pow(2.0, k));
224 ap_uint<16> tempOutput = 0;
225 unsigned short int tempValue = 16;
226 static const char*
const lut =
"0123456789ABCDEF";
228 for (
unsigned short int i = 0; i<4;++i) {
229 for (
unsigned short int j = 0;j<16;++j) {
230 if (lut[j] == parseString[i]) {
235 if (tempValue != 16) {
236 for (
short int k = 3;k>=0;--k) {
237 if (tempValue >= pow(2.0, k)) {
238 tempOutput.bit(15-(4*i+(3-k))) = 1;
239 tempValue -=
static_cast <unsigned short int>(pow(2.0, k));
247 int main(
int argc,
char *argv[]) {
249 stream<axiWord> inputPathInDataFIFO(
"inputPathInDataFIFO");
250 stream<axiWord> inputPathOutDataFIFO(
"inputPathOutDataFIFO");
251 stream<ap_uint<16> > openPortFIFO(
"openPortFIFO");
252 stream<bool> confirmPortStatusFIFO(
"confirmPortStatusFIFO");
253 stream<ap_uint<16> > inputPathPortRealeaseFIFO(
"inputPathPortRealeaseFIFO");
254 stream<metadata> inputPathOutputMetadataFIFO(
"inputPathOutputMetadataFIFO");
255 stream<axiWord> outputPathInDataFIFO(
"outputPathInDataFIFO");
256 stream<axiWord> outputPathOutDataFIFO(
"outputPathOutDataFIFO");
257 stream<metadata> outputPathInMetadataFIFO(
"outputPathInMetadataFIFO");
258 stream<ap_uint<16> > outputpathInLengthFIFO(
"outputpathInLengthFIFO");
259 stream<ipTuple> outIPaddressesFIFO(
"outIPaddressesFIFO");
260 stream<axiWord> outPortUnreachableFIFO(
"outPortUnreachableFIFO");
266 ap_uint<16> openPortData = 0;
267 bool portStatusData =
false;
271 ap_uint<16> outputPathInputLength = 0;
275 uint16_t inputSourceIP = 0;
276 uint16_t inputDestinationIP = 0;
278 std::string dataString;
285 uint32_t errCount = 0;
292 ifstream goldenOutputRx;
293 ifstream goldenOutputTx;
295 uint32_t overflowCounter = 0;
299 std::cout <<
"You need to provide at least one parameter (the input file name)!" << std::endl;
302 rxInput.open(argv[1]);
304 std::cout <<
" Error opening Rx input file!" << std::endl;
307 txInput.open(argv[2]);
309 std::cout <<
" Error opening Tx input file!" << std::endl;
312 rxOutput.open(
"rxOutput.dat");
314 std::cout <<
" Error opening output file!" << std::endl;
317 portStatus.open(
"portStatus.dat");
319 std::cout <<
" Error opening port status file!" << std::endl;
322 txOutput.open(
"txOutput.dat");
324 cout <<
"Error openingn Tx Output file!" << endl;
327 goldenOutputRx.open(
"../../../../sources/goldenOutput/rxGoldenOutput.short.dat");
328 if (!goldenOutputRx) {
329 cout <<
"Error opening golden output file for the Rx side. Check that the correct path is provided!" << endl;
332 goldenOutputTx.open(
"../../../../sources/goldenOutput/txGoldenOutput.short.dat");
333 if (!goldenOutputTx) {
334 cout <<
"Error opening golden output file for the Tx side. Check that the correct path is provided!" << endl;
337 std::cerr <<
"Input File: " << argv[1] << std::endl << std::endl;
339 inputPathPortRealeaseFIFO.write(0x1532);
340 for (
short int i= 0;i<10;++i)
341 udp(inputPathInDataFIFO, inputPathOutDataFIFO, openPortFIFO, confirmPortStatusFIFO,
342 inputPathOutputMetadataFIFO, inputPathPortRealeaseFIFO, outputPathInDataFIFO, outputPathOutDataFIFO, outputPathInMetadataFIFO, outputpathInLengthFIFO, outPortUnreachableFIFO);
346 openPortFIFO.write(0x80);
347 for (
short int i= 0;i<3;++i)
348 udp(inputPathInDataFIFO, inputPathOutDataFIFO, openPortFIFO, confirmPortStatusFIFO,
349 inputPathOutputMetadataFIFO, inputPathPortRealeaseFIFO, outputPathInDataFIFO, outputPathOutDataFIFO, outputPathInMetadataFIFO, outputpathInLengthFIFO, outPortUnreachableFIFO);
351 if (!confirmPortStatusFIFO.empty()) {
352 temp = confirmPortStatusFIFO.read();
353 std::cerr <<
"Port opened successfully!" << std::endl;
356 std::cerr <<
"Error, port not opened successfully." << std::endl;
360 inputPathPortRealeaseFIFO.write(temp);
361 for (
short int i= 0;i<10;++i)
362 udp(inputPathInDataFIFO, inputPathOutDataFIFO, openPortFIFO, confirmPortStatusFIFO,
363 inputPathOutputMetadataFIFO, inputPathPortRealeaseFIFO, outputPathInDataFIFO, outputPathOutDataFIFO, outputPathInMetadataFIFO, outputpathInLengthFIFO, outPortUnreachableFIFO);
366 uint32_t noOfLines = 0;
367 while (!rxInput.eof()) {
368 std::string stringBuffer;
369 getline(rxInput, stringBuffer);
370 std::vector<std::string> stringVector =
parseLine(stringBuffer);
371 string dataString = stringVector[0];
372 string keepString = stringVector[2];
375 inputPathInputData.
last = atoi(stringVector[1].c_str());
376 inputPathInDataFIFO.write(inputPathInputData);
380 while (!inputPathInDataFIFO.empty() || overflowCounter <
maxOverflowValue) {
381 udp(inputPathInDataFIFO, inputPathOutDataFIFO, openPortFIFO, confirmPortStatusFIFO, inputPathOutputMetadataFIFO,
382 inputPathPortRealeaseFIFO, outputPathInDataFIFO, outputPathOutDataFIFO, outputPathInMetadataFIFO, outputpathInLengthFIFO, outPortUnreachableFIFO);
385 if (inputPathInDataFIFO.empty())
389 rxInput.open(argv[1]);
391 cerr << endl <<
"Test 4: Exercising the Rx Path" << endl;
392 openPortFIFO.write(0x80);
393 for (
short int i= 0;i<3;++i)
394 udp(inputPathInDataFIFO, inputPathOutDataFIFO, openPortFIFO, confirmPortStatusFIFO,
395 inputPathOutputMetadataFIFO, inputPathPortRealeaseFIFO, outputPathInDataFIFO, outputPathOutDataFIFO, outputPathInMetadataFIFO, outputpathInLengthFIFO, outPortUnreachableFIFO);
397 if (!confirmPortStatusFIFO.empty()) {
398 temp = confirmPortStatusFIFO.read();
399 std::cerr << endl <<
"Port opened successfully!" << std::endl;
402 std::cerr << endl <<
"Error, port not opened successfully." << std::endl;
407 while (!rxInput.eof()) {
408 std::string stringBuffer;
409 getline(rxInput, stringBuffer);
410 std::vector<std::string> stringVector =
parseLine(stringBuffer);
411 string dataString = stringVector[0];
412 string keepString = stringVector[2];
416 inputPathInputData.
last = atoi(stringVector[1].c_str());
417 inputPathInDataFIFO.write(inputPathInputData);
421 while (!inputPathInDataFIFO.empty() || overflowCounter <
maxOverflowValue) {
422 udp(inputPathInDataFIFO, inputPathOutDataFIFO, openPortFIFO, confirmPortStatusFIFO, inputPathOutputMetadataFIFO,
423 inputPathPortRealeaseFIFO, outputPathInDataFIFO, outputPathOutDataFIFO, outputPathInMetadataFIFO, outputpathInLengthFIFO, outPortUnreachableFIFO);
426 if (inputPathInDataFIFO.empty())
430 cerr << endl <<
"Rx test complete." << endl;
433 cerr << endl <<
"Test 5: Exercising the Tx Path" << endl;
436 while (!txInput.eof()) {
437 std::string stringBuffer;
438 getline(txInput, stringBuffer);
439 std::vector<std::string> stringVector =
parseLine(stringBuffer);
440 string sourcePort = stringVector[0];
441 string destinationPort = stringVector[1];
442 string sourceIP = stringVector[2];
443 string destinationIP = stringVector[3];
444 string payloadLength = stringVector[4];
445 string dataString = stringVector[5];
446 string keepString = stringVector[6];
449 outputPathInData.
last = atoi(stringVector[7].c_str());
455 outputPathInDataFIFO.write(outputPathInData);
456 if (outputPathInputLength != 0) {
457 outputPathInMetadataFIFO.write(outputPathInputMetadata);
458 outputpathInLengthFIFO.write(outputPathInputLength);
463 while (!outputPathInDataFIFO.empty() || overflowCounter <
maxOverflowValue) {
464 udp(inputPathInDataFIFO, inputPathOutDataFIFO, openPortFIFO, confirmPortStatusFIFO, inputPathOutputMetadataFIFO,
465 inputPathPortRealeaseFIFO, outputPathInDataFIFO, outputPathOutDataFIFO, outputPathInMetadataFIFO, outputpathInLengthFIFO, outPortUnreachableFIFO);
468 if (outputPathInDataFIFO.empty())
473 cerr << endl <<
"Tx test complete. Verifying result." << endl;
475 while (!outputPathOutDataFIFO.empty()) {
476 axiWord tempOutput = outputPathOutDataFIFO.read();
477 goldenOutputTx >> hex >> txCompareOutput.
data >> txCompareOutput.
last >> txCompareOutput.
keep;
478 if (txCompareOutput.
data != tempOutput.
data || txCompareOutput.
last != tempOutput.
last || txCompareOutput.
keep != tempOutput.
keep) {
486 txOutput << dataOutput <<
" " << tempOutput.
last <<
" " << keepOutput << endl;
494 while (!inputPathOutDataFIFO.empty() && !goldenOutputRx.eof()) {
498 axiWord tempOutput = inputPathOutDataFIFO.read();
499 goldenOutputRx >> hex >> compareWord.
data >> compareWord.
last;
500 if (compareWord.
data != tempOutput.
data || compareWord.
last != tempOutput.
last) {
507 rxOutput << dataOutput <<
" " << tempOutput.
last << endl;
510 cerr << endl <<
"Errors during testing. Check the output file." << endl;
513 cerr << endl <<
"All Tests passed succesfully." << endl;
515 while(!outPortUnreachableFIFO.empty())
516 outPortUnreachableFIFO.read();
517 while(!inputPathOutputMetadataFIFO.empty())
518 inputPathOutputMetadataFIFO.read();
519 while(!inputPathOutDataFIFO.empty())
520 inputPathOutDataFIFO.read();
ap_uint< 16 > encodeApUint16(string parseString)
int main(int argc, char *argv[])
ap_uint< 64 > encodeApUint64(string dataString)
string decodeApUint32(ap_uint< 32 > inputNumber)
ap_uint< 32 > encodeApUint32(string parseString)
string decodeApUint8(ap_uint< 8 > inputNumber)
ap_uint< 8 > encodeApUint8(string keepString)
std::vector< std::string > parseLine(std::string stringBuffer)
string decodeApUint16(ap_uint< 16 > inputNumber)
string decodeApUint64(ap_uint< 64 > inputNumber)
ap_uint< 64 > convertString(std::string stringToConvert)