cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
test_session_lookup_controller.cpp File Reference
#include "session_lookup_controller.hpp"
#include <map>
Include dependency graph for test_session_lookup_controller.cpp:

Go to the source code of this file.

Functions

void sessionLookupStub (stream< rtlSessionLookupRequest > &lup_req, stream< rtlSessionLookupReply > &lup_rsp, stream< rtlSessionUpdateRequest > &upd_req, stream< rtlSessionUpdateReply > &upd_rsp)
 
void updateRequestMerger (stream< rtlSessionUpdateRequest > &in1, stream< rtlSessionUpdateRequest > &in2, stream< rtlSessionUpdateRequest > &out)
 
int main ()
 

Function Documentation

◆ main()

int main ( )

Definition at line 120 of file test_session_lookup_controller.cpp.

121 {
122  stream<sessionLookupQuery> rxEng2sLookup_req;
123  stream<sessionLookupReply> sLookup2rxEng_rsp("sLookup2rxEng_rsp");
124  stream<ap_uint<16> > stateTable2sLookup_releaseSession;
125  stream<ap_uint<16> > sLookup2portTable_releasePort;
126  stream<fourTuple> txApp2sLookup_req;
127  stream<sessionLookupReply> sLookup2txApp_rsp;
128  stream<ap_uint<16> > txEng2sLookup_rev_req;
129  stream<fourTuple> sLookup2txEng_rev_rsp;
130  stream<rtlSessionLookupRequest> sessionLookup_req;
131  stream<rtlSessionLookupReply> sessionLookup_rsp("test_sessionLookup_rsp");
132  stream<rtlSessionUpdateRequest> sessionUpdate_req;
133  stream<rtlSessionUpdateReply> sessionUpdate_rsp("test_sessionUpdate_rsp");
134 
135  stream<rtlSessionUpdateRequest> sessionInsert_req;
136  stream<rtlSessionUpdateRequest> sessionDelete_req;
137 
138 
139 
140  //stream<sessionLookupQueryInternal> lookups("lookups");
141 
142  ap_uint<16> regSessionCount;
143 
144  int count = 0;
145  fourTuple tuple;
146  tuple.dstIp = 0x01010101;
147  tuple.dstPort = 7;
148  tuple.srcIp = 0x0101010a;
149  tuple.srcPort = 3489;
150 
151  int lastSessionCount = 0;
152  while (count < 500)
153  {
154  if (count == 20)
155  {
156  rxEng2sLookup_req.write(sessionLookupQuery(tuple, false));
157  }
158 
159  if (count == 70)
160  {
161  rxEng2sLookup_req.write(sessionLookupQuery(tuple, true));
162  }
163 
164  if (count == 80)
165  {
166  txEng2sLookup_rev_req.write(0);
167  }
168 
169  if (count == 90)
170  {
171  txApp2sLookup_req.write(tuple);
172  }
173  session_lookup_controller( //lookups,
174  rxEng2sLookup_req,
175  sLookup2rxEng_rsp,
176  stateTable2sLookup_releaseSession,
177  sLookup2portTable_releasePort,
178  txApp2sLookup_req,
179  sLookup2txApp_rsp,
180  txEng2sLookup_rev_req,
181  sLookup2txEng_rev_rsp,
182  sessionLookup_req,
183  sessionLookup_rsp,
184  sessionUpdate_req,
185  //sessionInsert_req,
186  //sessionDelete_req,
187  sessionUpdate_rsp,
188  regSessionCount);
189  //lookupRequestMerger(rxEng2sLookup_req, txApp2sLookup_req, sessionLookup_req, lookups);
190  //updateRequestMerger(sessionInsert_req, sessionDelete_req, sessionUpdate_req);
191  if ( lastSessionCount != regSessionCount)
192  {
193  std::cout << "SessionCount\t" << regSessionCount << std::endl;
194  lastSessionCount = regSessionCount;
195  }
196  sessionLookupStub(sessionLookup_req, sessionLookup_rsp, sessionUpdate_req, sessionUpdate_rsp);
197  count++;
198  }
199 
200  sessionLookupReply reply;
201  while (!sLookup2rxEng_rsp.empty())
202  {
203  sLookup2rxEng_rsp.read(reply);
204  std::cout << "rxEng "<< reply.sessionID << "\t" << reply.hit << std::endl;
205  }
206  while (!sLookup2txApp_rsp.empty())
207  {
208  sLookup2txApp_rsp.read(reply);
209  std::cout << "txApp "<< reply.sessionID << "\t" << reply.hit << std::endl;
210  }
211  while (!sLookup2txEng_rev_rsp.empty())
212  {
213  sLookup2txEng_rev_rsp.read(tuple);
214  std::cout << "txEng " << tuple.dstIp << ":" << tuple.dstPort << "\t " << tuple.srcIp << ":" << tuple.srcPort << std::endl;
215  }
216 
217  return 0;
218 }
void session_lookup_controller(stream< SessionLookupQuery > &siRXe_SessLookupReq, stream< SessionLookupReply > &soRXe_SessLookupRep, stream< SessionId > &siSTt_SessReleaseCmd, stream< TcpPort > &soPRt_ClosePortCmd, stream< SocketPair > &siTAi_SessLookupReq, stream< SessionLookupReply > &soTAi_SessLookupRep, stream< SessionId > &siTXe_ReverseLkpReq, stream< fourTuple > &soTXe_ReverseLkpRep, stream< CamSessionLookupRequest > &soCAM_SessLookupReq, stream< CamSessionLookupReply > &siCAM_SessLookupRep, stream< CamSessionUpdateRequest > &soCAM_SessUpdateReq, stream< CamSessionUpdateReply > &siCAM_SessUpdateRep, stream< ap_uint< 16 > > &soSssRelCnt, stream< ap_uint< 16 > > &soSssRegCnt)
Session Lookup Controller (SLc)
ap_uint< 32 > dstIp
Definition: nts_types.hpp:231
ap_uint< 32 > srcIp
Definition: nts_types.hpp:230
ap_uint< 16 > dstPort
Definition: nts_types.hpp:233
ap_uint< 16 > srcPort
Definition: nts_types.hpp:232
void sessionLookupStub(stream< rtlSessionLookupRequest > &lup_req, stream< rtlSessionLookupReply > &lup_rsp, stream< rtlSessionUpdateRequest > &upd_req, stream< rtlSessionUpdateReply > &upd_rsp)
Here is the call graph for this function:

