cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
test_state_table.cpp
Go to the documentation of this file.
1 
26 #include "state_table.hpp"
27 
28 
29 using namespace hls;
30 
31 struct readVerify
32 {
33  int id;
34  char fifo;
35  int exp;
36 };
37 
38 void emptyFifos(std::ofstream& out, stream<sessionState>& rxFifoOut, stream<sessionState>& appFifoOut, stream<sessionState>& app2FifoOut, stream<ap_uint<16> >& slupOut, int iter)
39 {
40  sessionState outData;
41  ap_uint<16> outDataId;
42  while (!(rxFifoOut.empty()))
43  {
44  rxFifoOut.read(outData);
45  out << "Step " << iter << ": RX Fifo\t\t";
46  out << outData << std::endl;
47  }
48 
49  while (!(appFifoOut.empty()))
50  {
51  appFifoOut.read(outData);
52  out << "Step " << iter << ": App Fifo\t\t";
53  out << outData << std::endl;
54  }
55 
56  while (!(app2FifoOut.empty()))
57  {
58  app2FifoOut.read(outData);
59  out << "Step " << iter << ": App2 Fifo\t\t";
60  out << outData << std::endl;
61  }
62 
63  while (!(slupOut.empty()))
64  {
65  slupOut.read(outDataId);
66  out << "Step " << iter << ": Slup Fifo\t\t";
67  out << std::hex;
68  out << std::setfill('0');
69  out << std::setw(4) << outDataId;
70  out << std::endl;
71  }
72 }
73 
74 int main()
75 {
76  stream<stateQuery> rxIn;
77  stream<sessionState> rxOut;
78  stream<stateQuery> txAppIn;
79  stream<sessionState> txAppOut;
80  stream<stateQuery> txApp2In;
81  stream<sessionState> txApp2Out;
82  stream<ap_uint<16> > timerIn;
83  stream<ap_uint<16> > slupOut;
84 
85  stateQuery inData;
86  sessionState outData;
87 
88  std::ifstream inputFile;
89  std::ofstream outputFile;
90 
91  /*inputFile.open("/home/dasidler/toe/hls/toe/state_table/in.dat");
92  if (!inputFile)
93  {
94  std::cout << "Error: could not open test input file." << std::endl;
95  return -1;
96  }*/
97  outputFile.open("/home/dasidler/toe/hls/toe/state_table/out.dat");
98  if (!outputFile)
99  {
100  std::cout << "Error: could not open test output file." << std::endl;
101  }
102 
103  int count = 0;
104 
105  /*
106  * Test 1: rx(x, ESTA); timer(x), rx(x, FIN_WAIT)
107  */
108  //ap_uint<16> id = rand() % 100;
109  ap_uint<16> id = 0x57;
110  outputFile << "Test 1" << std::endl;
111  outputFile << "ID: " << id << std::endl;
112  while (count < 20)
113  {
114  switch (count)
115  {
116  case 1:
117  rxIn.write(stateQuery(id, ESTABLISHED, 1));
118  break;
119  case 2:
120  timerIn.write(id);
121  break;
122  case 3:
123  rxIn.write(stateQuery(id, FIN_WAIT_1, 1));
124  break;
125  default:
126  break;
127 
128  }
129  state_table(rxIn, txAppIn, txApp2In, timerIn, rxOut, txAppOut, txApp2Out, slupOut);
130  emptyFifos(outputFile, rxOut, txAppOut, txApp2Out, slupOut, count);
131  count++;
132  }
133  outputFile << "------------------------------------------------" << std::endl;
134 
135  //BREAK
136  count = 0;
137  while (count < 200)
138  {
139  state_table(rxIn, txAppIn, txApp2In, timerIn, rxOut, txAppOut, txApp2Out, slupOut);
140  count++;
141  }
142 
143  /*
144  * Test 2: rx(x, ESTA); rx(y, ESTA); timer(x), time(y)
145  */
146  //ap_uint<16> id = rand() % 100;
147  count = 0;
148  id = 0x6f;
149  ap_uint<16> id2 = 0x3a;
150  outputFile << "Test 2" << std::endl;
151  outputFile << "ID: " << id << " ID2: " << id2 << std::endl;
152  while (count < 20)
153  {
154  switch (count)
155  {
156  case 1:
157  rxIn.write(stateQuery(id, ESTABLISHED, 1));
158  break;
159  case 2:
160  rxIn.write(stateQuery(id2, ESTABLISHED, 1));
161  break;
162  case 3:
163  timerIn.write(id2);
164  break;
165  case 4:
166  timerIn.write(id);
167  break;
168  case 5:
169  timerIn.write(id);
170  break;
171  default:
172  break;
173 
174  }
175  state_table(rxIn, txAppIn, txApp2In, timerIn, rxOut, txAppOut, txApp2Out, slupOut);
176  emptyFifos(outputFile, rxOut, txAppOut, txApp2Out, slupOut, count);
177  count++;
178  }
179  outputFile << "------------------------------------------------" << std::endl;
180  //BREAK
181  count = 0;
182  while (count < 200)
183  {
184  state_table(rxIn, txAppIn, txApp2In, timerIn, rxOut, txAppOut, txApp2Out, slupOut);
185  count++;
186  }
187 
188  /*
189  * Test 3: rx(x); timer(x), rx(x, ESTABLISHED)
190  * Pause then: rx(y), txApp(y), rx(y, ESTABLISHED), txApp(y, value)
191  */
192  //ap_uint<16> id = rand() % 100;
193  count = 0;
194  id = 0x6f;
195  id2 = 0x3a;
196  outputFile << "Test 3" << std::endl;
197  outputFile << "ID: " << id << " ID2: " << id2 << std::endl;
198  while (count < 40)
199  {
200  switch (count)
201  {
202  case 1:
203  rxIn.write(stateQuery(id));
204  break;
205  case 2:
206  timerIn.write(id);
207  break;
208  case 5:
209  rxIn.write(stateQuery(id, ESTABLISHED, 1));
210  break;
211  case 10:
212  rxIn.write(stateQuery(id2));
213  break;
214  case 11:
215  txAppIn.write(stateQuery(id2));
216  break;
217  case 14:
218  rxIn.write(stateQuery(id2, CLOSING, 1));
219  break;
220  case 15:
221  txAppIn.write(stateQuery(id2, SYN_SENT, 1));
222  break;
223  case 19:
224  txApp2In.write(id2);
225  break;
226  default:
227  break;
228 
229  }
230  state_table(rxIn, txAppIn, txApp2In, timerIn, rxOut, txAppOut, txApp2Out, slupOut);
231  emptyFifos(outputFile, rxOut, txAppOut, txApp2Out, slupOut, count);
232  count++;
233  }
234  outputFile << "------------------------------------------------" << std::endl;
235  //BREAK
236  count = 0;
237  while (count < 200)
238  {
239  state_table(rxIn, txAppIn, txApp2In, timerIn, rxOut, txAppOut, txApp2Out, slupOut);
240  count++;
241  }
242 
243 
244  /*
245  * Test 4: txApp(x); rx(x), txApp(x, SYN_SENT), rx(x, ESTABLISHED), txApp2(x)
246  */
247  //ap_uint<16> id = rand() % 100;
248  count = 0;
249  id = 0x7f3;
250  outputFile << "Test 4" << std::endl;
251  outputFile << "ID: " << id << std::endl;
252  while (count < 40)
253  {
254  switch (count)
255  {
256  case 1:
257  txAppIn.write(stateQuery(id));
258  break;
259  case 2:
260  rxIn.write(stateQuery(id));
261  break;
262  case 5:
263  txAppIn.write(stateQuery(id, SYN_SENT, 1));
264  break;
265  case 7:
266  rxIn.write(stateQuery(id, ESTABLISHED, 1));
267  break;
268  case 19:
269  txApp2In.write(id);
270  break;
271  default:
272  break;
273 
274  }
275  state_table(rxIn, txAppIn, txApp2In, timerIn, rxOut, txAppOut, txApp2Out, slupOut);
276  emptyFifos(outputFile, rxOut, txAppOut, txApp2Out, slupOut, count);
277  count++;
278  }
279  outputFile << "------------------------------------------------" << std::endl;
280 
281  return 0;
282 }
283 
284 /*int main()
285 {
286  stream<stateQuery> rxIn;
287  stream<sessionState> rxOut;
288  stream<stateQuery> txAppIn;
289  stream<sessionState> txAppOut;
290  stream<stateQuery> txApp2In;
291  stream<sessionState> txApp2Out;
292  stream<ap_uint<16> > timerIn;
293  stream<ap_uint<16> > slupOut;
294 
295  stateQuery inData;
296  sessionState outData;
297 
298  std::ifstream inputFile;
299  std::ofstream outputFile;
300 
301  inputFile.open("/home/dasidler/toe/hls/toe/state_table/in.dat");
302  if (!inputFile)
303  {
304  std::cout << "Error: could not open test input file." << std::endl;
305  return -1;
306  }
307  outputFile.open("/home/dasidler/toe/hls/toe/state_table/out.dat");
308  if (!outputFile)
309  {
310  std::cout << "Error: could not open test output file." << std::endl;
311  }
312 
313 
314 
315 
316  std::string fifoTemp;
317  int sessionIDTemp;
318  char opTemp;
319  int valueTemp;
320  int exp_valueTemp;
321  sessionState response;
322  int errCount = 0;
323 
324  std::vector<readVerify> reads;
325 
326  int count = 0;
327  while (count < 500)
328  {
329  if ((count % 10) == 0)
330  {
331  if (inputFile >> fifoTemp >> sessionIDTemp >> opTemp >> valueTemp >> exp_valueTemp)
332  {
333  inData.sessionID = sessionIDTemp;
334  inData.state = (sessionState)valueTemp;
335  inData.write = (opTemp == 'W');
336  if (fifoTemp == "TX")
337  {
338  txAppIn.write(inData);
339  if (opTemp == 'R')
340  {
341  reads.push_back( (readVerify){sessionIDTemp, fifoTemp[0], exp_valueTemp});
342  }
343  }
344  else // RX
345  {
346  rxIn.write(inData);
347  if (opTemp == 'R')
348  {
349  reads.push_back((readVerify) {sessionIDTemp, fifoTemp[0], exp_valueTemp});
350  }
351  }
352  }
353  }
354  state_table(rxIn, txAppIn, txApp2In, timerIn, rxOut, txAppOut, txApp2Out, slupOut);
355  count++;
356  }
357 
358  std::vector<readVerify>::const_iterator it;
359  it = reads.begin();
360  bool readData = false;
361  while (it != reads.end())
362  {
363  readData = false;
364  if (it->fifo == 'T')
365  {
366  if (!txAppOut.empty())
367  {
368  txAppOut.read(response);
369  readData = true;
370  }
371  }
372  else
373  {
374  if (!rxOut.empty())
375  {
376  rxOut.read(response);
377  readData = true;
378  }
379  }
380 
381  if (readData)
382  {
383  if (((int)response) != it->exp)
384  {
385  outputFile << "Error at ID " << it->id << " on fifo ";
386  outputFile << it->fifo << " response value was " << response << " instead of " << it->exp << std::endl;
387  errCount ++;
388  }
389  else
390  {
391  outputFile << "Success at ID " << it->id << " on fifo ";
392  outputFile << it->fifo << " response value was " << response << " instead of " << it->exp << std::endl;
393  }
394  it++;
395  }
396  }
397 
398  if (errCount == 0)
399  {
400  outputFile << "No errors coccured." << std::endl;
401  }
402  else
403  {
404  outputFile << errCount << " errors coccured." << std::endl;
405  }
406 }*/
void state_table(stream< StateQuery > &siRXe_SessStateQry, stream< TcpState > &soRXe_SessStateRep, stream< StateQuery > &siTAi_ConnectStateQry, stream< TcpState > &soTAi_ConnectStateRep, stream< SessionId > &siTAi_StreamStateReq, stream< TcpState > &soTAi_StreamStateRep, stream< SessionId > &siTIm_SessCloseCmd, stream< SessionId > &soSLc_SessReleaseCmd)
State Table (STt)
Definition: state_table.cpp:99
@ FIN_WAIT_1
Definition: nts_types.hpp:297
@ SYN_SENT
Definition: nts_types.hpp:296
@ ESTABLISHED
Definition: nts_types.hpp:296
@ CLOSING
Definition: nts_types.hpp:297
out
Definition: test.py:12
: State Table (STt) for the TCP Offload Engine (TOE)
void emptyFifos(std::ofstream &out, stream< sessionState > &rxFifoOut, stream< sessionState > &appFifoOut, stream< sessionState > &app2FifoOut, stream< ap_uint< 16 > > &slupOut, int iter)
int main()