cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
test_port_table.cpp File Reference
#include "port_table.hpp"
Include dependency graph for test_port_table.cpp:

Go to the source code of this file.

Functions

ap_uint< 16 > swappedBytes (ap_uint< 16 > in)
 
int main ()
 

Function Documentation

◆ main()

int main ( )

Definition at line 40 of file test_port_table.cpp.

41 {
42 #pragma HLS inline region off
43 
44 
45  stream<ap_uint<16> > rxPortTableIn("rxPortTableIn");
46  stream<bool> rxPortTableOut("rxPortTableOut");
47  stream<ap_uint<16> > rxAppListenIn("rxAppListenIn");
48  stream<bool> rxAppListenOut("rxAppListenOut");
49  //stream<ap_uint<16> > rxAppCloseIn("rxAppCloseIn");
50  //stream<ap_uint<1> > txAppGetPortIn("txAppGetPortIn");
51  stream<ap_uint<16> > txAppGetPortOut("txAppGetPortOut");
52  stream<ap_uint<16> > txAppFreePort("txAppFreePort");
53 
54  std::ifstream inputFile;
55  std::ofstream outputFile;
56 
57  /*inputFile.open("/home/dsidler/workspace/toe/port_table/in.dat");
58 
59  if (!inputFile)
60  {
61  std::cout << "Error: could not open test input file." << std::endl;
62  return -1;
63  }*/
64  outputFile.open("/home/dasidler/toe/hls/toe/port_table/out.dat");
65  if (!outputFile)
66  {
67  std::cout << "Error: could not open test output file." << std::endl;
68  }
69 
70  uint16_t strbTemp;
71  uint64_t dataTemp;
72  uint16_t lastTemp;
73  int count = 0;
74 
75  int pkgCount = 0;
76 
77  /*while (inputFile >> std::hex >> dataTemp >> strbTemp >> lastTemp)
78  {
79  inData.data = dataTemp;
80  inData.keep = strbTemp;
81  //inData.user = 0;
82  inData.last = lastTemp;
83  inFIFO.write(inData);
84  count++;
85  if (count == 3)
86  break;
87  }*/
88 
89  bool currBool = false;
90  ap_uint<16> currPort = 0;
91  ap_uint<16> port;
92  bool isOpen = false;
93  int mod = 0;
94  int randPort = 32767;
95  ap_uint<16> temp;
96  while (count < 500) //was 250
97  {
98  /*mod = count % 10;
99  switch (mod)
100  {
101  case 2:
102  port = 80;
103  //temp = swappedBytes(randPort);
104  //temp[15] = 1;
105  rxPortTableIn.write(swappedBytes(port)); //swap bytes, this is 80
106  //randPort = rand() % 65535;
107  break;
108  case 3:
109  //txAppGetPortIn.write(1);
110  break;
111  case 5:
112  outputFile << "Try to listen on " << randPort << std::endl;
113  rxAppListenIn.write(randPort);
114  randPort = rand() % 65535;
115  break;
116  case 7:
117  if (!isOpen)
118  {
119  rxAppListenIn.write(80);
120  outputFile << "Start listening on port 80"<< std::endl;
121  isOpen = true;
122  }
123  break;
124  default:
125  break;
126  }*/
127 
128  port_table(rxPortTableIn, rxAppListenIn, //txAppGetPortIn,
129  txAppFreePort,
130  rxPortTableOut, rxAppListenOut,txAppGetPortOut);
131  if (!rxPortTableOut.empty())
132  {
133  rxPortTableOut.read(currBool);
134  outputFile << "Port 80 is open: " << (currBool ? "yes" : "no");
135  outputFile << std::endl;
136  }
137  if (!rxAppListenOut.empty())
138  {
139  rxAppListenOut.read(currBool);
140  outputFile << "Listening " << (currBool ? "" : "not") << " successful" << std::endl;
141  }
142  /*if (!txAppGetPortOut.empty())
143  {
144  txAppGetPortOut.read(currPort);
145  outputFile << "Get free port:" << currPort << std::endl;
146  assert(currPort >= 32768);
147  }*/
148  if (count == 20)
149  {
150  rxAppListenIn.write(0x0007);
151  }
152  if (count == 40)
153  {
154  rxPortTableIn.write(0x0700);
155  }
156  count++;
157  }
158 
159 
160 
161  //should return comparison
162 
163  return 0;
164 }
void port_table(StsBool &poTOE_Ready, stream< TcpPort > &siRXe_GetPortStateReq, stream< RepBit > &soRXe_GetPortStateRep, stream< TcpPort > &siRAi_OpenLsnPortReq, stream< AckBit > &soRAi_OpenLsnPortAck, stream< ReqBit > &siTAi_GetFreePortReq, stream< TcpPort > &soTAi_GetFreePortRep, stream< TcpPort > &siSLc_CloseActPortCmd)
Port Table (PRt)
Definition: port_table.cpp:453
Here is the call graph for this function:

◆ swappedBytes()

ap_uint<16> swappedBytes ( ap_uint< 16 >  in)

Definition at line 32 of file test_port_table.cpp.

33 {
34  ap_uint<16> swapped;
35  swapped(7, 0) = in(15, 8);
36  swapped(15, 8) = in(7, 0);
37  return swapped;
38 }