◆ sessionLookupStub()

void sessionLookupStub ( stream< rtlSessionLookupRequest > &  lup_req,
stream< rtlSessionLookupReply > &  lup_rsp,
stream< rtlSessionUpdateRequest > &  upd_req,
stream< rtlSessionUpdateReply > &  upd_rsp 
)

Definition at line 32 of file test_session_lookup_controller.cpp.

35 {
36  static std::map<fourTupleInternal, ap_uint<14> > lookupTable;
37 
38  rtlSessionLookupRequest request;
39  rtlSessionUpdateRequest update;
40 
41  std::map<fourTupleInternal, ap_uint<14> >::const_iterator findPos;
42 
43  if (!lup_req.empty())
44  {
45  lup_req.read(request);
46  findPos = lookupTable.find(request.key);
47  if (findPos != lookupTable.end()) //hit
48  {
49  lup_rsp.write(rtlSessionLookupReply(true, findPos->second, request.source));
50  }
51  else
52  {
53  lup_rsp.write(rtlSessionLookupReply(false, request.source));
54  }
55  }
56 
57  if (!upd_req.empty()) //TODO what if element does not exist
58  {
59  upd_req.read(update);
60  if (update.op == INSERT) //Is there a check if it already exists?
61  {
62  // Read free id
63  //new_id.read(update.value);
64  lookupTable[update.key] = update.value;
65  upd_rsp.write(rtlSessionUpdateReply(update.value, INSERT, update.source));
66 
67  }
68  else // DELETE
69  {
70  //fin_id.write(update.value);
71  lookupTable.erase(update.key);
72  upd_rsp.write(rtlSessionUpdateReply(update.value, DELETE, update.source));
73  }
74  }
75 }
@ DELETE
Definition: nts_types.hpp:382
@ INSERT
Definition: nts_types.hpp:382
Here is the caller graph for this function:

◆ updateRequestMerger()

void updateRequestMerger ( stream< rtlSessionUpdateRequest > &  in1,
stream< rtlSessionUpdateRequest > &  in2,
stream< rtlSessionUpdateRequest > &  out 
)

Definition at line 108 of file test_session_lookup_controller.cpp.

109 {
110  if (!in1.empty())
111  {
112  out.write(in1.read());
113  }
114  else if (!in2.empty())
115  {
116  out.write(in2.read());
117  }
118 }
out
Definition: test.py:12